:root {
  --ink: #1e293b;
  --panel: #fff;
  --go: #22c55e; --go-dark: #15803d;
  --blue: #3b82f6; --blue-dark: #1d4ed8;
  --gold: #fbbf24;
  --pink: #f472b6;
  --violet: #8b5cf6;
  --font: "Nunito", "Arial Rounded MT Bold", "PingFang HK", "Heiti TC", system-ui, sans-serif;
  --shadow: 0 6px 0 rgba(0,0,0,.22);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(180deg, #7dd3fc 0%, #a5b4fc 45%, #c4b5fd 100%);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.hidden { display: none !important; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

.btn {
  font-family: var(--font); font-weight: 900; border: 0; border-radius: 16px;
  cursor: pointer; color: #fff; background: var(--blue);
  box-shadow: 0 5px 0 var(--blue-dark); padding: 12px 22px; font-size: 20px;
  transition: transform .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.go { background: var(--go); box-shadow: 0 5px 0 var(--go-dark); }
.btn.go:active { box-shadow: 0 1px 0 var(--go-dark); }
.btn.big { font-size: clamp(28px, 6vw, 40px); padding: 16px 48px; border-radius: 22px; }
.btn.mid { font-size: 20px; }
.btn.icon {
  width: 52px; height: 52px; padding: 0; font-size: 24px;
  background: #fff; color: var(--ink); box-shadow: 0 5px 0 #cbd5e1;
}
.btn.gray { background: #94a3b8; box-shadow: 0 5px 0 #64748b; }
.btn.chip {
  background: rgba(255,255,255,.92); color: var(--ink); box-shadow: 0 4px 0 #cbd5e1;
  font-size: 16px; padding: 10px 16px;
}
.btn.chip[aria-pressed="false"] { opacity: .55; }

.pill {
  background: rgba(255,255,255,.94); padding: 8px 14px; border-radius: 999px;
  font-size: clamp(14px, 3.5vw, 20px); font-weight: 900; box-shadow: var(--shadow);
}
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: max(16px, env(safe-area-inset-top)) 16px 24px;
}
.screen-title { margin: 0; font-size: clamp(24px, 6vw, 34px); font-weight: 900; color: #fff;
  text-shadow: 0 4px 0 rgba(30,41,59,.25); }

.logo { text-align: center; filter: drop-shadow(0 8px 0 rgba(0,0,0,.15)); }
.logo-emoji { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
.logo-en { font-size: clamp(18px, 4vw, 28px); font-weight: 900; letter-spacing: 4px; color: #fff;
  -webkit-text-stroke: 1px #1e3a8a; }
.logo-zh { margin: 6px 0 0; font-size: clamp(36px, 9vw, 56px); font-weight: 900; color: #1e3a8a;
  background: #fff; display: inline-block; padding: 4px 18px; border-radius: 14px; }
.logo-sub { margin: 8px 0 0; font-weight: 800; color: #1e3a8a; background: rgba(255,255,255,.75);
  padding: 4px 12px; border-radius: 10px; display: inline-block; }
.title-toggles { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-4deg); } }

.buddy-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  width: min(420px, 94vw);
}
.buddy {
  border: 0; border-radius: 20px; padding: 16px 8px; cursor: pointer;
  background: rgba(255,255,255,.92); box-shadow: 0 6px 0 #c7d2fe;
  font-weight: 900; font-size: 15px; color: var(--ink);
}
.buddy .em { font-size: 42px; display: block; margin-bottom: 6px; }
.buddy.selected { outline: 4px solid #22c55e; transform: translateY(-2px); }

.bar {
  width: min(980px, 100%); display: flex; align-items: center; justify-content: space-between;
  gap: 10px; color: #fff;
}
.bar h2 { margin: 0; font-size: clamp(18px, 4vw, 26px); font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.2); }
.world-grid {
  width: min(720px, 96vw); display: flex; flex-direction: column; gap: 10px;
  max-height: 62vh; overflow-y: auto; touch-action: pan-y; padding: 4px;
}
.world-node {
  border: 0; border-radius: 18px; padding: 14px 16px; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center;
  background: linear-gradient(135deg, #fff, #eef2ff); box-shadow: 0 7px 0 rgba(0,0,0,.12);
  font-weight: 900; color: var(--ink);
}
.world-node:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.world-node.locked { filter: grayscale(.75); opacity: .7; cursor: not-allowed; }
.world-node .em { font-size: 32px; }
.world-node .tag { font-size: 12px; background: #ede9fe; color: #5b21b6; padding: 4px 8px; border-radius: 999px; }
.hint { color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,.2); margin: 0; }

#play { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px 12px; }
#play.hidden { display: none !important; }
.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.world-pill { background: linear-gradient(135deg, #a78bfa, #60a5fa); color: #fff; }
.progress-wrap {
  position: relative; height: 18px; margin: 10px 0; border-radius: 999px;
  background: rgba(255,255,255,.45); overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.1);
}
#progFill {
  height: 100%; width: 0; background: linear-gradient(90deg, #fbbf24, #f472b6, #8b5cf6);
  transition: width .3s ease;
}
#progText {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #1e293b;
}

.arena {
  flex: 1; min-height: 0; border-radius: 28px; position: relative; overflow: hidden;
  background: radial-gradient(circle at 30% 20%, #fff7, transparent 40%),
              linear-gradient(165deg, #60a5fa, #818cf8 50%, #c084fc);
  box-shadow: 0 12px 0 rgba(30,41,59,.2), inset 0 0 0 4px rgba(255,255,255,.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px;
}
.arena.w2 { background: linear-gradient(165deg, #34d399, #22d3ee 55%, #60a5fa); }
.arena.w3 { background: linear-gradient(165deg, #c084fc, #e879f9 50%, #f472b6); }
.arena.w4 { background: linear-gradient(165deg, #fb923c, #fbbf24 50%, #f87171); }
.arena.w5 { background: linear-gradient(165deg, #1e293b, #7c3aed 55%, #db2777); }
.scene-art {
  position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background:
    radial-gradient(circle at 15% 80%, #fff8 0 8%, transparent 9%),
    radial-gradient(circle at 80% 20%, #fff6 0 6%, transparent 7%),
    radial-gradient(circle at 70% 75%, #0002 0 12%, transparent 13%);
}
.big-num {
  font-size: clamp(56px, 18vw, 96px); font-weight: 900; color: #fff;
  text-shadow: 0 6px 0 rgba(30,41,59,.35), 0 0 24px rgba(255,255,255,.4);
  line-height: 1; z-index: 2; animation: popIn .35s ease;
}
.prompt {
  z-index: 2; margin: 8px 12px 14px; text-align: center; font-weight: 900;
  font-size: clamp(16px, 4.2vw, 22px); color: #0f172a;
  background: rgba(255,255,255,.92); padding: 10px 16px; border-radius: 16px;
  max-width: 92%; box-shadow: var(--shadow);
}
.action-zone {
  z-index: 2; width: min(560px, 96%); display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr;
}
.action-zone.one-col { grid-template-columns: 1fr; }
.door, .chest, .brick-btn, .choice-act {
  border: 0; border-radius: 18px; min-height: 72px; padding: 14px 10px;
  font-family: var(--font); font-weight: 900; font-size: clamp(15px, 3.8vw, 20px);
  cursor: pointer; color: #0f172a; background: rgba(255,255,255,.95);
  box-shadow: 0 6px 0 rgba(15,23,42,.2); transition: transform .08s;
}
.door:active, .chest:active, .brick-btn:active, .choice-act:active {
  transform: translateY(4px); box-shadow: 0 2px 0 rgba(15,23,42,.2);
}
.door.yes { background: linear-gradient(180deg, #bbf7d0, #86efac); }
.door.no { background: linear-gradient(180deg, #fecaca, #fca5a5); }
.chest { background: linear-gradient(180deg, #fef08a, #fde047); }
.chest.picked { outline: 4px solid #16a34a; }
.brick-btn { background: linear-gradient(180deg, #e9d5ff, #d8b4fe); font-size: 28px; }
.choice-act.primary {
  grid-column: 1 / -1; background: linear-gradient(180deg, #86efac, #22c55e); color: #052e16;
}

.tutor {
  margin-top: 10px; min-height: 48px; border-radius: 16px; padding: 10px 14px;
  background: rgba(255,255,255,.95); font-weight: 800; font-size: 15px;
  box-shadow: var(--shadow); color: #1e293b;
}
.toast {
  position: fixed; left: 50%; bottom: 18%; transform: translateX(-50%);
  background: #0f172a; color: #fff; font-weight: 900; padding: 12px 20px;
  border-radius: 999px; z-index: 60; animation: popIn .25s ease;
}

.panel-wrap {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(15,23,42,.45); padding: 16px;
}
.panel {
  width: min(440px, 94vw); background: #fff; border-radius: 24px; padding: 22px 18px;
  box-shadow: 0 16px 0 rgba(0,0,0,.2); text-align: center;
}
.panel-title { font-size: 24px; font-weight: 900; margin-bottom: 14px; }
.tiles { display: grid; gap: 10px; }
.tile {
  border: 0; border-radius: 16px; padding: 14px; font-family: var(--font);
  font-weight: 900; font-size: 18px; cursor: pointer;
  background: linear-gradient(180deg, #e0e7ff, #c7d2fe); color: #1e1b4b;
  box-shadow: 0 5px 0 #818cf8;
}
.tile:active { transform: translateY(3px); box-shadow: 0 2px 0 #818cf8; }
.celebrate .huge { font-size: 64px; animation: bob 1s ease-in-out infinite; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 12px; }

@keyframes popIn {
  from { transform: scale(.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.shake { animation: shake .35s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
.glow { animation: glow .45s ease; }
@keyframes glow {
  50% { filter: drop-shadow(0 0 16px #fde047); transform: scale(1.08); }
}

.digit-row {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px;
  grid-column: 1 / -1;
}
.digit-chip {
  width: 56px; height: 64px; border-radius: 12px; display: grid; place-items: center;
  font-size: 28px; font-weight: 900; color: #fff;
  background: linear-gradient(180deg, #a78bfa, #7c3aed); box-shadow: 0 5px 0 #5b21b6;
  transition: transform .2s, opacity .2s;
}
.digit-chip.popped { transform: translateY(-40px) scale(1.2); opacity: 0; }
.sum-fly {
  grid-column: 1 / -1; text-align: center; font-size: 28px; font-weight: 900; color: #fff;
  text-shadow: 0 3px 0 #4c1d95; min-height: 36px;
}
