/* ============================================================================
   Sinhala Jump-Starter — design system
   Calm, paper-like canvas · one restrained accent · dictionary typography.
   ============================================================================ */

@font-face {
  font-family: "Noto Sinhala Web";
  src: url("/assets/fonts/noto-sinhala.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0D80-0DFF, U+200C-200D;
}

/* ---- Tokens (light) ------------------------------------------------------ */
:root {
  --bg: #f7f6f3;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #fffdf8 0%, #f7f6f3 60%);
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --ink: #1b1d20;
  --ink-soft: #3b3e44;
  --muted: #74787f;
  --faint: #9aa0a8;
  --line: rgba(20, 22, 26, 0.09);
  --line-strong: rgba(20, 22, 26, 0.16);
  --accent: #0f8a78;
  --accent-ink: #0a5e52;
  --accent-soft: rgba(15, 138, 120, 0.10);
  --accent-glow: rgba(15, 138, 120, 0.18);
  --star: #e0a93b;
  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.05), 0 1px 1px rgba(20, 22, 26, 0.04);
  --shadow-md: 0 6px 24px -8px rgba(20, 22, 26, 0.16);
  --shadow-lg: 0 20px 60px -20px rgba(20, 22, 26, 0.28);

  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 26px;

  --ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Source Serif 4", Georgia, serif;
  --sinhala: "Noto Sinhala Web", "Noto Sans Sinhala", "Iskoola Pota", "Sinhala Sangam MN", "Nirmala UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --head-h: 3.7rem;   /* sticky header height; the scrolled search bar tucks beneath it */
}

:root[data-theme="dark"],
.dark-fallback {
  --bg: #0f1115;
  --bg-grad: radial-gradient(1100px 560px at 50% -12%, #161a22 0%, #0f1115 62%);
  --surface: #171a20;
  --surface-2: #1c2027;
  --ink: #e9e7e2;
  --ink-soft: #c7c9cf;
  --muted: #9aa0a8;
  --faint: #6b7079;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #2fd4bd;
  --accent-ink: #7defd9;
  --accent-soft: rgba(47, 212, 189, 0.12);
  --accent-glow: rgba(47, 212, 189, 0.22);
  --star: #f0c14b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 30px -10px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 70px -24px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --bg-grad: radial-gradient(1100px 560px at 50% -12%, #161a22 0%, #0f1115 62%);
    --surface: #171a20;
    --surface-2: #1c2027;
    --ink: #e9e7e2;
    --ink-soft: #c7c9cf;
    --muted: #9aa0a8;
    --faint: #6b7079;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.16);
    --accent: #2fd4bd;
    --accent-ink: #7defd9;
    --accent-soft: rgba(47, 212, 189, 0.12);
    --accent-glow: rgba(47, 212, 189, 0.22);
    --star: #f0c14b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 30px -10px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 24px 70px -24px rgba(0, 0, 0, 0.7);
  }
}

/* ---- Base ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0;
  font-family: var(--ui);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-glow); }

.sinhala { font-family: var(--sinhala); }

/* ---- Header -------------------------------------------------------------- */
.site-head {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 0.5rem 1rem; padding: 0.6rem clamp(1rem, 4vw, 2.2rem);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { white-space: nowrap; }
/* On wide screens, a 3-column grid with equal side tracks centers the search in the viewport */
@media (min-width: 1240px) {
  .site-head { display: grid; grid-template-columns: 1fr minmax(0, 560px) 1fr; }
  .site-head .brand { justify-self: start; }
  .site-head .nav { justify-self: end; }
  .head-search { width: 100%; }
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  font-family: var(--sinhala); font-size: 1.5rem; line-height: 1;
  color: var(--accent); transition: transform 0.3s var(--ease);
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }
.brand-name { font-size: 1.02rem; }
.nav { display: flex; align-items: center; gap: 0.35rem; }
.nav-link {
  padding: 0.4rem 0.7rem; border-radius: var(--r-sm); color: var(--muted);
  font-size: 0.92rem; font-weight: 550; transition: 0.15s var(--ease);
}
.nav-link:hover { color: var(--ink); background: var(--accent-soft); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 0.5rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: var(--r-sm); font-size: 0.95rem; transition: 0.15s var(--ease);
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }
/* fixed width so switching std/book/ipa never shifts the layout */
.icon-btn.wide { width: 5.25rem; min-width: 5.25rem; padding: 0 0.4rem; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; }

/* ---- Layout -------------------------------------------------------------- */
.main { max-width: 940px; margin: 0 auto; padding: 0.8rem clamp(0.8rem, 4vw, 1.6rem) 5rem; }
.search-wrap { display: flex; flex-direction: column; }
.search-wrap.hero .filters { justify-content: center; margin-top: 0; }
.page-title { font-size: 1.5rem; font-weight: 680; letter-spacing: -0.02em; margin: 0.4rem 0 1.2rem; }

/* ---- Hero ---------------------------------------------------------------- */
/* top-aligned hero with even spacing above/below "සිංහල": above = .main 0.8 + 1.6 = 2.4rem,
   below = wordmark 0.2 + 2.2 + filters-mt 0 = 2.4rem */
.hero-head { text-align: center; margin: 1.6rem 0 2.2rem; animation: rise 0.5s var(--ease) both; }
.wordmark {
  font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em;
  font-size: clamp(2.1rem, 6vw, 3.2rem); margin: 0 0 0.2rem; line-height: 1.05;
}
.wordmark span {
  font-family: var(--sinhala);
}
.wordmark { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; }
.wordmark > :first-child { font-family: var(--sinhala); color: var(--ink); }
.wordmark span { font-family: var(--serif); font-size: 0.5em; color: var(--muted); font-weight: 500; }
.tagline { color: var(--muted); font-size: 1.02rem; margin: 0; }

/* ---- Search (lives inside the header, on every page) --------------------- */
.head-search {
  flex: 1 1 auto; min-width: 0; max-width: 560px; cursor: text;
  display: flex; align-items: center; gap: 0.35rem;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 100px; padding: 0 0.35rem 0 0.85rem; height: 40px;
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.head-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
/* the icon + slash are decoration: they share the input's text cursor and never block clicks */
.search-ico { width: 18px; height: 18px; flex: none; color: var(--faint); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; cursor: text; }
.search-input {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink);
  font-size: 1rem; padding: 0.5rem 0.2rem; min-width: 0;
}
.search-input::placeholder { color: var(--faint); }
/* hide the native search 'x' — we render our own with a real button + bigger hitbox */
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.slash-hint {
  flex: none; cursor: text; font-family: var(--mono); font-size: 0.72rem; color: var(--faint);
  border: 1px solid var(--line); border-radius: 5px; padding: 0.12rem 0.45rem; margin-right: 0.35rem;
}
.head-search:focus-within .slash-hint { opacity: 0; }
.head-clear {
  flex: none; border: 0; background: none; color: var(--faint); cursor: pointer;
  font-size: 1rem; line-height: 1; width: 30px; height: 30px; border-radius: 50%;
  display: inline-grid; place-items: center; transition: 0.15s var(--ease);
}
.head-clear:hover { color: var(--accent); background: var(--accent-soft); }

/* ---- Filters ------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.filter-chip {
  font-size: 0.8rem; font-weight: 540; color: var(--muted);
  padding: 0.3rem 0.65rem; border: 1px solid var(--line); border-radius: 100px;
  background: var(--surface); transition: 0.15s var(--ease); white-space: nowrap;
}
.filter-chip:hover { color: var(--ink); border-color: var(--line-strong); }
.filter-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
:root[data-theme="dark"] .filter-chip.on { color: #08110f; }
.filter-chip.clear-filters { color: var(--faint); font-weight: 600; }
.filter-chip.clear-filters:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Result meta + grid -------------------------------------------------- */
.result-meta { color: var(--faint); font-size: 0.82rem; margin: 0.7rem 0 0.5rem; letter-spacing: 0.02em; }
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.85rem; }

/* ---- Card ---------------------------------------------------------------- */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.05rem 1.1rem 0.9rem;
  box-shadow: var(--shadow-sm); transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), border-color 0.18s var(--ease);
  animation: rise 0.32s var(--ease) both;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.card-head { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.card-tools { display: flex; align-items: center; gap: 0.45rem; flex-shrink: 0; padding-top: 0.15rem; }
.pdf-ref { color: var(--faint); font-size: 0.8rem; white-space: nowrap; line-height: 1; }
.headword { display: inline-flex; align-items: baseline; }
.headword .sinhala {
  font-size: 2rem; line-height: 1.25; font-weight: 500; letter-spacing: 0;
  color: var(--ink); border-bottom: 2px solid transparent; transition: 0.15s var(--ease);
}
.headword:hover .sinhala { color: var(--accent-ink); border-bottom-color: var(--accent-glow); }
.roman-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.2rem 0.6rem; margin-top: 0.15rem; }
.roman-primary { font-size: 1.05rem; color: var(--accent-ink); font-weight: 560; }
.roman-secondary { font-size: 0.8rem; color: var(--faint); display: inline-flex; flex-wrap: wrap; gap: 0.3rem; align-items: baseline; }
.roman-secondary .sep { opacity: 0.5; }
.roman-secondary .r-ipa { font-family: var(--mono); }
.meaning { margin-top: 0.55rem; font-size: 1rem; color: var(--ink); font-weight: 500; }
.def { margin-top: 0.2rem; font-size: 0.88rem; color: var(--muted); }
.syn { margin-top: 0.2rem; font-size: 0.84rem; color: var(--faint); font-style: italic; }

/* tags */
.tags { display: flex; flex-wrap: wrap; gap: 0.32rem; margin-top: 0.6rem; }
.tag {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; text-transform: lowercase;
  padding: 0.16rem 0.5rem; border-radius: 100px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.tag[data-tag="verb"]        { color: #b4612b; background: color-mix(in srgb, #b4612b 12%, var(--surface)); border-color: transparent; }
.tag[data-tag="noun"]        { color: #2f7d9a; background: color-mix(in srgb, #2f7d9a 12%, var(--surface)); border-color: transparent; }
.tag[data-tag="adjective"]   { color: #6a5acd; background: color-mix(in srgb, #6a5acd 13%, var(--surface)); border-color: transparent; }
.tag[data-tag="pronoun"]     { color: #1f9e6b; background: color-mix(in srgb, #1f9e6b 12%, var(--surface)); border-color: transparent; }
.tag[data-tag="question"]    { color: #c2497a; background: color-mix(in srgb, #c2497a 13%, var(--surface)); border-color: transparent; }
.tag[data-tag="phrase"]      { color: #8a7322; background: color-mix(in srgb, #8a7322 14%, var(--surface)); border-color: transparent; }
.tag[data-tag="present-tense"],.tag[data-tag="past-tense"],.tag[data-tag="future-tense"],.tag[data-tag="polite-command"] {
  color: #b4612b; background: color-mix(in srgb, #b4612b 10%, var(--surface)); border-color: transparent;
}
.tag.review { color: var(--star); background: color-mix(in srgb, var(--star) 16%, var(--surface)); border-color: transparent; }

/* star */
.star {
  background: none; border: 0; cursor: pointer;
  font-size: 1.05rem; color: var(--line-strong); transition: 0.15s var(--ease); line-height: 1;
  padding: 0.15rem;
}
.star:hover { color: var(--star); transform: scale(1.15); }
.star.on { color: var(--star); }

/* confidence / reference button — sits just left of the star in .card-tools */
.conf {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; box-sizing: border-box;
  background: none; border: 0;
  font-size: 1rem; color: var(--line-strong); line-height: 1; padding: 0.15rem;
  cursor: pointer; transition: 0.15s var(--ease);
}
.conf:hover { color: var(--accent); transform: scale(1.15); }
.conf.flag { color: #d9962f; }            /* needs_review -> ❕ */
.conf.flag:hover { color: #eaa83f; }
.conf.copied, .conf.copied:hover { color: var(--accent); transform: none; }

/* copy — generous tap target, ~2× the old glyph size */
.copy {
  border: 0; background: none; color: var(--faint); font-size: 1.7rem; line-height: 1;
  padding: 0.2rem 0.4rem; border-radius: 8px; transition: 0.15s var(--ease); align-self: center;
}
.copy:hover { color: var(--accent); background: var(--accent-soft); }

/* card foot */
.card-foot { margin-top: 0.7rem; display: flex; align-items: center; gap: 0.7rem; }
.pdf-link { font-size: 0.78rem; color: var(--faint); transition: 0.15s var(--ease); }
.pdf-link:hover { color: var(--accent); }

/* ---- Audio player -------------------------------------------------------- */
.player {
  display: flex; align-items: center; gap: 0.55rem; margin-top: 0.8rem;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 100px; padding: 0.3rem 0.6rem 0.3rem 0.34rem;
}
.play-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
  box-shadow: 0 2px 8px -2px var(--accent-glow);
}
:root[data-theme="dark"] .play-btn { color: #08110f; }
.play-btn:hover { transform: scale(1.07); box-shadow: 0 4px 14px -2px var(--accent-glow); }
.play-btn.is-playing { box-shadow: 0 0 0 4px var(--accent-glow); }
.play-btn .ico { width: 18px; height: 18px; fill: currentColor; }
.seek {
  flex: 1; height: 6px; background: var(--line); border-radius: 100px; cursor: pointer;
  position: relative; overflow: hidden; min-width: 40px;
}
.seek-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 100px; width: 0; }
.time { flex: none; font-family: var(--mono); font-size: 0.7rem; color: var(--faint); min-width: 64px; text-align: right; }
.rate, .ctx, .loop {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 100px; font-size: 0.7rem; padding: 0.18rem 0.45rem; transition: 0.15s var(--ease); min-width: 32px;
}
.rate:hover, .ctx:hover, .loop:hover { color: var(--ink); border-color: var(--line-strong); }
.ctx, .loop { display: inline-grid; place-items: center; padding: 0.25rem; }
.ctx .ico, .loop .ico { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ctx.on, .loop.on { color: var(--accent); border-color: var(--accent); }
.player.compact .time { display: none; }
@media (min-width: 420px) { .player.compact .time { display: block; } }

/* ---- States -------------------------------------------------------------- */
.empty-state { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 1.4rem; align-items: center; }
.chips-label { color: var(--faint); font-size: 0.8rem; margin-right: 0.2rem; }
.chip {
  font-size: 0.85rem; padding: 0.35rem 0.8rem; border-radius: 100px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  transition: 0.15s var(--ease);
}
.chip:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.corpus-note { text-align: center; color: var(--faint); font-size: 0.78rem; margin-top: 1.6rem; }

/* ---- Entry page ---------------------------------------------------------- */
.entry-page { animation: rise 0.3s var(--ease) both; }
.back { color: var(--muted); font-size: 0.88rem; display: inline-block; margin-bottom: 1rem; transition: 0.15s var(--ease); }
.back:hover { color: var(--accent); }
.entry-detail {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: clamp(1.3rem, 4vw, 2.4rem); box-shadow: var(--shadow-md);
}
.entry-hero { display: flex; flex-wrap: wrap; align-items: center; gap: 1.2rem 2rem; }
.sinhala.big { font-family: var(--sinhala); font-size: clamp(2.6rem, 9vw, 4.4rem); line-height: 1.2; font-weight: 500; }
.entry-romans { display: flex; flex-direction: column; gap: 0.25rem; }
.r-line { display: flex; gap: 0.6rem; align-items: baseline; }
.r-line .lbl { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); width: 38px; }
.r-line .val { font-size: 1.05rem; color: var(--ink-soft); }
.r-line:first-child .val { color: var(--accent-ink); font-weight: 600; }
.entry-english { font-size: 1.7rem; font-weight: 680; letter-spacing: -0.02em; margin: 1.3rem 0 0.3rem; }
.def.big { font-size: 1.05rem; color: var(--muted); margin: 0; }
.entry-player { margin: 1.3rem 0; max-width: 460px; }
.notes { margin: 1rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.92rem; }
.notes li { margin: 0.25rem 0; }
.syn.big { color: var(--faint); font-style: italic; margin-top: 0.8rem; }
.entry-source { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.5rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.src-chip {
  font-size: 0.82rem; padding: 0.35rem 0.7rem; border-radius: 100px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); transition: 0.15s var(--ease);
}
.src-chip:hover { color: var(--accent); border-color: var(--accent); }
.src-chip.static { cursor: default; }
.src-chip.static:hover { color: var(--muted); border-color: var(--line); }

/* ---- Browse -------------------------------------------------------------- */
.browse-section { margin-bottom: 2rem; }
.browse-section h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 0 0 0.7rem; }
.browse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.7rem; }
.browse-card {
  display: flex; flex-direction: column; gap: 0.2rem; padding: 0.9rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  transition: 0.16s var(--ease); box-shadow: var(--shadow-sm);
}
.browse-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow-md); }
.bc-num { font-family: var(--mono); font-size: 0.72rem; color: var(--accent); font-weight: 700; }
.bc-title { font-weight: 600; font-size: 0.96rem; }
.bc-count { font-size: 0.76rem; color: var(--faint); }

/* ---- Random -------------------------------------------------------------- */
.random-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.4rem 0.8rem; }
.random-head .page-title { margin-bottom: 0.6rem; }
.random-meta { color: var(--faint); font-size: 0.85rem; font-family: var(--mono); }
.random-hint { color: var(--faint); font-size: 0.78rem; margin-left: auto; }
.random-stage { max-width: 460px; margin: 0.4rem auto 0; width: 100%; }
.random-stage .card { animation: rise 0.25s var(--ease) both; }
.random-nav { display: flex; gap: 0.7rem; justify-content: center; margin-top: 1.3rem; }
.rand-btn {
  padding: 0.55rem 1.3rem; border-radius: 100px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-soft); font-weight: 560; font-size: 0.95rem;
  transition: 0.15s var(--ease);
}
.rand-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.rand-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
:root[data-theme="dark"] .rand-btn.primary { color: #08110f; }

/* ---- Command palette ----------------------------------------------------- */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 16, 0.45);
  backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh; animation: rise 0.12s var(--ease);
}
.palette {
  width: min(92vw, 560px); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.palette-input {
  width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink);
  font-size: 1.1rem; padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--line);
}
.palette-results { max-height: 50vh; overflow-y: auto; }
.palette-item {
  display: flex; align-items: baseline; gap: 0.7rem; padding: 0.65rem 1.2rem;
  border-bottom: 1px solid var(--line); transition: background 0.12s var(--ease);
}
.palette-item:hover { background: var(--accent-soft); }
.pi-script { font-size: 1.25rem; min-width: 2.5em; }
.pi-rom { color: var(--accent-ink); font-weight: 560; }
.pi-eng { color: var(--muted); margin-left: auto; font-size: 0.9rem; }
.palette-foot { padding: 0.5rem 1.2rem; color: var(--faint); font-size: 0.75rem; }
.palette-foot kbd {
  font-family: var(--mono); border: 1px solid var(--line); border-radius: 4px;
  padding: 0 0.3rem; margin: 0 0.15rem;
}

/* ---- Footer -------------------------------------------------------------- */
.site-foot {
  max-width: 940px; margin: 0 auto; padding: 2rem 1.6rem 3rem;
  color: var(--faint); font-size: 0.78rem; display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.site-foot .dot { opacity: 0.5; }

/* ---- Motion -------------------------------------------------------------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.results .card:nth-child(1) { animation-delay: 0.01s; }
.results .card:nth-child(2) { animation-delay: 0.04s; }
.results .card:nth-child(3) { animation-delay: 0.07s; }
.results .card:nth-child(4) { animation-delay: 0.10s; }
.results .card:nth-child(5) { animation-delay: 0.13s; }
.results .card:nth-child(n+6) { animation-delay: 0.15s; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- Mobile -------------------------------------------------------------- */
@media (max-width: 560px) {
  .results { grid-template-columns: 1fr; }
  /* drop the desktop grid; stack brand · search · nav */
  .site-head { display: flex; flex-wrap: wrap; align-items: center; padding: 0.5rem 0.8rem; gap: 0.4rem 0.5rem; }
  .brand-name { display: none; }
  /* search on its own row (top); below it the logo + nav buttons share ONE wrapping flex
     row. display:contents dissolves the .nav box so its children become direct flex items
     of .site-head — the logo flows inline with them and is never stranded on its own row. */
  .head-search { order: 1; flex-basis: 100%; max-width: none; }
  .brand { order: 2; margin-right: 0; }
  .nav { display: contents; }
  .nav > * { order: 3; }
  .nav-link { padding: 0.35rem 0.5rem; font-size: 0.88rem; }
  .icon-btn { min-width: 32px; height: 32px; }
  .icon-btn.wide { width: 4.6rem; min-width: 4.6rem; }
}

/* ---- Offline-download dialog (built by offline.js) ---------------------- */
.dl-backdrop {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: 1rem; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px);
}
.dl-modal {
  width: min(92vw, 380px); background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-md);
  padding: 1.3rem; animation: rise 0.2s var(--ease) both;
}
.dl-title { font-size: 1.1rem; font-weight: 650; margin: 0 0 0.3rem; }
.dl-sub { color: var(--muted); font-size: 0.9rem; margin: 0; }
.dl-row { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.1rem; }
.dl-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 100px; padding: 0.45rem 1rem; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: 0.15s var(--ease);
}
.dl-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dl-btn.ghost { background: none; color: var(--muted); }
.dl-btn:disabled { opacity: 0.5; cursor: default; }
.dl-progress { height: 8px; background: var(--surface-2); border-radius: 100px; overflow: hidden; margin: 0.9rem 0 0; }
.dl-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.12s linear; }
.dl-status { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 0; }
