/* ── Learn Cebuano ─────────────────────────────────────────────────────────
   Palette leans on Philippine flag colours: deep blue ink, flag red as the
   primary accent, sun-gold as the secondary. Both themes are authored; the
   `data-theme` attribute on <html> overrides the media query in both
   directions so the toggle always wins.
   ─────────────────────────────────────────────────────────────────────── */

:root {
  --bg: #fbf8f3;
  --bg-soft: #f3ede3;
  --surface: #ffffff;
  --surface-2: #f7f3ec;
  --border: #e2d9c9;
  --border-strong: #cdc0aa;
  --text: #1d1a16;
  --text-soft: #5c554b;
  --text-faint: #8a8175;
  --accent: #c1272d;          /* flag red */
  --accent-soft: #f7e4e3;
  --accent-text: #ffffff;
  --gold: #b8860b;
  --gold-soft: #fbf1d6;
  --blue: #14418b;
  --good: #17694a;
  --good-soft: #e0f0e6;
  --bad: #a8271f;
  --bad-soft: #fbe5e2;
  --shadow: 0 1px 2px rgba(29, 26, 22, .05), 0 12px 32px -12px rgba(29, 26, 22, .18);
  --radius: 18px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e;
    --bg-soft: #1a1714;
    --surface: #1c1917;
    --surface-2: #24201d;
    --border: #322c27;
    --border-strong: #463e37;
    --text: #f5f0e8;
    --text-soft: #b6ada1;
    --text-faint: #857c72;
    --accent: #e8484c;
    --accent-soft: #33191a;
    --accent-text: #1a0e0e;
    --gold: #e5b45c;
    --gold-soft: #2b2317;
    --blue: #6f9be8;
    --good: #6cd9a0;
    --good-soft: #16281f;
    --bad: #f0736b;
    --bad-soft: #2c1917;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px -14px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="light"] {
  --bg: #fbf8f3; --bg-soft: #f3ede3; --surface: #ffffff; --surface-2: #f7f3ec;
  --border: #e2d9c9; --border-strong: #cdc0aa;
  --text: #1d1a16; --text-soft: #5c554b; --text-faint: #8a8175;
  --accent: #c1272d; --accent-soft: #f7e4e3; --accent-text: #ffffff;
  --gold: #b8860b; --gold-soft: #fbf1d6; --blue: #14418b;
  --good: #17694a; --good-soft: #e0f0e6; --bad: #a8271f; --bad-soft: #fbe5e2;
  --shadow: 0 1px 2px rgba(29, 26, 22, .05), 0 12px 32px -12px rgba(29, 26, 22, .18);
}

:root[data-theme="dark"] {
  --bg: #12100e; --bg-soft: #1a1714; --surface: #1c1917; --surface-2: #24201d;
  --border: #322c27; --border-strong: #463e37;
  --text: #f5f0e8; --text-soft: #b6ada1; --text-faint: #857c72;
  --accent: #e8484c; --accent-soft: #33191a; --accent-text: #1a0e0e;
  --gold: #e5b45c; --gold-soft: #2b2317; --blue: #6f9be8;
  --good: #6cd9a0; --good-soft: #16281f; --bad: #f0736b; --bad-soft: #2c1917;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px -14px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

/* Several elements below set `display`, which would otherwise beat the UA
   stylesheet's rule for the `hidden` attribute and leave them on screen. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Subtle warm glow behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(60% 45% at 50% -5%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    radial-gradient(45% 40% at 92% 8%, color-mix(in srgb, var(--gold) 10%, transparent), transparent 70%);
}

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

.skip-link {
  position: absolute; left: -999px; top: .5rem; z-index: 100;
  background: var(--surface); color: var(--text); padding: .6rem 1rem;
  border-radius: 10px; border: 1px solid var(--border);
}
.skip-link:focus { left: .5rem; }

:where(button, select, input, a):focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

/* ── Top bar ───────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .85rem clamp(.9rem, 3vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: .55rem; font-size: 1.05rem; }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-text { letter-spacing: -.01em; color: var(--text-soft); }
.brand-text strong { color: var(--text); font-weight: 700; }

.tabs {
  display: flex;
  gap: .25rem;
  margin-inline: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: .9rem;
  padding: .45rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.icon-btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 2.4rem; height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  transition: color .18s, border-color .18s, background .18s;
  flex: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn-sm { width: 2rem; height: 2rem; border-color: transparent; background: transparent; }

/* Show the icon for the theme you'd switch *to*. */
.i-moon { display: none; }
@media (prefers-color-scheme: dark) { .i-sun { display: none; } .i-moon { display: block; } }
:root[data-theme="light"] .i-sun  { display: none; }
:root[data-theme="light"] .i-moon { display: block; }
:root[data-theme="dark"]  .i-sun  { display: block; }
:root[data-theme="dark"]  .i-moon { display: none; }

/* ── Layout ────────────────────────────────────────────────────────────── */

main { flex: 1; width: 100%; max-width: 62rem; margin: 0 auto; padding: clamp(1.1rem, 3vw, 2.2rem) clamp(.9rem, 3vw, 1.5rem); }

.view { display: none; }
.view.is-active { display: block; animation: fade .25s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Flashcard ─────────────────────────────────────────────────────────── */

.flash-wrap { max-width: 40rem; margin: 0 auto; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: clamp(1.3rem, 4vw, 2.1rem);
  overflow: hidden;
}

/* Thin gradient rule along the top edge. */
.card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold) 55%, var(--blue));
}

.card.is-swapping { animation: swap .38s ease; }
@keyframes swap {
  0%   { opacity: .25; transform: translateY(8px) scale(.995); }
  100% { opacity: 1;   transform: none; }
}

.card-top { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; }
.spacer { flex: 1; }

.chip {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 650;
  padding: .22rem .6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.chip-quiet { background: var(--surface-2); color: var(--text-faint); }

#star-btn[aria-pressed="true"] { color: var(--gold); }
#star-btn[aria-pressed="true"] svg path { fill: var(--gold); }

.ceb {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.05;
  margin: .2rem 0 1.1rem;
  overflow-wrap: break-word;
  hyphens: auto;
}

.translations { display: grid; gap: .55rem; }
.translations.is-hidden { visibility: hidden; height: 0; overflow: hidden; margin: 0; }

.tr {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: .6rem .85rem;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.tr-label {
  flex: none;
  width: 4.6rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 650;
  color: var(--text-faint);
}
.tr-value { font-size: clamp(1.05rem, 3.6vw, 1.3rem); font-weight: 550; }

.reveal-btn {
  width: 100%;
  appearance: none;
  border: 1.5px dashed var(--border-strong);
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  padding: 1.15rem;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .18s, color .18s;
}
.reveal-btn:hover { border-color: var(--accent); color: var(--accent); }

.example {
  margin: 1.1rem 0 0;
  padding: .85rem 0 0;
  border-top: 1px solid var(--border);
}
.example blockquote {
  margin: 0;
  font-size: 1.02rem;
  font-style: italic;
  color: var(--text);
}
.example figcaption { margin-top: .2rem; font-size: .9rem; color: var(--text-faint); }

.note {
  margin: .9rem 0 0;
  padding: .6rem .75rem;
  font-size: .87rem;
  background: var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
  color: var(--text-soft);
}

/* Controls */

.controls { display: flex; align-items: center; justify-content: center; gap: 1.4rem; margin: 1.4rem 0 .4rem; }

.ctl {
  appearance: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  width: 2.9rem; height: 2.9rem;
  transition: color .18s, border-color .18s, transform .12s;
}
.ctl:hover { color: var(--text); border-color: var(--border-strong); }
.ctl:active { transform: scale(.94); }

.ctl-timer {
  position: relative;
  width: 3.9rem; height: 3.9rem;
  border: 0;
  background: transparent;
}
.ring { position: absolute; inset: 0; transform: rotate(-90deg); width: 100%; height: 100%; }
.ring-track { stroke: var(--border); }
.ring-fill { stroke: var(--accent); transition: stroke-dashoffset .95s linear; }
.ctl-timer[aria-pressed="true"] .ring-fill { stroke: var(--text-faint); transition: none; }

.countdown {
  position: relative;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}
.ctl-timer[aria-pressed="true"] .countdown { color: var(--text-faint); }

/* Options row under the card */

.flash-opts {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem 1.4rem;
  align-items: end;
  justify-content: center;
  margin-top: 1.2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}

.field { display: grid; gap: .3rem; font-size: .82rem; color: var(--text-faint); }
.field > span { font-weight: 600; letter-spacing: .01em; }

select, input[type="search"] {
  appearance: none;
  font: inherit;
  font-size: .92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .5rem 2rem .5rem .7rem;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1.05rem center, right .8rem center;
  background-size: .28rem .28rem, .28rem .28rem;
  background-repeat: no-repeat;
}
input[type="search"] { background-image: none; padding-right: .7rem; cursor: text; }

.check { display: flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--text-soft); cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); cursor: pointer; }

.seen-line { text-align: center; font-size: .82rem; color: var(--text-faint); margin: 1rem 0 0; }

/* ── Panels (quiz + browse) ────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.2rem, 4vw, 2rem);
  max-width: 44rem;
  margin: 0 auto;
}

.panel h2 { margin: 0 0 .35rem; font-size: 1.45rem; letter-spacing: -.02em; }
.panel h3 { margin: 1.6rem 0 .6rem; font-size: 1.05rem; }
.lede { margin: 0 0 1.4rem; color: var(--text-soft); font-size: .95rem; }

.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.setup-grid select { width: 100%; }

.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  padding: .7rem 1.4rem;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform .12s, filter .18s, background .18s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  width: 100%;
}

.link-btn {
  appearance: none; border: 0; background: none; font: inherit; font-size: .85rem;
  color: var(--text-faint); text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer; padding: 0; margin-top: 1.5rem;
}
.link-btn:hover { color: var(--accent); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 1rem;
  margin: 1.8rem 0 0;
  padding-top: 1.3rem;
  border-top: 1px solid var(--border);
}
.stats dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 650; }
.stats dd { margin: .15rem 0 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Quiz in play */

.q-head { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.8rem; }
.q-progress, .q-score { font-size: .82rem; font-variant-numeric: tabular-nums; color: var(--text-faint); font-weight: 650; flex: none; }
.q-score::before { content: "✓ "; color: var(--good); }
.q-bar { flex: 1; height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.q-bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 999px; transition: width .3s ease; }

.q-prompt-label { margin: 0; font-size: .85rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .07em; font-weight: 650; text-align: center; }
.q-word {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -.03em;
  text-align: center;
  margin: .3rem 0 1.7rem;
  overflow-wrap: break-word;
}

.options { display: grid; gap: .6rem; }

.opt {
  appearance: none;
  font: inherit;
  font-size: 1rem;
  text-align: left;
  padding: .9rem 1.1rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .8rem;
  transition: border-color .15s, background .15s, transform .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:active:not(:disabled) { transform: scale(.99); }
.opt:disabled { cursor: default; }

.opt-key {
  flex: none;
  display: grid; place-items: center;
  width: 1.6rem; height: 1.6rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 650;
  color: var(--text-faint);
}

.opt.is-right { border-color: var(--good); background: var(--good-soft); }
.opt.is-right .opt-key { border-color: var(--good); color: var(--good); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.is-wrong .opt-key { border-color: var(--bad); color: var(--bad); }
.opt.is-dim { opacity: .5; }

.q-foot { min-height: 3.2rem; display: flex; align-items: center; gap: 1rem; margin-top: 1.2rem; flex-wrap: wrap; }
.q-feedback { margin: 0; font-size: .95rem; font-weight: 550; flex: 1; min-width: 12rem; }
.q-feedback.is-right { color: var(--good); }
.q-feedback.is-wrong { color: var(--bad); }

/* Quiz results */

.score-hero { text-align: center; margin: 1.5rem 0 2rem; }
.score-big { display: block; font-family: var(--font-display); font-size: clamp(3.4rem, 15vw, 5rem); font-weight: 700; letter-spacing: -.04em; line-height: 1; color: var(--accent); }
.score-sub { display: block; margin-top: .4rem; color: var(--text-soft); }

.done-actions { display: flex; flex-wrap: wrap; gap: .7rem; }
.done-actions .btn { flex: 1; min-width: 12rem; }
.done-actions .btn-primary { width: auto; }

.missed { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.missed li {
  padding: .7rem .9rem;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--bad);
  font-size: .93rem;
}
.missed .m-ceb { font-weight: 700; font-size: 1.05rem; }
.missed .m-tr { color: var(--text-soft); }
.missed .m-tr span { color: var(--text-faint); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }

/* ── Browse ────────────────────────────────────────────────────────────── */

.browse-bar { display: flex; gap: .7rem; flex-wrap: wrap; margin: 1.1rem 0 .5rem; }
.browse-bar input[type="search"] { flex: 1; min-width: 12rem; }

.result-count { font-size: .82rem; color: var(--text-faint); margin: 0 0 .8rem; }

.table-scroll { overflow-x: auto; }

.words { width: 100%; border-collapse: collapse; font-size: .93rem; }
.words th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border-strong);
  position: sticky; top: 0;
  background: var(--surface);
}
.words td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.words tbody tr:hover { background: var(--surface-2); }
.words .w-ceb { font-weight: 650; }
.words .col-cat { color: var(--text-faint); }
.words td.col-cat { font-size: .8rem; color: var(--text-faint); }
.col-save { width: 2.2rem; }
.save-cell { text-align: right; }
.save-btn {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: var(--border-strong); padding: .1rem; line-height: 1;
}
.save-btn:hover { color: var(--gold); }
.save-btn[aria-pressed="true"] { color: var(--gold); }
.save-btn[aria-pressed="true"] svg path { fill: var(--gold); }

#load-more { margin: 1.1rem auto 0; display: block; }

.empty { text-align: center; color: var(--text-faint); padding: 2.5rem 1rem; }

/* ── Footer + toast ────────────────────────────────────────────────────── */

.footer {
  text-align: center;
  padding: 2rem 1.2rem 2.6rem;
  color: var(--text-faint);
  font-size: .84rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.footer p { margin: .2rem 0; }
.footer-small { font-size: .78rem; opacity: .8; max-width: 34rem; margin-inline: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--text);
  color: var(--bg);
  padding: .6rem 1.1rem;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 550;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  pointer-events: none;
}
.toast.is-up { opacity: 1; transform: translateX(-50%); }

@media (max-width: 34rem) {
  .topbar { gap: .6rem; }
  .brand-text { display: none; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; text-align: center; padding: .45rem .6rem; }
  .brand { margin-right: auto; }
  .tr-label { width: 3.9rem; }
  .col-cat { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
