/* ── Variables ────────────────────────────────────────────────────────────────── */
:root {
  --bg:       #FAFAF8;
  --bg2:      #F2F1EE;
  --surface:  #FFFFFF;
  --text:     #18181B;
  --muted:    #71717A;
  --subtle:   #A1A1AA;
  --border:   #E4E4E7;
  --border2:  #D4D4D8;
  --accent:   #E8652A;
  --accent-l: #F0824A;
  --radius:   8px;
  --tr:       0.18s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #111111;
    --bg2:     #1A1A1A;
    --surface: #1C1C1C;
    --text:    #F4F4F5;
    --muted:   #71717A;
    --subtle:  #52525B;
    --border:  #27272A;
    --border2: #3F3F46;
    --accent:  #F07540;
    --accent-l:#F5915E;
  }

  .board-wrap {
    box-shadow:
      0 0 0 1px rgba(255,255,255,0.07),
      0 12px 48px rgba(0,0,0,0.60),
      0 3px 14px rgba(0,0,0,0.45);
  }
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background:  var(--bg);
  color:       var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size:   1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
.hidden { display: none !important; }

/* ── Main: two-column desktop / stacked mobile ───────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "left right";
  max-width: 1100px;
  margin: 0 auto;
  height: 100vh;
  overflow: hidden;
  padding: 0 2rem;
  gap: 3rem;
}

/* Left column */
.left-col {
  grid-area: left;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.75rem 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

/* Hero section — always visible */
.hero-section {
  flex-shrink: 0;
}

/* Status zone — the only part that switches between idle/loading/playing */
.status-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 0.25rem;
}

.status-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

/* Bottom controls always anchored to the bottom of left-col */
.bottom-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  margin-top: 1.5rem;
  flex-shrink: 0;
}

/* Right column */
.right-col {
  grid-area: right;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem 0;
}

/* ── Board ────────────────────────────────────────────────────────────────── */
.board-wrap {
  position: relative;
  height: min(calc(100vh - 3rem), 640px);
  aspect-ratio: 9 / 16;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.09),
    0 12px 40px rgba(0,0,0,0.20),
    0 3px 10px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

#stage {
  display: block;
  width:   100%;
  height:  100%;
  background: #131313;
}

/* ── Morph overlay ─────────────────────────────────────────────────────────────── */
.morph-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 62%;
  filter: url(#morphThreshold) blur(0.5px);
  pointer-events: none;
}

.morph-text {
  position: absolute;
  left: 13%; right: 13%;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: break-word;
  font-family: 'Syne', 'Space Grotesk', 'Noto Sans', 'Noto Sans SC',
    'Noto Sans JP', 'Noto Sans KR', 'Noto Sans Arabic', 'Noto Sans Devanagari',
    'Noto Sans Tamil', 'Noto Sans Thai', 'Noto Sans Hebrew', 'Noto Serif', sans-serif;
  font-weight: 800;
  line-height: 1.25;
  color: #F5F0E8;
}

/* ── Board caption ─────────────────────────────────────────────────────────────── */
.board-caption {
  font-size: 0.75rem;
  color: var(--subtle);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.board-caption em { color: var(--accent); font-style: normal; }

.caption-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 2s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.65); }
}

/* ── Hero ──────────────────────────────────────────────────────────────────── */
.hero-heading {
  font-size: clamp(1.85rem, 3vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.08;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.serif {
  font-family: 'Instrument Serif', Georgia, serif;
  font-style: italic;
  font-weight: 400;
}

.hero-sub {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.65;
  max-width: 40ch;
  margin-bottom: 1.5rem;
}

/* ── Input row ────────────────────────────────────────────────────────────────── */
.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.85rem;
}

.phrase-input {
  flex: 1;
  min-width: 0;
  background:  var(--surface);
  border:      1px solid var(--border2);
  border-radius: var(--radius);
  color:       var(--text);
  font-family: inherit;
  font-size:   0.95rem;
  padding:     0.6rem 0.85rem;
  outline:     none;
  transition:  border-color var(--tr), box-shadow var(--tr);
}
.phrase-input::placeholder { color: var(--subtle); }
.phrase-input:focus {
  border-color: var(--accent);
  box-shadow:   0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.phrase-input.shake {
  animation: shake 0.45s cubic-bezier(.36,.07,.19,.97);
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.animate-btn {
  display:     flex;
  align-items: center;
  gap:         0.38rem;
  background:  var(--accent);
  border:      none;
  border-radius: var(--radius);
  color:       #fff;
  cursor:      pointer;
  font-family: inherit;
  font-size:   0.875rem;
  font-weight: 600;
  padding:     0.6rem 1.1rem;
  white-space: nowrap;
  flex-shrink: 0;
  transition:  opacity var(--tr), transform var(--tr);
}
.animate-btn:hover  { opacity: 0.88; }
.animate-btn:active { transform: scale(0.97); }

/* Language badges */
#langBadges { display: flex; flex-wrap: wrap; gap: 0.28rem; }

.badge {
  background:   var(--bg2);
  border:       1px solid var(--border);
  border-radius: 99px;
  color:        var(--muted);
  font-size:    0.7rem;
  padding:      0.1rem 0.52rem;
}
.badge.dim { color: var(--subtle); border-style: dashed; }

/* ── Bottom controls shared styles ─────────────────────────────────────────────── */
.ctrl-section { display: flex; flex-direction: column; gap: 0.4rem; }

.ctrl-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle);
}

/* ── Mode toggle ────────────────────────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.mode-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  transition: background var(--tr), color var(--tr), box-shadow var(--tr);
  white-space: nowrap;
}
.mode-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.06);
}
.mode-btn:not(.active):hover { color: var(--text); }

/* ── Speed control ─────────────────────────────────────────────────────────────── */
.speed-header { display: flex; justify-content: space-between; align-items: baseline; }

.speed-val {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: var(--border2);
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}
.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  transition: box-shadow var(--tr);
}
.speed-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent);
}
.speed-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.speed-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--subtle);
}

/* ── Loading state ─────────────────────────────────────────────────────────────── */
.loading-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.spin {
  width: 20px; height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.load-label { font-size: 0.875rem; color: var(--muted); }
.load-label strong { color: var(--accent); }

#loadingItems {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  max-height: 130px;
  overflow-y: auto;
  scrollbar-width: none;
}
#loadingItems::-webkit-scrollbar { display: none; }

.load-item {
  background:   var(--bg2);
  border:       1px solid var(--border);
  border-radius: 99px;
  color:        var(--muted);
  font-size:    0.7rem;
  padding:      0.1rem 0.52rem;
  animation:    popIn 0.2s ease both;
}
@keyframes popIn { from { opacity:0; transform: scale(0.82); } to { opacity:1; transform: scale(1); } }

/* ── Playback controls ─────────────────────────────────────────────────────────────── */
#progressWrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

#progressBar {
  flex: 1;
  height: 3px;
  background: var(--border2);
  border-radius: 99px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s linear;
}

#langCounter {
  font-size:   0.7rem;
  font-weight: 600;
  color:       var(--muted);
  white-space: nowrap;
  min-width:   3.5ch;
  text-align:  right;
}

#controls { display: flex; align-items: center; gap: 0.4rem; }

.ctrl-btn {
  display:       flex;
  align-items:   center;
  justify-content: center;
  width: 34px; height: 34px;
  background:    none;
  border:        1px solid var(--border2);
  border-radius: var(--radius);
  color:         var(--muted);
  cursor:        pointer;
  transition:    background var(--tr), color var(--tr), border-color var(--tr);
}
.ctrl-btn:hover         { background: var(--bg2); color: var(--text); }
.ctrl-btn.active        { color: var(--accent); border-color: var(--accent); }
.ctrl-btn.primary       { background: var(--text); color: var(--bg); border-color: var(--text); }
.ctrl-btn.primary:hover { opacity: 0.82; }

.spacer { flex: 1; }
.export-group { display: flex; gap: 0.3rem; }

.export-btn {
  display:     flex;
  align-items: center;
  gap:         0.3rem;
  background:  none;
  border:      1px solid var(--border2);
  border-radius: var(--radius);
  color:       var(--muted);
  cursor:      pointer;
  font-family: inherit;
  font-size:   0.72rem;
  font-weight: 500;
  padding:     0.28rem 0.62rem;
  transition:  background var(--tr), color var(--tr);
}
.export-btn:hover { background: var(--bg2); color: var(--text); }

/* ── Render progress bar ─────────────────────────────────────────────────────────────── */
.cooking-panel {
  overflow:       hidden;
  max-height:     0;
  margin-top:     0;
  border-radius:  var(--radius);
  pointer-events: none;
  transition:
    max-height  0.34s cubic-bezier(0.4, 0, 0.2, 1),
    margin-top  0.28s ease;
}

.cooking-panel.active {
  max-height:     120px;
  margin-top:     0.85rem;
  pointer-events: auto;
}

.cooking-inner {
  padding:       0.8rem 0.9rem;
  background:    var(--bg2);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  opacity:       0;
  transform:     translateY(7px);
  transition:    opacity 0.24s ease 0.1s, transform 0.24s ease 0.1s;
}

.cooking-panel.active .cooking-inner {
  opacity:   1;
  transform: translateY(0);
}

.cooking-header {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  font-size:       0.8rem;
  font-weight:     600;
  color:           var(--text);
  margin-bottom:   0.55rem;
}

.cooking-bar {
  height:        6px;
  background:    var(--border2);
  border-radius: 99px;
  overflow:      hidden;
}

.cooking-fill {
  height:        100%;
  width:         0%;
  background:    var(--accent);
  border-radius: 99px;
  transition:    width 0.14s linear, background 0.3s ease;
}
.cooking-fill.done { background: #16a34a; }

/* Playback controls fade out while rendering */
#progressWrap,
#controls {
  transition: opacity 0.24s ease, transform 0.24s ease;
}

#playbackPanel.cooking-active #progressWrap,
#playbackPanel.cooking-active #controls {
  opacity:        0;
  transform:      translateY(-5px);
  pointer-events: none;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position:    fixed;
  bottom:      1.5rem;
  left:        50%;
  transform:   translateX(-50%);
  background:  var(--surface);
  border:      1px solid var(--border2);
  border-radius: 99px;
  color:       var(--muted);
  font-size:   0.8rem;
  font-weight: 500;
  padding:     0.45rem 1.1rem;
  white-space: nowrap;
  z-index:     200;
  box-shadow:  0 4px 16px rgba(0,0,0,0.12);
  animation:   toastIn 0.2s ease;
  pointer-events: none;
}
.toast.success { color: #16a34a; border-color: #86efac; }
.toast.error   { color: #dc2626; border-color: #fca5a5; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── About page ────────────────────────────────────────────────────────────────── */
.about-main  { max-width: 680px; margin: 0 auto; padding: 3.5rem 2rem 6rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 2.5rem;
  transition: color var(--tr);
}
.back-link:hover { color: var(--text); }

.about-eyebrow {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.5rem;
}

.about-title {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700; letter-spacing: -0.03em;
  line-height: 1.1; margin-bottom: 1.5rem; color: var(--text);
}

.about-body p { font-size: 1rem; color: var(--muted); line-height: 1.75; margin-bottom: 1rem; max-width: 58ch; }
.about-body p strong { color: var(--text); font-weight: 600; }

.divider { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.section-label {
  font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--subtle); margin-bottom: 1.25rem;
}

.credit-list { display: flex; flex-direction: column; }
.credit-item {
  display: flex; gap: 0.9rem;
  padding: 0.9rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
  border-radius: 4px; margin: 0 -0.5rem;
  transition: background var(--tr);
}
.credit-item:hover { background: var(--bg2); }
.credit-item:last-child { border-bottom: none; }
.credit-icon  { font-size: 1.2rem; margin-top: 2px; flex-shrink: 0; }
.credit-name  { font-size: 0.9rem; font-weight: 600; color: var(--text); margin-bottom: 0.15rem; }
.credit-desc  { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }
.credit-tag   { font-size: 0.72rem; color: var(--subtle); margin-top: 0.2rem; }

.lang-wrap { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.75rem; }
.lang-pill {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 99px; color: var(--muted);
  font-size: 0.78rem; padding: 0.2rem 0.65rem;
}
.lang-pill.first {
  border-color: var(--accent); color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* ── Responsive: mobile (<768px) ───────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .main {
    display:        flex;
    flex-direction: column;
    height:         auto;
    overflow:       visible;
    padding:        0 1.25rem 3rem;
    gap:            0;
  }

  .right-col {
    order:         -1;
    padding:       1rem 0 0;
    margin-bottom: 1.25rem;
    width:         100%;
  }

  .board-wrap {
    height:       min(60vh, 480px);
    aspect-ratio: 9 / 16;
    width:        auto;
    margin:       0 auto;
  }

  .left-col {
    padding:  0;
    overflow: visible;
  }

  .status-zone { flex: 0 0 auto; }

  .bottom-controls { margin-top: 1.25rem; }

  .hero-heading  { font-size: 1.7rem; }
  .hero-sub      { font-size: 0.875rem; margin-bottom: 1.1rem; }
  .input-row     { flex-direction: column; }
  .animate-btn   { justify-content: center; }
  #controls      { flex-wrap: wrap; }
}

/* ── Narrow desktop (768-1000px) ─────────────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1000px) {
  .main      { gap: 2rem; padding: 0 1.5rem; }
  .left-col  { padding-right: 0; }
}
