/* =========================================================
   chemdoomscroller — dark editorial × lab-tape aesthetic
   ========================================================= */

:root {
  --bg: #0a0a0c;
  --bg-elev: #131318;
  --bg-card: #15151b;
  --ink: #f3efe6;
  --ink-dim: #8a8a93;
  --ink-dimmer: #4a4a55;
  --accent: #d4ff3a;    /* electric lime, lab-tape yellow */
  --accent-ink: #0a0a0c;
  --correct: #6fff8e;
  --wrong: #ff5e5e;
  --border: rgba(243, 239, 230, 0.08);
  --border-strong: rgba(243, 239, 230, 0.18);

  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg: #faf9f7;
  --bg-elev: #f0ebe5;
  --bg-card: #ede8e0;
  --ink: #2d2622;
  --ink-dim: #6d6662;
  --ink-dimmer: #a5a098;
  --accent: #a3c600;
  --accent-ink: #faf9f7;
  --correct: #2d8c4d;
  --wrong: #d32f2f;
  --border: rgba(45, 38, 34, 0.08);
  --border-strong: rgba(45, 38, 34, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}

body {
  /* subtle grain */
  background-image:
    radial-gradient(ellipse at top, rgba(212, 255, 58, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(212, 255, 58, 0.02) 0%, transparent 50%);
  min-height: 100dvh;
}

/* =========================================================
   TOP BAR
   ========================================================= */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  padding: calc(var(--safe-top) + 12px) 18px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, rgba(10,10,12,0.85) 0%, rgba(10,10,12,0) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.iconbtn {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.iconbtn:active { transform: scale(0.92); background: var(--bg-card); }

.streak {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
}
.streak-flame { color: var(--accent); font-size: 11px; }
.streak-num { letter-spacing: 0.5px; }

/* =========================================================
   PROGRESS
   ========================================================= */
.progress {
  position: fixed;
  top: calc(var(--safe-top) + 66px);
  left: 18px; right: 18px;
  height: 2px;
  background: var(--border);
  z-index: 49;
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* =========================================================
   FEED + CARDS
   ========================================================= */
.feed {
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

.card {
  height: 100dvh;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 90px) 22px calc(var(--safe-bot) + 30px);
  position: relative;
  content-visibility: auto;
  contain-intrinsic-size: 100dvh;
}

/* splash */
.splash { justify-content: center; align-items: center; text-align: center; }
.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.brand-mark {
  width: 72px; height: 72px;
  border: 2px solid var(--accent);
  color: var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 32px;
  border-radius: 4px;
  transform: rotate(-4deg);
  margin-bottom: 8px;
}
.brand {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 11vw, 64px);
  line-height: 0.9;
  letter-spacing: -0.02em;
}
.brand span { font-style: italic; color: var(--accent); }
.brand-sub {
  color: var(--ink-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-top: 4px;
}
.swipe-hint {
  margin-top: 60px;
  color: var(--ink-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: bob 1.8s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50%      { transform: translateY(-6px); opacity: 1; }
}

/* question card */
.q-card .topic-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 5px 10px;
  border-radius: 3px;
  align-self: flex-start;
  transform: rotate(-1deg);
}

.q-card .q-number {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-dimmer);
  margin-top: 10px;
  letter-spacing: 0.15em;
}

.q-card .q-text {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-top: 20px;
  flex-shrink: 1;
}

.q-card .options {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  padding: 16px 18px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}
.option:active { transform: scale(0.985); }
.option .letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  color: var(--accent);
  font-size: 18px;
  width: 22px;
  flex-shrink: 0;
}
.option.correct {
  border-color: var(--correct);
  background: rgba(111, 255, 142, 0.08);
}
.option.correct .letter { color: var(--correct); }
.option.wrong {
  border-color: var(--wrong);
  background: rgba(255, 94, 94, 0.08);
}
.option.wrong .letter { color: var(--wrong); }
.option.locked { pointer-events: none; opacity: 0.7; }
.option.locked.correct, .option.locked.wrong { opacity: 1; }

/* =========================================================
   BOTTOM SHEETS
   ========================================================= */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg-elev);
  border-top: 1px solid var(--border-strong);
  border-radius: 18px 18px 0 0;
  padding: 10px 22px calc(var(--safe-bot) + 22px);
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 50dvh;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-tall { max-height: 85dvh; }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--ink-dimmer);
  border-radius: 2px;
  margin: 0 auto 14px;
}

.sheet-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.sheet-sub {
  color: var(--ink-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 16px;
}

.feedback-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  padding: 5px 10px;
  border-radius: 3px;
  margin-bottom: 12px;
  font-weight: 700;
}
.feedback-tag.correct { color: var(--correct); border: 1px solid var(--correct); }
.feedback-tag.wrong { color: var(--wrong); border: 1px solid var(--wrong); }

.feedback-explanation {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  margin-bottom: 18px;
}

.nextbtn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 16px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.nextbtn:active { transform: scale(0.98); }

/* booklet tabs */
.booklet-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.booklet-tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-dim);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  text-transform: lowercase;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.placeholder {
  color: var(--ink-dimmer);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 20px 0;
}

/* filter list */
.filter-body { margin-bottom: 16px; }
.filter-unit { margin-bottom: 18px; }
.filter-unit-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  font-size: 15px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.filter-topic {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.filter-topic input { accent-color: var(--accent); width: 18px; height: 18px; }
.filter-topic span { font-family: var(--font-mono); font-size: 14px; }

/* theme toggle */
.theme-toggle-section {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.theme-toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.theme-toggle input::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.3s ease;
}

.theme-toggle input:checked {
  background: var(--accent);
}

.theme-toggle input:checked::after {
  left: 18px;
  background: var(--accent-ink);
}

.theme-label {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink);
}

#sentinel { position: absolute; bottom: 200vh; width: 1px; height: 1px; }
