/* ================================================================
   TYPEFORM — HANDWRITTEN FONT CREATOR & TYPOGRAPHY EDITOR
   style.css — Grayscale, Wireframe-Functional, Clean DOM Targeting
   ================================================================ */

/* ── 1. TOKENS & RESET ─────────────────────────────────────────── */
@font-face {
  font-family: 'MyFontNew';
  src: url('Myfontnew-Regular.ttf') format('truetype');
}

:root {
  /* Grayscale palette */
  --clr-bg:          #f5f5f5;
  --clr-surface:     #ffffff;
  --clr-border:      #d0d0d0;
  --clr-border-dark: #999999;
  --clr-text-base:   #1a1a1a;
  --clr-text-muted:  #666666;
  --clr-text-faint:  #aaaaaa;
  --clr-accent:      #1a1a1a;
  --clr-accent-inv:  #ffffff;
  --clr-danger:      #444444;

  /* Grid / overlay */
  --clr-grid:        #1a1a1a;

  /* Spacing */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:   16px;
  --space-lg:   24px;
  --space-xl:   40px;
  --space-2xl:  64px;

  /* Typography */
  --font-ui:    -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono:  "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --font-editor: var(--font-ui); /* swapped to handwriting font after extraction */

  /* Sizing */
  --header-h:  52px;
  --radius-sm: 3px;
  --radius-md: 6px;

  /* Transitions */
  --ease-std:  0.18s ease;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--clr-text-base);
  background: var(--clr-bg);
  min-height: 100vh;
}

/* Accessibility */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ── 2. HEADER ──────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 var(--space-xl);
  max-width: 1280px;
  margin: 0 auto;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--clr-accent);
  color: var(--clr-accent-inv);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  display: none;
}

.logo-text {
  font-family: 'MyFontNew', sans-serif;
  font-size: 24px; /* Increased size to match custom handwriting style */
  font-weight: 400; /* Adjusted weight for custom font */
  letter-spacing: -0.01em;
  color: var(--clr-text-base);
}

.header-nav {
  display: none; /* Removed the attached image thingy and font creator text */
}

.nav-label {
  font-size: 12px;
  color: var(--clr-text-muted);
  letter-spacing: 0.02em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot--idle    { background: var(--clr-border-dark); }
.status-dot--working { background: #555; animation: pulse-dot 1s infinite; }
.status-dot--ready   { background: #2a2a2a; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.status-text {
  font-size: 11px;
  color: var(--clr-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── 3. MAIN LAYOUT ─────────────────────────────────────────────── */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xl);
}

/* ── 4. SECTIONS ────────────────────────────────────────────────── */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.section-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--clr-border);
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--clr-text-base);
}

.section-index {
  font-size: 11px;
  font-weight: 400;
  color: var(--clr-text-faint);
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  padding-top: 2px;
}

.section-description {
  font-size: 13px;
  color: var(--clr-text-muted);
  max-width: 560px;
}

/* ── 5. UPLOAD ZONE ─────────────────────────────────────────────── */
.upload-zone {
  position: relative;
  border: 1.5px dashed var(--clr-border-dark);
  border-radius: var(--radius-md);
  background: var(--clr-surface);
  cursor: pointer;
  transition: border-color var(--ease-std), background var(--ease-std);
  min-height: 540px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover,
.upload-zone:focus-within,
.upload-zone--drag-over {
  border-color: var(--clr-accent);
  background: #f9f9f9;
}

.upload-zone__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xl);
  pointer-events: none;
  text-align: center;
  color: var(--clr-text-muted);
}

.upload-zone__icon {
  color: var(--clr-border-dark);
  margin-bottom: var(--space-sm);
}

.upload-zone__primary {
  font-size: 15px;
  font-weight: 500;
  color: var(--clr-text-base);
}

.upload-zone__secondary {
  font-size: 12px;
  color: var(--clr-text-faint);
}

.upload-zone__label {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

.upload-zone__input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ── 6. EDITOR SECTION CONTROLS ────────────────────────────────── */
.section--editor .section-header {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.editor-controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.control-label {
  font-size: 11px;
  color: var(--clr-text-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.control-slider {
  -webkit-appearance: none;
  width: 80px;
  height: 2px;
  background: var(--clr-border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--clr-accent);
  cursor: pointer;
  transition: transform var(--ease-std);
}

.control-slider::-webkit-slider-thumb:hover { transform: scale(1.3); }

.control-value {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--clr-text-muted);
  min-width: 32px;
  text-align: right;
}

.control-btn {
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--ease-std);
}

.control-btn--ghost {
  background: transparent;
  border: 1px solid var(--clr-border);
  color: var(--clr-text-muted);
  padding: var(--space-xs) var(--space-sm);
}

.control-btn--ghost:hover {
  border-color: var(--clr-border-dark);
  color: var(--clr-text-base);
}

.control-btn--primary {
  background: var(--clr-accent);
  color: var(--clr-accent-inv);
  border: 1px solid var(--clr-accent);
  padding: var(--space-xs) var(--space-sm);
}

.control-btn--primary:hover {
  background: #333;
  border-color: #333;
  color: var(--clr-accent-inv);
}

/* ── 7. BLOB KEY LEGEND ─────────────────────────────────────────── */
.blob-legend {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
  padding: var(--space-sm) var(--space-md);
  background: #f0f0f0;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  font-size: 11px;
}

.blob-legend__label {
  font-weight: 600;
  color: var(--clr-text-base);
  letter-spacing: 0.04em;
}

.blob-legend__key {
  color: var(--clr-text-muted);
  font-family: var(--font-mono);
  padding: 2px var(--space-xs);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 2px;
}

.blob-legend__meta {
  margin-left: auto;
  color: var(--clr-text-faint);
  font-family: var(--font-mono);
}

/* ── 8. EDITOR CANVAS (FULL SCREEN) ───────────────────────────────── */
.editor-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--clr-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-wrapper {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.editor-canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100px;
  max-height: 100vh;
  padding: 40px 15vw;
  font-family: var(--font-editor);
  font-size: 33px;
  line-height: 1.5;
  letter-spacing: 0px;
  color: var(--clr-text-base);
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  transition: transform 0.2s ease, font-family 0.1s ease;
  word-break: break-word;
  white-space: pre-wrap;
  text-align: center;
  overflow-y: auto;
}

.editor-canvas:empty::before {
  content: attr(data-placeholder);
  color: var(--clr-text-faint);
  pointer-events: none;
}

/* ── 9. SVG BLOBS (Positioned Absolutely in editor-wrapper) ─────── */
.blob-element {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  animation: blob-appear 0.25s ease forwards;
  opacity: 0;
}

@keyframes blob-appear {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 0.55; transform: scale(1); }
}

/* ── 10. TRAILING DOTS (Incomplete Sentence) ────────────────────── */
.trailing-dots {
  display: inline-block;
  color: var(--clr-text-faint);
  animation: dots-fade 1.5s ease forwards;
  font-style: normal;
  letter-spacing: 0.05em;
}

@keyframes dots-fade {
  0%   { opacity: 0.8; }
  70%  { opacity: 0.5; }
  100% { opacity: 0; }
}

/* ── 11. SIDE PANEL & CONTROLS ──────────────────────────────────── */
.editor-side-trigger {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 40px;
  z-index: 1010;
}

.editor-side-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100vh;
  width: 320px;
  background: rgba(255, 255, 255, 0.98);
  border-left: 1px solid var(--clr-border);
  box-shadow: -4px 0 24px rgba(0,0,0,0.05);
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.editor-side-trigger:hover .editor-side-panel,
.editor-side-panel:hover,
.editor-side-panel:focus-within {
  transform: translateX(0);
}

.side-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--clr-text-base);
  letter-spacing: -0.01em;
  text-transform: uppercase;
  margin-bottom: -10px;
}

.editor-controls-vertical {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.editor-controls-vertical .control-group {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-xs);
}

.control-slider-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
}

.control-slider-wrap .control-slider {
  flex: 1;
}

.editor-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: auto;
}

.editor-actions .control-btn {
  width: 100%;
  padding: 10px;
  text-align: center;
  justify-content: center;
}

.blob-legend-vertical {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  background: #f9f9f9;
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--clr-border);
}

.blob-keys-list {
  list-style: none;
  font-size: 11px;
  color: var(--clr-text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.editor-stats {
  margin-top: var(--space-sm);
  font-size: 11px;
  color: var(--clr-text-faint);
  font-family: var(--font-mono);
}

.editor-status-vertical {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--clr-text-faint);
  font-family: var(--font-mono);
}

/* ── 12. MODAL BACKDROP ─────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: all;
}

/* ── 13. MODAL ──────────────────────────────────────────────────── */
.modal {
  position: relative;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  width: 98vw;
  height: 96vh;
  max-width: 1800px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.22s ease;
}

.modal-backdrop.is-open .modal {
  transform: translateY(0);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--clr-border);
  flex-shrink: 0;
}

.modal__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--clr-text-base);
}

.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.crop-polygon {
  fill: rgba(0, 122, 255, 0.15);
  stroke: #007aff;
  stroke-width: 2;
  stroke-dasharray: 4 4;
}

.crop-handle {
  fill: #fff;
  stroke: #007aff;
  stroke-width: 3;
  cursor: crosshair;
  pointer-events: all;
  transition: r 0.2s ease;
  touch-action: none;
}

.crop-handle:hover,
.crop-handle.is-dragging {
  r: 14;
  fill: #007aff;
  stroke: #fff;
}

/* ── 15. ALIGNMENT CONTROLS (Crop Instructions) ─────────────────── */
.alignment-controls {
  padding: var(--space-md) var(--space-lg);
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--clr-text-muted);
  transition: all var(--ease-std);
}

.modal__close:hover {
  background: #f0f0f0;
  color: var(--clr-text-base);
}

.modal__body {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  flex: 1 1 0%;
  min-height: 0;          /* critical for flex children to shrink correctly */
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--clr-border);
  flex-shrink: 0;
}

/* ── 14. ALIGNMENT STAGE ────────────────────────────────────────── */
.alignment-stage {
  position: relative;
  flex: 1 1 0%;
  min-height: 500px;       /* ensure it always has height */
  background: #1a1a1a;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.alignment-canvas {
  position: absolute;
  display: block;
  transform-origin: center center;
}

/* Crop overlay fills exact canvas area (set by JS) */
.crop-overlay {
  position: absolute;
  overflow: visible;
}

/* ── 16. BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--ease-std);
  border: 1px solid transparent;
  line-height: 1;
}

.btn--primary {
  background: var(--clr-accent);
  color: var(--clr-accent-inv);
  border-color: var(--clr-accent);
}

.btn--primary:hover {
  background: #333;
  border-color: #333;
}

.btn--secondary {
  background: transparent;
  color: var(--clr-text-muted);
  border-color: var(--clr-border);
}

.btn--secondary:hover {
  background: #f0f0f0;
  color: var(--clr-text-base);
}

.btn__icon { flex-shrink: 0; }

/* ── 17. PROCESSING OVERLAY ─────────────────────────────────────── */
.processing-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.processing-overlay.is-active {
  opacity: 1;
  pointer-events: all;
}

.processing-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  width: 380px;
  padding: var(--space-xl);
}

.processing-spinner {
  width: 40px;
  height: 40px;
  position: relative;
}

.spinner-ring {
  width: 100%;
  height: 100%;
  border: 2px solid var(--clr-border);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.processing-step {
  font-size: 15px;
  font-weight: 500;
  color: var(--clr-text-base);
  text-align: center;
  letter-spacing: -0.01em;
}

.processing-progress-bar {
  width: 100%;
  height: 2px;
  background: var(--clr-border);
  border-radius: 2px;
  overflow: hidden;
}

.processing-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--clr-accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.processing-log {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--clr-text-faint);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.processing-log__entry {
  display: flex;
  gap: var(--space-sm);
  padding: 4px 0;
  border-bottom: 1px solid #eee;
  animation: log-entry 0.2s ease;
}

@keyframes log-entry {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

.processing-log__entry .log-tick {
  color: #555;
  flex-shrink: 0;
}

/* ── 18. TOAST ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 700;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-left: 3px solid var(--clr-accent);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  max-width: 340px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.toast__icon {
  font-size: 14px;
  font-weight: 700;
  color: var(--clr-text-base);
  flex-shrink: 0;
  margin-top: 1px;
}

.toast__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--clr-text-base);
}

.toast__message {
  font-size: 12px;
  color: var(--clr-text-muted);
}

/* ── 19. RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  .site-header {
    position: fixed;
    width: 100%;
    top: 0;
  }

  .main-content { 
    padding: var(--space-md); 
    padding-top: calc(var(--header-h) + var(--space-md));
    gap: var(--space-md); 
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .header-inner { padding: 0 var(--space-md); }
  .nav-label    { display: none; }

  .section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
  }

  .upload-zone {
    min-height: 0;
    flex: 1;
    margin-top: var(--space-sm);
  }

  .section-header {
    padding-bottom: var(--space-sm);
  }

  .glyph-preview-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    align-content: start;
    grid-auto-rows: max-content;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
  }

  .glyph-card {
    padding: 2px;
    border-radius: 2px;
  }

  .glyph-card__lbl {
    font-size: 8px;
    padding: 1px 0;
    margin: auto -2px -2px -2px;
  }

  .section--glyphs > div:last-child {
    margin-top: var(--space-sm) !important;
    padding-bottom: var(--space-xs);
    flex-shrink: 0;
  }

  .modal-backdrop {
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
    align-items: flex-start;
  }

  .modal {
    width: 100vw;
    height: 100%;
    max-width: 100vw;
    max-height: 100%;
    border-radius: 0;
    transform: translateY(0);
  }

  .modal__body  { 
    flex-direction: column; 
    flex: 1;
    min-height: 0;
  }

  .alignment-stage {
    min-height: 0;
    flex: 1;
  }

  .alignment-controls {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--clr-border);
    padding: var(--space-sm);
  }

  .section--editor .section-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .editor-controls { gap: var(--space-sm); }

  .editor-side-panel {
    width: 85vw;
    max-width: 320px;
    padding: var(--space-md);
    gap: var(--space-md);
    overflow-y: auto;
  }

  body.font-loaded .section--generator {
    display: none !important;
  }
}

/* ── 20. FONT LOADED STATE ──────────────────────────────────────── */
body.font-loaded .editor-canvas {
  /* JS will override font-family inline; this class marks the state */
  transition: font-family 0s, transform 0.2s ease;
}

/* ── 21. DRAG OVER STATE ────────────────────────────────────────── */
.upload-zone--drag-over {
  border-style: solid;
  background: #f2f2f2;
}

/* ── 22. DOWNLOAD BUTTON (glow on appear) ───────────────────────── */
#js-download-btn {
  animation: btn-appear 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  background: #1a1a1a;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 0 rgba(26,26,26,0.4);
}

#js-download-btn:hover {
  background: #333;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

@keyframes btn-appear {
  from { opacity: 0; transform: scale(0.85) translateY(4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

/* ── 23. FONT READY BANNER ──────────────────────────────────────── */
.font-ready-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #1a1a1a;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  letter-spacing: 0.04em;
  animation: badge-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes badge-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* ── 24. GLYPH PREVIEW GRID ─────────────────────────────────────── */
.glyph-preview-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--space-md);
  padding: var(--space-md) 0;
  align-content: start;
  grid-auto-rows: max-content;
}

.glyph-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs);
  aspect-ratio: 1 / 1.3;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
}

.glyph-card:not(.glyph-card--empty):hover {
  border-color: var(--clr-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.glyph-card__img {
  width: 100%;
  height: auto;
  object-fit: contain;
  mix-blend-mode: multiply;
  margin-top: 4px;
}

.glyph-card__lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--clr-text-muted);
  background: #f0f0f0;
  width: calc(100% + 8px);
  text-align: center;
  padding: 2px 0;
  margin: auto -4px -4px -4px;
  border-top: 1px solid var(--clr-border);
}

.glyph-card__empty-ph {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #eee;
  font-family: var(--font-mono);
}

.glyph-card--empty {
  cursor: default;
  background: #fafafa;
  border-color: #eee;
}
.glyph-card--empty .glyph-card__lbl {
  background: #fafafa;
  color: #ccc;
  border-color: #eee;
}

.glyph-card__dl {
  position: absolute;
  top: 0; right: 0;
  background: var(--clr-accent);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 0 0 0 4px;
  opacity: 0;
  transform: translateY(-100%);
  transition: all 0.2s ease;
}

.glyph-card:hover .glyph-card__dl {
  opacity: 1;
  transform: translateY(0);
}

/* ── 23. ADVANCED EDITOR SPANS ──────────────────────────────────── */
.char-span {
  display: inline-block;
  white-space: pre-wrap;
  transform-origin: bottom center;
  transition: opacity 0.2s ease;
}

.char-span.struck-out {
  text-decoration: line-through;
  text-decoration-thickness: 0.08em;
  opacity: 0.5;
}

.char-span.auto-dot {
  color: #ccc;
}


/* ── 24. ORGANIC INK BLOBS ──────────────────────────────────────── */
.char-span {
  position: relative; /* ensure blobs anchor to the character */
}

.char-span.has-blob-tl::before,
.char-span.has-blob-bl::before,
.char-span.has-blob-tr::after,
.char-span.has-blob-br::after {
  content: "";
  position: absolute;
  width: 0.28em;
  height: 0.35em;
  background-color: currentColor;
  pointer-events: auto; /* allow hover */
  opacity: 0.95;
  mix-blend-mode: multiply;
  
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  
  /* Give it a slight permanent blur to simulate capillary bleeding into paper */
  filter: blur(0.4px);
  
  /* Initial state, overridden by animation */
  transform: rotate(var(--blob-rot)) scale(1);
  transition: transform 0.4s ease, filter 0.4s ease;
  
  animation: 
    penSeep 1.5s cubic-bezier(0.1, 0.7, 0.1, 1) forwards,
    inkWobble 5s ease-in-out infinite alternate;
}

@keyframes penSeep {
  0% { transform: rotate(var(--blob-rot)) scale(0); opacity: 0.85; filter: blur(0px); }
  100% { transform: rotate(var(--blob-rot)) scale(1); opacity: 0.95; filter: blur(0.4px); }
}

@keyframes inkWobble {
  0% { transform: rotate(var(--blob-rot)) scale(1) skewX(0deg); }
  50% { transform: rotate(var(--blob-rot)) scale(1.02) skewX(2deg); }
  100% { transform: rotate(var(--blob-rot)) scale(0.98) skewX(-1deg); }
}

.char-span.has-blob-tl:hover::before,
.char-span.has-blob-bl:hover::before,
.char-span.has-blob-tr:hover::after,
.char-span.has-blob-br:hover::after {
  transform: rotate(var(--blob-rot)) scale(1.3);
  filter: blur(1.2px);
}

.char-span.has-blob-tl::before { --blob-rot: 0deg; top: var(--b-top, 35%); left: var(--b-x, 0.12em); transform-origin: bottom right; -webkit-mask-image: url('blob1.svg'); mask-image: url('blob1.svg'); }
.char-span.has-blob-bl::before { --blob-rot: 0deg;  bottom: var(--b-bot, 35%); left: var(--b-x, 0.12em); transform-origin: top right; -webkit-mask-image: url('blob2.svg'); mask-image: url('blob2.svg'); }
.char-span.has-blob-tr::after  { --blob-rot: 0deg;  top: var(--b-top, 35%); right: var(--b-x, 0.12em); transform-origin: bottom left; -webkit-mask-image: url('blob3.svg'); mask-image: url('blob3.svg'); }
.char-span.has-blob-br::after  { --blob-rot: 0deg; bottom: var(--b-bot, 35%); right: var(--b-x, 0.12em); transform-origin: top left; -webkit-mask-image: url('blob4.svg'); mask-image: url('blob4.svg'); }
