/* ════════════════════════════════════════════════════════
   CSS VARIABLES
═══════════════════════════════════════════════════════════ */
:root {
  --bg:       #06080f;
  --bg2:      #0b1020;
  --panel:    #0e1628;
  --panel2:   #131c35;
  --border:   #1e3a5f;
  --gold:     #FFD166;
  --amber:    #f59e0b;
  --red:      #ef4444;
  --green:    #22c55e;
  --blue:     #3b82f6;
  --teal:     #06b6d4;
  --txt:      #e2e8f0;
  --txt2:     #94a3b8;
  --txt3:     #475569;
  --radius:   10px;
  --font:     'Segoe UI', system-ui, sans-serif;
  --mono:     'Share Tech Mono', 'Courier New', monospace;
}

/* ════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
}

/* ════════════════════════════════════════════════════════
   CONFETTI
═══════════════════════════════════════════════════════════ */
.confetti-piece {
  position: fixed;
  top: -10px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  pointer-events: none;
  z-index: 9999;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ════════════════════════════════════════════════════════
   SCREEN SYSTEM
═══════════════════════════════════════════════════════════ */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  overflow: hidden;
}
.screen.active { display: flex; flex-direction: column; }
/* Suppress the default active screen when launched from hub — JS picks it up after */
.from-hub .screen { display: none !important; }

/* ════════════════════════════════════════════════════════
   HUD
═══════════════════════════════════════════════════════════ */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: rgba(6,8,15,0.95);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  z-index: 200;
  backdrop-filter: blur(8px);
}
.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}
.hud-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.hud-label  { font-size: 9px; letter-spacing: .1em; color: var(--txt3); text-transform: uppercase; }
.hud-val    { font-family: var(--mono); font-size: 16px; color: var(--gold); }
.hud-lives  { display: flex; gap: 2px; }
.life-icon  { font-size: 15px; }
.life-icon.lost { filter: grayscale(1) opacity(.3); }
.hud-timer  { font-family: var(--mono); font-size: 15px; color: var(--teal); }
.hud-timer.danger { color: var(--red); animation: timerPulse .7s infinite alternate; }
@keyframes timerPulse { to { opacity: .5; } }
.hud-locks  { display: flex; gap: 3px; }
.hud-lock   { font-size: 14px; opacity: .4; }
.hud-lock.unlocked { opacity: 1; filter: drop-shadow(0 0 5px var(--gold)); }
.hud-title  { font-size: 11px; color: var(--txt3); }
.hud-how-btn {
  font-size: 10px; padding: 3px 10px; border-radius: 20px;
  background: transparent; border: 1px solid var(--border);
  color: var(--txt2); cursor: pointer;
}
.hud-how-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ════════════════════════════════════════════════════════
   BUTTONS (shared)
═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 22px; border-radius: var(--radius);
  font-size: 14px; font-weight: 700; letter-spacing: .03em;
  cursor: pointer; border: none; transition: filter .15s, transform .1s;
}
.btn:hover  { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }

.btn-ghost  { background: transparent; border: 1.5px solid var(--border); color: var(--txt2); }
.btn-ghost:hover { border-color: var(--txt2); }

.btn-launch { background: linear-gradient(135deg,#2563eb,#7c3aed); color: #fff; }
.btn-red-solid { background: var(--red); color: #fff; }
.btn-green  { background: #16a34a; color: #fff; }

.btn-sys-red  { background: linear-gradient(135deg,#7f1d1d,#991b1b); color: #fca5a5; border: 1px solid #ef4444; }
.btn-sys-green{ background: linear-gradient(135deg,#14532d,#15803d); color: #86efac; border: 1px solid #22c55e; }
.btn-sys-blue { background: linear-gradient(135deg,#1e3a8a,#1d4ed8); color: #93c5fd; border: 1px solid #3b82f6; }
.btn-sys-gold { background: linear-gradient(135deg,#78350f,#92400e); color: #fde68a; border: 1px solid var(--gold); }
.btn-sys-teal { background: linear-gradient(135deg,#164e63,#0e7490); color: #a5f3fc; border: 1px solid var(--teal); }

/* ════════════════════════════════════════════════════════
   INTRO SCREEN
═══════════════════════════════════════════════════════════ */
#screen-intro {
  background: var(--bg);
  align-items: center; justify-content: center;
}
#screen-intro::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 40%, rgba(37,99,235,.12), transparent);
  pointer-events: none;
}
.intro-content {
  width: 100%; max-width: 600px;
  padding: 24px 18px;
  overflow-y: auto; max-height: 100vh;
}
.intro-story-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.intro-title {
  font-size: 2.4rem; font-weight: 900; line-height: 1.1;
  text-transform: uppercase; letter-spacing: -.01em;
}
.intro-title span { color: var(--gold); }
/* Comic strip — full width, no card */
.intro-comic-img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 10px;
  margin: 4px 0;
}

/* Character strip with story */
.intro-char-strip {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.intro-char-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}
.intro-char-portrait {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 50%;
  background: var(--panel2);
  border: 2px solid var(--border);
}
.intro-char-label {
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--txt3);
  text-transform: uppercase;
}
.intro-story-text  { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.char-name-rb      { color: #f97316; }
.char-name-ri      { color: var(--gold); }

/* WHOOSH effect */
.whoosh-line { text-align: center; }
.whoosh {
  display: inline-block;
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: .05em;
  background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #ef4444);
  background-size: 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: whooshSweep 1.4s linear infinite, whooshShake .18s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(239,68,68,.6));
  text-shadow: none;
}
@keyframes whooshSweep {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
@keyframes whooshShake {
  0%,100% { transform: translateX(0) scale(1); }
  25%     { transform: translateX(-2px) scale(1.03); }
  75%     { transform: translateX(2px)  scale(1.03); }
}

.char-img        { object-fit: contain; }
.intro-divider   { height: 1px; background: var(--border); }
.intro-scene-tag { font-size: 12px; color: var(--txt3); }
.story-line      { font-size: 14px; color: var(--txt2); line-height: 1.6; }
.story-line.amber { color: var(--amber); }
.ricci-text      { color: var(--gold); }
.intro-mission-box {
  background: rgba(255,209,102,.06); border: 1px solid rgba(255,209,102,.25);
  border-radius: 8px; padding: 12px 14px;
}
.intro-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ════════════════════════════════════════════════════════
   HOW TO PLAY
═══════════════════════════════════════════════════════════ */
#screen-howto {
  background: var(--bg);
  align-items: center; justify-content: center;
}
.howto-wrap {
  width: 100%; max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  margin: 20px;
  overflow-y: auto; max-height: 96vh;
  display: flex; flex-direction: column; gap: 14px;
}
.howto-title  { font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; }
.howto-item   { display: flex; gap: 12px; align-items: flex-start; }
.hi-icon      { font-size: 20px; flex: 0 0 28px; margin-top: 2px; }
.hi-title     { font-size: 14px; font-weight: 700; color: var(--gold); margin-bottom: 3px; }
.hi-desc      { font-size: 13px; color: var(--txt2); line-height: 1.55; }
.howto-btns   { display: flex; gap: 10px; flex-wrap: wrap; }

/* ════════════════════════════════════════════════════════
   GAME SCREENS — SHARED
═══════════════════════════════════════════════════════════ */
.game-screen {
  background: var(--bg);
  flex-direction: column;
  padding-top: 52px; /* HUD height */
}
.g-screen-inner {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden; min-height: 0;
}

/* Title bar */
.g-title-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.gtb-left   { display: flex; align-items: center; gap: 10px; }
.gtb-icon   { font-size: 20px; }
.gtb-title  { font-size: 15px; font-weight: 800; color: var(--gold); }
.gtb-sub    { font-size: 11px; color: var(--txt3); }
.gtb-right  { display: flex; align-items: center; gap: 10px; }
.gtb-badge  {
  font-size: 11px; padding: 3px 10px; border-radius: 20px;
  background: rgba(255,209,102,.1); border: 1px solid rgba(255,209,102,.3);
  color: var(--gold); font-family: var(--mono);
}
.gtb-exit {
  font-size: 12px; padding: 3px 10px; border-radius: 6px;
  background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3);
  color: #f87171; cursor: pointer;
}
.gtb-exit:hover { background: rgba(239,68,68,.2); }

/* Intro splash inside game screen */
.g-intro-splash {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px;
  gap: 20px;
}
.game-intro-row {
  display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap;
  justify-content: center;
  max-width: 700px; width: 100%;
}
.game-intro-char-img { width: 90px; height: 90px; border-radius: 50%; object-fit: contain; }
.g-intro-instructions { flex: 1; min-width: 220px; }
.g-intro-title  { font-size: 1.2rem; font-weight: 800; margin-bottom: 10px; }
.g-intro-list   { padding-left: 18px; display: flex; flex-direction: column; gap: 7px; }
.g-intro-list li{ font-size: 13.5px; color: var(--txt2); line-height: 1.5; }
.g-intro-list li strong { color: var(--txt); }
.g-intro-body   { font-size: 14px; color: var(--txt2); line-height: 1.6; margin-bottom: 8px; }
.g-intro-tip    {
  margin-top: 12px; font-size: 12px; color: var(--amber);
  background: rgba(245,158,11,.08); border-left: 3px solid var(--amber);
  padding: 7px 10px; border-radius: 0 6px 6px 0;
}
.g-intro-btn    { margin-top: 4px; font-size: 15px; padding: 13px 32px; }

/* ════════════════════════════════════════════════════════
   GAME 1 — STROKE SEARCH
═══════════════════════════════════════════════════════════ */
.g1-layout {
  flex: 1; display: flex; gap: 0;
  min-height: 0; overflow: hidden;
}

.g1-grid-panel {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 14px;
  background: radial-gradient(ellipse 80% 80% at 50% 50%, rgba(37,99,235,.06), transparent),
              var(--bg);
  overflow: hidden;
}

.g1-grid-label {
  font-size: 10px; letter-spacing: .12em; color: var(--txt3);
  text-transform: uppercase; font-family: var(--mono);
}

.g1-ws-grid {
  display: grid;
  gap: 3px;
  user-select: none;
  touch-action: none;
}

.g1-cell {
  width: clamp(30px, 5.5vmin, 42px);
  height: clamp(30px, 5.5vmin, 42px);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: clamp(12px, 2vmin, 16px);
  font-weight: 700;
  color: var(--txt2);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background .08s, color .08s, border-color .08s;
}
.g1-cell.selecting {
  background: rgba(255,209,102,.22);
  color: var(--gold);
  border-color: var(--gold);
}
.g1-cell.hinted {
  color: rgba(255,255,255,.22);
  border: 1.5px dashed var(--fc, rgba(255,255,255,.3));
  box-shadow: 0 0 8px var(--fc, transparent) inset;
  animation: hintPulse 2s ease-in-out infinite;
}
@keyframes hintPulse {
  0%,100% { opacity:.45; }
  50%      { opacity:.75; }
}
.g1-cell.found {
  background: var(--fc, var(--green));
  color: #fff;
  border-color: transparent;
  border-style: solid;
  font-weight: 900;
  animation: none;
  opacity: 1;
}

/* Sidebar */
.g1-sidebar {
  width: 220px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center;
  gap: 12px; padding: 16px 14px;
  overflow-y: auto;
}
.g1-mai-display {
  font-size: 68px; line-height: 1;
  color: rgba(255,209,102,.12);
  font-weight: 900;
  pointer-events: none;
}
.g1-sidebar-title {
  font-size: 10px; letter-spacing: .12em;
  color: var(--txt3); text-transform: uppercase;
  font-family: var(--mono); align-self: flex-start;
}
.g1-ws-words { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.g1-ws-row {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--panel2);
  border: 1.5px solid var(--border);
  transition: border-color .2s, opacity .3s;
}
.g1-ws-row.found { opacity: .5; }
.g1-ws-char  { font-size: 20px; flex: 0 0 24px; }
.g1-ws-jyut  { font-family: var(--mono); font-size: 11px; color: var(--txt3); flex: 0 0 48px; }
.g1-ws-en    { font-size: 11px; color: var(--txt2); flex: 1; }
.g1-ws-arrow { font-size: 16px; font-weight: 900; flex: 0 0 18px; text-align:center; }
.g1-ws-tick  { font-size: 14px; font-weight: 700; color: var(--txt3); flex: 0 0 14px; text-align:right; }
.g1-ws-progress {
  font-family: var(--mono); font-size: 14px;
  color: var(--txt3);
}
.g1-hint-btn {
  width: 100%; padding: 9px 10px;
  border-radius: 8px; border: 1px solid rgba(245,158,11,.35);
  background: rgba(245,158,11,.07);
  color: var(--amber); font-size: 12px; font-weight: 700;
  cursor: pointer; margin-top: auto;
  transition: background .15s, opacity .2s;
}
.g1-hint-btn:hover:not(:disabled) { background: rgba(245,158,11,.14); }
.g1-hint-btn:disabled { opacity: .35; cursor: default; }
.g1-hint-cost { font-size: 10px; color: var(--red); margin-left: 4px; }
.g1-hint-msg {
  font-size: 12px; font-weight: 700;
  text-align: center; min-height: 16px;
}

/* ════════════════════════════════════════════════════════
   GAME 2 — WHACK-A-BUG
═══════════════════════════════════════════════════════════ */
.g2-layout {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.g2-target-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.g2-target-label {
  font-size: 11px; letter-spacing: .1em; color: var(--txt3); text-transform: uppercase;
}
.g2-target-word {
  font-size: 1.6rem; font-weight: 900; color: var(--gold);
  font-family: var(--mono); letter-spacing: .04em;
}
.g2-round-tag {
  margin-left: auto;
  font-size: 11px; padding: 3px 10px; border-radius: 20px;
  background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3);
  color: var(--green); font-family: var(--mono);
}
.g2-arena-wrap {
  flex: 1; position: relative; overflow: hidden;
}
.g2-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.g2-status-bar {
  height: 36px; display: flex; align-items: center; padding: 0 18px;
  background: var(--panel); border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.g2-feedback { font-size: 14px; font-weight: 700; }

/* ════════════════════════════════════════════════════════
   GAME 3 — DAY DIAL
═══════════════════════════════════════════════════════════ */
.g3-layout {
  flex: 1; display: flex; gap: 0;
  min-height: 0; overflow: hidden;
}
.g3-dial-col {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 8px;
  background: radial-gradient(ellipse 70% 70% at 50% 50%, rgba(59,130,246,.07), transparent);
  min-height: 0;
}
.g3-dial-wrap {
  flex: 1; height: 100%; display: flex;
  align-items: center; justify-content: center;
  min-height: 0;
}
.g3-canvas {
  cursor: grab; display: block;
  border-radius: 50%;
  box-shadow: 0 0 40px rgba(59,130,246,.15);
}
.g3-canvas:active { cursor: grabbing; }

.g3-sidebar {
  width: 220px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  gap: 12px; padding: 16px 14px;
  overflow-y: auto;
}
.g3-round-badge {
  font-size: 11px; color: var(--blue); font-family: var(--mono);
  letter-spacing: .06em;
}
.g3-info-card {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.g3-card-label { font-size: 10px; color: var(--txt3); text-transform: uppercase; letter-spacing: .1em; }
.g3-cantonese  { font-size: 2rem; font-weight: 900; color: var(--txt); }
.g3-jyutping   { font-size: 13px; color: var(--blue); font-family: var(--mono); }
.g3-english { font-size: 13px; color: var(--txt2); margin-top: 2px; }

.g3-hint-btn {
  width: 100%; padding: 12px 10px; border-radius: 10px;
  background: linear-gradient(135deg,#78350f,#92400e);
  color: var(--gold); font-size: 13px; font-weight: 800;
  border: 2px solid var(--gold); cursor: pointer;
  line-height: 1.4;
  box-shadow: 0 0 16px rgba(255,209,102,.25);
  animation: hintGlowG3 2s ease-in-out infinite;
  transition: opacity .2s;
}
.g3-hint-btn:disabled { opacity: .35; animation: none; cursor: default; }
.g3-hint-cost { font-size: 11px; opacity: .8; font-weight: 600; }
@keyframes hintGlowG3 {
  0%,100% { box-shadow: 0 0 10px rgba(255,209,102,.2); }
  50%      { box-shadow: 0 0 26px rgba(255,209,102,.6); }
}
.g3-selected-display {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
}
.g3-sel-label { font-size: 10px; color: var(--txt3); text-transform: uppercase; letter-spacing: .08em; }
.g3-sel-num   { font-size: 1.6rem; font-weight: 900; color: var(--gold); font-family: var(--mono); }
.g3-confirm-btn {
  padding: 11px; border-radius: 8px; font-size: 14px; font-weight: 800;
  cursor: pointer; border: none; width: 100%;
  background: linear-gradient(135deg,#1e3a8a,#1d4ed8);
  color: #93c5fd; border: 1px solid #3b82f6;
}
.g3-confirm-btn:hover { filter: brightness(1.15); }
.g3-feedback { font-size: 13px; font-weight: 600; min-height: 18px; }

/* ════════════════════════════════════════════════════════
   GAME 4 — iMESSAGE CHAT
═══════════════════════════════════════════════════════════ */
.g4-layout {
  flex: 1; display: flex; gap: 0;
  min-height: 0; overflow: hidden;
}

/* Phone mockup */
.g4-phone-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse 70% 70% at 50% 50%, rgba(255,209,102,.05), transparent);
  position: relative; overflow: hidden;
}
.g4-phone {
  width: 300px; max-height: 580px; height: 100%;
  background: #000;
  border-radius: 40px;
  border: 2.5px solid #2a2a2a;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(255,209,102,.12), inset 0 0 0 1px #111;
}
.g4-phone-bar   { background: #000; height: 30px; display: flex; justify-content: center; align-items: center; }
.g4-phone-notch { width: 100px; height: 22px; background: #000; border-radius: 0 0 14px 14px; border: 2px solid #2a2a2a; }
.g4-phone-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px 8px;
  background: rgba(20,20,20,.95);
  border-bottom: 1px solid #222;
}
.g4-back-arrow   { font-size: 24px; color: #4fc3f7; cursor: pointer; }
.g4-contact-info { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.g4-contact-avatar { font-size: 22px; }
.g4-contact-name   { font-size: 11px; color: #fff; font-weight: 600; }
.g4-phone-dots     { font-size: 18px; color: #4fc3f7; cursor: pointer; }

.g4-chat-area {
  flex: 1; overflow-y: auto;
  background: #1c1c1e;
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}
.g4-chat-hint { font-size: 12px; color: #555; text-align: center; padding: 20px 10px; }
/* Shake animation */
@keyframes phoneShakeRed {
  0%,100% { transform: translateX(0); box-shadow: 0 0 40px rgba(255,209,102,.12), inset 0 0 0 1px #111; }
  15%     { transform: translateX(-10px) rotate(-1.2deg); box-shadow: 0 0 40px rgba(239,68,68,.65), inset 0 0 0 1px #111; }
  30%     { transform: translateX(9px)  rotate(1.2deg);  box-shadow: 0 0 30px rgba(239,68,68,.5),  inset 0 0 0 1px #111; }
  50%     { transform: translateX(-6px); }
  70%     { transform: translateX(5px); }
  85%     { transform: translateX(-3px); }
}
.g4-phone.shake-red { animation: phoneShakeRed .55s ease; }

/* Countdown bar */
.g4-countdown-wrap { height: 3px; background: rgba(255,255,255,.06); flex-shrink: 0; }
.g4-countdown-bar  { height: 100%; width: 100%; background: #22c55e; transition: width .1s linear, background .4s; }

/* Typing indicator */
.g4-typing {
  display: flex; gap: 5px; align-items: center;
  padding: 9px 13px;
  background: #2a2a2e;
  border-radius: 16px 16px 16px 4px;
  width: fit-content;
  align-self: flex-start;
}
.g4-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #666;
  animation: typingBounce 1.1s ease-in-out infinite;
}
.g4-typing span:nth-child(2) { animation-delay: .18s; }
.g4-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typingBounce {
  0%,80%,100% { transform: translateY(0); opacity: .35; }
  40%          { transform: translateY(-5px); opacity: 1; }
}

/* Bubble whoosh slide-in */
@keyframes bubbleIn {
  0%   { opacity: 0; transform: translateX(24px) scale(.92); }
  55%  { transform: translateX(-3px) scale(1.02); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

/* Confetti inside phone wrap */
.g4-confetti {
  position: absolute; top: -10px;
  width: 7px; height: 7px; border-radius: 2px;
  pointer-events: none; z-index: 99;
  animation: g4ConfettiFall linear forwards;
}
@keyframes g4ConfettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(600px) rotate(540deg); opacity: 0; }
}

.g4-bubble {
  align-self: flex-end;
  background: #2196f3;
  border-radius: 18px 18px 4px 18px;
  padding: 9px 12px;
  max-width: 90%;
  position: relative;
  animation: bubbleIn .32s cubic-bezier(.34,1.56,.64,1) forwards;
}
.g4-bubble-zh { font-size: 14px; color: #fff; font-weight: 600; }
.g4-bubble-py { font-size: 10px; color: rgba(255,255,255,.55); font-family: var(--mono); margin-top: 2px; }
.g4-bubble-en { font-size: 11px; color: rgba(255,255,255,.7); margin-top: 2px; }
.g4-bubble-remove {
  position: absolute; top: -7px; right: -7px;
  background: #ef4444; border: none; color: #fff;
  width: 20px; height: 20px; border-radius: 50%;
  font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

.g4-input-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  background: #1c1c1e;
  border-top: 1px solid #333;
}
.g4-input-fake {
  flex: 1; background: #2c2c2e; border-radius: 20px;
  padding: 8px 14px; font-size: 14px; color: #555;
}
.g4-send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: #2196f3; color: #fff; border: none;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.g4-send-btn:hover { background: #1976d2; }

/* Options column */
.g4-options-col {
  width: 260px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  gap: 8px; padding: 14px 12px;
  overflow-y: auto;
}
.g4-options-label {
  font-size: 10px; letter-spacing: .12em; color: var(--txt3); text-transform: uppercase;
}
.g4-tiles { display: flex; flex-direction: column; gap: 7px; }
.g4-tile {
  background: var(--panel2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.g4-tile:hover { border-color: var(--gold); background: rgba(255,209,102,.06); }
.g4-tile.used  { opacity: .35; pointer-events: none; }
.g4-tile-label { font-size: 11px; color: var(--txt3); margin-bottom: 3px; }
.g4-tile-zh    { font-size: 15px; color: var(--txt); font-weight: 700; }
.g4-tile-py    { font-size: 10px; color: var(--txt3); font-family: var(--mono); margin-top: 2px; }
.g4-tile-en    { font-size: 11px; color: var(--txt2); margin-top: 2px; }
.g4-feedback   { font-size: 13px; font-weight: 600; min-height: 18px; }
.g4-clear-btn  {
  margin-top: auto; padding: 8px; border-radius: 7px; font-size: 12px;
  background: transparent; border: 1px solid var(--border); color: var(--txt3);
  cursor: pointer;
}
.g4-clear-btn:hover { border-color: var(--red); color: var(--red); }

/* ════════════════════════════════════════════════════════
   GAME 5 — TORNADO CALM
═══════════════════════════════════════════════════════════ */
.g5-layout {
  flex: 1; position: relative;
  overflow: hidden;
  background: #03050a;
}
.g5-canvas {
  position: absolute; inset: 0;
  display: block;
  width: 100%; height: 100%;
}
.g5-ui {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  pointer-events: none;
  text-align: center;
  z-index: 10;
}
.g5-phase-label {
  font-size: 2rem; font-weight: 900;
  letter-spacing: .04em;
  text-shadow: 0 0 20px currentColor, 0 0 40px currentColor;
}
.g5-instruction {
  font-size: 14px; color: var(--txt2); max-width: 260px; line-height: 1.5;
}
.g5-breath-pips {
  display: flex; gap: 14px; font-size: 22px;
  color: var(--teal);
}
.g5-pip { transition: text-shadow .3s; }
.g5-pip:not(:empty[textContent='●']) { text-shadow: 0 0 10px var(--teal); }

.g5-start-btn {
  pointer-events: all;
  padding: 13px 32px; border-radius: 50px;
  background: rgba(6,182,212,.15);
  border: 2px solid var(--teal);
  color: #a5f3fc; font-size: 15px; font-weight: 800;
  cursor: pointer;
  text-shadow: 0 0 10px var(--teal);
  box-shadow: 0 0 20px rgba(6,182,212,.25);
  transition: background .2s, box-shadow .2s;
}
.g5-start-btn:hover {
  background: rgba(6,182,212,.25);
  box-shadow: 0 0 30px rgba(6,182,212,.4);
}

/* ════════════════════════════════════════════════════════
   TRANSITION SCREEN
═══════════════════════════════════════════════════════════ */
#screen-transition {
  background: var(--bg);
  align-items: center; justify-content: center;
}
.trans-wrap {
  display: flex; gap: 20px; flex-wrap: wrap;
  max-width: 840px; width: 100%;
  padding: 24px 18px;
  justify-content: center;
}
.trans-left, .trans-right {
  flex: 1; min-width: 260px;
  display: flex; flex-direction: column; gap: 12px;
}
.trans-icon   { font-size: 3rem; }
.trans-title  { font-size: 1.8rem; font-weight: 900; color: var(--gold); }
.trans-pts    { font-size: 1.3rem; font-weight: 800; color: var(--green); }
.trans-score-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.trans-row {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--txt2);
}
.trans-num { font-family: var(--mono); color: var(--gold); }

.trans-unlock-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
/* Key assembly */
/* Key puzzle assembly */
.trans-key-zone   { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.trans-key-target { width: 100%; }
.trans-key-svg    { width: 100%; max-width: 280px; min-height: 64px; display: block; margin: 0 auto; overflow: visible; }
.trans-key-svg.key-glow { animation: keyPuzzleGlow .8s ease-out forwards; }
@keyframes keyPuzzleGlow {
  0%   { filter: none; }
  40%  { filter: drop-shadow(0 0 22px #FFD166) brightness(1.6); }
  100% { filter: drop-shadow(0 0 10px #FFD16688); }
}
.trans-pieces {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
}
.trans-kpiece {
  width: 78px; height: 78px;
  background: rgba(255,255,255,0.04);
  border: 1.5px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, opacity .35s, background .15s;
}
.trans-kpiece:hover { transform: scale(1.1) translateY(-3px); background: rgba(255,255,255,.1); }
.trans-kpiece.placed { opacity: 0; transform: scale(0.4); pointer-events: none; }
.trans-piece-svg { width: 100%; height: 100%; overflow: visible; }
.trans-kpiece-reward {
  width: 110px; height: 110px; cursor: default;
  animation: pieceEarn .65s cubic-bezier(.34,1.56,.64,1) both;
  border-color: rgba(255,255,255,.25);
}
.trans-kpiece-reward:hover { transform: none; }
@keyframes pieceEarn {
  0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg);   opacity: 1; }
}
.trans-key-msg { font-size: 12px; color: var(--txt3); min-height: 18px; text-align: center; }
.trans-learned-label { font-size: 11px; color: var(--txt3); text-transform: uppercase; letter-spacing: .1em; }
.trans-vocab-list  { display: flex; flex-direction: column; gap: 7px; }
.trans-vocab-row   { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.tv-zh   { font-size: 18px; color: var(--txt); font-weight: 700; }
.tv-jyut { font-family: var(--mono); color: var(--blue); font-size: 12px; }
.tv-en   { color: var(--txt2); }

/* ════════════════════════════════════════════════════════
   SCORE SCREEN
═══════════════════════════════════════════════════════════ */
#screen-score {
  background: var(--bg);
  align-items: center; justify-content: center;
}
.score-wrap {
  display: flex; gap: 20px; flex-wrap: wrap;
  max-width: 860px; width: 100%;
  padding: 20px 18px;
  justify-content: center;
  overflow-y: auto; max-height: 100vh;
}
.score-left, .score-right {
  flex: 1; min-width: 280px;
  display: flex; flex-direction: column; gap: 14px;
}
.rank-icon   { font-size: 3.5rem; }
.rank-title  { font-size: 1.6rem; font-weight: 900; color: var(--txt); }
.rank-tag    { font-size: 1.1rem; font-weight: 700; color: var(--gold); }
.score-breakdown {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 7px;
}
.sb-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--txt2); }
.sb-num { font-family: var(--mono); color: var(--gold); }
.stars-label  { font-size: 12px; color: var(--txt3); margin-bottom: 6px; }
.stars-row    { display: flex; gap: 6px; margin-bottom: 8px; }
.star-btn     { font-size: 22px; background: none; border: none; cursor: pointer; filter: grayscale(1) opacity(.4); }
.star-btn.lit { filter: none; }
.rating-send-btn {
  padding: 8px 18px; border-radius: 8px; font-size: 13px; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--border); color: var(--txt);
  cursor: pointer; display: block; margin-bottom: 10px;
}
.rating-thanks { font-size: 13px; color: var(--green); margin-bottom: 8px; }
.play-again-btn {
  padding: 11px 22px; border-radius: 8px; font-size: 14px; font-weight: 800;
  background: linear-gradient(135deg,#2563eb,#7c3aed); color: #fff;
  border: none; cursor: pointer; display: block;
}

.score-hq-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.score-hq-bowl  { width: 90px; height: 90px; object-fit: contain; margin-bottom: 10px; filter: drop-shadow(0 0 14px rgba(255,209,102,.5)); }
.score-hq-title { font-size: 1.3rem; font-weight: 900; color: var(--gold); }
.score-hq-sub   { font-size: 13px; color: var(--txt2); line-height: 1.7; }
.score-tags-label { font-size: 11px; color: var(--txt3); text-transform: uppercase; letter-spacing: .1em; }
.score-tags  { display: flex; flex-wrap: wrap; gap: 6px; }
.score-tag   {
  font-size: 12px; padding: 3px 10px; border-radius: 20px;
  background: rgba(255,209,102,.1); border: 1px solid rgba(255,209,102,.25); color: var(--gold);
}

/* Formspree form */
.score-form  { display: flex; flex-direction: column; gap: 8px; }
.sf-title    { font-size: 13px; color: var(--txt2); font-weight: 700; }
.sf-input    {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--txt);
  font-size: 13px; font-family: var(--font); width: 100%;
}
.sf-input:focus { outline: none; border-color: var(--blue); }
.sf-textarea { resize: vertical; min-height: 60px; }
.sf-submit   {
  padding: 9px; border-radius: 8px; font-size: 13px; font-weight: 700;
  background: linear-gradient(135deg,#14532d,#15803d); border: 1px solid var(--green);
  color: #86efac; cursor: pointer;
}
.score-footer { font-size: 12px; color: var(--txt3); text-align: center; }

/* ════════════════════════════════════════════════════════
   GAME OVER
═══════════════════════════════════════════════════════════ */
#screen-gameover {
  background: var(--bg);
  align-items: center; justify-content: center;
}
.gameover-wrap {
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
  max-width: 480px; text-align: center;
  padding: 32px 24px;
}
.go-title { font-size: 2rem; font-weight: 900; color: var(--red); }
.go-sub   { font-size: 14px; color: var(--txt2); line-height: 1.6; }
.go-score {
  font-size: 2.2rem; font-weight: 900; color: var(--gold);
  font-family: var(--mono);
}

/* ════════════════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════════════════ */
.modal-bg {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
  z-index: 500;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 360px; width: 90%;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
}
.modal-icon  { font-size: 2.5rem; }
.modal-title { font-size: 1.3rem; font-weight: 800; color: var(--red); }
.modal-body  { font-size: 14px; color: var(--txt2); line-height: 1.6; }
.modal-btns  { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ════════════════════════════════════════════════════════
   SCROLLBARS
═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════ */
img { display: block; }
