:root {
  --p1: #38e6ff; --p2: #ff4fd8; --warn: #ff4a3d; --good: #7dff9a; --ink: #f3f5ff; --panel: rgba(12, 10, 32, 0.82);
  --ui: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, "Segoe UI", Arial, sans-serif;
  --display: "Black Han Sans", var(--ui);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0820; color: var(--ink); font-family: var(--ui); font-weight: 700;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
small, button, select { font-size: 14px; }
button { font-family: var(--ui); font-weight: 900; cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s; }
#hud.on { opacity: 1; }
#cards { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 14px; right: 14px; display: flex; justify-content: space-between; }
.pcard { width: min(300px, 34vw); padding: 8px 12px 10px; border-radius: 14px; background: linear-gradient(160deg, rgba(20,18,48,.85), rgba(10,8,26,.7));
  border: 2px solid color-mix(in srgb, var(--pc) 70%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--pc) 35%, transparent); position: relative; }
.pcard.p2 { text-align: right; }
.pcard.down { filter: grayscale(.8) brightness(.7); }
.pname { font-family: var(--display); font-size: 20px; letter-spacing: 1px; color: var(--pc); text-shadow: 0 0 10px var(--pc); margin-bottom: 4px; }
.bar { position: relative; height: 16px; border-radius: 7px; background: rgba(255,255,255,.1); overflow: hidden; margin: 4px 0; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: 7px; transition: width .12s; }
.pcard.p2 .bar i { inset: 0 0 0 auto; }
.bar span { position: absolute; left: 8px; top: 0; line-height: 16px; font-size: 14px; color: rgba(255,255,255,.85); text-shadow: 0 1px 2px #000; }
.pcard.p2 .bar span { left: auto; right: 8px; }
.bar.hp i { background: linear-gradient(90deg, #36f28a, #b6ff5a); }
.bar.hp.low i { background: linear-gradient(90deg, #ff3b3b, #ff9a3b); animation: pulse .5s infinite alternate; }
.bar.heat i { background: linear-gradient(90deg, #3bc7ff, #ffd23f, #ff5a1f); transition: width .05s; }
.bar.heat.warm i { box-shadow: 0 0 10px #ff8a3b; }
.bar.heat.over { animation: over .18s infinite alternate; }
.bar .overheat { display: none; }
.bar.heat.over .overheat { display: inline; color: #ffdd55; }
@keyframes over { from { background: rgba(255,60,30,.35); } to { background: rgba(255,200,60,.35); } }
@keyframes pulse { from { opacity: .6; } to { opacity: 1; } }
.bombs { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 14px; }
.pcard.p2 .bombs { justify-content: flex-end; }
.bombs b { margin-right: 4px; opacity: .8; }
.bombs em { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #ffb02e; opacity: .35; }
.bombs em.full { background: radial-gradient(circle at 40% 35%, #ffe08a, #ff7a1c 60%, #8a2a00); opacity: 1; box-shadow: 0 0 8px #ff8a2e; }
.ptoast { position: absolute; left: 12px; bottom: -30px; font-family: var(--display); font-size: 22px; color: #fff; text-shadow: 0 0 10px var(--pc), 0 2px 0 #000; opacity: 0; }
.pcard.p2 .ptoast { left: auto; right: 12px; }
.ptoast.on { animation: toast 1.4s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px) scale(1.3); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(6px); } }
#center-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; text-shadow: 0 2px 6px #000; }
#score { font-family: var(--display); font-size: 38px; letter-spacing: 3px; color: #fff; text-shadow: 0 0 14px #9a7bff, 0 3px 0 #2a1a5a; }
#zone { font-size: 14px; color: #cfd3ff; }
#center-top .sub { font-size: 14px; color: #a9aed8; margin-top: 2px; }
/* During a fight the two middle columns share the top row with the player cards. */
#hud:has(#bossbar.on) .pcard { width: min(20vw, 265px); }
#hud:has(#bossbar.on) #center-top { left: 36%; max-width: 23%; }
#bossbar { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 63%; transform: translateX(-50%);
  width: min(28vw, 330px); padding: 5px 8px; display: none; text-align: center; line-height: 1.15;
  border-radius: 8px; background: rgba(12,16,28,.91); }
#center-top::before {
  content: ''; position: absolute; inset: -4px -10px; z-index: -1; pointer-events: none;
  border-radius: 8px; background: rgba(15,29,45,.76);
}
#bossbar.on { display: block; }
#bossbar .label { font-family: var(--display); font-weight:400; font-size: 18px; color: #fff4e8; -webkit-text-stroke: 1px #27141a; paint-order: stroke fill; text-shadow: 0 1px 3px #000; }
#bossbar .track { height: 14px; margin-top: 4px; border-radius: 7px; background: rgba(0,0,0,.5); border: 2px solid #ff5a4a; overflow: hidden; }
#bossbar .fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff2a2a, #ffb03b); transition: width .15s; }
#bossbar .pods { font-size: 14px; margin-top: 4px; color: #ffd0c8; }
#bossbar.on ~ #banner { top: max(87px, calc(env(safe-area-inset-top) + 78px)); font-size: 18px; letter-spacing: 0; }
body:has(#bossbar.on) .touch-tag { top: auto; bottom: 4px; }
#banner { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-family: var(--display); font-size: clamp(28px, 5vw, 58px); white-space: nowrap;
  color: #fff; opacity: 0; text-shadow: 0 0 22px #5ad1ff, 0 4px 0 #1a1440; letter-spacing: 2px; }
#banner, .ptoast { -webkit-text-stroke: 2px #172335; paint-order: stroke fill; }
#banner.on { animation: banner 2.6s ease-out forwards; }
#banner.warn { color: #ffd9d4; text-shadow: 0 0 24px #ff2a2a, 0 4px 0 #3a0a0a; }
#banner.good { color: #eaffef; text-shadow: 0 0 24px #3aff7a, 0 4px 0 #0a2a14; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); } 10% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%); } }
.popup { position: absolute; transform: translate(-50%, -100%); font-family: var(--display); font-size: 30px; color: #ffe08a; text-shadow: 0 0 12px #ff7a1c, 0 3px 0 #3a1a00; animation: pop 1.1s ease-out forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -60%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -100%) scale(1.2); } 100% { opacity: 0; transform: translate(-50%, -180%) scale(1); } }

#corner { position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; z-index: 30; }
body:not(.playing) #corner { bottom: auto; top: 14px; left: auto; right: 14px; transform: none; }
#corner button { width: 40px; height: 40px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: rgba(10,8,30,.6); color: #fff; font-size: 16px; }
body:not(.playing) #btn-pause { display: none; }
body.results #corner { display: none; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 20; }
.screen.on { display: flex; }
#title { background: radial-gradient(ellipse at 50% 60%, rgba(10,6,30,0) 0%, rgba(8,5,22,.55) 70%); }
.title-wrap { text-align: center; padding: 20px; max-width: 900px; }
.kicker { font-size: 14px; letter-spacing: 6px; color: #9fb4ff; text-shadow: 0 0 10px #4a6aff; }
h1 { margin: 10px 0 6px; font-family: var(--display); font-weight: 400; line-height: .95; font-size: clamp(54px, 10vw, 128px); }
h1 .neon { display: block; }
h1 .a { color: #e9fbff; text-shadow: 0 0 6px #fff, 0 0 18px var(--p1), 0 0 44px var(--p1), 0 6px 0 #0a3a5a; animation: flicker 5s infinite; }
h1 .b { color: #ffe9fb; text-shadow: 0 0 6px #fff, 0 0 18px var(--p2), 0 0 44px var(--p2), 0 6px 0 #4a0a3a; }
@keyframes flicker { 0%, 92%, 96%, 100% { opacity: 1; } 94% { opacity: .55; } }
.tag { font-size: 17px; color: #d8dcff; text-shadow: 0 2px 6px #000; margin: 6px 0 26px; }
.modes { display: flex; gap: 14px; justify-content: center; flex-wrap: nowrap; }
.mode { flex: 1 1 0; min-width: 0; padding: 16px 14px; border-radius: 18px; border: 3px solid var(--p1); background: linear-gradient(160deg, rgba(20,60,110,.85), rgba(10,14,40,.85));
  color: #fff; box-shadow: 0 0 24px rgba(56,230,255,.45), inset 0 0 18px rgba(56,230,255,.25); transition: transform .12s; }
.mode[data-mode="2"] { border-color: var(--p2); background: linear-gradient(160deg, rgba(110,20,90,.85), rgba(30,10,40,.85)); box-shadow: 0 0 24px rgba(255,79,216,.45), inset 0 0 18px rgba(255,79,216,.25); }
.mode:hover, .mode:focus-visible { transform: translateY(-3px) scale(1.03); outline: none; }
.mode b { display: block; font-family: var(--display); font-weight: 400; font-size: 30px; }
.mode small { display: block; font-size: 14px; opacity: .8; margin-top: 2px; }
.options { margin-top: 22px; display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap; font-size: 14px; color: #cfd3ff; }
.options select, .options input { font-family: var(--ui); font-weight: 700; }
.options select { background: #1a1640; color: #fff; border: 1px solid #5a54a0; border-radius: 8px; padding: 4px 6px; }
button.ghost, .panel button { padding: 9px 18px; border-radius: 12px; border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; font-size: 15px; margin: 6px; }
.panel button:not(.ghost) { border-color: var(--p1); background: rgba(56,230,255,.18); }
#loading { margin-top: 18px; font-size: 14px; color: #9fa4d8; }
#loading.err { color: #ff8a7a; }
.panel { background: var(--panel); border: 2px solid rgba(160,140,255,.45); border-radius: 22px; padding: 24px 30px; max-width: min(920px, 94vw); max-height: 92vh; overflow: auto;
  box-shadow: 0 0 40px rgba(120,90,255,.35); text-align: center; }
.panel.small { min-width: 300px; }
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 40px; margin: 0 0 12px; text-shadow: 0 0 16px #7a5aff; }
.panel h3 { margin: 4px 0 8px; font-size: 18px; }
.p1c { color: var(--p1); } .p2c { color: var(--p2); }
.cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; text-align: left; font-size: 14px; line-height: 1.7; }
.cols p { margin: 2px 0; }
.tips { font-size: 14px; color: #d4d7ff; }
kbd { display: inline-block; min-width: 24px; padding: 1px 6px; margin: 0 2px; border-radius: 6px; background: #2a2660; border: 1px solid #6a64c0; border-bottom-width: 3px; font-family: var(--ui); font-size: 14px; text-align: center; }
#results .r-title { font-size: 52px; }
#results.fail .r-title { color: #ffb0a8; text-shadow: 0 0 16px #ff3b2b; }
.r-rank { font-family: var(--display); font-size: 110px; line-height: 1; color: #ffe08a; text-shadow: 0 0 30px #ff9a1c, 0 6px 0 #5a2a00; margin: 4px 0 10px; }
#results dl { display: grid; grid-template-columns: auto auto; gap: 6px 26px; justify-content: center; font-size: 20px; margin: 0 0 16px; }
#results dt { color: #aab0e0; text-align: right; } #results dd { margin: 0; text-align: left; font-family: var(--display); font-size: 24px; }
body.playing #title { display: none; }

/* ---------- rotate / context-lost overlays ---------- */
#rotate, #ctxlost { z-index: 60; background: radial-gradient(ellipse at 50% 45%, rgba(24,16,60,.97), rgba(6,4,18,.99)); touch-action: none; }
.rotate-box { text-align: center; padding: 24px; }
.rot-icon { width: min(30vmin, 140px); height: auto; animation: rotphone 2.6s ease-in-out infinite; filter: drop-shadow(0 0 14px #5ad1ff); }
@keyframes rotphone { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
.rot-main { font-family: var(--display); font-size: clamp(24px, 6vmin, 46px); margin: 18px 0 6px; text-shadow: 0 0 18px #5ad1ff; }
.rot-sub { font-size: clamp(14px, 3vmin, 20px); color: #b8bff0; margin: 0; }
#countdown { position: fixed; inset: 0; z-index: 55; display: none; align-items: center; justify-content: center; pointer-events: none;
  font-family: var(--display); font-size: clamp(120px, 34vmin, 320px); color: #fff; text-shadow: 0 0 40px #ffd34a, 0 8px 0 #4a3000; }
#countdown.on { display: flex; animation: countpop .85s ease-out; }
@keyframes countpop { 0% { opacity: 0; transform: scale(1.6); } 20% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
.pause-opt { margin: 10px 0 6px; font-size: 14px; color: #cfd3ff; }
.pause-opt small { display: block; margin-top: 4px; font-size: 14px; opacity: .75; }
.pause-opt select { background: #1a1640; color: #fff; border: 1px solid #5a54a0; border-radius: 8px; padding: 6px 8px; font-family: var(--ui); font-weight: 700; font-size: 15px; }

/* ---------- touch ---------- */
#touch { position: fixed; inset: 0; z-index: 10; display: none; touch-action: none; }
#touch.on { display: block; }
body:not(.playing) #touch { display: none; }
.stick { position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.28); background: radial-gradient(circle, rgba(255,255,255,.08), rgba(255,255,255,.02)); }
.stick.p1 { border-color: rgba(56,230,255,.5); } .stick.p2 { border-color: rgba(255,79,216,.5); }
.stick.active { background: radial-gradient(circle, rgba(255,255,255,.16), rgba(255,255,255,.04)); }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; margin: -23% 0 0 -23%; border-radius: 50%; background: rgba(255,255,255,.55); box-shadow: 0 0 14px rgba(255,255,255,.5); }
.stick.aim .knob { background: radial-gradient(circle, #fff, rgba(255,120,120,.7)); }
.stick-label { position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); font-size: 14px; white-space: nowrap; color: #fff; background: #192a3bda; border-radius: 4px; box-shadow: 0 0 0 2px #192a3bda; }
.reticle { position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; pointer-events: none;
  border: 3px solid rgba(255,255,255,.85); box-shadow: 0 0 16px rgba(56,230,255,.7), inset 0 0 12px rgba(56,230,255,.5); }
.reticle::before, .reticle::after { content: ''; position: absolute; left: 50%; top: 50%; background: rgba(255,255,255,.9); transform: translate(-50%, -50%); }
.reticle::before { width: 2px; height: 86px; } .reticle::after { width: 86px; height: 2px; }
.reticle.p2 { border-color: rgba(255,200,240,.9); box-shadow: 0 0 16px rgba(255,79,216,.7), inset 0 0 12px rgba(255,79,216,.5); }
.tbtn { position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--display); color: #fff;
  background: rgba(20,18,50,.55); border: 3px solid rgba(255,255,255,.4); text-shadow: 0 2px 4px #000; }
.tbtn.bomb { border-color: #ffb02e; }
.tbtn.down { background: rgba(46,65,88,.85); }
.touch-divider { position: absolute; left: 50%; top: 22%; bottom: 0; width: 2px; background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,.18)); }
.touch-tag { position: absolute; top: 30%; transform: translateX(-50%); font-family: var(--display); font-size: 22px; text-shadow: 0 1px 3px #000; background: #192a3bd9; border-radius: 4px; }
.touch-tag.p1 { color: var(--p1); } .touch-tag.p2 { color: var(--p2); }

@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
  #score { font-size: 28px; }
  .pname { font-size: 16px; }
}
@media (max-height: 520px) {
  .tag { display: none; } h1 { font-size: 64px; } .modes .mode { padding: 6px 8px; min-width: 0; }
  .mode b, .mode[data-mode="tower"] b { font-size: 21px; white-space: nowrap; }
  .mode small { font-size: 14px; margin-top: 0; }
}
@media (max-height: 500px) { .touch-tag { display: none; } }

.reticle.locked, .lock-ring { border-color: #ff4848; box-shadow: 0 0 10px #ff4848; }
.lock-ring { position: absolute; width: 28px; height: 28px; transform: translate(-50%, -50%);
  border: 2px solid #ff4848; border-radius: 50%; pointer-events: none; }
.aim-line { position: absolute; height: 1px; background: rgba(255,255,255,.35); transform-origin: left center; pointer-events: none; }

.language { display: flex; justify-content: center; margin: 8px auto; }
.language input { min-width: 76px; min-height: 44px; padding: 4px 12px; border: 1px solid #8985ab;
  background: #17132d; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; }
.language input:first-child { border-radius: 10px 0 0 10px; }
.language input:last-child { border-radius: 0 10px 10px 0; }
.language input[aria-pressed="true"] { background: var(--p1); color: #101329; }
#title, #pause { padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
  max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
/* Reserve the bottom row for the in-game pause and sound buttons. */
#pause { padding-bottom: calc(48px + max(10px, env(safe-area-inset-bottom))); }
#center-top { max-width: calc(32vw - 32px); }
.title-wrap, #pause .panel { max-height: 100%; overflow-y: auto; touch-action: pan-y; }
.title-wrap { max-width: min(100%, 1000px); }
.panel { touch-action: pan-y; }
#banner { white-space: normal; width: max-content; max-width: 94vw; text-wrap: balance; text-align: center; }
@media (max-height: 520px) {
  .title-wrap { padding: 4px; }
  .options { margin-top: 6px; gap: 8px; }
  h1 { font-size: clamp(40px, 13vh, 64px); }
}

.stage-cards { display: flex; justify-content: center; gap: 12px; margin: 8px auto 14px; }
.stage-card { flex: 1; max-width: 224px; min-height: 56px; padding: 8px; border: 2px solid #737290;
  border-radius: 12px; background: #18172c; color: white; font: bold 16px var(--ui); }
.stage-card::before { content: ''; display: block; height: 24px; margin-bottom: 5px; border-radius: 5px;
  background: repeating-linear-gradient(90deg, transparent 0 9%, #262245 9% 15%) bottom/100% 60% no-repeat,
    linear-gradient(#272155, #d76f9d); }
.stage-card[data-stage="2"]::before { background: linear-gradient(0deg, #42828c 0 22%, transparent 22%),
  repeating-linear-gradient(90deg, transparent 0 14%, #5c5264 14% 16%) center/100% 45% no-repeat,
  linear-gradient(#945779, #ffbd79); }
#factory-difficulty[hidden] { display:none; }
.stage-card[data-stage="3"]::before { content:'⚙'; line-height:1; color:#ffce7c;
  background:repeating-linear-gradient(130deg, #e2a154 0 8px, #546365 8px 16px) bottom/100% 18% no-repeat,
    linear-gradient(90deg,#275b5b,#397c75,#2c5456); }
.stage-card[aria-pressed="true"] { border-color: #ffdc79; box-shadow: inset 0 0 0 1px #ffdc79; }
.stage-card:focus-visible { outline: 3px solid white; outline-offset: 2px; }
@media (max-height: 440px) {
  #title h1 { font-size: 46px; margin: 0; }
  .stage-cards { margin: 3px auto 7px; }
  .stage-card { min-height: 46px; padding: 3px 8px; }
  .stage-card::before { height: 14px; margin-bottom: 2px; }
}


@media (max-height: 520px) {
  #hud:has(#bossbar.on) .pcard { padding: 3px 6px; }
  #hud:has(#bossbar.on) .pname { font-size: 14px; margin: 0; }
  #hud:has(#bossbar.on) .bar { height: 16px; margin: 2px 0; }
  #hud:has(#bossbar.on) .bombs { margin-top: 2px; }
  #hud:has(#bossbar.on) #score { font-size: 23px; }
  #hud:has(#bossbar.on) #zone { font-size: 14px; }
  #bossbar .label { font-size: 15px; }
  #bossbar .track { height: 9px; }
  #bossbar.on ~ #banner { top: max(75px, calc(env(safe-area-inset-top) + 65px)); font-size: 15px; }
}

.mode[data-mode="tower"] { border-color: #ffd06b; background: linear-gradient(155deg,#654323,#302449); }
#puzzle-select, #puzzle-result { background: rgba(19,22,42,.64); text-align: center; }
#puzzle-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
#puzzle-grid .puzzle-card { margin: 0; display: grid; align-content: center; gap: 4px; }
.puzzle-card:disabled { opacity: .58; }
.puzzle-card strong, #puzzle-stars { color: #ffd470; letter-spacing: .1em; }
#puzzle-select .panel, #puzzle-result .panel { width: min(740px,94vw); }
#puzzle-select button, #puzzle-result button, #puzzle-overlay button { min-width: 64px; min-height: 64px; }
#puzzle-hud, #puzzle-nav, #puzzle-actions { position: fixed; z-index: 14; display: flex; gap: 8px; }
#puzzle-hud { top: max(8px,env(safe-area-inset-top)); left: max(12px,env(safe-area-inset-left));
  max-width: calc(100% - 240px); flex-wrap: wrap; gap: 3px 14px; padding: 7px 14px;
  border-radius: 13px; background: #18223aeb; color: #fff; pointer-events: none; }
#puzzle-name { flex-basis: 100%; color: #ffd470; }
#puzzle-nav { top: max(8px,env(safe-area-inset-top)); right: max(12px,env(safe-area-inset-right)); }
#puzzle-actions { bottom: max(14px,env(safe-area-inset-bottom)); left: max(16px,env(safe-area-inset-left)); }
#puzzle-overlay button { padding: 6px 12px; border: 2px solid #cccbde; background: #252e46ee; border-radius: 16px; color: white; font-weight: bold; }
#puzzle-actions button { background: #ffce77; color: #362515; border-color: #fff0be; font-size: 17px; }
#puzzle-actions #puzzle-detonate { background: #ffae95; }
body.puzzle #corner button { width: 64px; height: 64px; }
body:has(#pause.on) #puzzle-overlay, body.results #puzzle-overlay, body.results.puzzle #touch { display: none; }
@media (max-height: 440px) {
  #puzzle-select .panel { padding: 8px 18px; }
  #puzzle-select h2 { font-size: 28px; }
  #puzzle-select p { margin: 6px 0; }
}

#puzzle-result .panel { position: relative; }
#puzzle-result.won #puzzle-stars { display: block; position: relative; font-size: 3rem; line-height: 1.15; }
#puzzle-stars span { display: inline-block; }
#puzzle-star-count { color: #ffe4a9; font-variant-numeric: tabular-nums; }
#puzzle-confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; border-radius: inherit; }
#puzzle-confetti i { position: absolute; top: 44%; left: 50%; width: 5px; height: 9px; border-radius: 2px; background: #ffd470; }
#puzzle-confetti i:nth-child(3n) { background: #81dcff; }
#puzzle-confetti i:nth-child(3n + 1) { background: #ffabb0; }
@media (prefers-reduced-motion: no-preference) {
  #puzzle-stars .pop { animation: puzzle-pop .32s ease-out; }
  #puzzle-confetti i { animation: puzzle-confetti .74s ease-out forwards; }
}
@keyframes puzzle-pop {
  from { transform: scale(.55); }
  55% { transform: scale(1.18); }
  to { transform: scale(1); }
}
@keyframes puzzle-confetti {
  from { opacity: 0; transform: scale(.4); }
  18% { opacity: 1; }
  70% { opacity: .95; transform: translate(var(--dx), var(--dy)) rotate(130deg); }
  to { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 18px)) rotate(190deg); }
}
@media (prefers-reduced-motion: reduce) {
  #puzzle-confetti { display: none; }
}
@media (max-height: 440px) {
  #puzzle-result.won .panel { padding: 8px 16px; }
  #puzzle-result.won h2 { font-size: 28px; margin-bottom: 2px; }
  #puzzle-result.won p { margin: 6px 0; }
}

.mode[data-mode="tower"] b { font-size: clamp(20px, 2.65vw, 28px); }
#tower-select { background: rgba(19,22,42,.64); text-align: center; }
#tower-select .stage-card { display: block; margin: 1em auto; min-width: 180px; }
.throw-power { width: 100%; height: 7px; accent-color: #ffbc42; }
.tbtn.bomb.charging { background: conic-gradient(#ffa936 var(--charge), #54391d 0); box-shadow: inset 0 0 0 3px white; }

.mode b { white-space: nowrap; }

/* Tour atlas */
#tower-select { background: linear-gradient(145deg,#b9f2f5,#80c6f1 55%,#e8dcfa); color:#183955; }
.atlas { width:min(94vw,940px); height:min(90dvh,660px); display:grid; grid-template-rows:auto minmax(0,1fr) auto; gap:10px; }
.atlas header,.atlas footer { display:flex; align-items:center; justify-content:space-between; gap:14px; }
.atlas h2 { font:clamp(24px,4vw,45px)/1 var(--display); margin:0; }
.atlas header button,.atlas footer button { border:1px solid #85a6b3; background:#fff8de; color:#253e59; border-radius:12px; padding:9px 16px; }
#world-map,#passport { position:relative; border:3px solid #f8ffec; border-radius:20px; box-shadow:0 8px 30px #315b7a33; overflow:hidden; }
#world-map { background:radial-gradient(ellipse at 68% 35%,#def9fc,#a4dbe8 65%,#84bddb); }
#world-map svg,#tour-pins { position:absolute; inset:0; width:100%; height:100%; }
.map-route { animation:tour-route 9s linear infinite; }
@keyframes tour-route { to { stroke-dashoffset:-18; } }
@media(prefers-reduced-motion:reduce) { .map-route { animation:none; } }
.tour-pin { position:absolute; transform:translate(-50%,-50%); border:2px solid white; border-radius:20px 20px 20px 4px; padding:6px 9px; min-height:32px; font-size:clamp(14px,1.3vw,15px); color:#294458; background:#e4eef1; box-shadow:0 3px 5px #34617d44; white-space:nowrap; }
.tour-pin[data-status=open] { background:#ffda6b; border-color:#fff3ba; color:#443519; }
.atlas button:focus-visible { outline:3px solid #993464; outline-offset:2px; }
#map-note { text-align:right; font-size:clamp(14px,2vw,18px); }
#passport:not([hidden]) { background:#fff7df; display:grid; grid-template-columns:repeat(5,1fr); align-content:center; gap:12px; padding:3%; }
.stamp-slot { border:2px dashed #b2b2a3; color:#626d75; border-radius:50%; aspect-ratio:1.6; display:grid; place-content:center; text-align:center; font-size:clamp(14px,1.5vw,17px); }
.stamp-slot[data-stamped=true] { color:#207057; border:4px double #25866e; transform:rotate(-6deg); background:#d4f5da; }
#tour-counts,#tour-height,.tour-hud #score { display:none; }
.tour-hud #center-top { max-width:45vw; left:55%; }
.tour-hud .pcard { width:min(25vw,265px); }
.tour-hud #tour-counts { display:block; font-size:14px; }
.tour-hud #tour-height { display:block; position:absolute; right:calc(100% + 3px); width:14px; height:100%; background:linear-gradient(to top,#69ffe5 var(--height),#6f8aa3 var(--height)); clip-path:polygon(44% 0,60% 8%,85% 62%,100% 100%,0 100%,20% 58%); }
@media(max-height:460px) { .atlas { gap:4px; height:96dvh; } .tour-pin { min-height:28px; padding:3px 7px; } }
body:has(#tower-select.on) #corner,body:has(#tour-result.on) #touch { display:none; }
.tour-hud #banner { white-space:normal; text-align:center; width:min(76vw,620px); font-size:clamp(18px,2.8vw,32px); }

.citizen-bubble {
  position:fixed; pointer-events:none; white-space:nowrap; font-weight:900;
  color:#233e46; background:#fff3c9; border:2px solid #324f52;
  border-radius:12px; box-shadow:0 2px 0 #29434966;
}
.citizen-bubble {
  padding:3px 9px; font-size:clamp(14px,1.2vw,16px); transform:translate(-50%,-100%);
}
.citizen-bubble::after {
  content:""; position:absolute; left:42%; bottom:-6px; width:8px;height:8px;
  background:#fff3c9;border-right:2px solid #324f52;border-bottom:2px solid #324f52; transform:rotate(45deg);
}
.citizen-bubble[hidden] {display:none}

.tour-tip { position:absolute; left:50%; top:max(122px,16vh); transform:translateX(-50%);
  width:max-content; max-width:min(235px,64vw); box-sizing:border-box; padding:6px 13px;
  border:1px solid #c7f3df; border-radius:14px; background:#183c47ed; color:#fff9e6;
  font:600 clamp(14px,1.4vw,16px)/1.3 var(--ui); text-align:center; overflow-wrap:anywhere; }
#tour-result { text-align:center; background:#183b45ad; padding:8px; box-sizing:border-box; }
.tour-postcard { box-sizing:border-box; width:min(520px,96vw); max-height:96dvh; overflow:auto;
  background:#faf1d9; color:#244953; border:6px double #92b5a7; border-radius:17px;
  box-shadow:0 14px 56px #102c3f66; padding:clamp(10px,2.2vh,22px) clamp(14px,3vw,30px); }
.tour-postcard header,.tour-postcard footer,#tour-summary { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.tour-postcard header { border-bottom:1px solid #a8baaa; padding-bottom:5px; color:#476c68; font-weight:bold; }
.tour-postcard .language { margin:0; }
.tour-postcard h2 { color:#224d56; margin:8px 0 0; font-size:clamp(24px,4.6vh,40px); }
#tour-stars { line-height:1.1; margin:2px 0 8px; color:#e6a123; font-size:clamp(32px,6vh,52px); text-shadow:0 2px #84591a; }
#tour-stars span { display:inline-block; animation:tour-star .36s backwards; }
@keyframes tour-star { from { opacity:0; transform:scale(.35) rotate(-18deg); } 70% { transform:scale(1.18); } }
#tour-summary { justify-content:center; flex-wrap:wrap; font-weight:bold; font-size:clamp(14px,2vh,16px); }
#tour-summary span+span { border-left:1px solid #a8baaa; padding-left:8px; }
#tour-fact { display:grid; grid-template-columns:minmax(46px,18%) 1fr auto; align-items:center; text-align:left;
  gap:10px; margin:12px 0; padding:8px; background:#e4ecde; border-radius:8px; font-size:clamp(14px,1.8vh,16px); }
#tour-fact svg { width:100%; } #tour-fact strong { font-size:1.16em; } #tour-story { font-style:normal; }
.tower-copy { display:grid; min-width:0; word-break:keep-all; overflow-wrap:anywhere; }
#tour-stamp { display:grid; justify-items:center; align-content:center; border-radius:50%; width:clamp(78px,10vh,92px); container-type:inline-size; white-space:nowrap;
  aspect-ratio:1; border:4px double #a94a3e; color:#a94a3e; font-weight:800; line-height:1.05;
  transform:rotate(-12deg); animation:tour-stamp .38s .62s backwards; }
#tour-stamp b { font-size:1.35em; } #tour-stamp span { font-size:max(14px,16cqi); } #tour-stamp small { font-size:max(14px,12cqi); }
@keyframes tour-stamp { from { opacity:0; transform:scale(2) rotate(-23deg); } 78% { transform:scale(.92) rotate(-12deg); } }
.tour-postcard footer { justify-content:center; }
.tour-postcard footer button { color:#fffaed; background:#275b61; border-radius:8px; padding:6px 16px; }
@media(max-height:520px) { .tour-tip { top:96px; } #tour-fact { margin:6px 0; grid-template-columns:58px 1fr auto; } #tour-fact svg { height:66px; } }

.tour-postcard footer button { min-height:40px; }

.champion-badge { grid-column:1/-1; justify-self:center; color:#815318; background:#ffe192; border-radius:1em; padding:.5em 1em; }

.taipei-icon, [data-tower="tw-taipei101"] .seoul-icon { display:none; }
[data-tower="tw-taipei101"] .taipei-icon { display:inline; }

#tour-party:not([hidden]) { display:flex; align-items:center; justify-content:center; gap:12px; }
.difficulty-options { display:inline-flex; border:2px solid #255560; border-radius:12px; overflow:hidden; }
.difficulty-options button { border:0; background:#fff8de; color:#253e59; }
.difficulty-options button[aria-pressed=true] { background:#255560; color:white; }
.atlas .difficulty-options button:focus-visible { outline-offset:-4px; }
#tour-party button { min-width:70px; min-height:44px; }
.tour-hud #center-top:has(#twin-status:not([hidden])) { left:50%; max-width:40vw; }
#twin-status { width:max-content; max-width:100%; margin:4px auto 0; display:flex; gap:5px; align-items:end; padding:5px 8px; color:#a6bbc7; border-radius:6px; background:#173346eb; }
#twin-status b { padding:4px 5px 1px; border-top:3px solid; font-size:14px; }
#twin-status b.active { background:#35647b; color:white; }
#twin-status i { width:10px; height:10px; align-self:center; border:2px solid var(--lamp); border-radius:50%; }
#twin-status i.lit { background:var(--lamp); box-shadow:0 0 4px var(--lamp); }
#hud:has(#twin-status.split)::after { content:''; position:fixed; left:50%; top:0; height:100vh; border-left:2px solid #aacadc; pointer-events:none; }
@media (orientation:portrait) {
  #hud:has(#twin-status.split)::after { left:0; top:50%; width:100vw; height:0; border:0; border-top:2px solid #aacadc; }
}
#twin-status[hidden] { display:none; }
#twin-status span { align-self:center; margin-left:4px; color:#e6f6fb; font-size:14px; }

.floor-strip {position:absolute;right:max(12px,env(safe-area-inset-right));top:20%;max-height:52%;overflow-y:auto;display:flex;flex-direction:column;gap:2px;padding:5px;background:#193438eb;border:1px solid #82b7bc;border-radius:7px;pointer-events:auto;touch-action:pan-y}
.floor-strip[hidden] {display:none}
.floor-strip button {background:#29494d;color:#e2fff5;border:0;padding:3px 10px;min-height:25px;font:bold 14px monospace;border-radius:3px}
.floor-strip button[aria-current=true] {background:#89ffe2;color:#123b3c}

#hud.tour-hud.on {z-index:11}
.partner-strip {right:auto;left:12px}

.pin-order { position:absolute; top:-.65em; right:-.45em; display:grid; place-items:center; width:1.45em; height:1.45em; border-radius:50%; background:#16394a; color:white; font-size:max(14px,.78em); }

.boss-edge { position:absolute; z-index:6; pointer-events:none; color:#fff3cf; background:#922738;
  border:2px solid #ffb099; border-radius:50%; width:30px; height:30px; line-height:28px;
  text-align:center; font:bold 23px/28px sans-serif; box-shadow:0 1px 5px #341018; }
#bossbar .objective { display:block; font-weight:700; color:#fff3af; white-space:nowrap; }

.boss-target { position:absolute; z-index:6; transform:translate(-50%,-50%); pointer-events:none;
  display:grid; justify-items:center; color:#ffe45b; white-space:nowrap; font:bold 14px/1.25 var(--display),sans-serif; }
.boss-target span { background:#252018; border-radius:4px; padding:2px 6px; }
.boss-target b { font: bold 24px/1 sans-serif; -webkit-text-stroke:1px #382b06; }

.boss-target[hidden],.floor-badge[hidden] { display:none; }
.floor-badge { position:absolute; box-sizing:border-box; padding:3px 4px; border-radius:6px;
  container-type:inline-size; transform-origin:top right; background:#142831ed; color:#f4f6e8;
  font:700 14px/1.2 sans-serif; text-align:center; white-space:nowrap; pointer-events:none; }
.floor-badge strong,.floor-badge span,.floor-badge small { display:block; }
.floor-badge strong { font-size:clamp(14px,8.8cqw,17px); color:#ffdc80; }
.floor-badge > span { font-size:14px; }
.floor-badge small { font-size:14px; }
.mission-intro { display:block; padding:2px 0; color:#b8ffdf; font-size:clamp(14px,10cqw,17px); white-space:normal; }
.mission-intro[hidden] { display:none; }
#hud.climbing #center-top { display:contents; }
#hud.climbing #center-top::before,#hud.climbing #center-top > :not(#twin-status) { display:none; }
#hud.climbing #twin-status { position:fixed; left:8px; top:var(--twin-y); margin:0;
  max-width:var(--card-width); flex-wrap:wrap; gap:2px; padding:3px; }
#hud.climbing #twin-status span { margin:0; font-size:14px; }
#hud.climbing .pcard { position:fixed; left:8px; top:8px; width:var(--card-width); padding:4px 6px; }
#hud.climbing .pcard.p2 { left:var(--p2-x); top:var(--p2-y); }
.climb-lives { display:none; }
#hud.climbing .climb-lives { display:block; font-size:14px; }
#hud.climbing .bombs { gap:2px; }
#hud.climbing .bombs em { width:9px; height:9px; }
#hud.climbing .tour-tip { white-space:nowrap; max-width:none; }
body:has(#hud.climbing) .touch-tag { display:none; }

.tour-hud:has(#bossbar.on) #banner,
.tour-hud:has(#bossbar.on) #popups { display:none; }
.floor-badge.roof-badge { width:auto !important; height:auto !important; container-type:normal; padding:2px 6px; }
.roof-badge strong { font-size:14px; }
.roof-badge > :not(strong) { display:none; }
.boss-target span { font-size:18px; -webkit-text-stroke:2px #171418; paint-order:stroke fill; }

.tour-hud:has(#bossbar.on) .pcard { position:fixed; }

#hud.tour-hud:has(#bossbar.on) #center-top {
  left:var(--roof-stats-x,14px); top:var(--roof-stats-y,140px); transform:none;
  width:min(20vw,265px); max-width:none; text-align:left;
}
.tour-hud #bossbar.on { display:grid; grid-template-columns:1fr auto; align-items:center; }
.tour-hud #bossbar .label { text-align:left; }
.tour-hud #bossbar .pods { grid-column:2; grid-row:1; white-space:nowrap; }
.tour-hud #bossbar .track,.tour-hud #bossbar .objective { grid-column:1 / -1; }
.tour-hud #bossbar .objective { margin-top:3px; }

@media(max-height:520px) {
  #hud.tour-hud:has(#bossbar.on):has(.p2) .pcard,
  #hud.tour-hud:has(#bossbar.on):has(.p2) #center-top { width:96px; }
  #hud.tour-hud:has(#bossbar.on):has(.p2) .bombs { gap:2px; }
  #hud.tour-hud:has(#bossbar.on):has(.p2) .bombs em { width:9px; height:9px; }
}

.tour-hud:has(.roof-badge:not([hidden])) #zone { display:none; }

.floor-badge > strong,.floor-badge > span,.floor-badge > small { white-space:normal; overflow-wrap:anywhere; }
.key-rack { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:2px; }
.key-slot { display:flex; flex-direction:column; align-items:center; font-size:14px; line-height:1.1; color:#abb2b8; }
.key-slot span { max-width:100%; white-space:normal; overflow-wrap:anywhere; }
.key-slot i { min-width:28px; min-height:28px; font:28px/1 sans-serif; }
.key-slot.owned { color:#ffdc80; }
.key-slot.owned i { filter:none; opacity:1; }
@container (min-width:192px) {
  .key-rack { grid-template-columns:repeat(4,minmax(0,1fr)); }
}
.roof-badge .key-rack { display:none }
.flying-key { position:fixed; left:50%; top:50%; font-size:40px; pointer-events:none; z-index:10 }
.hall-button { position:absolute; transform:translate(-50%,-50%); pointer-events:auto; touch-action:manipulation; min-width:44px; min-height:36px; background:#194b46; border:1px solid #8efade; color:white; border-radius:5px }
.hall-button.locked { background:#782e31; border-color:#ff9691 }
.key-slot:not(.owned) i,.key-slot.receiving i { filter:grayscale(1) brightness(.4) drop-shadow(1px 0 #bac3ca) drop-shadow(-1px 0 #bac3ca); opacity:.85 }

.hub-controls { display:flex; justify-content:center; flex-wrap:wrap; gap:8px; margin-top:8px; }
.hub-controls button { margin:0; min-width:56px; min-height:56px; padding:6px 14px;
  border:1px solid #737290; border-radius:12px; color:white; background:#252540; }
.tour-postcard { touch-action:pan-y; }
@media (pointer:coarse) {
  button, .language input, .hall-button, .stage-card, .tour-pin, .floor-strip button,
  #corner button, #tour-party button, .tour-postcard footer button { min-height:56px; }
  button, #corner button, .hall-button, .modes .mode { min-width:56px; }
  #pause { padding-bottom:calc(64px + max(10px,env(safe-area-inset-bottom))); }
}

@container (max-width:140px) {
  .floor-badge > :is(strong,span,small), .key-slot { line-height:1.05; }
}
