/* Layout: sticky top bar with search; on wide screens a sticky section rail on the left and a main column of
   dictionary entries (live demo "stage" on top, definition below) in an auto-fill grid. */
:root {
  --paper: #f2f3f7;
  --sheet: #ffffff;
  --ink: #161a33;
  --ink-2: #474e6c;
  --ink-3: #6f7591;
  --rule: #d8dbe6;
  --accent: #3b32d9;
  --accent-ink: #ffffff;
  --accent-soft: #ebeaff;
  --code-bg: #eceef5;
  --stage: #e7e9f1;
  --stage-ink: #1f2440;
  --stage-card: #ffffff;
  --stage-line: #cdd1df;

  /* vivid demo colours: identical in both themes, used inside stages only */
  --d-pink: #ff4f9a;
  --d-violet: #7b5cff;
  --d-blue: #2f7bff;
  --d-cyan: #19c3d6;
  --d-lime: #9bdc28;
  --d-amber: #ffb020;
  --d-coral: #ff6b4a;

  --f-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Newsreader", Georgia, "Times New Roman", serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --r-card: 14px;
  --r-ctl: 8px;
  --shadow-pop: 0 1px 2px rgb(22 26 51 / 0.08), 0 12px 32px -8px rgb(22 26 51 / 0.22);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1120;
    --sheet: #171a2c;
    --ink: #e8eaf6;
    --ink-2: #b1b6cf;
    --ink-3: #868ca8;
    --rule: #2a2f48;
    --accent: #918cff;
    --accent-ink: #0f1120;
    --accent-soft: #232350;
    --code-bg: #20243a;
    --stage: #1d2135;
    --stage-ink: #e8eaf6;
    --stage-card: #2a2f48;
    --stage-line: #3a4060;
    --shadow-pop: 0 1px 2px rgb(0 0 0 / 0.4), 0 16px 40px -8px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1120;
  --sheet: #171a2c;
  --ink: #e8eaf6;
  --ink-2: #b1b6cf;
  --ink-3: #868ca8;
  --rule: #2a2f48;
  --accent: #918cff;
  --accent-ink: #0f1120;
  --accent-soft: #232350;
  --code-bg: #20243a;
  --stage: #1d2135;
  --stage-ink: #e8eaf6;
  --stage-card: #2a2f48;
  --stage-line: #3a4060;
  --shadow-pop: 0 1px 2px rgb(0 0 0 / 0.4), 0 16px 40px -8px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(84px + env(safe-area-inset-top, 0px)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.55 var(--f-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd { font-family: var(--f-mono); font-size: 0.86em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -60px; z-index: 50; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--r-ctl); font: 600 14px var(--f-display); }
.skip:focus { top: 12px; }

/* ---------- buttons ---------- */
.btn, .tbtn, .linkbtn { font-family: var(--f-display); cursor: pointer; }
.btn {
  font-size: 0.82rem; font-weight: 600; letter-spacing: 0.01em;
  padding: 7px 13px; border-radius: var(--r-ctl); border: 1px solid transparent;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--rule); }
.btn-ghost:hover { border-color: var(--ink-3); color: var(--ink); }
.btn-ghost[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.linkbtn { background: none; border: 0; padding: 2px 0; color: var(--accent); font-size: 0.8rem; font-weight: 600; }
.linkbtn:hover { text-decoration: underline; text-underline-offset: 0.2em; }
.tbtn {
  background: transparent; color: var(--ink-2); border: 1px solid var(--rule);
  border-radius: var(--r-ctl); padding: 6px 10px; font-size: 0.78rem; font-weight: 600; white-space: nowrap;
}
.tbtn:hover { color: var(--ink); border-color: var(--ink-3); }
.tbtn[aria-pressed="false"] { color: var(--ink-3); border-style: dashed; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px 20px;
  padding: 10px clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--rule);
}
.wordmark {
  font: 800 1.05rem/1 var(--f-display); font-stretch: 118%; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.wordmark span { font-weight: 380; }
.search { position: relative; max-width: 620px; width: 100%; justify-self: center; }
.search input {
  width: 100%; font: 400 1rem/1.2 var(--f-body); font-style: italic; color: var(--ink);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 999px;
  padding: 10px 40px 10px 40px; appearance: none;
}
.search input:not(:placeholder-shown) { font-style: normal; }
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.search-icon { position: absolute; left: 14px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-kbd {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  border: 1px solid var(--rule); border-radius: 5px; padding: 0 6px; color: var(--ink-3); font-size: 0.75rem; background: var(--paper);
}
.toggles { display: flex; gap: 8px; }

/* ---------- frame + rail ---------- */
.frame {
  display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 40px;
  max-width: 1440px; margin: 0 auto; padding-inline: clamp(16px, 3vw, 40px);
}
.rail { position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); align-self: start; padding-block: 28px; }
.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail a {
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  padding: 5px 8px; border-radius: 6px; color: var(--ink-2); text-decoration: none;
  font: 500 0.88rem/1.3 var(--f-display);
}
.rail a span { font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: 0.78rem; }
.rail a:hover { background: var(--sheet); color: var(--ink); }
.rail a[aria-current="true"] { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.rail a[aria-current="true"] span { color: var(--accent); }
.rail .rail-elsewhere { margin-top: 14px; border-top: 1px solid var(--rule); border-radius: 0; padding-top: 12px; }

main { min-width: 0; padding-block: 28px 120px; container-type: inline-size; }

/* ---------- the dictionary-entry hero ---------- */
.entryhead { max-width: 980px; padding-block: 12px 36px; }
.headword {
  margin: 0; font-family: var(--f-display); font-weight: 860; font-stretch: 125%;
  font-size: clamp(1.6rem, 9.4cqi, 7.2rem); line-height: 0.92; letter-spacing: -0.035em; color: var(--ink);
}
.pron { margin: 14px 0 0; font-size: 1.15rem; color: var(--ink-2); display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.pron span { font-family: var(--f-body); letter-spacing: 0.02em; }
.senses { margin: 18px 0 0; padding-left: 1.6em; max-width: 64ch; display: grid; gap: 8px; font-size: 1.16rem; line-height: 1.5; }
.senses li::marker { font: 800 1rem var(--f-display); color: var(--accent); }
.senses strong { font-weight: 500; font-variant-numeric: tabular-nums; }
.tryline { margin-top: 26px; display: grid; gap: 10px; }
.tryline-label { font: 600 0.85rem var(--f-display); color: var(--ink-3); }
.trychips { display: flex; flex-wrap: wrap; gap: 8px; }
.trychips button {
  font: italic 400 0.98rem/1.2 var(--f-body); color: var(--ink); cursor: pointer;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 999px; padding: 7px 14px;
  transition: border-color 0.15s, color 0.15s;
}
.trychips button::before { content: "“"; }
.trychips button::after { content: "”"; }
.trychips button:hover { border-color: var(--accent); color: var(--accent); }

.formula { margin: 34px 0 0; padding: 20px 22px; border: 1px solid var(--rule); border-radius: var(--r-card); background: var(--sheet); max-width: 860px; }
.formula figcaption { font: 600 0.9rem var(--f-display); color: var(--ink-2); }
.formula-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 14px; }
.fpart { display: grid; gap: 1px; padding: 8px 12px; border-radius: var(--r-ctl); background: var(--accent-soft); }
.fpart b { font: 750 1rem/1.1 var(--f-display); font-stretch: 110%; color: var(--accent); }
.fpart small { font: 400 0.78rem/1.2 var(--f-display); color: var(--ink-2); }
.fplus { font: 300 1.4rem var(--f-display); color: var(--ink-3); }
.formula-ex { margin: 16px 0 0; font-size: 1.05rem; line-height: 1.55; color: var(--ink); max-width: 70ch; }
.formula-ex u { text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent); text-decoration-thickness: 2px; text-underline-offset: 0.22em; }

/* ---------- sections + grid ---------- */
.results-status { margin: 0; font: 600 0.92rem var(--f-display); color: var(--ink-2); }
.results-status:empty { display: none; }
.is-searching .entryhead { display: none; }
.is-searching .results-status { padding-block: 8px 16px; }
.lx-section { padding-block: 36px 8px; border-top: 1px solid var(--rule); }
.lx-section.results { border-top: 0; padding-top: 0; }
.sec-head { display: grid; gap: 6px; margin-bottom: 22px; max-width: 70ch; }
.sec-head h2 {
  margin: 0; font: 780 clamp(1.6rem, 3.4cqi, 2.3rem)/1.05 var(--f-display); font-stretch: 115%;
  letter-spacing: -0.02em; text-wrap: balance;
}
.sec-head p { margin: 0; color: var(--ink-2); font-size: 1.05rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 20px; }

/* ---------- entry ---------- */
.entry {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-card); overflow: hidden;
}
.entry.flash { animation: lx-flash 1.6s ease-out; }
@keyframes lx-flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }

.stage {
  position: relative; aspect-ratio: 16 / 10; max-width: 100%; overflow: hidden; isolation: isolate;
  background: var(--stage); color: var(--stage-ink); border-bottom: 1px solid var(--rule);
  font-family: var(--f-display); font-size: 14px; line-height: 1.35;
  container-type: inline-size;
}
.stage--tall { aspect-ratio: 4 / 3; }
.stage--dark { background: #0d0f1f; color: #e9ebf7; --stage-card: #22263c; --stage-line: #343a58; --stage-ink: #e9ebf7; }
.stage--light { background: #f4f5fa; color: #1f2440; --stage-card: #ffffff; --stage-line: #cdd1df; --stage-ink: #1f2440; }
.stage-inner { position: absolute; inset: 0; display: grid; place-items: center; }
.stage-hint {
  position: absolute; left: 10px; bottom: 10px; z-index: 5; pointer-events: none;
  font: 600 11px/1 var(--f-mono); letter-spacing: 0.02em; padding: 5px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--sheet) 88%, transparent); color: var(--ink-2); border: 1px solid var(--rule);
  transition: opacity 0.2s;
}
.stage:hover .stage-hint, .stage:focus-within .stage-hint { opacity: 0; }
.stage-replay {
  position: absolute; right: 8px; top: 8px; z-index: 5; width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 999px; border: 1px solid var(--rule); background: color-mix(in srgb, var(--sheet) 88%, transparent);
  color: var(--ink-2); cursor: pointer; opacity: 0.7; transition: opacity 0.15s;
}
.stage-replay svg { width: 16px; height: 16px; }
.stage:hover .stage-replay, .stage-replay:focus-visible { opacity: 1; }

/* pause demos that are offscreen, or everywhere when motion is off (unless the reader pressed replay) */
.stage[data-live="0"] .stage-inner *, .stage[data-live="0"] .stage-inner *::before, .stage[data-live="0"] .stage-inner *::after,
.motion-off .stage:not([data-force="1"]) .stage-inner *, .motion-off .stage:not([data-force="1"]) .stage-inner *::before, .motion-off .stage:not([data-force="1"]) .stage-inner *::after {
  animation-play-state: paused !important;
}

.entry-body { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px 18px; flex: 1; min-width: 0; }
.entry-sec { display: none; margin: 0; font: 600 0.75rem var(--f-display); color: var(--ink-3); }
.is-searching .entry-sec { display: block; }
.entry-name { margin: 0; font: 720 1.32rem/1.15 var(--f-display); font-stretch: 108%; letter-spacing: -0.012em; text-wrap: balance; }
.entry-name a { color: var(--ink); text-decoration: none; }
.entry-name a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.entry-aka { margin: -4px 0 0; font-size: 0.95rem; color: var(--ink-2); line-height: 1.4; }
.entry-aka i { color: var(--ink-3); margin-right: 2px; }
.entry-def { margin: 0; font-size: 1rem; line-height: 1.5; }
.entry-def code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.entry-how { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.entry-how code {
  display: inline-block; background: var(--code-bg); color: var(--ink); border-radius: 6px;
  padding: 3px 8px; font-size: 0.74rem; line-height: 1.35; overflow-wrap: anywhere;
}
.entry-cf { display: flex; gap: 8px; align-items: baseline; font-size: 0.93rem; line-height: 1.4; }
.cf-label { font-style: italic; color: var(--accent); flex: none; }
.entry-cf ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; min-width: 0; }
.entry-cf a { font: 650 0.86rem var(--f-display); color: var(--ink); text-decoration-color: var(--rule); }
.entry-cf a:hover { text-decoration-color: var(--accent); }
.cf-note { color: var(--ink-2); }
.cf-note::before { content: ": "; }
.entry-prompt { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px 12px; }
.entry-prompt-head { display: flex; justify-content: space-between; align-items: center; }
.entry-prompt-head span { font: 650 0.78rem var(--f-display); color: var(--accent); }
.entry-prompt p { margin: 4px 0 0; font: 400 0.9rem/1.5 var(--f-display); color: var(--ink); }
.entry-lib { margin: 0; font: 400 0.8rem/1.4 var(--f-display); color: var(--ink-2); }
.entry-lib span { font-weight: 650; color: var(--ink-3); margin-right: 4px; }
.entry-foot { margin-top: auto; padding-top: 4px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.entry-vocab { font: 500 0.8rem var(--f-display); }
.entry-foot .add-tray { margin-left: auto; }

/* ---------- empty + elsewhere + footer ---------- */
.empty { padding-block: 24px 48px; max-width: 64ch; }
.empty h2 { font: 720 1.5rem/1.2 var(--f-display); margin: 0 0 8px; text-wrap: balance; }
.empty p { margin: 0; color: var(--ink-2); }
.elsewhere { margin-top: 48px; padding-top: 36px; border-top: 1px solid var(--rule); }
.elsewhere h2 { margin: 0; font: 780 clamp(1.6rem, 3.4cqi, 2.3rem)/1.05 var(--f-display); font-stretch: 115%; letter-spacing: -0.02em; }
.lede { color: var(--ink-2); max-width: 66ch; margin: 8px 0 24px; font-size: 1.05rem; }
.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 22px 36px; margin: 0; }
.refs > div { min-width: 0; }
.refs dt { font: 700 1.05rem var(--f-display); }
.refs dt a { text-decoration: none; }
.refs dt a:hover { text-decoration: underline; }
.refs dd { margin: 4px 0 0; color: var(--ink-2); font-size: 0.98rem; }
.refs code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.is-searching .elsewhere { display: none; }
.foot { margin-top: 56px; color: var(--ink-3); font-size: 0.92rem; }

/* ---------- prompt tray ---------- */
.tray { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.tray-tab {
  order: 2; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font: 650 0.86rem var(--f-display); background: var(--ink); color: var(--paper);
  border: 0; border-radius: 999px; padding: 10px 12px 10px 16px; box-shadow: var(--shadow-pop);
}
.tray-count {
  min-width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 22%, transparent); font-size: 0.78rem; font-variant-numeric: tabular-nums;
}
.tray.has-items .tray-count { background: var(--accent); color: var(--accent-ink); }
.tray-panel {
  order: 1; width: min(440px, calc(100vw - 32px)); max-height: min(70vh, 620px); overflow: auto;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-card); box-shadow: var(--shadow-pop);
  padding: 16px; display: grid; gap: 12px;
}
.tray-head { display: flex; justify-content: space-between; align-items: baseline; }
.tray-head h2 { margin: 0; font: 750 1.1rem var(--f-display); }
.tray-help { margin: 0; color: var(--ink-2); font-size: 0.95rem; }
.tray-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.tray-list li { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; font: 500 0.9rem var(--f-display); }
.tray-list a { color: var(--ink); }
#tray-text {
  width: 100%; resize: vertical; font: 400 0.78rem/1.5 var(--f-mono); color: var(--ink);
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: var(--r-ctl); padding: 10px;
}
.tray-actions { display: flex; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--paper); font: 600 0.88rem var(--f-display);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-pop); max-width: calc(100vw - 32px);
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .frame { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .rail { position: static; padding-block: 14px 0; overflow-x: auto; margin-inline: calc(-1 * clamp(16px, 3vw, 40px)); padding-inline: clamp(16px, 3vw, 40px); scrollbar-width: none; }
  .rail ol { display: flex; gap: 6px; width: max-content; }
  .rail a { border: 1px solid var(--rule); border-radius: 999px; padding: 5px 12px; white-space: nowrap; background: var(--sheet); }
  .rail .rail-elsewhere { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .topbar { grid-template-columns: 1fr auto; padding-block: 8px; }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .search-kbd { display: none; }
  .tbtn { padding: 5px 8px; }
  .formula { padding: 16px; }
  .tray-tab { padding: 9px 10px 9px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .entry.flash { animation: none; outline: 3px solid var(--accent); }
}
