:root {
  --bg: #0a0f1e;
  --bg-2: #060a14;
  --panel: #131a2c;
  --panel-hi: #1a2540;
  --ink: #e6e8ee;
  --muted: #7d8aa6;
  --line: #232a3d;
  --accent: #6ea8ff;
  --moon: #f5e2a3;
  --good: #4ade80;
  --danger: #f87171;
  --card-bg: #f6f0dc;      /* warm parchment for cards */
  --card-ink: #1c1a12;
  --card-mute: #6b6555;
  --cat-math:      #6ea8ff;
  --cat-science:   #4ade80;
  --cat-language:  #c084fc;
  --cat-history:   #f5b342;
  --cat-arts:      #f472b6;
  --cat-riddles:   #facc15;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(230, 232, 238, .35), transparent 50%),
    radial-gradient(1px 1px at 70% 20%, rgba(230, 232, 238, .30), transparent 50%),
    radial-gradient(1px 1px at 80% 60%, rgba(230, 232, 238, .25), transparent 50%),
    radial-gradient(1px 1px at 40% 70%, rgba(230, 232, 238, .35), transparent 50%),
    radial-gradient(1px 1px at 15% 85%, rgba(230, 232, 238, .30), transparent 50%),
    radial-gradient(2px 2px at 55% 40%, rgba(245, 226, 163, .4), transparent 50%),
    radial-gradient(circle at 50% -40%, #1c2846 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  user-select: none;
}
body {
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============ card view ============ */
main#card-view {
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: .75rem;
  padding: .75rem;
  min-height: 0;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .65rem;
}
.top-bar .badges { display: flex; gap: .35rem; }
.top-bar .counter { color: var(--muted); font-size: .75rem; margin-left: auto; font-family: ui-monospace, Menlo, monospace; }
.top-bar .leave-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .2rem .55rem;
  font: inherit; font-size: .72rem;
  cursor: pointer;
}
.top-bar .leave-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Filter button: opens the mid-session filter panel. The compact "summary"
   span only shows text when a non-default filter is active — passive gear
   icon otherwise. When active, uses the moon accent so you notice the pool
   is narrowed. */
.top-bar .filter-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .2rem .55rem;
  font: inherit; font-size: .72rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.top-bar .filter-btn:hover { color: var(--moon); border-color: var(--moon); }
.top-bar .filter-btn.active {
  color: var(--bg);
  background: var(--moon);
  border-color: var(--moon);
  font-weight: 700;
}
.top-bar .filter-btn .filter-icon { font-size: .85rem; line-height: 1; }
.top-bar .filter-btn .filter-summary { display: none; }
.top-bar .filter-btn.active .filter-summary { display: inline; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-family: ui-monospace, Menlo, monospace;
}
.badge.cat   { background: rgba(110, 168, 255, .18); color: var(--accent); border: 1px solid rgba(110, 168, 255, .35); }
.badge.diff  { background: rgba(245, 226, 163, .12); color: var(--moon); border: 1px solid rgba(245, 226, 163, .35); }
.badge.diff.easy    { color: var(--good);   border-color: rgba(74, 222, 128, .35);  background: rgba(74, 222, 128, .12); }
.badge.diff.medium  { color: var(--moon);   border-color: rgba(245, 226, 163, .35); background: rgba(245, 226, 163, .12); }
.badge.diff.stretch { color: var(--danger); border-color: rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .12); }

.badge.cat[data-cat="math"]     { background: rgba(110, 168, 255, .18); color: var(--cat-math); border-color: rgba(110, 168, 255, .35); }
.badge.cat[data-cat="science"]  { background: rgba(74, 222, 128, .16);  color: var(--cat-science); border-color: rgba(74, 222, 128, .35); }
.badge.cat[data-cat="language"] { background: rgba(192, 132, 252, .16); color: var(--cat-language); border-color: rgba(192, 132, 252, .35); }
.badge.cat[data-cat="history"]  { background: rgba(245, 179, 66, .16);  color: var(--cat-history); border-color: rgba(245, 179, 66, .35); }
.badge.cat[data-cat="arts"]     { background: rgba(244, 114, 182, .16); color: var(--cat-arts); border-color: rgba(244, 114, 182, .35); }
.badge.cat[data-cat="riddles"]  { background: rgba(250, 204, 21, .16);  color: var(--cat-riddles); border-color: rgba(250, 204, 21, .35); }

/* ============ the flip card ============ */
/* Stage sets the perspective; flip is the rotating box; face is either side.
   Uses GPU-composited rotateY — Pi-safe. */
.card-stage {
  perspective: 1400px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.flip {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  transform-style: preserve-3d;
  transition: transform .65s cubic-bezier(.45, .05, .25, 1);
  cursor: pointer;
}
.flip.flipped { transform: rotateY(180deg); }
.flip.no-transition { transition: none; }

.face {
  position: absolute;
  inset: 0;
  background: var(--card-bg);
  color: var(--card-ink);
  border: 1px solid #b6b0a0;
  border-radius: 12px;
  padding: 1.5rem 1.75rem 1.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45), 0 2px 4px rgba(0, 0, 0, .25);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face::before {
  content: '';
  position: absolute;
  inset: .35rem;
  border: 1px dashed rgba(0, 0, 0, .12);
  border-radius: 8px;
  pointer-events: none;
}
.face.back {
  transform: rotateY(180deg);
  background: #efe6cc;
}
.face.back::before { border-color: rgba(107, 68, 34, .2); }

.q-num {
  font-family: ui-monospace, Menlo, monospace;
  font-size: .75rem;
  color: var(--card-mute);
  letter-spacing: .12em;
}
.question {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.35;
  min-height: 3rem;
}
.reveal-hint {
  margin-top: auto;
  padding-top: 1rem;
  color: var(--card-mute);
  font-size: .8rem;
  font-style: italic;
  text-align: center;
  border-top: 1px dashed rgba(0, 0, 0, .12);
}
.answer-label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: .7rem;
  color: var(--card-mute);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.answer {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #6b4422;
  line-height: 1.3;
}
.why {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px dashed rgba(0, 0, 0, .18);
  font-size: .9rem;
  color: var(--card-mute);
  font-style: italic;
  line-height: 1.5;
}

/* ============ mark bar ============ */
.mark-bar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: .5rem;
}
.mark-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: .85rem 1rem;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.mark-btn:hover { background: var(--panel-hi); }
.mark-btn.wrong  { border-color: rgba(248, 113, 113, .5); color: var(--danger); }
.mark-btn.wrong:hover  { background: rgba(248, 113, 113, .12); }
.mark-btn.right  { border-color: rgba(74, 222, 128, .5); color: var(--good); }
.mark-btn.right:hover  { background: rgba(74, 222, 128, .12); }
.mark-btn.retire { font-size: .9rem; padding-left: .85rem; padding-right: .85rem; color: var(--muted); }

/* ============ overlays ============ */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 1rem;
  z-index: 100;
}
.overlay.setup-overlay {
  background: var(--bg);
  z-index: 200;
  justify-content: flex-start;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(230, 232, 238, .35), transparent 50%),
    radial-gradient(1px 1px at 70% 20%, rgba(230, 232, 238, .30), transparent 50%),
    radial-gradient(1px 1px at 80% 60%, rgba(230, 232, 238, .25), transparent 50%),
    radial-gradient(1px 1px at 40% 70%, rgba(230, 232, 238, .35), transparent 50%),
    radial-gradient(2px 2px at 55% 40%, rgba(245, 226, 163, .4), transparent 50%),
    radial-gradient(circle at 50% -40%, #1c2846 0%, var(--bg) 60%);
}
.overlay.session-end-overlay { background: rgba(6, 10, 20, .95); z-index: 250; }
/* Filter panel — mid-session filter change. Solid enough backdrop to focus
   attention on the choices; not so opaque that you lose the card behind it. */
.overlay.filter-overlay {
  background: rgba(6, 10, 20, .82);
  z-index: 220;
  justify-content: flex-start;
  padding-top: 4vh;
  padding-bottom: 4vh;
}
.filter-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem 1.75rem 1.35rem;
  max-width: 460px;
  width: 100%;
  max-height: calc(100dvh - 8vh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  position: relative;
}
.filter-content h2 { margin: 0 0 .35rem; font-size: 1.35rem; color: var(--moon); }
.filter-content .tag { color: var(--muted); font-size: .8rem; margin: 0 0 1rem; }
.filter-content .filter-close {
  position: absolute;
  top: .5rem; right: .5rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  font-size: 1.15rem;
  cursor: pointer;
  padding: .25rem .55rem;
  line-height: 1;
  border-radius: 5px;
}
.filter-content .filter-close:hover { color: var(--ink); background: var(--line); }
.filter-group { margin: .85rem 0; text-align: left; }
.filter-label {
  font-size: .7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  margin-bottom: .45rem;
}
.filter-chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.cat-chip {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .35rem .8rem;
  font: inherit; font-size: .78rem;
  cursor: pointer;
}
.cat-chip:hover { color: var(--ink); border-color: var(--accent); }
.cat-chip.active { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 700; }
.filter-preview {
  margin: .85rem 0 .35rem;
  padding: .55rem .75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  text-align: center;
}
.filter-preview strong { color: var(--moon); font-weight: 700; }

.setup-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.75rem 2rem;
  max-width: 460px;
  width: 100%;
  max-height: calc(100vh - 4rem);
  max-height: calc(100dvh - 4rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}
.moon-mark {
  font-size: 2.5rem;
  filter: drop-shadow(0 0 12px rgba(245, 226, 163, .4));
  margin-bottom: .35rem;
}
.setup-content h1 { margin: 0 0 .25rem; font-size: 1.7rem; color: var(--moon); }
.setup-content h2 { margin: 0 0 .5rem; font-size: 1.5rem; color: var(--moon); }
.setup-content .tag { color: var(--muted); margin: 0 0 1.25rem; font-size: .85rem; }

.diff-picker { margin: 1rem 0; text-align: left; }
.diff-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; margin-bottom: .4rem; }
.diff-chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.diff-chip {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .35rem .8rem;
  font: inherit; font-size: .78rem;
  cursor: pointer;
}
.diff-chip:hover { color: var(--ink); border-color: var(--accent); }
.diff-chip.active { color: var(--bg); background: var(--moon); border-color: var(--moon); font-weight: 700; }

.progress-block {
  margin: 1rem 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .85rem;
  text-align: left;
}
.progress-row { display: flex; justify-content: space-between; padding: .15rem 0; }
.progress-row span { color: var(--muted); }
.progress-row strong { color: var(--ink); font-family: ui-monospace, Menlo, monospace; }

.actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  margin-top: 1.25rem;
}
.actions button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  padding: .75rem 2rem;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.actions button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.actions button:hover { filter: brightness(1.1); }

.reset-details {
  margin-top: 1.25rem;
  text-align: left;
  font-size: .8rem;
  color: var(--muted);
}
.reset-details summary { cursor: pointer; color: var(--muted); }
.reset-details summary:hover { color: var(--ink); }
.reset-body { margin-top: .5rem; padding: .75rem; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.reset-body p { margin: 0 0 .65rem; font-size: .8rem; }
.reset-body button {
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
  border-radius: 6px; padding: .45rem .95rem; font: inherit; font-size: .8rem; cursor: pointer;
}
.reset-body button:hover { background: var(--danger); color: white; }

.setup-version-line {
  margin-top: 1.5rem;
  text-align: center;
  font-size: .7rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
}
.setup-version-line a { color: var(--ink); text-decoration: none; opacity: .85; }
.setup-version-line a:hover { color: var(--moon); text-decoration: underline; opacity: 1; }
.setup-version-line a:visited { color: var(--ink); }

.session-tally {
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: .9rem;
  line-height: 1.7;
  margin: .75rem 0;
}
.session-tally strong { color: var(--moon); font-weight: 700; }

@media (max-width: 500px) {
  main#card-view { padding: .5rem; gap: .5rem; }
  .top-bar { padding: .35rem .5rem; gap: .5rem; }
  .badge { font-size: .6rem; padding: .15rem .45rem; }
  .top-bar .counter { font-size: .68rem; }
  .card-face { padding: 1.15rem 1.25rem 1.35rem; gap: .75rem; }
  .question { font-size: 1.2rem; }
  .answer { font-size: 1.15rem; }
  .why { font-size: .82rem; }
  .mark-btn { padding: .7rem .5rem; font-size: .9rem; }
  .setup-content { padding: 1.25rem 1.35rem; }
}
