/* Tokens from the অসমীয়াGPT design system (project/tokens.json). */
@font-face { font-family: "Anek Bangla"; src: url("fonts/AnekBangla-Variable.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }
@font-face { font-family: "Noto Sans Bengali"; src: url("fonts/NotoSansBengali-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Tiro Bangla"; src: url("fonts/TiroBangla-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Tiro Bangla"; src: url("fonts/TiroBangla-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --surface-000: #ffffff;
  --surface-050: #faf8f5;
  --surface-100: #f3efe9;
  --surface-200: #e8e2da;
  --line: #ebe5de;
  --line-strong: #d3cbc0;
  --ink: #1c1917;
  --ink-muted: #5c534b;
  --ink-subtle: #6b6158;
  --brand: #9b1c23;
  --brand-hover: #7e151b;
  --brand-050: #fbefed;
  --brand-100: #f6dcd9;
  --on-brand: #ffffff;
  --accent: #0d6b68;
  --muga-050: #fbf3e1;
  --muga-ink: #7a5410;
  --success: #1c7a4b;
  --success-bg: #e7f4ec;
  --warning: #9a5a06;
  --danger: #b42318;
  --danger-bg: #fcebe9;

  --font-display: "Anek Bangla", "Noto Sans Bengali", system-ui, sans-serif;
  --font-sans: "Noto Sans Bengali", "Anek Bangla", system-ui, sans-serif;
  --font-serif: "Tiro Bangla", "Noto Serif Bengali", Georgia, serif;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px; --space-12: 48px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px; --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow-md: 0 1px 2px rgba(28, 25, 23, 0.04), 0 8px 24px rgba(28, 25, 23, 0.07);
  --control-height: 40px;
  --reading-max: 640px;
  --motion: 120ms ease;
  color-scheme: light;
}

/* Dark theme: same tokens, dark values from the design system. app.js sets data-theme from the system or the user's choice. */
:root[data-theme="dark"] {
  --surface-000: #1b1816; --surface-050: #131110; --surface-100: #24201d; --surface-200: #302a27;
  --line: #2d2724; --line-strong: #4a423d;
  --ink: #f5f1ec; --ink-muted: #b0a69c; --ink-subtle: #978d83;
  --brand: #ff9c92; --brand-hover: #ffb8b0; --brand-050: #2b1415; --brand-100: #401c1d; --on-brand: #3a0b0e;
  --accent: #5cccc4; --muga-050: #2a2111; --muga-ink: #eac77a;
  --success: #5fd39a; --success-bg: #11291d; --warning: #f0b45a; --danger: #ff8a7a; --danger-bg: #331614;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface-050);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 26px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; min-height: 100%; height: 100%; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  padding-top: max(var(--space-4), env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.mark {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--radius-md); background: var(--brand); color: var(--on-brand);
  font-family: var(--font-display); font-weight: 600; font-size: 22px; line-height: 1;
}
.wordmark { font-family: var(--font-display); font-weight: 500; font-size: 22px; line-height: 34px; color: var(--brand); }
.top-actions { display: flex; align-items: center; gap: var(--space-2); }
.top-link { padding: 0 var(--space-3); font-size: 14px; line-height: 40px; color: var(--accent); text-decoration: none; font-weight: 500; border-radius: var(--radius-md); }
.top-link:hover { background: var(--surface-200); }

.btn {
  height: var(--control-height); padding: 0 var(--space-4);
  border-radius: var(--radius-md); border: 1px solid transparent;
  background: transparent; cursor: pointer;
  font-size: 14px; line-height: 22px; font-weight: 500;
  transition: background var(--motion), border-color var(--motion), opacity var(--motion);
}
.btn.ghost { border-color: var(--line-strong); background: var(--surface-000); }
.btn:hover { background: var(--surface-200); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.danger-text { color: var(--danger); }
.btn.danger-text:hover { background: var(--danger-bg); }

.icon-btn {
  display: grid; place-items: center; width: var(--control-height); height: var(--control-height);
  border-radius: var(--radius-md); border: 1px solid var(--line-strong); background: var(--surface-000);
  cursor: pointer; transition: background var(--motion);
}
.icon-btn:hover { background: var(--surface-200); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }

/* Layout: mic on one side, the writing canvas on the other */
.stage {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: var(--space-6);
  padding: 0 var(--space-6) var(--space-6);
}

/* Mic side */
.mic-pane { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); padding-top: var(--space-8); }
.mic-stage { position: relative; width: 200px; height: 200px; display: grid; place-items: center; }
.halo {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, var(--brand-100) 0%, transparent 70%);
  opacity: 0; transform: scale(0.8);
  transition: opacity var(--motion), transform var(--motion);
  pointer-events: none;
}
.mic-stage.live .halo, .listening .halo { opacity: calc(0.35 + var(--level, 0) * 0.65); transform: scale(calc(0.85 + var(--level, 0) * 0.35)); }
.mic {
  position: relative; width: 132px; height: 132px; border-radius: 50%; border: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--brand); color: var(--on-brand);
  box-shadow: var(--shadow-md);
  transition: background var(--motion), transform var(--motion);
}
.mic:hover:not(:disabled) { background: var(--brand-hover); }
.mic:active:not(:disabled) { transform: scale(0.98); }
.mic:disabled { opacity: 0.45; cursor: default; }
.mic svg { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.mic .i-stop { display: none; }
.listening .mic { background: var(--surface-000); color: var(--brand); border: 1.5px solid var(--brand); }
.listening .mic:hover:not(:disabled) { background: var(--brand-050); }
.listening .i-mic { display: none; }
.listening .i-stop { display: block; }
.listening .i-stop rect { fill: currentColor; }

.mic-label { margin: 0; font-size: 16px; color: var(--ink-muted); text-align: center; min-height: 26px; }
.meter { width: 180px; height: 4px; border-radius: var(--radius-full); background: var(--surface-200); overflow: hidden; }
.meter span { display: block; height: 100%; width: calc(var(--level, 0) * 100%); background: var(--accent); border-radius: inherit; transition: width 60ms linear; }

.model-card {
  width: 100%; padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface-000); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.model-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.model-name { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 16px; line-height: 26px; }
.model-sub { margin: 0; font-size: 13px; line-height: 20px; color: var(--ink-muted); }
.model-pct { font-size: 14px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.progress { margin-top: var(--space-3); height: 4px; border-radius: var(--radius-full); background: var(--surface-200); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 200ms ease; }
.model-status { margin: var(--space-2) 0 0; font-size: 13px; line-height: 20px; color: var(--ink-muted); }
.model-card.ok .progress span { background: var(--success); }
.model-card.err .model-status { color: var(--danger); }

.notes { list-style: none; margin: auto 0 0; padding: 0 0 var(--space-4); display: grid; gap: var(--space-2); font-size: 14px; line-height: 22px; color: var(--ink-muted); align-self: stretch; }
.notes li { padding-left: var(--space-3); border-left: 2px solid var(--line-strong); }

/* Canvas side */
.canvas-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface-000); border: 1px solid var(--line); border-radius: var(--radius-xl); overflow: hidden; }
.canvas-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
.status { font-size: 14px; color: var(--ink-muted); }
.status.live { color: var(--accent); }
.bar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.bar-actions .btn { height: 34px; padding: 0 var(--space-3); }

.canvas {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: var(--space-8) var(--space-8) var(--space-12);
  font-family: var(--font-serif); font-size: 18px; line-height: 32px; color: var(--ink);
  max-width: calc(var(--reading-max) + var(--space-8) * 2); width: 100%; margin: 0 auto;
}
.placeholder { margin: 0; font-family: var(--font-sans); font-size: 16px; line-height: 26px; color: var(--ink-subtle); }
.canvas p.line { margin: 0 0 var(--space-4); }
.preview { margin: 0 0 var(--space-4); color: var(--ink-muted); }
.mic-pane:not(.listening) .meter { visibility: hidden; }
.canvas p.line:last-child { margin-bottom: 0; }

.w {
  border-radius: 4px; cursor: pointer; padding: 0 1px;
  text-decoration: underline; text-decoration-style: dotted; text-decoration-color: var(--accent); text-underline-offset: 5px;
  transition: background var(--motion);
}
.w:hover, .w.active { background: var(--surface-200); }
.w:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.w.in { animation: wordIn 260ms ease both; animation-delay: var(--d, 0ms); }
@keyframes wordIn { from { opacity: 0; } to { opacity: 1; } }

.caret { display: inline-block; width: 2px; height: 1.15em; margin-left: 2px; vertical-align: -0.2em; background: var(--accent); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .w.in, .caret { animation: none; }
}

/* Popover: floats near the word on hover; becomes a bottom sheet on phones. */
.popover {
  position: fixed; z-index: 20; width: min(340px, calc(100vw - 24px));
  padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface-000); border: 1px solid var(--line); box-shadow: var(--shadow-md);
  font-size: 14px; line-height: 22px;
  animation: pop 120ms ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.pop-term { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 22px; line-height: 34px; color: var(--ink); }
.pop-roman { margin: 0; font-size: 13px; line-height: 20px; color: var(--ink-muted); font-style: italic; }
.pop-head { padding-bottom: var(--space-3); border-bottom: 1px solid var(--line); }
.pop-note { margin: var(--space-3) 0 0; font-size: 13px; color: var(--warning); }
.pop-sense { padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.pop-sense:last-of-type { border-bottom: 0; }
.pop-pos { display: inline-block; padding: 0 var(--space-2); border-radius: var(--radius-sm); background: var(--brand-050); color: var(--brand); font-size: 13px; line-height: 22px; }
.pop-as { margin: var(--space-1) 0 0; font-size: 16px; line-height: 26px; color: var(--ink); }
.pop-en { margin: var(--space-1) 0 0; font-size: 13px; line-height: 20px; color: var(--ink-muted); }
.pop-syn { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.chip { padding: 0 var(--space-2); border-radius: var(--radius-sm); background: var(--surface-100); font-size: 13px; line-height: 24px; }
.pop-label { margin: var(--space-3) 0 0; font-size: 13px; color: var(--ink-muted); }
.pop-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.pop-source { margin: 0; font-size: 13px; color: var(--ink-subtle); }
.pop-link { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--accent); font-size: 14px; text-decoration: none; font-weight: 500; }
.pop-link:hover { text-decoration: underline; }
.pop-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.pop-loading { margin: 0; color: var(--ink-muted); }
.pop-loading::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--surface-000); border: 1px solid var(--line-strong); box-shadow: var(--shadow-md);
  font-size: 14px; line-height: 22px;
}
.toast.err { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

/* Phones: canvas on top, mic dock at the bottom. Model progress shows in the dock label. */
@media (max-width: 767px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: var(--space-3); padding: 0 var(--space-4) max(var(--space-4), env(safe-area-inset-bottom)); }
  .canvas-pane { order: 1; }
  .mic-pane { order: 2; flex-direction: row; justify-content: center; gap: var(--space-4); padding-top: var(--space-3); }
  .mic-stage { width: 84px; height: 84px; }
  .mic { width: 72px; height: 72px; }
  .mic svg { width: 28px; height: 28px; }
  .halo { inset: -8px; }
  .mic-label { min-height: 0; max-width: 46vw; text-align: left; font-size: 14px; line-height: 22px; }
  .meter, .model-card, .notes { display: none; }
  .canvas { padding: var(--space-6) var(--space-4) var(--space-8); font-size: 17px; line-height: 30px; }
  .popover { left: 12px !important; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); top: auto !important; width: auto; }
}
