:root {
  --bg: #012530;
  --panel: rgba(7, 54, 66, 0.55);
  --panel-solid: #073642;
  --border: rgba(88, 110, 117, 0.3);
  --text: #fdf6e3;
  --text-dim: #93a1a1;
  --text-faint: #657b83;
  --teal: #2aa198;
  --teal-shadow: #1c766c;
  --violet: #6c71c4;
  --violet-shadow: #4b4f8c;
  --yellow: #b58900;
  --orange: #cb4b16;
  --orange-shadow: #961f1c;
  --red: #dc322f;
  --red-shadow: #961f1c;
  --green: #859900;
  --green-shadow: #5c6b00;
  --easy: #859900;
  --medium: #b58900;
  --hard: #cb4b16;
  --expert: #dc322f;
  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Belt-and-suspenders: several classes below (.btn-chunky, .node-btn, ...) set
   their own `display`, which ties the browser's default [hidden]{display:none}
   rule on specificity - and author styles win ties over the UA stylesheet, so
   without this, toggling the `hidden` property leaves the element visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

button { font-family: inherit; -webkit-tap-highlight-color: transparent; }
textarea:focus, button:focus { outline: none; }

a { color: var(--teal); text-decoration: none; }
a:hover { color: #3fc3b5; }

.app-shell { position: relative; min-height: 100vh; overflow-x: hidden; }

/* ---------- watercolor background ---------- */
.blob-bg { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
/* will-change promotes each blob to its own GPU layer, so the (expensive)
   blur is computed once into a texture and each animation frame is just a
   cheap GPU transform of that texture - without it, the browser re-blurs
   the affected screen region on the main thread on every frame, forever. */
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.45; animation: drift 24s ease-in-out infinite; will-change: transform; }
@media (prefers-reduced-motion: reduce) {
  .blob, .flame-icon, .flame-icon:hover, .mascot-flame, .node-circle.current { animation: none; }
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  50% { transform: translate(18px, -14px) rotate(4deg); }
}
.blob-teal { left: -10%; top: -15%; width: 560px; height: 560px; background: radial-gradient(circle, var(--teal) 0%, transparent 68%); }
.blob-violet { right: -8%; top: 5%; width: 480px; height: 480px; background: radial-gradient(circle, var(--violet) 0%, transparent 68%); animation-direction: reverse; opacity: 0.5; }
.blob-diff { left: 10%; top: 38%; width: 420px; height: 420px; background: radial-gradient(circle, var(--medium) 0%, transparent 70%); opacity: 0.4; transition: background 0.4s ease; }
.blob-yellow { right: 6%; bottom: 0; width: 520px; height: 520px; background: radial-gradient(circle, var(--yellow) 0%, transparent 68%); opacity: 0.35; animation-direction: reverse; }
.blob-olive { left: 35%; bottom: -12%; width: 380px; height: 380px; background: radial-gradient(circle, var(--green) 0%, transparent 70%); opacity: 0.35; }

/* ---------- shell ---------- */
.shell-main { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 26px 20px 70px; }

/* Deliberately nowrap: brand + stats + History/Leaderboard/Profile always
   stay on one row (overflow-x scrolls rather than wrapping to a second
   line - see the mobile rules below for how the action buttons shrink to
   avoid needing that in the first place). */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 6px; }

.guest-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--orange); color: var(--text);
  border-radius: 14px; padding: 10px 16px; margin: 0 0 14px;
  box-shadow: 0 4px 0 var(--orange-shadow);
  font-size: 0.88rem; font-weight: 600;
  margin-top: 10px;
  animation: guest-banner-in 0.25s ease-out;
}
.guest-banner-flame { flex: 0 0 auto; }
.guest-banner.guest-banner-pulse { animation: guest-banner-pulse 0.4s ease-out; }
@keyframes guest-banner-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes guest-banner-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.brand { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; opacity: 0.85; color: inherit; text-decoration: none; }
.stats { display: flex; align-items: center; gap: 14px; flex-wrap: nowrap; flex-shrink: 0; }
.stat-points, .stat-streak {
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 1.05rem; font-family: var(--font-display);
}
.stat-star {
  transition: transform 0.6s ease-in-out; 
  
  transform-origin: center; 
}

.stat-star:hover { transform: rotate(360deg) scale(1.2); }

/* Frozen (no animation, no transform) at rest - only flickers, and only
   gets a touch bigger, on hover. flicker-hover is flicker's own keyframes
   with a uniform scale(1.15) baked into every frame (rather than a plain
   `.flame-icon:hover { transform: scale(1.15) }`, which an already-running
   `animation: flicker` would just overwrite every frame - moot now that the
   base rule has no animation, but keeping the scale inside the keyframes
   means hover and the flicker motion never fight over `transform`). */
.flame-icon { transform-origin: 50% 90%; }
@keyframes flicker {
  0%, 100% { transform: scaleY(1) scaleX(1) rotate(0deg); }
  25% { transform: scaleY(1.08) scaleX(0.95) rotate(-2deg); }
  50% { transform: scaleY(0.93) scaleX(1.05) rotate(1.5deg); }
  75% { transform: scaleY(1.04) scaleX(0.97) rotate(-1deg); }
}
@keyframes flicker-hover {
  0%, 100% { transform: scale(1.15) scaleY(1) scaleX(1) rotate(0deg); }
  25% { transform: scale(1.15) scaleY(1.08) scaleX(0.95) rotate(-2deg); }
  50% { transform: scale(1.15) scaleY(0.93) scaleX(1.05) rotate(1.5deg); }
  75% { transform: scale(1.15) scaleY(1.04) scaleX(0.97) rotate(-1deg); }
}

.flame-icon:hover { animation: flicker-hover 2.1s ease-in-out infinite; }

/* ---------- track switcher ---------- */
.track-switcher { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 0; }
.track-pill {
  border: 1px solid var(--border); background: rgba(0, 0, 0, 0.15); color: var(--text-dim);
  padding: 7px 16px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.track-pill:hover { color: var(--text); border-color: var(--text-faint); }
.track-pill:active { transform: scale(0.96); }
.track-pill.active { background: var(--teal); color: var(--bg); border-color: var(--teal); }
.track-pill-add { border-style: dashed; }

/* ---------- add-topic popover ---------- */
.add-topic-popover {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 8px 0 0; padding: 10px 12px; border-radius: 14px;
  background: var(--panel-solid); border: 1px solid var(--border);
}
.add-topic-popover .hint { margin: 0; flex-basis: 100%; }

/* ---------- reset day ---------- */
.reset-day-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid color-mix(in oklch, var(--red) 45%, transparent);
  color: color-mix(in oklch, var(--red) 80%, var(--text)); padding: 5px 12px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 700; cursor: pointer;
}
.reset-day-btn:hover { background: rgba(220, 50, 47, 0.12); }
.reset-day-btn:active { transform: scale(0.96); }
.difficulty-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; position: relative; }

/* ---------- mascot ---------- */
.mascot-row { display: flex; align-items: flex-end; gap: 14px; margin: 22px 0 8px; }
.mascot-flame { flex: 0 0 auto; transform-origin: 50% 90%; animation: flicker 2.4s ease-in-out infinite; }
.mascot-bubble {
  position: relative; background: var(--panel-solid); border-radius: 20px 20px 20px 4px;
  padding: 12px 18px; font-size: 0.95rem; font-weight: 600; max-width: 420px;
}

/* ---------- difficulty badge ---------- */
.difficulty-row { text-align: center; margin: 20px 0 6px; }
.badge {
  display: inline-block; padding: 5px 16px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
}
.badge-easy { background: rgba(133, 153, 0, 0.18); color: var(--easy); }
.badge-medium { background: rgba(181, 137, 0, 0.18); color: var(--medium); }
.badge-hard { background: rgba(203, 75, 22, 0.18); color: var(--hard); }
.badge-expert { background: rgba(220, 50, 47, 0.18); color: var(--expert); }
.badge-late { margin-left: 8px; background: rgba(220, 50, 47, 0.18); color: var(--red); }
.badge-bonus { margin-left: 8px; background: rgba(181, 137, 0, 0.18); color: var(--yellow); }

/* ---------- streak milestone toast ---------- */
.milestone-toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; z-index: 100;
  background: linear-gradient(135deg, var(--yellow), var(--orange)); color: var(--bg);
  padding: 12px 20px; border-radius: 18px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: min(90vw, 380px); animation: milestone-toast-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.milestone-toast.milestone-toast-out { animation: milestone-toast-out 0.3s ease-in forwards; }
.milestone-toast-icon { font-size: 1.6rem; flex: 0 0 auto; }
.milestone-toast-text { display: flex; flex-direction: column; line-height: 1.25; }
.milestone-toast-text strong { font-family: var(--font-display); font-size: 0.95rem; }
.milestone-toast-text span { font-size: 0.8rem; opacity: 0.85; font-weight: 600; }
@keyframes milestone-toast-in {
  0% { opacity: 0; transform: translate(-50%, -16px) scale(0.9); }
  60% { opacity: 1; transform: translate(-50%, 4px) scale(1.03); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes milestone-toast-out {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -12px); }
}

/* ---------- streak badges (History) ---------- */
.badges-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0 22px; }
.milestone-badge {
  display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 800; background: rgba(181, 137, 0, 0.18); color: var(--yellow);
}
.milestone-badge.locked { background: rgba(255, 255, 255, 0.06); color: var(--text-faint); }

/* ---------- profile ---------- */
.profile-account {
  display: flex; align-items: center; gap: 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 32px 32px 32px 8px;
  padding: 20px 24px; margin-bottom: 20px; backdrop-filter: blur(6px);
}
.profile-avatar {
  flex: 0 0 auto; width: 56px; height: 56px; border-radius: 50%;
  background: var(--violet); box-shadow: 0 4px 0 var(--violet-shadow);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; color: var(--text);
}
.profile-account-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.profile-account-info strong { font-family: var(--font-display); font-size: 1.05rem; }
.profile-account-info .hint { margin: 0; }
.profile-track-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 32px 32px 32px 8px;
  padding: 20px 24px; margin-bottom: 16px; backdrop-filter: blur(6px);
}
.profile-track-card h3 { margin: 0 0 12px; font-family: var(--font-display); font-size: 1.05rem; }
.profile-track-stats { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 10px; }
.profile-track-stat { display: flex; flex-direction: column; }
.profile-track-stat strong { font-family: var(--font-mono); font-size: 1.1rem; }
.profile-track-stat span { font-size: 0.75rem; color: var(--text-faint); }
.profile-track-card .badges-row { justify-content: flex-start; margin: 0 0 4px; }
.profile-logout-form { text-align: center; margin-top: 8px; }

.profile-recap {
  display: flex; flex-direction: column; gap: 2px; margin: 14px 0;
  padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.05);
}
.profile-recap-label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.profile-recap-body { font-size: 0.92rem; }
.profile-recap-body strong { font-family: var(--font-mono); }

.profile-chart { margin: 14px 0; }
.profile-chart-label { display: block; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px; }
.profile-sparkline { width: 100%; height: 70px; display: block; }

.profile-topics { margin: 14px 0; }
.profile-topic-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.profile-topic-label { flex: 1 1 40%; font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-topic-track { flex: 1 1 auto; height: 8px; border-radius: 5px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.profile-topic-fill { height: 100%; border-radius: 5px; }
.profile-topic-frac { flex: 0 0 auto; font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-faint); min-width: 34px; text-align: right; }

.profile-export-row { display: flex; gap: 10px; margin-top: 16px; }
.profile-export-btn { width: auto; flex: 1 1 0; padding: 10px 16px; font-size: 0.82rem; }

/* ---------- username + friends (profile) ---------- */
.profile-username-row {
  background: var(--panel); border: 1px solid var(--border); border-radius: 32px 32px 32px 8px;
  padding: 18px 24px; margin-bottom: 16px; backdrop-filter: blur(6px);
}
.profile-username-edit { display: flex; gap: 10px; margin: 8px 0 4px; }
.profile-username-edit input {
  flex: 1 1 auto; min-width: 0; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font-family: var(--font-mono); font-size: 0.9rem;
}
.profile-username-edit button { width: auto; padding: 10px 18px; font-size: 0.82rem; }

.profile-friend-add { display: flex; gap: 10px; margin: 10px 0 4px; }
.profile-friend-add input {
  flex: 1 1 auto; min-width: 0; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font-size: 0.9rem;
}
.profile-friend-add button { width: auto; padding: 10px 18px; font-size: 0.82rem; }

.friend-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.friend-row:last-child { border-bottom: none; }
.friend-row-name { font-size: 0.9rem; font-weight: 700; }
.friend-row-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.friend-row-actions button {
  width: auto; padding: 6px 14px; font-size: 0.76rem;
}

/* ---------- leaderboard ---------- */
.leaderboard-table {
  width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border);
  border-radius: 32px 32px 32px 8px; overflow: hidden; backdrop-filter: blur(6px);
}
.leaderboard-table th, .leaderboard-table td { padding: 12px 16px; text-align: left; font-size: 0.9rem; }
.leaderboard-table th { color: var(--text-faint); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.leaderboard-table tbody tr { border-top: 1px solid var(--border); }
.leaderboard-table tbody tr.me-row { background: rgba(147, 161, 255, 0.1); font-weight: 800; }
.leaderboard-table td:first-child, .leaderboard-table th:first-child { font-family: var(--font-mono); width: 40px; }

/* ---------- node nav ---------- */
.node-nav {
  position: relative; display: flex; justify-content: space-around; align-items: center;
  margin: 26px 0 30px; padding: 0 10px;
}
.node-nav::before {
  content: ""; position: absolute; left: 15%; right: 15%; top: 32px;
  border-top: 3px dashed rgba(147, 161, 161, 0.3); z-index: 0;
}
.node-btn {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center;
  gap: 8px; background: none; border: none; cursor: pointer; padding: 0;
}
.node-circle {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  position: relative; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); background: #52717a;
  color: var(--text); font-weight: 800; font-size: 1.4rem; font-family: var(--font-mono);
  transition: background 0.2s ease;
}
.node-circle.current { animation: bounce 1.6s ease-in-out infinite; }
@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.05); }
}
.node-circle.done { background: var(--green) !important; box-shadow: 0 4px 0 var(--green-shadow) !important; }
.node-check { display: none; }
.node-circle.done .node-icon { display: none; }
.node-circle.done .node-check { display: block; }
/* "partial": the section was submitted/completed but not answered fully
   correctly - a distinct look from .done so a completed-but-wrong section
   doesn't read as a success at a glance (see renderNodes in app.js). */
.node-circle.partial { background: var(--orange) !important; box-shadow: 0 4px 0 var(--orange-shadow) !important; }
.node-partial { display: none; }
.node-circle.partial .node-icon { display: none; }
.node-circle.partial .node-partial { display: block; }
.node-label { font-size: 0.78rem; font-weight: 700; color: var(--text-dim); }
.node-btn.current .node-label { color: var(--text); }

/* ---------- panels ---------- */
.blob-panel {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: 32px 32px 32px 8px; padding: 26px 24px; margin-bottom: 24px; backdrop-filter: blur(6px);
}

.prose { color: var(--text-dim); white-space: pre-wrap; margin: 0 0 8px; line-height: 1.6; }
.hint { color: var(--text-faint); font-size: 0.85rem; margin: 0 0 12px; }

/* ---------- quiz ---------- */
.question { margin-bottom: 20px; }
.question:last-child { margin-bottom: 0; }
.q-text { font-weight: 800; margin: 0 0 12px; font-family: var(--font-display); font-size: 1.02rem; }
.choice {
  display: flex; align-items: center; width: 100%; text-align: left; margin-bottom: 8px; padding: 12px 16px;
  border-radius: 14px; cursor: pointer; background: rgba(0, 0, 0, 0.18); color: var(--text);
  border: none; font-size: 0.92rem; font-weight: 600; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.05s ease, background 0.15s ease; min-height: 44px;
}
.choice:active:not(.locked) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.choice:disabled:not(.correct):not(.incorrect) { opacity: 0.6; cursor: default; }
.choice.correct { background: var(--green); color: var(--bg); box-shadow: 0 3px 0 var(--green-shadow); }
.choice.incorrect { background: var(--red); color: var(--bg); box-shadow: 0 3px 0 var(--red-shadow); }
.choice.locked { cursor: default; }
.q-explain { margin: 6px 0 0; padding: 0 2px; font-size: 0.85rem; opacity: 0.8; }

/* ---------- buttons ---------- */
.btn-row { display: flex; flex-direction: column; gap: 10px; margin: 4px 0; }
.btn-chunky {
  border: none; border-radius: 16px; padding: 13px 26px; font-weight: 800; font-size: 0.92rem;
  letter-spacing: 0.01em; cursor: pointer; transition: transform 0.05s ease, box-shadow 0.05s ease;
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
/* compact icon/nav controls stay their natural size, not full-width */
#history-toggle, #leaderboard-toggle, #profile-toggle, .cal-nav-btn { width: auto; display: inline-flex; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
/* .shell-main caps the whole app at 640px regardless of the actual browser
   width (see below), so these always share a narrow row with the brand +
   stats - not just below some mobile breakpoint. Compact by default, not
   only under a max-width media query, so they stay one line at full
   desktop width too. */
#history-toggle, #leaderboard-toggle, #profile-toggle, #logout-btn { padding: 9px 14px; font-size: 0.78rem; white-space: nowrap; }
.btn-chunky:active { transform: translateY(4px); }
.btn-chunky:disabled { cursor: not-allowed; opacity: 0.7; }

/* a small lift on hover - just enough to feel responsive before the press -
   applied to every topbar action button consistently */
#history-toggle, #leaderboard-toggle, #profile-toggle, #logout-btn { transition: transform 0.15s ease, box-shadow 0.15s ease; }
#history-toggle:hover, #leaderboard-toggle:hover, #profile-toggle:hover, #logout-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 rgba(0, 0, 0, 0.3); }
#history-toggle:active, #leaderboard-toggle:active, #profile-toggle:active, #logout-btn:active { transform: translateY(4px); }

/* #logout-btn-label and #logout-btn-google are stacked in the same grid cell
   (rather than one being display:none) so the button's width is always the
   max of both - swapping which is visible on hover can't resize the button. */
#logout-btn { width: auto; display: inline-grid; place-items: center; }
#logout-btn-label, #logout-btn-google { grid-area: 1 / 1; transition: opacity 0.1s ease; }
#logout-btn-google { opacity: 0; pointer-events: none; }
#logout-btn.guest-mode:hover #logout-btn-label { opacity: 0; }
#logout-btn.guest-mode:hover #logout-btn-google { opacity: 1; }
.btn-teal { background: var(--teal); color: var(--bg); box-shadow: 0 5px 0 var(--teal-shadow); }
.btn-teal:active { box-shadow: 0 1px 0 var(--teal-shadow); }
.btn-violet { background: var(--violet); color: var(--text); box-shadow: 0 5px 0 var(--violet-shadow); }
.btn-violet:active { box-shadow: 0 1px 0 var(--violet-shadow); }
.btn-green { background: var(--green); color: var(--bg); box-shadow: 0 5px 0 var(--green-shadow); }
.btn-green:active { box-shadow: 0 1px 0 var(--green-shadow); }
.btn-ghost { background: rgba(255, 255, 255, 0.08); color: var(--text); box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3); }
.btn-ghost:active { box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }
.btn-suggested { outline: 3px solid var(--text); outline-offset: 2px; }

/* ---------- code review panel ---------- */
.code-snippet {
  width: 100%; background: #00161d; color: #dbe4ff; border: none; overflow-x: auto;
  border-radius: 18px; font-family: var(--font-mono); font-size: 0.86rem; padding: 8px 0;
  margin: 6px 0 16px; box-shadow: inset 0 0 0 1px var(--border);
}
.cr-line {
  display: flex; align-items: flex-start; width: 100%; cursor: pointer; border: none; background: transparent;
  color: inherit; font: inherit; text-align: left; padding: 3px 16px; gap: 14px; white-space: pre; word-break: normal;
  border-left: 3px solid transparent; transition: background 0.1s ease, border-color 0.1s ease;
}
.cr-line:hover:not(.locked) { background: rgba(255, 255, 255, 0.05); }
.cr-line-num { flex: 0 0 auto; width: 1.6em; color: var(--text-faint); text-align: right; user-select: none; }
.cr-line-code { white-space: pre-wrap; word-break: break-word; }
/* flagged-but-unmatched: just a neutral marker - it isn't a "guess" yet
   since no reason is attached, so it stays visually quiet until it is */
.cr-line.flagged { border-left-color: var(--text-faint); }
/* matched: a reason is attached - this is the real, submittable guess */
.cr-line.matched { border-left-color: var(--yellow); background: rgba(181, 137, 0, 0.14); }
.cr-line.active { border-left-color: var(--teal); background: rgba(42, 161, 152, 0.18); }
.cr-line.locked { cursor: default; }
.cr-line.result-hit { border-left-color: var(--green); background: rgba(133, 153, 0, 0.16); }
.cr-line.result-miss { border-left-color: var(--red); background: rgba(220, 50, 47, 0.14); }
.cr-line-chip {
  margin-left: auto; flex: 0 0 auto; font-size: 0.74rem; font-weight: 700; padding: 2px 10px;
  border-radius: 999px; background: var(--teal); color: var(--bg); white-space: normal; max-width: 40%;
}
.cr-line-chip.wrong { background: var(--red); color: var(--bg); }

.reason-bank { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.reason-chip {
  border: none; border-radius: 999px; padding: 9px 16px; font-size: 0.84rem; font-weight: 700;
  cursor: pointer; background: rgba(255, 255, 255, 0.08); color: var(--text);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); transition: transform 0.05s ease, opacity 0.1s ease;
}
.reason-chip:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }
.reason-chip:disabled { opacity: 0.3; cursor: not-allowed; }
#code-review-bank-hint.dim { opacity: 0.5; }

textarea {
  width: 100%; min-height: 190px; background: #00161d; color: #dbe4ff; border: none;
  border-radius: 18px; font-family: var(--font-mono); font-size: 0.86rem; padding: 16px;
  resize: vertical; margin: 6px 0 16px; box-shadow: inset 0 0 0 1px var(--border);
}
#concept-notes { min-height: 100px; font-family: inherit; color: var(--text); font-size: 0.92rem; }

.panel-result {
  margin-top: 16px; font-weight: 700; font-size: 0.9rem; white-space: pre-wrap;
  font-family: var(--font-mono); color: var(--green);
}
.panel-result.fail { color: var(--red); }

/* ---------- concept AI feedback ---------- */
.ai-feedback { display: flex; align-items: flex-start; gap: 10px; margin-top: 16px; }
.ai-bubble {
  background: rgba(108, 113, 196, 0.16); border-radius: 16px 16px 16px 4px;
  padding: 12px 16px; font-size: 0.9rem; color: var(--text); font-weight: 600;
}
.model-answer-box {
  margin-top: 16px; padding: 14px 16px; border-radius: 16px; background: rgba(0, 0, 0, 0.18);
  font-size: 0.9rem; white-space: pre-wrap; color: var(--text-dim); font-family: inherit;
}
#code-reference { font-family: var(--font-mono); font-size: 0.82rem; white-space: pre-wrap; word-break: break-word; }

/* ---------- history ---------- */
.history-head { text-align: center; margin: 24px 0 28px; }
.history-head h1 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; }

.view-toggle { display: inline-flex; gap: 6px; margin-top: 14px; background: rgba(0, 0, 0, 0.18); border-radius: 999px; padding: 4px; }
.view-toggle-btn { border: none; background: transparent; color: var(--text-dim); padding: 7px 18px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; cursor: pointer; }
.view-toggle-btn.active { background: var(--teal); color: var(--bg); }

/* ---------- calendar ---------- */
.calendar-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 14px; }
.cal-nav-btn { padding: 8px 16px; font-size: 1rem; line-height: 1; }
.calendar-month-label { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; min-width: 160px; text-align: center; }
.calendar-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px;
  text-align: center; color: var(--text-faint); font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 18px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 12px; border: none; font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
  background: #33474d; transition: transform 0.05s ease;
}
.cal-cell:active:not(:disabled) { transform: scale(0.94); }
.cal-blank { visibility: hidden; cursor: default; }
.cal-future { background: transparent; color: var(--text-faint); opacity: 0.4; cursor: not-allowed; }
.cal-done { background: var(--green); color: var(--bg); }
.cal-late { background: var(--red); color: var(--bg); }
.cal-bonus { background: rgba(181, 137, 0, 0.35); }
.cal-open { background: #52717a; }
.cal-today { outline: 2px solid var(--text); outline-offset: 2px; }
.calendar-legend { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; color: var(--text-dim); font-size: 0.78rem; margin-bottom: 8px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend-dot.done { background: var(--green); }
.legend-dot.late { background: var(--red); }
.legend-dot.bonus { background: var(--yellow); }
.legend-dot.open { background: #52717a; }

/* ---------- mobile ---------- */
@media (max-width: 600px) {
  .shell-main { padding: 16px 14px 50px; }
  .brand { font-size: 0.92rem; }
  .stats { gap: 10px; }
  .stat-points, .stat-streak { font-size: 0.92rem; }
  .btn-chunky { padding: 11px 18px; font-size: 0.86rem; }
  /* History/Leaderboard/Profile/Log out stay on the same line as the brand
     and stats (see .topbar's nowrap) rather than wrapping to a second row -
     shrink them to fit instead of stacking. */
  .topbar-actions { gap: 6px; flex-shrink: 0; }
  #history-toggle, #leaderboard-toggle, #profile-toggle, #logout-btn { padding: 8px 10px; font-size: 0.72rem; white-space: nowrap; }
  /* Low-value at this width - dropping it buys back room the action
     buttons need to stay on one line without truncating. */
  #me-wrap { display: none; }

  .track-switcher { gap: 8px; }
  .track-pill { flex: 1 1 auto; padding: 12px 14px; font-size: 0.86rem; min-height: 44px; text-align: center; }

  .difficulty-row { justify-content: center; }
  .reset-day-btn { margin-left: 0; padding: 8px 14px; font-size: 0.8rem; }

  .mascot-row { gap: 10px; margin: 16px 0 8px; }
  .mascot-flame { width: 51px; height: 38px; }
  .mascot-bubble { font-size: 0.86rem; padding: 10px 14px; max-width: none; }

  .node-nav { margin: 20px 0 24px; padding: 0; }
  .node-circle { width: 52px; height: 52px; font-size: 1.15rem; }
  .node-label { font-size: 0.7rem; }

  .blob-panel { padding: 18px 16px; border-radius: 24px 24px 24px 6px; }
  textarea, .code-snippet { min-height: 150px; font-size: 0.8rem; padding: 12px; }

  .choice { padding: 11px 14px; font-size: 0.86rem; }

  .history-row, .history-row.align-right { justify-content: flex-start; }

  .calendar-month-label { min-width: 120px; font-size: 1rem; }
  .cal-cell { font-size: 0.78rem; border-radius: 8px; }
  .calendar-legend { gap: 12px; font-size: 0.72rem; }
}

@media (max-width: 380px) {
  .node-circle { width: 46px; height: 46px; font-size: 1rem; }
  .node-nav::before { left: 12%; right: 12%; top: 26px; }
  /* Still one line even here (see .topbar's nowrap) - shrink further
     rather than stack, so History/Leaderboard/Profile never fall below
     the brand. */
  .topbar { gap: 8px; }
  .brand { font-size: 0.78rem; }
  .stats { gap: 6px; }
  .stat-points, .stat-streak { font-size: 0.78rem; gap: 3px; }
  .stat-star, .flame-icon { width: 15px; height: 15px; }
  .topbar-actions { gap: 4px; }
  #history-toggle, #leaderboard-toggle, #profile-toggle, #logout-btn { padding: 6px 7px; font-size: 0.62rem; }
}
.history-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; cursor: pointer; }
.history-row.align-right { justify-content: flex-end; }
.history-circle {
  width: 52px; height: 52px; border-radius: 50%; border: none; display: flex; align-items: center;
  justify-content: center; cursor: pointer; flex: 0 0 auto; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  background: #52717a;
}
.history-circle.done { background: var(--green); }
.history-circle.late { background: var(--red); }
.history-circle.bonus { background: rgba(181, 137, 0, 0.6); }
.history-label { font-size: 0.92rem; font-weight: 700; }
.history-meta { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- onboarding (first-login topic selection) ---------- */
.onboarding-shell { max-width: 480px; margin: 40px auto; text-align: center; }
.onboarding-shell h1 { margin: 0 0 6px; font-family: var(--font-display); font-size: 1.4rem; }
.onboarding-shell p.hint { margin: 0 0 22px; }
/* Shared look for every "pick a topic" control - the onboarding grid's
   full-row cards and the track switcher's compact "add topic" chips are the
   same action (choosing a topic you want to know about), so they share one
   base style and differ only in layout/size. */
.topic-card, .topic-chip {
  border: 2px solid var(--border); background: var(--panel-solid); color: var(--text);
  border-radius: 16px; cursor: pointer; font-family: inherit;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.05s ease;
}
.topic-card:hover, .topic-chip:hover { border-color: var(--text-faint); }
.topic-card:active, .topic-chip:active { transform: scale(0.98); }
.topic-card.selected { border-color: var(--teal); background: rgba(42, 161, 152, 0.15); }

.topic-grid { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.topic-card {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 16px 18px;
}
.topic-card-check {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--text-faint);
  display: flex; align-items: center; justify-content: center;
}
.topic-card.selected .topic-card-check { background: var(--teal); border-color: var(--teal); }
.topic-card-check svg { display: none; }
.topic-card.selected .topic-card-check svg { display: block; }
.topic-card-name { font-weight: 700; font-size: 0.98rem; }

.topic-chip { display: inline-flex; align-items: center; padding: 9px 16px; font-size: 0.85rem; font-weight: 700; }
