/* =============================================================
   Marco Cavicchioli — Osservatorio · Telegram Mini App
   Theme: cream paper + deep blue + accent orange
   Fonts: Lora (serif) + Inter (sans)
   Vibe: scholarly newspaper / The Economist
   ============================================================= */

:root {
  color-scheme: light;
  --paper: #faf8f3;
  --paper-2: #f4f1e8;
  --paper-3: #ebe6d6;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --ink-4: #94a3b8;
  --rule: rgba(15, 23, 42, 0.12);
  --rule-strong: rgba(15, 23, 42, 0.2);

  --accent: #1e40af;        /* deep blue */
  --accent-dim: #1e3a8a;
  --accent-light: #dbeafe;
  --accent-glow: rgba(30, 64, 175, 0.12);

  --red: #be123c;           /* сrimson (красный свитер Marco) */
  --red-dim: #9f1239;
  --orange: #c2410c;        /* deep orange (bitcoin ссылка) */
  --orange-light: #fed7aa;
  --green: #047857;
  --amber: #b45309;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse at top right, rgba(30, 64, 175, 0.04) 0%, transparent 45%),
    radial-gradient(ellipse at bottom left, rgba(194, 65, 12, 0.03) 0%, transparent 50%),
    var(--paper);
  background-size: cover;
  min-height: 100vh;
  /* Subtle paper texture via overlay */
  background-image:
    radial-gradient(circle at 20% 10%, rgba(30, 64, 175, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(194, 65, 12, 0.02) 0%, transparent 50%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 24px 20px 40px;
  max-width: 480px;
  margin: 0 auto;
  animation: fadeIn 0.35s ease-out;
}

.screen.active { display: block; }

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

@supports (padding-top: env(safe-area-inset-top)) {
  .screen {
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }
}

/* =============================================================
   HOME — like newspaper masthead
   ============================================================= */

.hero {
  text-align: center;
  margin-bottom: 20px;
  padding-top: 8px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 20px;
}

.masthead {
  font-family: 'Inter', sans-serif;
  font-size: 10px; font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.35em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.hero-title { margin: 0; }
.hero-title .serif {
  font-family: 'Lora', Georgia, serif;
  font-weight: 700;
  font-size: 34px;
  line-height: 1.05;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.hero-sub {
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 6px;
  letter-spacing: 0;
}

.rule {
  width: 60px; height: 2px;
  background: var(--accent);
  margin: 14px auto 0;
}

.hero-tag {
  font-size: 13px; line-height: 1.55;
  color: var(--ink-2);
  margin: 14px auto 0;
  max-width: 340px;
}

/* Mascot on home */
.mascot-home {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.mascot-img {
  width: 56px; height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-2);
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.mascot-bubble {
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.4;
}

/* Stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-card {
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.stat-label {
  font-size: 10px; font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  margin-bottom: 4px;
  text-transform: uppercase;
}
.stat-value {
  font-family: 'Lora', Georgia, serif;
  font-size: 24px; font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Rank */
.rank-card {
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
  position: relative;
}
.rank-top { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.rank-label {
  font-size: 10px; letter-spacing: 0.12em;
  color: var(--ink-3);
  font-weight: 700; text-transform: uppercase;
}
.rank-name {
  font-family: 'Lora', Georgia, serif;
  font-size: 22px; font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}
.rank-xp {
  font-size: 14px; font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.rank-bar {
  height: 4px;
  background: var(--paper-3);
  border-radius: 2px; overflow: hidden;
}
.rank-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s ease;
}
.rank-next {
  font-size: 11px; color: var(--ink-3);
  margin-top: 6px;
}

/* Milestone */
.ach-showcase {
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.ach-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  text-transform: uppercase;
}
.ach-counter {
  color: var(--accent);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.ach-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ach-chip {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  opacity: 0.35;
  transition: all 0.3s;
  filter: grayscale(0.8);
}
.ach-chip.unlocked {
  opacity: 1;
  filter: grayscale(0);
  background: var(--accent-light);
  border-color: var(--accent);
}

/* Buttons */
.btn-primary {
  width: 100%; padding: 16px 20px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.15em;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.2);
  transition: all 0.2s;
  position: relative; overflow: hidden;
  text-transform: uppercase;
}
.btn-primary::before {
  content: ''; position: absolute; inset: 0;
  background: var(--accent);
  opacity: 0; transition: opacity 0.2s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:hover::before { opacity: 1; }
.btn-primary > * { position: relative; z-index: 1; }
.btn-arrow { font-size: 16px; }

.btn-ghost {
  width: 100%; margin-top: 10px; padding: 12px;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.btn-ghost:active { background: var(--paper-2); }

.credits {
  text-align: center; font-size: 11px;
  color: var(--ink-3);
  margin-top: 18px;
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
}

/* =============================================================
   GAME HUD
   ============================================================= */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.hud-lives { display: flex; gap: 4px; font-size: 14px; color: var(--red); }
.hud-lives .heart { transition: all 0.3s; }
.hud-lives .heart.lost {
  color: var(--paper-3);
  transform: scale(0.85);
}

.hud-timer {
  position: relative; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.timer-ring { transform: rotate(-90deg); display: block; }
.timer-track { fill: none; stroke: var(--paper-3); stroke-width: 3.5; }
.timer-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-dasharray: 125.66;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-progress.warn { stroke: var(--orange); }
.timer-progress.danger { stroke: var(--red); animation: pulseRed 0.5s ease infinite alternate; }
@keyframes pulseRed { from { opacity: 1; } to { opacity: 0.5; } }

.timer-num {
  position: absolute;
  font-family: 'Lora', serif;
  font-size: 14px; font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.hud-streak {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-size: 12px; font-weight: 700;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  transition: all 0.2s;
}
.hud-streak.hot {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.hud-score {
  font-family: 'Lora', serif;
  font-size: 15px; font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Timeline progress bar (unique!) */
.timeline-wrap {
  margin-bottom: 16px;
  padding: 12px 10px 18px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
}
.timeline-years {
  display: flex; justify-content: space-between;
  font-family: 'Lora', serif;
  font-size: 10px; font-weight: 700;
  color: var(--ink-3);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}
.timeline-track {
  height: 3px;
  background: var(--paper-3);
  position: relative;
  border-radius: 2px;
}
.timeline-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 2px;
  transition: width 0.6s ease;
}
.timeline-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px; height: 32px;
  background: var(--paper);
  border: 2px solid var(--accent);
  border-radius: 50%;
  transition: left 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  left: 0%;
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}
.dot-img {
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

/* Level row */
.level-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.level-pill {
  padding: 5px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  text-transform: uppercase;
}
.year-pill {
  padding: 5px 12px;
  background: var(--accent);
  color: var(--paper);
  border-radius: 100px;
  font-family: 'Lora', serif;
  font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  animation: multPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes multPop {
  from { transform: scale(0) rotate(-6deg); }
  to { transform: scale(1) rotate(0); }
}

/* Question card with mascot */
.question-card {
  padding: 22px 20px 18px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
  position: relative;
  animation: slideIn 0.4s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.mascot-game {
  position: absolute;
  top: -20px; right: 16px;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--accent);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(30, 64, 175, 0.25);
  transition: transform 0.3s;
}
.mascot-game.correct { animation: mascotNod 0.5s ease; border-color: var(--green); }
.mascot-game.wrong { animation: mascotShake 0.5s ease; border-color: var(--red); }
.mascot-game .mascot-img { width: 100%; height: 100%; border-radius: 0; }

@keyframes mascotNod {
  0%, 100% { transform: rotate(0); }
  40% { transform: rotate(-8deg) scale(1.1); }
  70% { transform: rotate(8deg) scale(1.1); }
}
@keyframes mascotShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-3deg); }
  75% { transform: translateX(6px) rotate(3deg); }
}

/* idle breathing */
@keyframes idleBreathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.02); }
}
.mascot-game:not(.correct):not(.wrong) {
  animation: idleBreathe 3s ease-in-out infinite;
}

.question-number {
  font-size: 10px; font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.15em;
  margin-bottom: 10px;
  text-transform: uppercase;
  padding-right: 60px; /* evita sovrapposizione mascot */
}
.question-text {
  font-family: 'Lora', Georgia, serif;
  font-size: 18px; font-weight: 500;
  line-height: 1.4;
  color: var(--ink);
  text-wrap: balance;
}

.fact-reveal {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  animation: revealIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.fact-reveal.wrong {
  background: rgba(190, 18, 60, 0.08);
  border-left-color: var(--red);
}
.fact-label {
  font-size: 9px; font-weight: 800;
  color: var(--accent-dim);
  letter-spacing: 0.15em;
  margin-bottom: 4px;
}
.fact-reveal.wrong .fact-label { color: var(--red); }
.fact-text {
  font-family: 'Lora', Georgia, serif;
  font-size: 13px; font-style: italic;
  line-height: 1.5;
  color: var(--ink-2);
}
@keyframes revealIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Answers */
.answers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.answer {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px; font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%; min-width: 0;
  animation: ansIn 0.35s ease backwards;
}
.answer:nth-child(1) { animation-delay: 0.05s; }
.answer:nth-child(2) { animation-delay: 0.1s; }
.answer:nth-child(3) { animation-delay: 0.15s; }
.answer:nth-child(4) { animation-delay: 0.2s; }
@keyframes ansIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}
.answer:not(:disabled):active { transform: scale(0.98); }
.answer:not(:disabled):hover {
  border-color: var(--ink);
  background: var(--paper-2);
}
.answer-letter {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: 'Lora', serif;
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.answer-text { flex: 1; line-height: 1.35; min-width: 0; }
.answer.correct {
  background: rgba(4, 120, 87, 0.08);
  border-color: var(--green);
  color: var(--green);
}
.answer.correct .answer-letter {
  background: var(--green);
  border-color: var(--green);
  color: var(--paper);
}
.answer.wrong {
  background: rgba(190, 18, 60, 0.08);
  border-color: var(--red);
  color: var(--red);
  animation: shake 0.4s ease;
}
.answer.wrong .answer-letter {
  background: var(--red);
  border-color: var(--red);
  color: var(--paper);
}
.answer.hidden-5050 { opacity: 0.25; pointer-events: none; }
.answer:disabled { cursor: default; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Lifelines */
.lifelines { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.lifeline {
  padding: 10px 4px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: var(--shadow-card);
}
.lifeline:not(:disabled):active { transform: scale(0.96); }
.lifeline:not(:disabled):hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.ll-icon {
  font-family: 'Lora', serif;
  font-size: 15px; font-weight: 700;
  color: var(--accent);
}
.ll-label {
  font-size: 9px; font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.lifeline.used {
  opacity: 0.4; cursor: not-allowed; pointer-events: none;
  box-shadow: none;
}
.lifeline.used .ll-icon { color: var(--ink-3); text-decoration: line-through; }

.btn-quit {
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--ink-3);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius-md);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-quit:hover {
  color: var(--red);
  border-color: var(--red);
}

/* =============================================================
   RESULT
   ============================================================= */

#screen-result {
  text-align: center;
  display: none;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  padding-top: calc(40px + env(safe-area-inset-top));
  position: relative;
}
#screen-result.active { display: flex; }

.confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 1; }

.result-mascot {
  width: 120px; height: 120px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--paper);
  margin: 0 auto 8px;
  object-fit: cover;
  image-rendering: pixelated;
  box-shadow: 0 8px 24px rgba(30, 64, 175, 0.3);
  animation: popIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

.result-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 28px; font-weight: 700;
  margin: 12px 0 4px;
  color: var(--ink);
  text-wrap: balance;
  letter-spacing: -0.01em;
}
.result-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0 0 12px;
  font-family: 'Lora', serif;
  font-style: italic;
}
.result-prize {
  font-family: 'Lora', serif;
  font-size: 52px; font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  animation: scoreCount 0.8s ease;
}
@keyframes scoreCount {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.rank-badge {
  display: inline-block;
  margin: 0 auto 20px;
  padding: 6px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 11px; font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.result-stats {
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  text-align: left;
  box-shadow: var(--shadow-card);
  position: relative; z-index: 2;
}
.rs-row {
  display: flex; justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px dotted var(--rule);
  gap: 12px;
}
.rs-row-last { border-bottom: none; }
.rs-label {
  font-size: 13px; color: var(--ink-3);
  font-family: 'Lora', serif;
}
.rs-value {
  font-size: 14px; font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.result-ach {
  padding: 14px 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  text-align: left;
  position: relative; z-index: 2;
}
.result-ach-title {
  font-size: 11px; font-weight: 800;
  color: var(--accent-dim);
  letter-spacing: 0.15em;
  margin-bottom: 8px;
}
.result-ach-list { display: flex; flex-direction: column; gap: 6px; }
.result-ach-item {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
  color: var(--ink);
}
.result-ach-item .ach-ic { font-size: 18px; }

.disclaimer {
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 16px;
  line-height: 1.4;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
  font-family: 'Lora', serif;
  font-style: italic;
}

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  animation: fadeIn 0.2s;
}
.modal-box {
  max-width: 440px; width: 100%; max-height: 90vh;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  position: relative;
  box-shadow: var(--shadow-soft);
  -webkit-overflow-scrolling: touch;
}
.modal-close {
  position: sticky; top: 0; float: right;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--paper-2);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
  font-size: 18px; font-weight: 700;
  cursor: pointer;
  z-index: 1;
  display: flex; align-items: center; justify-content: center;
  margin-top: -6px; margin-right: -6px;
}
.modal-close:active { transform: scale(0.92); }
.modal-box h3 {
  font-family: 'Lora', Georgia, serif;
  font-size: 24px;
  margin: 0 0 16px;
  color: var(--ink);
}
.modal-section { margin-bottom: 14px; }
.modal-h {
  font-size: 12px; font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.modal-section p {
  font-size: 13px; line-height: 1.55;
  color: var(--ink-2);
  margin: 0;
}
.modal-section b { color: var(--ink); }

/* Popups */
.ach-popup {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  padding: 12px 18px;
  background: var(--ink);
  border-radius: 100px;
  display: flex; align-items: center; gap: 12px;
  color: var(--paper);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  z-index: 300;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  max-width: 320px;
}
.ach-popup.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.ach-pop-icon { font-size: 26px; line-height: 1; }
.ach-pop-sub {
  font-size: 9px; font-weight: 800;
  letter-spacing: 0.15em;
  opacity: 0.6;
}
.ach-pop-title { font-family: 'Lora', serif; font-size: 14px; font-weight: 700; }

.score-pop {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-family: 'Lora', serif;
  font-size: 48px; font-weight: 700;
  color: var(--green);
  opacity: 0; pointer-events: none;
  z-index: 250;
}
.score-pop.show {
  animation: scoreFloat 1.2s ease forwards;
}
@keyframes scoreFloat {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(0.9); }
}

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 20px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 100px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.2);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 280px;
  text-align: center;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.confetti-piece {
  position: absolute;
  width: 8px; height: 14px;
  opacity: 0;
  animation: confettiFall 2.5s linear forwards;
}
@keyframes confettiFall {
  0% { opacity: 1; transform: translateY(-20vh) rotate(0deg); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
