/* study — warm, minimal, sans throughout. One accent for actions; each deck gets
   its own identity hue (--h, set inline) for the roundel and progress bar. */

:root {
  color-scheme: light dark;
  --bg: #faf7f1;
  --fg: #211d16;
  --dim: #90887a;
  --line: #e7dfd1;
  --card: #fffdf8;
  --shadow: 0 1px 2px rgb(60 50 30 / 0.05), 0 6px 24px -12px rgb(60 50 30 / 0.18);
  --accent: #3b7a57;
  --accent-fg: #f6fbf7;
  /* verdict colors from the desktop app's light theme */
  --ok: #79740e;
  --bad: #9d0006;
  /* playing-animation bars: light, not accent; near-white where the theme
     allows, a light warm neutral on the cream card where white would vanish */
  --bars: #d5cebf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171511;
    --fg: #eae5da;
    --dim: #8f887a;
    --line: #2e2a22;
    --card: #201d17;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 28px -14px rgb(0 0 0 / 0.6);
    --accent: #6fbb92;
    --accent-fg: #10201a;
    /* verdict colors from the desktop app's dark theme */
    --ok: #22c55e;
    --bad: #ef4444;
    --bars: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}
.page { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ---- header ---- */
.bar {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  width: min(42rem, 100%);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.6rem;
}
.bar.home {
  flex-direction: column;
  gap: 0;
  align-items: center;
  padding-top: 3.5rem;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  color: var(--accent);
  text-decoration: none;
}
.bar.home .brand { font-size: 2.2rem; }
.bartitle {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crumb { color: var(--dim); font-weight: 500; text-decoration: none; }
.crumb:hover { color: var(--fg); }
.grouptitle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.9rem;
}
.grouptitle .roundel { width: 2.3rem; height: 2.3rem; font-size: 1.05rem; }
.barleft {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
}
.barright {
  flex: none;
  display: flex;
  gap: 0.75rem;
}
.bar form { margin: 0; }

/* session menu: a kebab in the corner so long deck names keep the line */
.menu { position: relative; }
.menu > summary {
  list-style: none;
  cursor: pointer;
  color: var(--dim);
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.1rem 0.5rem;
  border-radius: 6px;
  user-select: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover, .menu[open] > summary { color: var(--fg); }
.menuitems {
  position: absolute;
  right: 0;
  top: 1.7rem;
  z-index: 10;
  min-width: 10rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  display: grid;
  gap: 0.1rem;
}
.menuitems button {
  width: 100%;
  text-align: left;
  border: 0;
  box-shadow: none;
  background: none;
  color: var(--fg);
  font-size: 0.9rem;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
}
.menuitems button:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); }

/* The status strip above the card, as on the desktop: counter left, live
   tally dead center. The side zones flex equally to anchor the centering. */
.cardstatus {
  display: flex;
  align-items: baseline;
  margin-bottom: 0.45rem;
  font-size: 0.85rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cardstatus .pos { flex: 1; }
.cardstatus .statuspad { flex: 1; }
.cardstatus .tally { display: inline-flex; gap: 0.9rem; }

/* session progress: a hairline under the header, filled in the deck's hue */
.progress {
  width: min(42rem, 100%);
  margin: 0 auto;
  height: 3px;
  padding: 0 1.25rem;
}
.progress i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: hsl(var(--h) 45% 55%);
  transition: width 0.4s ease;
}
.progress.ghost i { display: none; }

/* ---- layout: the card is the stage, vertically centered ---- */
main {
  flex: 1;
  width: min(42rem, 100%);
  margin: 0 auto;
  padding: 0.9rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
}
main.list { padding-top: 2.5rem; }

.ok { color: var(--ok); }
.bad { color: var(--bad); }
.dim { color: var(--dim); }
.center { text-align: center; }

/* ---- the card ---- */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.75rem 2rem 1.9rem;
  margin: 0 0 1.1rem;
  text-align: center;
  animation: rise 0.22s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}
.cardtext {
  margin: 0.5rem 0 0.15rem;
  font-size: 1.05rem;
  color: var(--dim);
  overflow-wrap: break-word;
}
.cardtext.primary {
  font-size: 2.2rem;
  line-height: 1.5;
  color: var(--fg);
  margin: 0.55rem 0 0.3rem;
}
.answerside .cardtext.primary { font-size: 1.55rem; }
.cardimg {
  display: block;
  max-width: 100%;
  max-height: 34vh;
  margin: 0.9rem auto;
  border-radius: 10px;
}
.divider { border: 0; border-top: 1px solid var(--line); margin: 1.1rem 0 0.9rem; }

/* ---- custom audio player: a quiet outline button, not a billboard ---- */
.player { margin: 0.7rem 0 0.3rem; }
.play {
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.play:hover { color: var(--accent); }
.play:active { transform: scale(0.94); }
.play .icon { width: 18px; height: 18px; }

/* The cue's audio docks flush into the card's top-right corner: the
   button's outer corner continues the card border on the same curve, the
   inner corner answers it. Only the question side (a direct child of the
   card) docks — answer-side audio stays inline. */
.card > .player {
  position: absolute;
  top: -1px;
  right: -1px;
  margin: 0;
}
.card > .player .play {
  width: 3rem;
  height: 3rem;
  /* Only the tab's own two sides are drawn — the top and right would
     stack on the card's border and render darker than every other line. */
  border: 1px solid var(--line);
  border-top: 0;
  border-right: 0;
  border-radius: 0 16px 0 16px;
}
.play .bars { display: none; align-items: flex-end; gap: 2.5px; height: 15px; }
.play .bars i {
  width: 3.5px;
  border-radius: 2px;
  background: var(--bars);
  animation: bounce 0.9s ease-in-out infinite;
}
.play .bars i:nth-child(1) { height: 8px; }
.play .bars i:nth-child(2) { height: 14px; animation-delay: 0.15s; }
.play .bars i:nth-child(3) { height: 10px; animation-delay: 0.3s; }
@keyframes bounce { 50% { transform: scaleY(0.45); } }
.player.playing .play { color: var(--accent); }
.player.playing .icon { display: none; }
.player.playing .bars { display: inline-flex; }
.player audio { display: none; }

/* ---- badges ---- */
.badges { min-height: 1.3rem; margin-bottom: 0.2rem; display: flex; gap: 0.45rem; }
.badge {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.14rem 0.55rem;
  border-radius: 99px;
}
.badge.new { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.retry { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.ahead { color: var(--dim); background: color-mix(in srgb, var(--dim) 14%, transparent); }
.badge.timer {
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  font-variant-numeric: tabular-nums;
}
.badge.timer.low { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }

/* ---- controls ---- */
button {
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem 1.3rem;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
button:hover { border-color: var(--dim); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.07); }
button.quiet {
  border: 0;
  background: none;
  color: var(--dim);
  padding: 0 0.2rem;
  font-size: 0.85rem;
}
button.quiet:hover { color: var(--fg); }

.typed { display: flex; gap: 0.7rem; }
.typed input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.2rem;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 1rem;
  box-shadow: var(--shadow);
}
.typed input::placeholder { color: var(--dim); }
.typed input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.choices { display: grid; gap: 0.5rem; }
.choice {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-align: left;
  font-size: 1.1rem;
  padding: 0.5rem 1rem;
  box-shadow: var(--shadow);
}
.choice:hover { border-color: var(--accent); }
.choice kbd {
  flex: none;
  font: 0.78rem/1.5 ui-monospace, monospace;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 0.4rem;
}

.actions { display: flex; gap: 0.7rem; justify-content: center; margin: 0.4rem 0 0; }
.actions button { min-width: 11rem; padding: 0.7rem 1.4rem; }

/* ---- result ---- */
.verdict {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  margin: 0 0 0.6rem;
  animation: rise 0.3s ease-out;
}
.card.won { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.card.lost { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.typedanswer { color: var(--dim); margin: 0.2rem 0 0.4rem; }
.typedanswer s { color: var(--bad); text-decoration-thickness: 1.5px; }
.confused {
  color: var(--dim);
  font-size: 0.95rem;
  margin-top: 0.9rem;
}

/* ---- caught up / summary ---- */
.card.standalone { padding: 2.6rem 2rem; }
.bigmark { font-size: 2.6rem; margin: 0 0 0.4rem; color: var(--ok); }
.lede { font-size: 1.7rem; font-weight: 700; margin: 0 0 0.7rem; }
.score { font-size: 1.15rem; margin: 0.2rem 0 0.6rem; }
.backlink { margin-top: 1.6rem; }
.backlink a { text-decoration: none; }
.backlink a:hover { color: var(--fg); }

/* ---- deck picker ---- */
.decklist {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  display: grid;
  gap: 0.8rem;
}
.decklist li { display: flex; gap: 0.6rem; align-items: stretch; }
.decklist li .deck { flex: 1; min-width: 0; }
.decklist li form { display: flex; }
.flipbtn {
  color: var(--dim);
  font-size: 0.85rem;
  border-radius: 14px;
  padding: 0 1rem;
  animation: rise 0.25s ease-out;
}
.flipbtn:hover { color: var(--accent); }
.deck {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.12s ease, border-color 0.15s ease;
  animation: rise 0.25s ease-out;
}
.deck:hover { transform: translateY(-1px); border-color: hsl(var(--h) 40% 60%); }
.deck:hover .go { transform: translateX(3px); color: var(--fg); }
.roundel {
  flex: none;
  width: 2.9rem;
  height: 2.9rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 700;
  background: hsl(var(--h) 45% 90%);
  color: hsl(var(--h) 45% 28%);
}
@media (prefers-color-scheme: dark) {
  .roundel { background: hsl(var(--h) 30% 24%); color: hsl(var(--h) 45% 78%); }
}
.deck.topic { padding: 0.8rem 1.25rem; }
.deck.topic .deckname { font-size: 1.05rem; }
.deckinfo { min-width: 0; }
.deckname {
  display: block;
  font-weight: 700;
  font-size: 1.25rem;
}
.deckmeta { color: var(--dim); font-size: 0.88rem; }
.deckmeta .due { color: var(--accent); font-weight: 600; }
.deckmeta .done { color: var(--ok); font-weight: 600; }
.go { margin-left: auto; color: var(--dim); font-size: 1.2rem; transition: transform 0.12s ease; }

.contact {
  margin-top: 2.5rem;
  text-align: center;
  font-size: 0.85rem;
}
.contact a { color: var(--dim); text-decoration: none; }
.contact a:hover { color: var(--fg); }

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

@media (max-width: 480px) {
  .card { padding: 1.3rem 1.2rem 1.4rem; border-radius: 14px; }
  .card > .player .play { border-radius: 0 14px 0 14px; }
  .cardtext.primary { font-size: 1.6rem; }
  .bar { padding-top: 0.8rem; }
  .actions button { min-width: 0; flex: 1; }
}
