/* ==========================================================================
   Gaoye Quest (高業柴柴冒險筆記) — AAA Cozy Pixel-Art Design System
   Inspiration: Stardew Valley × Eastward × Coffee Talk × Octopath Traveler
   Responsive: Mobile (<640px) · Tablet (640–1024px) · Laptop (>1024px)
   ========================================================================== */

:root {
  /* Twilight Study Cabin Backdrop */
  --bg-night-deep: #181223;
  --bg-night: #1E182B;
  --bg-night-mid: #2A2139;
  --bg-night-soft: #362B4A;
  --lamp-glow: rgba(247, 198, 86, 0.15);
  --lamp-glow-strong: rgba(247, 198, 86, 0.28);

  /* Warm Parchment & Cream Surfaces */
  --parchment: #FFF8E7;
  --parchment-top: #FFFDF5;
  --parchment-warm: #FEF2D6;
  --parchment-deep: #F5E1B8;
  --parchment-mascot: #FDF3D7;
  --parchment-input: #FFFDF7;

  /* Espresso Ink & Carved Oak Wood */
  --ink: #38261B;
  --ink-strong: #291A11;
  --ink-soft: #634938;
  --ink-muted: #8B6E59;

  --wood-light: #B87B4B;
  --wood-mid: #8D5832;
  --wood-dark: #5C3820;
  --wood-deep: #3B2213;

  --brass-bright: #FFE285;
  --brass: #E6AE3F;
  --brass-dark: #9D6715;

  /* Semantic Accents */
  --gold: #F4B942;
  --gold-bright: #FFD466;
  --gold-deep: #D98F1E;
  --gold-shadow: #8F560C;
  --gold-bg: #FFF3CC;
  --gold-border: #DCA02D;

  --sage: #4E8E5A;
  --sage-bright: #67AC74;
  --sage-deep: #376E42;
  --sage-shadow: #234A2B;
  --sage-bg: #E4F5E6;
  --sage-border: #78B884;

  --coral: #D95A5A;
  --coral-bright: #EC7676;
  --coral-deep: #B23E3E;
  --coral-shadow: #782323;
  --coral-bg: #FDECEC;
  --coral-border: #E59494;

  --indigo: #6C63AC;
  --indigo-bright: #877EC7;
  --indigo-deep: #51488D;
  --indigo-shadow: #332C60;
  --indigo-bg: #EFEBFB;
  --indigo-border: #ABA3DC;

  /* Typography */
  --font-pixel-en: 'Press Start 2P', 'DotGothic16', monospace;
  --font-pixel: 'DotGothic16', 'Press Start 2P', 'Noto Sans TC', monospace;
  --font-body: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Microsoft JhengHei', sans-serif;

  /* Radii & Pixel Depth */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-panel:
    0 0 0 2px var(--wood-dark),
    0 5px 0 var(--wood-dark),
    0 14px 30px rgba(10, 6, 18, 0.48),
    inset 0 2px 0 rgba(255, 255, 255, 0.78),
    inset 0 -2px 0 rgba(141, 88, 50, 0.14);

  --shadow-card-sm:
    0 3px 0 var(--wood-dark),
    0 6px 14px rgba(10, 6, 18, 0.22),
    inset 0 2px 0 rgba(255, 255, 255, 0.68);

  --shadow-wood-bar:
    inset 0 2px 0 rgba(255, 226, 133, 0.22),
    inset 0 -2px 0 rgba(20, 12, 26, 0.55),
    0 6px 20px rgba(10, 6, 18, 0.42);

  /* Layout Rhythm */
  --bottom-nav-h: 68px;
  --topbar-h: 62px;
  --ease-snappy: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ==========================================================================
   1. Base Reset & Cozy Night Canvas
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: clip;
  background-color: var(--bg-night);
  scrollbar-color: var(--wood-mid) var(--bg-night-deep);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.68;
  color: var(--ink);
  background-color: var(--bg-night);
  background-image:
    radial-gradient(ellipse 75% 48% at 50% 0%, var(--lamp-glow) 0%, rgba(247, 198, 86, 0.04) 48%, transparent 76%),
    radial-gradient(circle at 18% 24%, rgba(255, 240, 180, 0.11) 0 1.5px, transparent 2px),
    radial-gradient(circle at 82% 18%, rgba(255, 240, 180, 0.12) 0 1.5px, transparent 2px),
    radial-gradient(circle at 65% 42%, rgba(255, 240, 180, 0.08) 0 1px, transparent 2px),
    radial-gradient(circle at 31% 66%, rgba(255, 240, 180, 0.09) 0 1.5px, transparent 2px),
    radial-gradient(circle at 88% 72%, rgba(255, 240, 180, 0.1) 0 1.5px, transparent 2px),
    linear-gradient(180deg, #1E182B 0%, #261E36 46%, #2A2139 76%, #1D1629 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--gold);
  color: var(--ink-strong);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-night-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--wood-mid);
  border: 2px solid var(--bg-night-deep);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--wood-light);
}

img {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p {
  margin-top: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Focus ring — warm lantern gold pixel outline */
:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

/* ==========================================================================
   2. Ambient Study Lamp Glow & Pixel Fireflies
   ========================================================================== */

.ambient-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle 420px at 50% -60px, rgba(247, 198, 86, 0.16), transparent 72%),
    radial-gradient(circle 340px at 12% 85%, rgba(108, 99, 172, 0.14), transparent 70%),
    radial-gradient(circle 340px at 88% 82%, rgba(244, 185, 66, 0.08), transparent 70%);
}

.fireflies {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.fireflies > span,
.firefly {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 1px;
  background: #FFE58A;
  box-shadow:
    0 0 6px 1px rgba(244, 185, 66, 0.85),
    0 0 14px 3px rgba(244, 185, 66, 0.35);
  opacity: 0;
  will-change: transform, opacity;
  animation: firefly-drift-a 14s ease-in-out infinite;
}

.fireflies > span:nth-child(1)  { left: 7%;  top: 78%; width: 5px; height: 5px; animation-duration: 15s; animation-delay: 0s; }
.fireflies > span:nth-child(2)  { left: 16%; top: 34%; width: 4px; height: 4px; animation-name: firefly-drift-b; animation-duration: 18s; animation-delay: -3s; }
.fireflies > span:nth-child(3)  { left: 26%; top: 86%; width: 3px; height: 3px; animation-duration: 13s; animation-delay: -6s; }
.fireflies > span:nth-child(4)  { left: 38%; top: 22%; width: 5px; height: 5px; animation-name: firefly-drift-b; animation-duration: 19s; animation-delay: -2s; }
.fireflies > span:nth-child(5)  { left: 49%; top: 68%; width: 4px; height: 4px; animation-duration: 16s; animation-delay: -9s; }
.fireflies > span:nth-child(6)  { left: 58%; top: 18%; width: 3px; height: 3px; animation-name: firefly-drift-b; animation-duration: 14s; animation-delay: -5s; }
.fireflies > span:nth-child(7)  { left: 69%; top: 82%; width: 5px; height: 5px; animation-duration: 17s; animation-delay: -11s; }
.fireflies > span:nth-child(8)  { left: 78%; top: 44%; width: 4px; height: 4px; animation-name: firefly-drift-b; animation-duration: 15s; animation-delay: -4s; }
.fireflies > span:nth-child(9)  { left: 86%; top: 26%; width: 4px; height: 4px; animation-duration: 20s; animation-delay: -8s; }
.fireflies > span:nth-child(10) { left: 93%; top: 72%; width: 5px; height: 5px; animation-name: firefly-drift-b; animation-duration: 16s; animation-delay: -1s; }
.fireflies > span:nth-child(11) { left: 11%; top: 56%; width: 3px; height: 3px; animation-duration: 12s; animation-delay: -7s; }
.fireflies > span:nth-child(12) { left: 63%; top: 56%; width: 4px; height: 4px; animation-name: firefly-drift-b; animation-duration: 17s; animation-delay: -13s; }

/* ==========================================================================
   3. Pixel-Craft Primitives (Panels, Buttons, Badges, Mascots, Bars)
   ========================================================================== */

.pixel-panel {
  position: relative;
  background: linear-gradient(180deg, var(--parchment-top) 0%, var(--parchment) 52%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 3px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  padding: 20px;
}

/* Brass corner pixel rivets on parchment panels */
.pixel-panel::before,
.pixel-panel::after {
  content: '';
  position: absolute;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--brass);
  box-shadow:
    inset 1px 1px 0 var(--brass-bright),
    1px 1px 0 var(--wood-dark);
  pointer-events: none;
  z-index: 2;
}

.pixel-panel::before {
  left: 7px;
}

.pixel-panel::after {
  right: 7px;
}

.pixel-panel--warm {
  background: linear-gradient(180deg, #FFF7DF 0%, var(--parchment-warm) 100%);
}

.pixel-panel--dark {
  background: linear-gradient(180deg, #342847 0%, #261D36 100%);
  color: var(--parchment);
  border-color: var(--wood-mid);
  box-shadow:
    0 0 0 2px #161021,
    0 5px 0 #161021,
    0 14px 28px rgba(8, 5, 16, 0.52),
    inset 0 2px 0 rgba(255, 226, 133, 0.22);
}

/* Tactile Pressable Pixel Buttons */
.pixel-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 2.5px solid var(--wood-dark);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #FFFDF5 0%, var(--parchment-warm) 100%);
  color: var(--ink-strong);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.72),
    inset 0 -2px 0 rgba(92, 56, 32, 0.15),
    0 4px 0 var(--wood-dark);
  transition: transform 0.1s var(--ease-snappy), box-shadow 0.1s var(--ease-snappy), filter 0.15s ease;
}

.pixel-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.8),
    inset 0 -2px 0 rgba(92, 56, 32, 0.15),
    0 5px 0 var(--wood-dark);
}

.pixel-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 1px 0 var(--wood-dark);
}

.pixel-btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

/* Gold — Primary Quest CTA */
.pixel-btn--gold {
  background: linear-gradient(180deg, #FFDC73 0%, var(--gold) 58%, var(--gold-deep) 100%);
  border-color: var(--gold-shadow);
  color: #361F0E;
  text-shadow: 0 1px 0 rgba(255, 248, 220, 0.65);
  box-shadow:
    inset 0 2px 0 rgba(255, 250, 224, 0.8),
    inset 0 -2px 0 rgba(143, 86, 12, 0.25),
    0 4px 0 var(--gold-shadow);
}

.pixel-btn--gold:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255, 250, 224, 0.88),
    inset 0 -2px 0 rgba(143, 86, 12, 0.25),
    0 5px 0 var(--gold-shadow),
    0 0 16px rgba(244, 185, 66, 0.35);
}

.pixel-btn--gold:active:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255, 250, 224, 0.4),
    0 1px 0 var(--gold-shadow);
}

/* Sage — Calm Focus / Correct / Master */
.pixel-btn--sage {
  background: linear-gradient(180deg, var(--sage-bright) 0%, var(--sage) 64%, var(--sage-deep) 100%);
  border-color: var(--sage-shadow);
  color: #FFFDF7;
  text-shadow: 0 1px 0 rgba(20, 48, 25, 0.45);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    inset 0 -2px 0 rgba(22, 50, 28, 0.28),
    0 4px 0 var(--sage-shadow);
}

.pixel-btn--sage:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    0 5px 0 var(--sage-shadow);
}

.pixel-btn--sage:active:not(:disabled) {
  box-shadow: 0 1px 0 var(--sage-shadow);
}

/* Coral — Mistake Revenge / Danger / Highlight */
.pixel-btn--coral {
  background: linear-gradient(180deg, var(--coral-bright) 0%, var(--coral) 62%, var(--coral-deep) 100%);
  border-color: var(--coral-shadow);
  color: #FFFDF7;
  text-shadow: 0 1px 0 rgba(88, 18, 18, 0.45);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    inset 0 -2px 0 rgba(90, 22, 22, 0.25),
    0 4px 0 var(--coral-shadow);
}

.pixel-btn--coral:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.44),
    0 5px 0 var(--coral-shadow);
}

.pixel-btn--coral:active:not(:disabled) {
  box-shadow: 0 1px 0 var(--coral-shadow);
}

/* Indigo — Codex / Study Guide / Often Tier */
.pixel-btn--indigo {
  background: linear-gradient(180deg, var(--indigo-bright) 0%, var(--indigo) 62%, var(--indigo-deep) 100%);
  border-color: var(--indigo-shadow);
  color: #FFFDF7;
  text-shadow: 0 1px 0 rgba(30, 24, 64, 0.45);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.34),
    inset 0 -2px 0 rgba(35, 28, 72, 0.28),
    0 4px 0 var(--indigo-shadow);
}

.pixel-btn--indigo:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    0 5px 0 var(--indigo-shadow);
}

.pixel-btn--indigo:active:not(:disabled) {
  box-shadow: 0 1px 0 var(--indigo-shadow);
}

/* Ghost — Subtle Warm Paper Action */
.pixel-btn--ghost {
  background: rgba(254, 242, 214, 0.85);
  border-color: #B4855C;
  color: var(--ink-soft);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.7),
    0 3px 0 #9D714B;
}

.pixel-btn--ghost:hover:not(:disabled) {
  background: var(--parchment-deep);
  color: var(--ink-strong);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.75),
    0 4px 0 #9D714B;
}

.pixel-btn--ghost:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #9D714B;
}

/* Dark surface ghost button adaptation */
.topbar .pixel-btn--ghost,
.quiz-hud .pixel-btn--ghost,
.pixel-panel--dark .pixel-btn--ghost {
  background: rgba(54, 42, 74, 0.88);
  border-color: var(--wood-mid);
  color: var(--parchment);
  box-shadow:
    inset 0 1px 0 rgba(255, 226, 133, 0.2),
    0 3px 0 #1A1226;
}

.topbar .pixel-btn--ghost:hover:not(:disabled),
.quiz-hud .pixel-btn--ghost:hover:not(:disabled),
.pixel-panel--dark .pixel-btn--ghost:hover:not(:disabled) {
  background: rgba(74, 57, 99, 0.95);
  border-color: var(--brass);
  color: var(--brass-bright);
  box-shadow:
    inset 0 1px 0 rgba(255, 226, 133, 0.28),
    0 4px 0 #1A1226;
}

/* Button Sizes */
.pixel-btn--sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 3px 0 var(--wood-dark);
}

.pixel-btn--lg {
  min-height: 54px;
  padding: 13px 24px;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.pixel-btn--block {
  width: 100%;
}

/* Badges & RPG Chips */
.tier-badge,
.tier-badge--must,
.tier-badge--often,
.repeat-badge,
.combo-badge,
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  vertical-align: middle;
}

.tier-badge--must {
  background: linear-gradient(180deg, #FFF7D6 0%, #FFE49B 100%);
  color: #824B05;
  border: 2px solid var(--gold-deep);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 2px 0 #BA7612;
  font-family: var(--font-pixel);
  letter-spacing: 0.03em;
}

.tier-badge--often {
  background: linear-gradient(180deg, #F5F2FF 0%, var(--indigo-bg) 100%);
  color: var(--indigo-deep);
  border: 2px solid var(--indigo);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 2px 0 #51488D;
  font-family: var(--font-pixel);
  letter-spacing: 0.03em;
}

.repeat-badge {
  background: linear-gradient(180deg, #FFF2EE 0%, #FDE2DF 100%);
  color: #A4322B;
  border: 2px solid var(--coral-border);
  box-shadow: 0 2px 0 #C46F6F;
}

.combo-badge {
  background: linear-gradient(180deg, #FFE07A 0%, var(--gold) 65%, var(--gold-deep) 100%);
  color: #361F0E;
  border: 2px solid var(--gold-shadow);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    0 2px 0 var(--gold-shadow),
    0 0 12px rgba(244, 185, 66, 0.45);
  font-family: var(--font-pixel-en);
  font-size: 11px;
  padding: 5px 10px;
  animation: combo-pop 0.32s var(--ease-snappy);
}

.stat-chip {
  background: var(--parchment-warm);
  color: var(--ink);
  border: 2px solid #C9A077;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 2px 0 #9D714B;
  font-size: 13px;
}

.topbar .stat-chip,
.quiz-hud .stat-chip,
.hero-banner .stat-chip,
.pixel-panel--dark .stat-chip {
  background: rgba(34, 26, 48, 0.86);
  color: var(--parchment);
  border-color: var(--wood-mid);
  box-shadow: inset 0 1px 0 rgba(255, 226, 133, 0.2), 0 2px 0 #140E1F;
}

/* Seamless Pixel Shiba Mascot Portrait */
.mascot-avatar {
  width: 78px;
  height: 78px;
  flex-shrink: 0;
  border-radius: 10px;
  background-color: var(--parchment-mascot);
  border: 3px solid var(--wood-mid);
  box-shadow:
    0 0 0 2px var(--wood-dark),
    0 4px 0 var(--wood-dark),
    inset 0 0 0 2px rgba(255, 252, 240, 0.7);
  object-fit: cover;
  image-rendering: auto;
  animation: mascot-float 3.4s ease-in-out infinite;
}

.mascot-avatar--sm {
  width: 52px;
  height: 52px;
  border-width: 2.5px;
}

.mascot-avatar--lg {
  width: 112px;
  height: 112px;
}

/* RPG Dialogue Mascot Bubble */
.mascot-bubble {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #FFFDF5 0%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.82),
    0 4px 0 var(--wood-dark);
}

.mascot-bubble > div,
.mascot-bubble-body {
  min-width: 0;
  flex: 1;
}

.mascot-bubble strong,
.mascot-bubble-title {
  color: var(--wood-dark);
  font-family: var(--font-pixel);
  font-size: 15px;
  letter-spacing: 0.02em;
}

.mascot-bubble p {
  margin: 4px 0 0;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* XP Progress Bar */
.xp-bar {
  position: relative;
  height: 12px;
  min-width: 86px;
  background: #1B1426;
  border: 2px solid var(--wood-mid);
  border-radius: 4px;
  overflow: hidden;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.65),
    0 1px 0 rgba(255, 226, 133, 0.2);
}

.xp-bar-fill {
  height: 100%;
  width: 0%;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.16) 0 6px,
      transparent 6px 12px
    ),
    linear-gradient(180deg, #FFE48A 0%, var(--gold) 55%, var(--gold-deep) 100%);
  box-shadow: 0 0 10px rgba(244, 185, 66, 0.6);
  transition: width 0.55s var(--ease-snappy);
}

/* Keyboard Shortcut Hint Keycap (hidden on touch/mobile, crisp on laptop) */
.kbd-hint {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  margin-left: 4px;
  font-family: var(--font-pixel-en);
  font-size: 9px;
  line-height: 1.2;
  border-radius: 4px;
  background: rgba(56, 38, 27, 0.12);
  border: 1px solid rgba(92, 56, 32, 0.35);
  box-shadow: 0 2px 0 rgba(92, 56, 32, 0.28);
  color: inherit;
  opacity: 0.82;
}

/* ==========================================================================
   4. Login Screen (AAA Cozy RPG Title Screen)
   ========================================================================== */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(20px, env(safe-area-inset-top))
    16px
    max(28px, env(safe-area-inset-bottom));
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 470px;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--parchment-top) 0%, var(--parchment) 55%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 3.5px solid var(--wood-mid);
  border-radius: var(--radius-lg);
  box-shadow:
    0 0 0 2.5px var(--wood-deep),
    0 8px 0 var(--wood-deep),
    0 24px 60px rgba(8, 4, 18, 0.68),
    0 0 50px rgba(244, 185, 66, 0.14);
}

.login-hero {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 196px;
  overflow: hidden;
  background-color: #241B35;
  background-image: url('/assets/hero-study-room.jpg');
  background-size: cover;
  background-position: center;
  border-bottom: 3.5px solid var(--wood-dark);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px 20px;
}

.login-hero > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* Warm lantern twilight vignette over study room artwork */
.login-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(circle at 28% 45%, rgba(255, 214, 102, 0.2), transparent 56%),
    linear-gradient(180deg, rgba(24, 18, 36, 0.12) 0%, rgba(24, 18, 36, 0.34) 48%, rgba(26, 17, 34, 0.92) 100%);
  pointer-events: none;
}

.login-hero > *:not(img) {
  position: relative;
  z-index: 2;
}

.login-hero h1,
.login-hero .login-title {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.25;
  color: #FFF4CC;
  text-shadow:
    0 2px 0 #3B2213,
    0 0 18px rgba(244, 185, 66, 0.45);
  letter-spacing: 0.04em;
}

.login-hero p,
.login-hero .login-subtitle {
  margin: 6px 0 0;
  font-size: 13.5px;
  font-weight: 500;
  color: #F4DFBE;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.login-hero .mascot-avatar {
  width: 68px;
  height: 68px;
  border-color: var(--brass);
  box-shadow:
    0 0 0 2px var(--wood-deep),
    0 4px 12px rgba(0, 0, 0, 0.45);
}

.login-form {
  padding: 22px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--wood-dark);
}

.login-input {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--parchment-input);
  color: var(--ink-strong);
  border: 2.5px solid #BD8E64;
  border-radius: var(--radius-sm);
  font-size: 16px; /* Prevents iOS Safari auto-zoom */
  font-weight: 500;
  box-shadow:
    inset 0 2px 4px rgba(92, 56, 32, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.8);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.login-input::placeholder {
  color: #A68B77;
}

.login-input:focus {
  outline: none;
  background: #FFFFFF;
  border-color: var(--gold-deep);
  box-shadow:
    inset 0 2px 3px rgba(143, 86, 12, 0.1),
    0 0 0 3px rgba(244, 185, 66, 0.34);
}

.login-error {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--coral-bg);
  border: 2px solid var(--coral);
  color: var(--coral-deep);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  box-shadow: 0 2px 0 rgba(178, 62, 62, 0.25);
}

.shake {
  animation: pixel-shake 0.42s ease-in-out;
}

/* ==========================================================================
   5. App Shell, Topbar, Desktop Nav Tabs & Mobile/Tablet Bottom Nav
   ========================================================================== */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  background: linear-gradient(180deg, #3A2A4A 0%, #2B1F3A 58%, #241931 100%);
  color: var(--parchment);
  border-bottom: 3px solid var(--wood-mid);
  box-shadow: var(--shadow-wood-bar);
  padding:
    max(10px, env(safe-area-inset-top))
    16px
    10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.topbar-brand img {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  border: 2px solid var(--brass);
  background: var(--parchment-mascot);
  box-shadow: 0 2px 0 #181124;
  flex-shrink: 0;
}

.topbar-brand-title,
.topbar-brand strong {
  font-family: var(--font-pixel);
  font-size: 17px;
  color: #FFF4CC;
  text-shadow: 0 2px 0 #1A1125;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-brand small,
.topbar-brand-sub {
  display: block;
  font-size: 11px;
  color: #CBB7DE;
  line-height: 1.2;
}

/* Desktop Top Navigation Tabs (hidden <= 1024px where bottom-nav rules) */
.nav-tabs {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: rgba(20, 14, 30, 0.55);
  border: 2px solid rgba(141, 88, 50, 0.72);
  border-radius: var(--radius-sm);
}

.nav-tabs button,
.nav-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 38px;
  border: 2px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: #DFD2EC;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
}

.nav-tabs button:hover,
.nav-tab:hover {
  background: rgba(244, 185, 66, 0.14);
  color: #FFF6D6;
}

.nav-tabs button.active,
.nav-tab.active {
  background: linear-gradient(180deg, #FFD86E 0%, var(--gold) 100%);
  color: #361F0E;
  border-color: var(--gold-shadow);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 2px 0 var(--gold-shadow);
}

.topbar-xp {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-xp .lv-badge,
.lv-badge {
  font-family: var(--font-pixel-en);
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 4px;
  background: linear-gradient(180deg, #FFE07D, var(--gold));
  color: #361F0E;
  border: 2px solid var(--gold-shadow);
  box-shadow: 0 2px 0 #181124;
  white-space: nowrap;
}

.topbar-xp .xp-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.topbar-xp .xp-label {
  font-family: var(--font-pixel-en);
  font-size: 9px;
  color: #F6DFAD;
  line-height: 1;
}

/* Main Content Stage */
.main-content {
  width: 100%;
  flex: 1;
  margin: 0 auto;
  padding: 14px 14px calc(var(--bottom-nav-h) + 26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Mobile & Tablet Carved-Wood Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  background: linear-gradient(180deg, #362747 0%, #241932 100%);
  border-top: 3px solid var(--wood-mid);
  box-shadow:
    inset 0 2px 0 rgba(255, 226, 133, 0.2),
    0 -6px 22px rgba(8, 4, 16, 0.52);
  padding: 4px 6px calc(6px + env(safe-area-inset-bottom));
}

.bottom-nav button,
.bottom-nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  padding: 6px 4px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #CDBEE0;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.14s ease, background-color 0.14s ease, transform 0.1s ease;
}

.bottom-nav button:active,
.bottom-nav-btn:active {
  transform: scale(0.95);
}

.bottom-nav button.active,
.bottom-nav-btn.active {
  color: #FFE48A;
  background: rgba(244, 185, 66, 0.15);
  border-color: rgba(244, 185, 66, 0.45);
}

.bottom-nav button.active::before,
.bottom-nav-btn.active::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 24%;
  right: 24%;
  height: 4px;
  background: var(--gold-bright);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(244, 185, 66, 0.85);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--coral);
  color: #FFFDF7;
  border: 1.5px solid #FFFDF7;
  font-family: var(--font-pixel-en);
  font-size: 9px;
  line-height: 1;
}

.bottom-nav .nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 24px);
}

/* ==========================================================================
   6. Home Quest Board (Hero Banner, Quest Config, Subjects & Topics)
   ========================================================================== */

.hero-banner {
  position: relative;
  overflow: hidden;
  border: 3px solid var(--wood-mid);
  border-radius: var(--radius-lg);
  background-color: #251C36;
  background-image:
    linear-gradient(105deg, rgba(24, 16, 36, 0.92) 0%, rgba(33, 23, 47, 0.78) 54%, rgba(28, 20, 40, 0.65) 100%),
    url('/assets/hero-study-room.jpg');
  background-size: cover;
  background-position: center;
  color: var(--parchment);
  padding: 20px;
  box-shadow:
    0 0 0 2px var(--wood-deep),
    0 6px 0 var(--wood-deep),
    0 18px 34px rgba(8, 4, 16, 0.52);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-banner h1,
.hero-banner h2 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(20px, 4.4vw, 28px);
  color: #FFF4CC;
  text-shadow: 0 2px 0 #1E132B, 0 0 18px rgba(244, 185, 66, 0.35);
}

.hero-banner p {
  margin: 4px 0 0;
  color: #EADAC3;
  font-size: 14.5px;
}

.hero-banner .mascot-bubble {
  background: rgba(255, 248, 231, 0.96);
  color: var(--ink);
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Quest Configurator Panel */
.quest-config {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quest-config-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quest-config-label,
.section-label {
  font-family: var(--font-pixel);
  font-size: 14px;
  font-weight: 700;
  color: var(--wood-dark);
  letter-spacing: 0.03em;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid #BA8D64;
  border-radius: var(--radius-sm);
  background: #FFFDF6;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.85), 0 3px 0 #A57850;
  transition: transform 0.1s var(--ease-snappy), background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.1s ease;
}

.pill-btn:hover {
  background: var(--gold-bg);
  border-color: var(--gold-deep);
  color: var(--ink-strong);
}

.pill-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A57850;
}

.pill-btn.active {
  background: linear-gradient(180deg, #FFDC73 0%, var(--gold) 100%);
  border-color: var(--gold-shadow);
  color: #361F0E;
  box-shadow:
    inset 0 2px 0 rgba(255, 252, 232, 0.85),
    0 3px 0 var(--gold-shadow),
    0 0 12px rgba(244, 185, 66, 0.35);
}

/* Subject Guild Cards */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.subject-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: linear-gradient(180deg, #FFFDF6 0%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card-sm);
  cursor: pointer;
  text-align: left;
  transition: transform 0.14s var(--ease-snappy), box-shadow 0.14s var(--ease-snappy), border-color 0.14s ease;
}

.subject-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold-deep);
  box-shadow:
    0 6px 0 var(--wood-dark),
    0 12px 24px rgba(10, 6, 18, 0.32),
    0 0 0 2px rgba(244, 185, 66, 0.35);
}

.subject-card:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 var(--wood-dark);
}

.subject-card.active {
  border-color: var(--gold-deep);
  background: linear-gradient(180deg, #FFFBF0 0%, #FFF0C2 100%);
}

.subject-card h3 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 17px;
  color: var(--ink-strong);
}

.subject-card p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

/* High-Frequency Topic Board */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topic-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: #FFFDF6;
  border: 2px solid #CAA179;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 3px 0 #9D714B;
  cursor: pointer;
  transition: transform 0.12s var(--ease-snappy), border-color 0.14s ease, background-color 0.14s ease;
}

.topic-row:hover {
  transform: translateY(-2px);
  border-color: var(--gold-deep);
  background: #FFFBF0;
}

.topic-row:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #9D714B;
}

.topic-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.topic-row-title {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink-strong);
  min-width: 0;
}

.prob-bar {
  position: relative;
  width: 100%;
  height: 10px;
  background: #EAD8BA;
  border: 1.5px solid #A47B55;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(56, 38, 27, 0.25);
}

.prob-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-deep) 0%, var(--gold) 60%, var(--gold-bright) 100%);
  transition: width 0.5s var(--ease-snappy);
}

/* ==========================================================================
   7. Quiz Arena (Distraction-Free Study Desk)
   ========================================================================== */

.quiz-arena {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quiz-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #352747 0%, #261C36 100%);
  color: var(--parchment);
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-wood-bar);
}

.progress-track {
  position: relative;
  flex: 1 1 160px;
  height: 12px;
  background: #171122;
  border: 2px solid var(--wood-mid);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.18) 0 8px,
      transparent 8px 16px
    ),
    linear-gradient(180deg, #FFE48A 0%, var(--gold) 60%, var(--gold-deep) 100%);
  box-shadow: 0 0 10px rgba(244, 185, 66, 0.55);
  transition: width 0.35s var(--ease-snappy);
}

/* Question Parchment Card */
.question-card {
  position: relative;
  background: linear-gradient(180deg, #FFFDF7 0%, var(--parchment) 60%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 3px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: card-enter 0.24s var(--ease-snappy);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding-bottom: 12px;
  border-bottom: 2px dashed rgba(141, 88, 50, 0.28);
}

.question-card h2,
.question-stem,
.question-text {
  margin: 0;
  font-family: var(--font-body);
  font-size: clamp(17px, 2.4vw, 19.5px);
  font-weight: 700;
  line-height: 1.75;
  letter-spacing: 0.015em;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

/* Negative / Reverse-Question Trap Word Highlight */
.trap-word {
  display: inline-block;
  padding: 0 6px;
  margin: 0 2px;
  border-radius: 4px;
  background: #FDE0E0;
  color: #A82424;
  border-bottom: 2.5px solid var(--coral);
  font-weight: 900;
  box-shadow: 0 1px 0 rgba(217, 90, 90, 0.25);
}

/* Options Stack — Big Ergonomic Tap Targets */
.option-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 11px;
}

.option-btn {
  position: relative;
  width: 100%;
  min-height: 56px;
  padding: 13px 15px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  background: #FFFDF8;
  color: var(--ink);
  border: 2.5px solid #C69B71;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    0 3.5px 0 #A4774E;
  transition:
    transform 0.1s var(--ease-snappy),
    border-color 0.14s ease,
    background-color 0.14s ease,
    box-shadow 0.1s var(--ease-snappy),
    opacity 0.2s ease;
}

.option-btn:hover:not(:disabled) {
  background: #FFF7DF;
  border-color: var(--gold-deep);
  transform: translateY(-1px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.92),
    0 4.5px 0 #B37718;
}

.option-btn:active:not(:disabled) {
  transform: translateY(2.5px);
  box-shadow: 0 1px 0 #A4774E;
}

.option-btn:disabled {
  cursor: default;
}

.option-key {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: linear-gradient(180deg, #FFF5D8 0%, #F1DBAE 100%);
  border: 2px solid #A87B50;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 2px 0 #8D5832;
  font-family: var(--font-pixel-en);
  font-size: 11px;
  color: var(--wood-dark);
}

.option-text {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.66;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

/* Answered Option States */
.option-btn--correct {
  background: linear-gradient(180deg, #EFFAF0 0%, var(--sage-bg) 100%);
  border-color: var(--sage);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.85),
    0 4px 0 var(--sage-shadow),
    0 0 0 2px rgba(78, 142, 90, 0.22);
  animation: correct-pop 0.34s var(--ease-snappy);
}

.option-btn--correct .option-key {
  background: linear-gradient(180deg, var(--sage-bright), var(--sage));
  border-color: var(--sage-shadow);
  color: #FFFDF7;
  box-shadow: 0 2px 0 var(--sage-shadow);
}

.option-btn--correct .option-text {
  font-weight: 700;
  color: #1D4525;
}

.option-btn--wrong {
  background: linear-gradient(180deg, #FFF2F2 0%, var(--coral-bg) 100%);
  border-color: var(--coral);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.8),
    0 4px 0 var(--coral-shadow);
  animation: wrong-nudge 0.36s ease-in-out;
}

.option-btn--wrong .option-key {
  background: linear-gradient(180deg, var(--coral-bright), var(--coral));
  border-color: var(--coral-shadow);
  color: #FFFDF7;
  box-shadow: 0 2px 0 var(--coral-shadow);
}

.option-btn--wrong .option-text {
  color: #7D2323;
}

.option-btn--dim {
  opacity: 0.54;
  filter: saturate(0.75);
  box-shadow: 0 2px 0 #B89879;
}

/* ==========================================================================
   8. Quick-Pass Coach Drawer (柴柴白話教練解析)
   ========================================================================== */

.coach-drawer {
  position: relative;
  border-radius: var(--radius-md);
  border: 3px solid var(--wood-mid);
  background: linear-gradient(180deg, #FFFDF7 0%, var(--parchment) 100%);
  color: var(--ink);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  animation: drawer-rise 0.3s var(--ease-snappy);
}

.coach-drawer--correct {
  border-color: var(--sage);
  box-shadow:
    0 0 0 2px var(--sage-shadow),
    0 5px 0 var(--sage-shadow),
    0 14px 28px rgba(10, 6, 18, 0.44);
}

.coach-drawer--wrong {
  border-color: var(--coral);
  box-shadow:
    0 0 0 2px var(--coral-shadow),
    0 5px 0 var(--coral-shadow),
    0 14px 28px rgba(10, 6, 18, 0.44);
}

.coach-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--parchment-warm);
  border-bottom: 2.5px solid rgba(141, 88, 50, 0.25);
  flex-wrap: wrap;
}

.coach-drawer--correct .coach-header {
  background: linear-gradient(90deg, #DDF2E0 0%, #EEF9EF 100%);
  border-bottom-color: var(--sage-border);
  color: #1F4E29;
}

.coach-drawer--wrong .coach-header {
  background: linear-gradient(90deg, #FDE4E4 0%, #FFF2EC 100%);
  border-bottom-color: var(--coral-border);
  color: #882626;
}

.coach-header .mascot-avatar {
  width: 58px;
  height: 58px;
}

.coach-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

/* Direct children fallback spacing if app.js places coach blocks directly inside .coach-drawer */
.coach-drawer > .coach-mantra,
.coach-drawer > .coach-plain,
.coach-drawer > .coach-steps,
.coach-drawer > .coach-formula,
.coach-drawer > .coach-guess,
.coach-drawer > .coach-actions {
  margin-left: 16px;
  margin-right: 16px;
}

.coach-drawer > .coach-mantra {
  margin-top: 14px;
}

.coach-drawer > .coach-plain,
.coach-drawer > .coach-steps,
.coach-drawer > .coach-formula,
.coach-drawer > .coach-guess {
  margin-top: 12px;
}

.coach-drawer > .coach-actions {
  margin-top: 14px;
  margin-bottom: 16px;
}

.coach-mantra {
  padding: 13px 15px;
  background: linear-gradient(180deg, #FFF9E0 0%, var(--gold-bg) 100%);
  border: 2px solid var(--gold-border);
  border-left: 5px solid var(--gold-deep);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.65;
  color: #4D2C0A;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.coach-plain {
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink);
  padding: 2px 2px;
}

.coach-steps {
  padding: 13px 15px;
  background: #FFFBF0;
  border: 2px solid #DEC09A;
  border-radius: var(--radius-sm);
}

.coach-steps ol,
.coach-steps ul {
  margin: 6px 0 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.coach-steps li {
  font-size: 15px;
  line-height: 1.68;
  color: var(--ink);
}

.coach-steps li::marker {
  font-family: var(--font-pixel);
  font-weight: 700;
  color: var(--wood-mid);
}

.coach-formula {
  padding: 12px 15px;
  background: linear-gradient(180deg, #2B223C 0%, #211A30 100%);
  color: #FFE48A;
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, 'SFMono-Regular', 'DotGothic16', Menlo, Consolas, monospace;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.65;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
  overflow-x: auto;
}

.coach-guess {
  padding: 12px 15px;
  background: linear-gradient(180deg, #F6F4FF 0%, var(--indigo-bg) 100%);
  border: 2px solid var(--indigo-border);
  border-left: 5px solid var(--indigo);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.65;
  color: #362E6B;
}

.coach-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
}

.coach-actions .pixel-btn--gold,
.coach-actions .pixel-btn--lg {
  flex: 1 1 200px;
}

/* ==========================================================================
   9. Mistake Notebook (錯題復仇本)
   ========================================================================== */

.mistake-filters {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mistake-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mistake-card {
  position: relative;
  background: linear-gradient(180deg, #FFFDF8 0%, var(--parchment) 100%);
  color: var(--ink);
  border: 2.5px solid #CCA07A;
  border-left: 6px solid var(--coral);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  box-shadow: var(--shadow-card-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.12s var(--ease-snappy), border-color 0.14s ease;
}

.mistake-card--mastered {
  background: linear-gradient(180deg, #F7FCF7 0%, #EAF6EC 100%);
  border-color: var(--sage-border);
  border-left: 6px solid var(--sage);
}

.mistake-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-xs);
  background: var(--coral-bg);
  color: var(--coral-deep);
  border: 1.5px solid var(--coral-border);
  font-family: var(--font-pixel);
  font-size: 12px;
  font-weight: 700;
}

.mistake-card--mastered .mistake-badge {
  background: var(--sage-bg);
  color: var(--sage-deep);
  border-color: var(--sage-border);
}

.mistake-expand {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 2px dashed rgba(141, 88, 50, 0.26);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: drawer-rise 0.22s var(--ease-snappy);
}

.streak-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.streak-dot {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: #EAD8BE;
  border: 1.5px solid #A47D59;
}

.streak-dot.filled {
  background: var(--sage);
  border-color: var(--sage-shadow);
  box-shadow: 0 0 6px rgba(78, 142, 90, 0.5);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 36px 20px;
  background: linear-gradient(180deg, #FFFDF6 0%, var(--parchment-warm) 100%);
  border: 3px dashed #C79A70;
  border-radius: var(--radius-md);
  color: var(--ink-soft);
}

.empty-state .mascot-avatar {
  width: 96px;
  height: 96px;
}

.empty-state h3 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 19px;
  color: var(--ink-strong);
}

.empty-state p {
  margin: 0;
  max-width: 420px;
  font-size: 15px;
}

/* ==========================================================================
   10. Quick-Pass Codex (黃金口訣・計算步驟・猜題技巧)
   ========================================================================== */

.codex-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px;
  background: rgba(34, 26, 48, 0.84);
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-wood-bar);
}

.codex-tabs button {
  flex: 1 1 110px;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #E2D5EF;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
}

.codex-tabs button:hover {
  background: rgba(244, 185, 66, 0.15);
  color: #FFF4CC;
}

.codex-tabs button.active {
  background: linear-gradient(180deg, #FFD86E 0%, var(--gold) 100%);
  color: #361F0E;
  border-color: var(--gold-shadow);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78), 0 2px 0 var(--gold-shadow);
}

.codex-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.codex-card {
  position: relative;
  background: linear-gradient(180deg, #FFFDF7 0%, var(--parchment) 56%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 2.5px solid var(--wood-mid);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  box-shadow: var(--shadow-card-sm);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.codex-card h3 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink-strong);
}

.codex-card p {
  margin: 0;
  font-size: 15px;
  line-height: 1.72;
  color: var(--ink-soft);
}

/* Interactive Hide-Answer Memorization Blur */
.codex-blur {
  position: relative;
  border-radius: var(--radius-xs);
  filter: blur(7px);
  user-select: none;
  cursor: pointer;
  background: rgba(244, 185, 66, 0.16);
  transition: filter 0.22s ease, background-color 0.22s ease;
}

.codex-blur:hover,
.codex-blur:focus-visible,
.codex-blur.revealed,
.codex-blur.is-revealed {
  filter: blur(0);
  user-select: auto;
  background: transparent;
}

.calc-steps {
  padding: 12px 14px;
  background: #FFFBF0;
  border: 2px solid #DEC09A;
  border-radius: var(--radius-sm);
}

.calc-steps ol,
.calc-steps ul {
  margin: 6px 0 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc-steps li {
  font-size: 15px;
  line-height: 1.66;
  color: var(--ink);
}

.guess-example {
  padding: 12px 14px;
  background: linear-gradient(180deg, #F7F5FF 0%, var(--indigo-bg) 100%);
  border: 2px solid var(--indigo-border);
  border-left: 5px solid var(--indigo);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.68;
  color: #352D66;
}

/* ==========================================================================
   11. Modals, Victory Celebration, Confetti & Toasts
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  background: rgba(16, 11, 26, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease-out;
}

.victory-modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 22px;
  background: linear-gradient(180deg, #FFFDF5 0%, var(--parchment) 55%, var(--parchment-warm) 100%);
  color: var(--ink);
  border: 3.5px solid var(--gold-deep);
  border-radius: var(--radius-lg);
  box-shadow:
    0 0 0 3px var(--wood-dark),
    0 8px 0 var(--wood-deep),
    0 24px 54px rgba(8, 4, 18, 0.72),
    0 0 40px rgba(244, 185, 66, 0.3);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: modal-pop 0.34s var(--ease-snappy);
}

.victory-modal .mascot-avatar {
  width: 120px;
  height: 120px;
  border-color: var(--gold-deep);
  box-shadow:
    0 0 0 2.5px var(--wood-dark),
    0 5px 0 var(--wood-dark),
    0 0 24px rgba(244, 185, 66, 0.45);
}

.victory-modal h2 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 24px;
  color: var(--ink-strong);
  letter-spacing: 0.04em;
}

.victory-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.victory-stat {
  padding: 10px 8px;
  background: #FFFDF7;
  border: 2px solid #D3A87C;
  border-radius: var(--radius-sm);
  box-shadow: 0 3px 0 #A87B50;
}

.victory-stat strong {
  display: block;
  font-family: var(--font-pixel-en);
  font-size: 16px;
  color: var(--gold-shadow);
  margin-bottom: 4px;
}

.victory-stat span {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.victory-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

/* Pixel Confetti Burst inside Victory Modal */
.confetti-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}

.confetti-burst > span,
.confetti-piece {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  background: var(--gold);
  animation: confetti-fall 2.2s ease-out forwards;
}

.confetti-burst > span:nth-child(4n + 1) { background: #FFD466; }
.confetti-burst > span:nth-child(4n + 2) { background: #67AC74; }
.confetti-burst > span:nth-child(4n + 3) { background: #EC7676; }
.confetti-burst > span:nth-child(4n + 4) { background: #877EC7; }

.confetti-burst > span:nth-child(1)  { left: 8%;  animation-delay: 0.05s; }
.confetti-burst > span:nth-child(2)  { left: 18%; animation-delay: 0.18s; }
.confetti-burst > span:nth-child(3)  { left: 28%; animation-delay: 0.08s; }
.confetti-burst > span:nth-child(4)  { left: 39%; animation-delay: 0.24s; }
.confetti-burst > span:nth-child(5)  { left: 50%; animation-delay: 0.02s; }
.confetti-burst > span:nth-child(6)  { left: 61%; animation-delay: 0.16s; }
.confetti-burst > span:nth-child(7)  { left: 72%; animation-delay: 0.1s; }
.confetti-burst > span:nth-child(8)  { left: 82%; animation-delay: 0.22s; }
.confetti-burst > span:nth-child(9)  { left: 91%; animation-delay: 0.12s; }
.confetti-burst > span:nth-child(10) { left: 14%; animation-delay: 0.34s; }
.confetti-burst > span:nth-child(11) { left: 45%; animation-delay: 0.3s; }
.confetti-burst > span:nth-child(12) { left: 76%; animation-delay: 0.28s; }

/* Cozy Wooden Toast Notification */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(92vw, 420px);
  padding: 11px 18px;
  background: linear-gradient(180deg, #3B2B4C 0%, #261B35 100%);
  color: #FFF6DC;
  border: 2.5px solid var(--gold);
  border-radius: var(--radius-sm);
  box-shadow:
    0 4px 0 #160F22,
    0 12px 26px rgba(0, 0, 0, 0.55);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  animation: toast-up 0.24s var(--ease-snappy);
}

/* Loading State */
.loading-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  color: #FFF4CC;
  font-family: var(--font-pixel);
  font-size: 17px;
  text-align: center;
}

/* ==========================================================================
   12. Helpful Structural Utilities
   ========================================================================== */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--ink-strong);
  letter-spacing: 0.03em;
}

.section-sub {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   13. Responsive Breakpoints — Tablet (640–1024px) & Laptop (>1024px)
   ========================================================================== */

/* Tablet: 640px – 1024px */
@media (min-width: 640px) {
  .topbar {
    padding: max(12px, env(safe-area-inset-top)) 22px 12px;
  }

  .main-content {
    max-width: 780px;
    padding: 20px 22px calc(var(--bottom-nav-h) + 32px + env(safe-area-inset-bottom));
    gap: 20px;
  }

  .pixel-panel {
    padding: 24px;
  }

  .hero-banner {
    padding: 24px 26px;
  }

  .subject-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topic-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .codex-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .question-card {
    padding: 24px 26px 26px;
  }

  .option-btn {
    padding: 15px 18px;
  }

  .option-text {
    font-size: 16.5px;
  }

  .victory-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .victory-actions .pixel-btn {
    flex: 1 1 140px;
  }
}

/* Laptop & Desktop: > 1024px */
@media (min-width: 1025px) {
  .topbar {
    padding: 10px 28px;
  }

  .nav-tabs {
    display: inline-flex;
  }

  .bottom-nav {
    display: none;
  }

  .main-content {
    max-width: 980px;
    padding: 26px 28px 54px;
    gap: 22px;
  }

  .subject-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .kbd-hint {
    display: inline-flex;
  }

  .toast {
    left: auto;
    right: 28px;
    bottom: 26px;
    transform: none;
    animation-name: toast-up-desktop;
  }

  .question-card {
    padding: 28px 30px 30px;
  }

  .option-text {
    font-size: 17px;
  }
}

/* Very small phones (< 380px) micro-polish */
@media (max-width: 379px) {
  .topbar {
    padding-left: 10px;
    padding-right: 10px;
    gap: 8px;
  }

  .topbar-brand-title,
  .topbar-brand strong {
    font-size: 15px;
  }

  .xp-bar {
    min-width: 64px;
  }

  .mascot-bubble {
    padding: 12px;
    gap: 10px;
  }

  .mascot-avatar {
    width: 64px;
    height: 64px;
  }

  .victory-stats {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   14. Animations & Reduced Motion
   ========================================================================== */

@keyframes firefly-drift-a {
  0%   { transform: translate(0, 0) scale(0.8); opacity: 0; }
  18%  { opacity: 0.78; }
  50%  { transform: translate(26px, -46px) scale(1.1); opacity: 0.92; }
  82%  { opacity: 0.5; }
  100% { transform: translate(-14px, -92px) scale(0.75); opacity: 0; }
}

@keyframes firefly-drift-b {
  0%   { transform: translate(0, 0) scale(0.85); opacity: 0; }
  22%  { opacity: 0.72; }
  54%  { transform: translate(-28px, -38px) scale(1.05); opacity: 0.88; }
  84%  { opacity: 0.45; }
  100% { transform: translate(18px, -84px) scale(0.7); opacity: 0; }
}

@keyframes mascot-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

@keyframes card-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes drawer-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes correct-pop {
  0%   { transform: scale(0.985); }
  55%  { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@keyframes wrong-nudge {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  60%      { transform: translateX(4px); }
  85%      { transform: translateX(-2px); }
}

@keyframes pixel-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(7px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(4px); }
}

@keyframes combo-pop {
  0%   { transform: scale(0.86); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-pop {
  0%   { opacity: 0; transform: scale(0.92) translateY(12px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(340px) rotate(300deg); opacity: 0; }
}

@keyframes toast-up {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes toast-up-desktop {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .fireflies {
    display: none;
  }
}
