/* ---------- Fonts (self-hosted) ---------- */
@font-face { font-family: "DM Sans"; src: url("../vendor/fonts/dm-sans-latin-wght-normal.woff2") format("woff2"); font-weight: 100 1000; font-style: normal; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url("../vendor/fonts/dm-sans-latin-wght-italic.woff2") format("woff2"); font-weight: 100 1000; font-style: italic; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../vendor/fonts/source-serif-4-latin-wght-normal.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../vendor/fonts/source-serif-4-latin-wght-italic.woff2") format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../vendor/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2"); font-weight: 100 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Noto Sans Sinhala"; src: url("../vendor/fonts/noto-sans-sinhala-sinhala-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; unicode-range: U+0964-0965, U+0D81-0DF4, U+1CF2, U+200C-200D, U+25CC, U+111E1-111F4; }

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #faf9f5;
  --bg-sidebar: #f3f1ea;
  --bg-hover: rgba(31, 30, 29, 0.06);
  --bg-active: rgba(31, 30, 29, 0.09);
  --surface: #ffffff;
  --surface-2: #f5f4ee;
  --bubble: #f0eee6;
  --text: #141413;
  --text-2: #3d3d3a;
  --muted: #73726c;
  --faint: #a19f97;
  --border: rgba(31, 30, 29, 0.13);
  --border-strong: rgba(31, 30, 29, 0.24);
  --accent: #c96442;
  --accent-hover: #b4573a;
  --accent-soft: rgba(201, 100, 66, 0.12);
  --accent-text: #ffffff;
  --danger: #b4332b;
  --danger-soft: rgba(180, 51, 43, 0.1);
  --ok: #3f7d4a;
  --learn: #2563c9;
  --learn-soft: rgba(37, 99, 201, 0.1);
  --code-bg: #f7f6f1;
  --shadow-sm: 0 1px 2px rgba(20, 20, 19, 0.06);
  --shadow-composer: 0 0.25rem 1.25rem rgba(20, 20, 19, 0.035), 0 0 0 0.5px rgba(31, 30, 29, 0.15);
  --shadow-pop: 0 10px 38px -10px rgba(20, 20, 19, 0.28), 0 0 0 0.5px rgba(31, 30, 29, 0.14);

  --font-ui: "DM Sans", "Noto Sans Sinhala", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Source Serif 4", "Noto Sans Sinhala", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --font-chat: var(--font-serif);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #262624;
  --bg-sidebar: #1f1e1d;
  --bg-hover: rgba(250, 249, 245, 0.06);
  --bg-active: rgba(250, 249, 245, 0.1);
  --surface: #30302e;
  --surface-2: #2b2b29;
  --bubble: #141413;
  --text: #faf9f5;
  --text-2: #e8e6dc;
  --muted: #a6a39a;
  --faint: #78766f;
  --border: rgba(250, 249, 245, 0.11);
  --border-strong: rgba(250, 249, 245, 0.22);
  --accent: #d97757;
  --accent-hover: #e08a6d;
  --accent-soft: rgba(217, 119, 87, 0.16);
  --danger: #f07a6e;
  --danger-soft: rgba(240, 122, 110, 0.12);
  --ok: #7cc489;
  --learn: #7aa7f5;
  --learn-soft: rgba(122, 167, 245, 0.13);
  --code-bg: #1f1e1d;
  --shadow-composer: 0 0.25rem 1.25rem rgba(0, 0, 0, 0.18), 0 0 0 0.5px rgba(250, 249, 245, 0.14);
  --shadow-pop: 0 12px 40px -8px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(250, 249, 245, 0.14);
}

:root[data-chat-font="sans"] { --font-chat: var(--font-ui); }
:root[data-chat-font="system"] { --font-chat: system-ui, -apple-system, "Segoe UI", "Noto Sans Sinhala", sans-serif; }

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
img, svg { display: block; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- Buttons + fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: 0.88; }
.btn-accent { background: var(--accent); color: var(--accent-text); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-outline { border: 1px solid var(--border-strong); color: var(--text); background: var(--surface); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; height: 44px; font-size: 15px; border-radius: 10px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm);
  color: var(--muted); transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.is-on { color: var(--accent); background: var(--accent-soft); }

.field {
  width: 100%; height: 44px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { height: auto; padding: 10px 14px; resize: vertical; line-height: 1.5; }
.label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
