/* Gloss — minimal, editorial, high contrast. */
:root {
  --serif: "Literata", "Noto Serif", "Source Serif 4", Charter, "Iowan Old Style", Georgia, serif;
  --sans: system-ui, -apple-system, "Roboto", "Segoe UI", sans-serif;
  --fs: 18px;
  --measure: 38rem;
  --pad: 20px;
  --app-h: 100dvh;
}
[data-size="1"] { --fs: 16px; }
[data-size="2"] { --fs: 18px; }
[data-size="3"] { --fs: 20.5px; }
[data-size="4"] { --fs: 23px; }

[data-theme="light"] {
  --bg: #FBFAF7; --ink: #121212; --muted: #4F4D48; --rule: #D9D5CC; --soft: #EFECE5;
  --accent: #8E1B1B; --sel: #F3E3A6; color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0E0E0D; --ink: #EDEAE3; --muted: #ABA79F; --rule: #34322E; --soft: #1C1B19;
  --accent: #F2958A; --sel: #5A4A12; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { font-family: var(--serif); line-height: 1.5; overflow: hidden; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--sel); }
::highlight(tap) { background: var(--sel); }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; flex: none; }

/* ---------- layout: view / search bar / tabs, sized to the visible viewport ---------- */
#app {
  height: var(--app-h);
  display: grid;
  grid-template-rows: 1fr auto auto;
  padding-top: env(safe-area-inset-top);
}
#view { overflow-y: auto; overscroll-behavior: contain; outline: none; position: relative; }
.pane { max-width: var(--measure); margin: 0 auto; padding: 0 var(--pad); }

#searchbar {
  display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 10px var(--pad);
  border-top: 1.5px solid var(--ink);
  background: var(--bg);
}
#searchbar .ico { color: var(--muted); }
#q {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-family: var(--serif); font-size: max(1.15rem, 17px); padding: 8px 0;
}
#q::placeholder { color: var(--muted); opacity: 1; }
#q::-webkit-search-cancel-button { display: none; }
.iconbtn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--ink); position: relative; flex: none; }
.iconbtn:active { background: var(--soft); }

#tabs {
  display: flex; align-items: center;
  padding: 0 calc(var(--pad) - 8px) env(safe-area-inset-bottom);
  border-top: 1px solid var(--rule);
  font-family: var(--sans); font-size: 0.78rem; letter-spacing: .08em; text-transform: uppercase;
}
#tabs a { flex: 1; text-align: center; padding: 14px 0 16px; color: var(--muted); text-decoration: none; font-weight: 600; }
#tabs a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 2px 0 var(--ink); }
#tabs .iconbtn { width: 48px; }
.dot { position: absolute; top: 9px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
body.typing #tabs { display: none; }
body.on-saved #searchbar { display: none; }

/* ---------- home ---------- */
.mast { padding: 12vh 0 1.2rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.2rem; }
.brand { font-size: 3.2rem; line-height: 1; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.tagline { margin: .5rem 0 0; color: var(--muted); font-style: italic; }
.kicker { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 1.4rem 0 .4rem; font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; font-style: italic; margin: 1.5rem 0; }
.small { font-family: var(--sans); font-size: .8rem; color: var(--muted); line-height: 1.45; margin: .5rem 0; }

.card { border: 1.5px solid var(--ink); padding: 1rem 1.1rem; margin: 1rem 0; }
.card h2 { font-size: 1.05rem; margin: 0 0 .3rem; }
.card p { margin: 0 0 .8rem; font-size: .92rem; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  font-family: var(--sans); font-size: .82rem; font-weight: 600; letter-spacing: .02em;
  padding: 10px 16px; border: 1.5px solid var(--ink); min-height: 44px;
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn:disabled { opacity: .5; }
.textbtn { font-family: var(--sans); font-size: .82rem; font-weight: 600; color: var(--ink); padding: 10px 4px; min-height: 44px; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.bar { height: 4px; background: var(--soft); margin: .6rem 0 .4rem; }
.bar > i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s linear; }

.wordlist { list-style: none; margin: 0; padding: 0; }
.wordlist li a { display: block; padding: 10px 0; border-bottom: 1px solid var(--rule); color: var(--ink); text-decoration: none; font-size: 1.05rem; }

/* ---------- results (best match sits nearest the thumb) ---------- */
#results { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.results { list-style: none; margin: 0; padding: 0 0 4px; display: flex; flex-direction: column-reverse; }
.results li a {
  display: block; padding: 11px 0 10px; border-bottom: 1px solid var(--rule);
  color: var(--ink); text-decoration: none; min-height: 48px;
}
.results li:first-child a { border-bottom: 0; }
.results .w { font-size: 1.12rem; font-weight: 600; }
.results .w b { font-weight: 400; color: var(--muted); }
.results .g { display: block; font-family: var(--sans); font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.results li.sel .w::after { content: "↵"; font-family: var(--sans); font-size: .75rem; color: var(--muted); margin-left: .5em; font-weight: 400; }
.results .none { padding: 1rem 0; color: var(--muted); font-style: italic; }
.results .head { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: .8rem 0 .2rem; font-weight: 600; }
.tag {
  font-family: var(--sans); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); font-weight: 700; margin-left: .45em; vertical-align: .15em;
}

/* ---------- entry ---------- */
#entry { padding-top: 1.4rem; padding-bottom: 2.5rem; }
.hw { display: flex; align-items: flex-start; gap: 8px; }
.hw h1 { flex: 1; margin: 0; font-size: 2.3rem; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.savebtn { width: 48px; height: 48px; margin-top: -4px; }
.savebtn svg { width: 26px; height: 26px; }
.savebtn[aria-pressed="true"] svg { fill: var(--ink); }
.pron { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: .5rem 0 .2rem; }
.ipa { font-family: "Noto Sans", "Doulos SIL", "Charis SIL", var(--sans); font-size: .98rem; }
.ipa small { font-family: var(--sans); font-size: .62rem; letter-spacing: .1em; color: var(--muted); margin-right: .35em; font-weight: 700; }
.speak { display: inline-flex; align-items: center; gap: 6px; font-family: var(--sans); font-size: .75rem; font-weight: 600; color: var(--ink); padding: 8px 12px 8px 8px; border: 1px solid var(--rule); border-radius: 999px; min-height: 40px; }
.speak svg { width: 18px; height: 18px; }
.speak.busy { border-color: var(--ink); }

.ety-n { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin: 1.6rem 0 0; padding-top: .8rem; border-top: 1px solid var(--rule); }
.pos { margin: 1.3rem 0 .2rem; font-style: italic; font-weight: 400; font-size: 1.12rem; }
.forms { font-family: var(--sans); font-size: .78rem; color: var(--muted); margin: 0 0 .5rem; line-height: 1.4; }
ol.senses { list-style: none; margin: .4rem 0 0; padding: 0; counter-reset: s; }
ol.senses li { position: relative; padding-left: 1.9em; margin: 0 0 .75rem; }
ol.senses li .n { position: absolute; left: 0; top: 0; font-family: var(--sans); font-weight: 700; font-size: .82rem; line-height: 1.85; min-width: 1.4em; }
ol.senses li.d1 { margin-left: 1.9em; padding-left: 1.5em; }
ol.senses li.d1 .n { font-weight: 600; color: var(--muted); }
ol.senses li.d2 { margin-left: 3.4em; padding-left: 1.2em; }
.lab { font-family: var(--sans); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-right: .5em; }
.ex { display: block; font-style: italic; color: var(--muted); margin-top: .2rem; }
.qt { display: block; margin: .45rem 0 .1rem; padding-left: .8em; border-left: 2px solid var(--rule); font-size: .93rem; }
.qt cite { display: block; font-style: normal; font-family: var(--sans); font-size: .72rem; color: var(--muted); margin-top: .15rem; }
.qt .en { display: block; color: var(--muted); font-style: italic; }
.syn { display: block; font-family: var(--sans); font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.syn button { color: var(--ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; padding: 2px 0; font-size: inherit; font-family: inherit; }
.of { font-family: var(--sans); font-size: .85rem; }
.of button { font-family: var(--serif); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; font-size: 1rem; }
body:not(.show-quotes) .qt { display: none; }
details.etym { margin: 1rem 0 0; }
details.etym summary { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--muted); cursor: pointer; padding: 8px 0; list-style: none; }
details.etym summary::-webkit-details-marker { display: none; }
details.etym summary::before { content: "+ "; }
details.etym[open] summary::before { content: "– "; }
details.etym p { margin: .2rem 0 0; font-size: .95rem; }
.qtoggle { margin: 1.2rem 0 0; }
.base { margin-top: 2rem; padding-top: 1rem; border-top: 1.5px solid var(--ink); }
.base .hw h1 { font-size: 1.7rem; }
.base .kicker { margin-top: 0; }
.foot { margin-top: 2.2rem; padding-top: .8rem; border-top: 1px solid var(--rule); }
.foot a { color: var(--muted); }
.crumbs { font-family: var(--sans); font-size: .75rem; color: var(--muted); margin-bottom: .6rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.crumbs button { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; font-size: inherit; font-family: inherit; padding: 4px 0; }
.missing { padding: 3rem 0; }
.missing h1 { font-size: 1.6rem; margin: 0 0 .5rem; }

/* ---------- saved ---------- */
.pagehead { padding-top: 1.4rem; position: sticky; top: 0; background: var(--bg); z-index: 1; padding-bottom: .4rem; border-bottom: 1px solid var(--rule); }
.pagetitle { font-size: 2rem; margin: 0 0 .7rem; }
.count { font-family: var(--sans); font-size: .9rem; color: var(--muted); font-weight: 500; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); margin: 0 8px 8px 0; }
.seg button { font-family: var(--sans); font-size: .78rem; font-weight: 600; padding: 9px 14px; min-height: 40px; min-width: 44px; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.tools { display: flex; gap: 16px; }
.savedlist { list-style: none; margin: 0; padding: 0 0 2rem; }
.savedlist li { display: flex; align-items: flex-start; gap: 8px; border-bottom: 1px solid var(--rule); }
.savedlist a { flex: 1; min-width: 0; padding: 12px 0; color: var(--ink); text-decoration: none; }
.savedlist .w { font-size: 1.15rem; font-weight: 600; }
.savedlist .g { display: block; font-size: .92rem; color: var(--muted); margin-top: 2px; }
.savedlist .when { font-family: var(--sans); font-size: .7rem; color: var(--muted); margin-left: .5em; font-weight: 500; }
.reviewing .savedlist .g { filter: blur(6px); opacity: .7; transition: filter .15s; }
.reviewing .savedlist li.reveal .g { filter: none; opacity: 1; }
.learn { width: 48px; height: 48px; margin-top: 4px; color: var(--muted); }
.learn svg { width: 22px; height: 22px; }
.learn[aria-pressed="true"] { color: var(--ink); }
.learn[aria-pressed="true"] circle { fill: var(--ink); }
.learn[aria-pressed="true"] path { stroke: var(--bg); }
.learned .w { color: var(--muted); }

/* ---------- settings sheet ---------- */
dialog#settings {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 88dvh;
  background: var(--bg); color: var(--ink); border-top: 1.5px solid var(--ink);
}
dialog#settings::backdrop { background: rgba(0,0,0,.45); }
@media (min-width: 640px) { dialog#settings { margin: auto; max-width: 30rem; border: 1.5px solid var(--ink); } }
.sheet { padding: 0 var(--pad) calc(1.5rem + env(safe-area-inset-bottom)); }
.sheethead { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg); padding: .6rem 0; border-bottom: 1px solid var(--rule); }
.sheethead h2 { margin: 0; font-size: 1.3rem; }
fieldset { border: 0; padding: 0; margin: 1.1rem 0 0; }
legend { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--muted); margin-bottom: .5rem; padding: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(120px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); font-family: var(--sans); font-size: .82rem; font-weight: 600;
  padding: 10px 16px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; max-width: 90vw; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

#offline-status h2 { font-size: 1.05rem; margin: 0 0 .3rem; }
#offline-status p { font-size: .92rem; color: var(--muted); margin: 0 0 .8rem; }
