:root {
  --t1: #ff3b78; --t2: #ff9e1c; --t3: #faee5c; --t4: #2eeb9e; --t5: #29c7ff; --t6: #b880ff;
  --gold: #ffc861; --ink: #f4eee6; --dim: #a59fb8; --night: #07060f; --panel: rgba(16, 12, 34, 0.86);
  --edge: rgba(255, 255, 255, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--night);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; justify-content: center; }
.screen { position: relative; width: 100%; max-width: 560px; height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.screen.wide { max-width: 980px; }

/* ---------- Shared bits ---------- */
.topbar { position: relative; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px; }
.topbar h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--edge); background: rgba(0,0,0,0.45); display: grid; place-items: center; font-size: 18px; flex: none; }
.pill { border: 1px solid var(--edge); background: var(--panel); border-radius: 999px; padding: 12px 20px; font-weight: 600; }
.pill.gold { background: linear-gradient(180deg, #ffd889, #e9a93a); color: #2a1800; border-color: #ffe2a6; box-shadow: 0 0 24px rgba(255, 200, 97, 0.45); }
.pill.ghost { background: transparent; }
.pill:disabled { opacity: 0.4; cursor: default; }
.lock { font-size: 0.8em; opacity: 0.85; margin-left: 4px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 24px; }
.card { background: var(--panel); border: 1px solid var(--edge); border-radius: 18px; padding: 16px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.muted { color: var(--dim); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.han { font-family: "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", serif; }
.jp { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.02em; }
.backdrop { position: absolute; inset: 0; background-size: cover; background-position: center; filter: saturate(1.1); }
.backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(7,6,15,0.55), rgba(7,6,15,0.25) 35%, rgba(7,6,15,0.85)); }
.layer { position: relative; z-index: 2; display: flex; flex-direction: column; height: 100%; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; background: var(--panel); border: 1px solid var(--gold); padding: 10px 18px; border-radius: 999px; font-weight: 600; transition: opacity 0.5s; }

/* ---------- Tower (home) ---------- */
#tower-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sign { position: relative; z-index: 3; text-align: center; padding: 18px 60px 0; }
@media (max-width: 520px) { .sign { padding: 62px 12px 0; } }
.sign h1 { margin: 0; font-size: clamp(26px, 7vw, 40px); letter-spacing: 0.04em; color: #ffe9f2;
  text-shadow: 0 0 6px var(--t1), 0 0 18px var(--t1), 0 0 36px rgba(255, 59, 120, 0.6); font-weight: 700; }
.sign .han { display: block; font-size: clamp(15px, 4vw, 20px); color: #dff8ff; text-shadow: 0 0 8px var(--t5), 0 0 20px var(--t5); letter-spacing: 0.3em; margin-top: 2px; }
.counter { margin-top: 8px; font-size: 13px; color: var(--dim); }
.corner { position: absolute; top: 14px; z-index: 6; display: flex; gap: 8px; }
.corner.left { left: 14px; } .corner.right { right: 14px; }
.window-btn { position: absolute; z-index: 4; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; }
.window-btn .glass { width: 30px; height: 38px; border-radius: 3px; background: radial-gradient(circle at 50% 40%, #fff3c9, var(--gold) 60%, #b97418); box-shadow: 0 0 18px rgba(255, 200, 97, 0.85); animation: breathe 4.2s ease-in-out infinite; }
.window-btn.done .glass { animation: none; box-shadow: 0 0 26px rgba(255, 200, 97, 1); }
.window-btn .tag { font-size: 11.5px; font-weight: 600; background: rgba(28, 18, 4, 0.82); border: 1px solid rgba(255, 200, 97, 0.7); color: var(--gold); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.window-btn.service .glass { width: 26px; height: 30px; background: radial-gradient(circle at 50% 40%, #e9e4ff, #6c63b8 70%); box-shadow: 0 0 12px rgba(150, 140, 255, 0.6); animation: none; }
.window-btn.service .tag { background: rgba(10, 8, 24, 0.86); border-color: var(--edge); color: var(--ink); }
@keyframes breathe { 0%, 100% { opacity: 0.82; } 50% { opacity: 1; } }
.tower-foot { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center;
  background: linear-gradient(180deg, transparent, rgba(7,6,15,0.92) 40%); }
.tower-foot .pill.gold { font-size: 18px; padding: 14px 34px; }
.tower-foot .goal { font-size: 13px; color: var(--dim); text-align: center; max-width: 360px; }
.trial-line { font-size: 13px; color: var(--gold); background: none; border: 0; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Lift lesson ---------- */
.lift { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.lift::before, .lift::after { content: ""; position: absolute; top: 0; bottom: 0; width: 14px; background: linear-gradient(90deg, #3a3d46, #9ea3ad, #4b4e57); opacity: 0.9; }
.lift::before { left: 0; } .lift::after { right: 0; }
.floor-indicator { font-family: ui-monospace, Menlo, monospace; color: #ffb648; text-shadow: 0 0 10px rgba(255, 150, 40, 0.9); background: #1b0c02; border: 1px solid #4b2a0d; border-radius: 6px; padding: 4px 10px; font-size: 18px; min-width: 56px; text-align: center; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 18px; padding: 10px 22px; text-align: center; }
.big-char { font-size: clamp(84px, 26vw, 140px); line-height: 1; text-shadow: 0 0 22px currentColor; }
.syll { font-size: 26px; }
.meaning { font-size: 17px; color: var(--ink); max-width: 360px; }
.tone-name { font-size: 14px; color: var(--dim); }
.play { width: 72px; height: 72px; border-radius: 36px; border: 1px solid var(--edge); background: rgba(255,255,255,0.08); font-size: 26px; display: grid; place-items: center; }
.play.playing { box-shadow: 0 0 0 6px rgba(255,255,255,0.12); }
.choices { display: grid; gap: 10px; width: 100%; max-width: 420px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choice { border: 1px solid var(--edge); background: var(--panel); border-radius: 14px; padding: 12px 10px; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.choice.big { font-size: 40px; min-height: 84px; }
.choice.right { border-color: var(--t4); box-shadow: 0 0 0 2px var(--t4) inset; }
.choice.wrong { border-color: var(--t1); animation: shake 0.35s; opacity: 0.6; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.tone-btn { display: flex; flex-direction: column; gap: 2px; align-items: center; font-size: 12px; }
.tone-btn svg { width: 54px; height: 26px; }
.progress { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; margin: 0 16px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); transition: width 0.4s; }
.prompt { font-size: 15px; color: var(--dim); }
.foot { padding: 12px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; justify-content: center; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--edge); background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: 26px; }
.chip.used { opacity: 0.25; }
.slots { display: flex; gap: 8px; justify-content: center; min-height: 64px; }
.slot { width: 56px; height: 64px; border-radius: 12px; border: 1px dashed var(--edge); display: grid; place-items: center; font-size: 30px; }
.slot.lit { border-style: solid; text-shadow: 0 0 14px currentColor; }

/* ---------- Rooms ---------- */
.room { position: relative; height: 100%; width: 100%; display: flex; flex-direction: column; }
.painting-wrap { position: absolute; inset: 0; display: flex; justify-content: center; overflow: hidden; }
.painting { position: relative; height: 100%; }
.painting img.base { height: 100%; display: block; }
.painting img.mouth { position: absolute; display: none; }
.room-head { position: relative; z-index: 4; display: flex; align-items: center; gap: 10px; padding: 14px 14px 0; }
.room-head .place { flex: 1; text-align: center; }
.room-head .place b { display: block; font-size: 16px; }
.room-head .place span { font-size: 12px; color: var(--dim); }
.room-panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, rgba(7,6,15,0.94) 22%); display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 84%; background: rgba(250, 246, 236, 0.96); color: #1c1626; border-radius: 18px; padding: 10px 14px; }
.bubble.right { align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.left { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble .han { font-size: 22px; }
.bubble .jp { font-size: 13px; color: #5a4f6e; }
.bubble .en { font-size: 14px; margin-top: 2px; }
.bubble.hidden-text .han { letter-spacing: 0.2em; color: #8b819c; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--edge); border-radius: 14px; text-align: left; width: 100%; }
.item .han { font-size: 24px; }
.item .grow { min-width: 0; }
.item .en { font-size: 14px; }
.item .jp { font-size: 12px; color: var(--dim); }
.section-title { margin: 18px 4px 8px; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.table { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.cell { aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--edge); background: rgba(255,255,255,0.03); display: grid; place-items: center; font-size: 20px; opacity: 0.4; padding: 0; }
.cell.learned { opacity: 1; background: rgba(255,255,255,0.07); text-shadow: 0 0 10px currentColor; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(4, 3, 10, 0.72); display: grid; place-items: center; padding: 18px; }
.modal .card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.modal h3 { margin: 0; font-size: 22px; }
.modal ul { text-align: left; margin: 0; padding-left: 20px; color: var(--dim); font-size: 14px; line-height: 1.5; }
.modal input { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--edge); background: rgba(0,0,0,0.4); color: var(--ink); font: inherit; }
.price { font-size: 34px; font-weight: 700; color: var(--gold); }
.room-head .place, .topbar h2 { text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 12px rgba(0,0,0,0.8); }
.room-head .place span { color: #e4ddf0; }
.tone-name { white-space: nowrap; }
.screen.tower { max-width: none; }
.screen.tower .sign { max-width: 560px; margin: 0 auto; width: 100%; }
.screen.tower .tower-foot > * { max-width: 560px; }
@media (max-width: 520px) { .window-btn .tag { font-size: 10.5px; padding: 2px 7px; } .counter { font-size: 12px; } }
