/* =========================================================
   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; }

.reel, .card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  place-items: center;
  background: var(--bg);
  overflow: hidden;
}

@media (min-width: 768px) {
  .reel, .card {
    aspect-ratio: 9 / 16;
    height: auto;
    max-height: 100dvh;
    margin: 0 auto;
  }
}

/* splash */
.splash {
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 90px) 22px calc(var(--safe-bot) + 30px);
  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; }
}

/* =========================================================
   REELS OVERLAY — matches angelajholden/reels-style-video
   ========================================================= */

.access-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.08) 0%,
    transparent 25%,
    transparent 55%,
    rgba(0,0,0,0.55) 100%
  );
}

/* question content — fills the card, padded so it doesn't sit behind the caption */
.top {
  position: absolute;
  top: calc(var(--safe-top) + 58px);
  left: 16px;
  right: 60px; /* leave room for sidebar */
  bottom: 120px; /* leave room for collapsed caption + author */
  display: flex;
  flex-direction: column;
  justify-content: safe center; /* vertically center; "safe" stops iOS clipping on overflow */
  gap: 0;
  overflow-y: auto;
  scrollbar-width: none;
  z-index: 2;
}
.top::-webkit-scrollbar { display: none; }

/* ---- bottom left: author + caption — sits OVER the questions ---- */
.meta_container {
  position: absolute;
  bottom: calc(var(--safe-bot) + 20px);
  left: 16px;
  right: 60px;
  z-index: 4; /* above .top so caption always covers questions when expanded */
}

.author {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.avatar-initials {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  border: 2px solid var(--ink);
}

.author_artist-container {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.reel_author {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}

.follow_btn {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  padding: 4px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.follow_btn:active { opacity: 0.7; }

.caption {
  max-width: 100%;
  display: flex;
  flex-direction: column-reverse; /* "more" btn anchors at bottom; text grows UP */
}

/* ---- bottom right: action buttons ---- */
.meta_sidebar {
  position: absolute;
  bottom: calc(var(--safe-bot) + 20px);
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  text-align: center;
  z-index: 4;
}

.meta_count-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.meta_count-container button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}

.meta_count-container svg {
  width: 28px;
  height: 28px;
  fill: var(--ink);
  stroke: var(--ink);
  stroke-width: 0;
  display: block;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}

/* comment icon uses stroke not fill */
.comments svg, .remix svg, .send svg, .ellipsis svg {
  fill: none;
  stroke: var(--ink);
  stroke-width: 32px;
}

.meta_count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.heart_button path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 30;
}
.heart_button.liked path {
  fill: red;
  stroke: red;
}

.heart-icon {
  width: 4rem;
  height: 4rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  fill: red;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-in-out;
}
.heart-icon.liked {
  animation: heart-pop 0.6s ease-out forwards;
}
@keyframes heart-pop {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  50%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(300%, -50%) scale(1);   opacity: 0; }
}

/* 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: 12px;
  flex-shrink: 1;
}

.q-card .options {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#leaderboard.hidden {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
  transition: all 0.3s ease;
}

.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; }

/* caption */
.caption p {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: #fff;
  margin: 0;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* collapsed: only 2 lines visible */
.caption-text.caption-collapsed {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* expanded: full text shown, subtle gradient bg so it reads over question content */
.caption-text:not(.caption-collapsed) {
  -webkit-line-clamp: unset;
  -webkit-box-orient: unset;
  display: block;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.4) 100%);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 4px;
}

/* "more/less" button sits at the bottom of the caption (column-reverse puts it visually below the text) */
.caption-expand-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.55);
  padding: 2px 0 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: block;
  text-align: left;
}
.caption-expand-btn:active { opacity: 0.7; }

/* =========================================================
   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; }

/* =========================================================
   COMMENT SHEET — Instagram Reels style
   ========================================================= */

#commentSheet {
  background: #1c1c1e;
  border-top: none;
}

#commentSheet .sheet-handle {
  background: #48484a;
}

.sheet-header {
  text-align: center;
  padding: 4px 16px 12px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.2px;
  border-bottom: 1px solid #3a3a3c;
  flex-shrink: 0;
}

.comment-list {
  overflow-y: auto;
  flex: 1;
  padding: 12px 16px;
  scrollbar-width: none;
  list-style: none;
  min-height: 0;
}
.comment-list::-webkit-scrollbar { display: none; }

.comment {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  align-items: flex-start;
}

.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #3a3a3c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

.comment-body {
  flex: 1;
  min-width: 0;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.comment-username {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.1px;
}

.comment-timestamp {
  font-size: 12px;
  color: rgba(235,235,245,0.3);
  font-weight: 400;
}

.comment-image {
  margin-top: 6px;
  border-radius: 10px;
  max-width: 200px;
  width: 100%;
  display: block;
  background: #3a3a3c;
}

.comment-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}

.btn-reply {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
  color: rgba(235,235,245,0.6);
  cursor: pointer;
  font-family: var(--font-mono);
}
.btn-reply:hover { color: #fff; }

.comment-like {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.like-icon {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: rgba(235,235,245,0.6);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, transform 0.15s;
}
.like-icon:hover { transform: scale(1.15); }
.like-icon.liked { color: #ff3b30; }

.like-count {
  font-size: 11px;
  color: rgba(235,235,245,0.3);
  font-weight: 400;
  text-align: center;
  min-width: 24px;
}

.reaction-row {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 16px;
  border-top: 1px solid #3a3a3c;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.reaction-row::-webkit-scrollbar { display: none; }

.reaction-btn {
  background: #2c2c2e;
  border: 1px solid #48484a;
  border-radius: 22px;
  padding: 6px 10px;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
  flex-shrink: 0;
  line-height: 1;
}
.reaction-btn:hover { background: #3a3a3c; transform: scale(1.2); }

.input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 20px;
  border-top: 1px solid #3a3a3c;
  background: #1c1c1e;
  flex-shrink: 0;
}

.input-bar .comment-avatar { width: 32px; height: 32px; font-size: 15px; }

.input-field {
  flex: 1;
  background: #2c2c2e;
  border: 1px solid #3a3a3c;
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 14px;
  color: rgba(235,235,245,0.6);
  font-family: var(--font-mono);
  outline: none;
  pointer-events: none;
  user-select: none;
}

.btn-sticker {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  opacity: 0.7;
}
.btn-sticker:hover { opacity: 1; }

#leaderboard {
  position: sticky;
  top: 0;
  z-index: 1000;

  background: var(--bg, #0f0f0f);
  padding: 16px 12px;

  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;

  border-bottom: 1px solid rgba(255,255,255,0.08);
}
/* 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; }
