html, body { height: 100%; }
body { overflow-x: hidden; }
.screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 64px 16px 28px; gap: 12px; }
.screen[hidden] { display: none; }
.topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; z-index: 5; }
.btn.small { padding: 8px 16px; font-size: 0.9rem; }
.td-logo { font-family: var(--display); font-size: clamp(2rem, 9vw, 3.4rem); margin: 8px 0 0; text-align: center; color: #fff;
  background: linear-gradient(180deg, #fff3c4, #ffb02e 55%, #d9561b); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 160, 40, 0.45)); letter-spacing: 0.04em; }
.td-logo .shield { -webkit-text-fill-color: initial; }
.muted { color: var(--muted); text-align: center; max-width: 560px; margin: 0; }
.sec { font-family: var(--display); font-size: 1rem; letter-spacing: 0.1em; color: var(--muted); margin: 14px 0 0; }
#playBtn { position: sticky; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 4; background: #2a0a2c; box-shadow: var(--glow-pink), 0 6px 24px rgba(0, 0, 0, 0.7); }
.how { color: var(--muted); font-size: 0.85rem; max-width: 560px; text-align: center; margin: 0; opacity: 0.85; }

.map-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: min(640px, 100%); }
.map-card { position: relative; border-radius: 16px; overflow: hidden; border: 2px solid var(--line); background: #0b0d20; cursor: pointer; padding: 0; color: #fff; text-align: left; transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s; }
.map-card canvas { display: block; width: 100%; aspect-ratio: 22 / 14; }
.map-card .info { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 8px; background: linear-gradient(transparent, rgba(5, 6, 15, 0.92)); }
.map-card b { font-family: var(--display); font-size: 1rem; display: block; }
.map-card small { color: var(--muted); font-size: 0.72rem; }
.map-card .medals { position: absolute; top: 6px; right: 8px; font-size: 0.9rem; letter-spacing: 1px; text-shadow: 0 1px 3px #000; }
.map-card.on { border-color: #ffb02e; box-shadow: 0 0 18px rgba(255, 176, 46, 0.45); transform: translateY(-2px); }
.map-card.locked { cursor: default; }
.map-card.locked canvas { filter: grayscale(1) brightness(0.45); }
.map-card.locked .info small { color: #ffb02e; }
.diffs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.diffs button { padding: 9px 16px; border-radius: 999px; border: 2px solid var(--line); background: rgba(14, 16, 40, 0.8); color: var(--muted); font-weight: 800; cursor: pointer; font-family: inherit; }
.diffs button.on { color: #05060f; background: #ffb02e; border-color: #ffb02e; box-shadow: 0 0 14px rgba(255, 176, 46, 0.6); }
.diffs button[data-d="nightmare"].on { background: #ff3d5a; border-color: #ff3d5a; color: #fff; box-shadow: 0 0 16px rgba(255, 61, 90, 0.7); }

/* game */
/* fixed to the visible viewport, so phone toolbars never cover the controls */
#game { position: fixed; inset: 0; min-height: 0; height: auto; padding: 0; gap: 0; overflow: hidden; background: #9fd8f5; z-index: 1; }
body.playing { overflow: hidden; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.hud { position: absolute; top: 0; left: 0; right: 0; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 10px 8px; pointer-events: none;
  background: linear-gradient(rgba(20, 30, 50, 0.55), rgba(20, 30, 50, 0)); z-index: 3; }
.hud > * { pointer-events: auto; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(10, 12, 26, 0.75); color: #fff; font-size: 0.95rem; font-weight: 800; cursor: pointer; }
.icon-btn.speed { width: 48px; font-family: var(--display); }
.icon-btn.speed.fast { border-color: #ffb02e; color: #ffb02e; }
.hud-wave { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.hud-wave b { font-family: var(--display); color: #fff; font-size: 1.02rem; text-shadow: 0 1px 4px #000; white-space: nowrap; }
.hud-wave span { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 0.72rem; white-space: nowrap; overflow: hidden; }
.hud-wave span img { width: 18px; height: 18px; transform: scale(1.5); margin: 0 2px; }
.hud-res { display: flex; gap: 10px; }
.res { display: flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 999px; background: rgba(10, 12, 26, 0.75); border: 1px solid rgba(255, 255, 255, 0.14); font-family: var(--display); font-size: 1rem; }
.res img { width: 20px; height: 20px; }
.res.lives { color: #ff6b81; }
.res.gold { color: #ffd34d; }
.res.flash { animation: resflash 0.5s; }
@keyframes resflash { 30% { transform: scale(1.18); background: rgba(255, 61, 90, 0.5); } }

.boss-bar { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); width: min(420px, 70vw); height: 14px; border-radius: 8px; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 80, 80, 0.6); z-index: 3; overflow: hidden; }
.boss-bar i { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #ff3d5a, #ffb02e); box-shadow: 0 0 12px #ff3d5a; transition: width 0.2s; }
.boss-bar span { position: absolute; inset: 0; z-index: 1; text-align: center; font: 800 0.65rem/14px var(--display); letter-spacing: 0.3em; color: #fff; }
.boss-bar[hidden] { display: none; }

.banner { position: absolute; top: 34%; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 4; opacity: 0; font-family: var(--display); }
.banner b { display: block; padding: 0 10px; font-size: clamp(1.3rem, 7vw, 3rem); color: #fff; letter-spacing: 0.08em; text-shadow: 0 0 18px rgba(255, 176, 46, 0.9), 0 3px 0 #000; }
.banner small { display: block; font-size: clamp(0.85rem, 3vw, 1.1rem); color: #ffd34d; text-shadow: 0 2px 4px #000; }
.banner.boss b { color: #ffd0d6; text-shadow: 0 0 22px #ff3d5a, 0 3px 0 #000; }
.banner.show { animation: banner 2.4s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.6); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
.toast { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); padding: 7px 14px; border-radius: 999px; background: rgba(10, 12, 26, 0.88); border: 1px solid rgba(255, 255, 255, 0.2); color: #fff; font-size: 0.85rem; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 5; white-space: nowrap; }
.toast.show { opacity: 1; }

.dock { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: flex-end; justify-content: space-between; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); z-index: 3;
  background: linear-gradient(rgba(5, 6, 15, 0), rgba(5, 6, 15, 0.9) 35%); pointer-events: none; }
.dock > * { pointer-events: auto; }
.shop { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.shop::-webkit-scrollbar { display: none; }
.tw { position: relative; flex: 0 0 auto; width: 64px; padding: 4px 2px 3px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.16); background: linear-gradient(180deg, rgba(40, 46, 80, 0.92), rgba(16, 18, 36, 0.95)); color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; font-family: inherit; transition: transform 0.1s, border-color 0.15s; }
.tw img { width: 44px; height: 44px; }
.tw small { font-size: 0.6rem; color: #cfd6ff; white-space: nowrap; overflow: hidden; max-width: 60px; text-overflow: ellipsis; }
.tw b { font-family: var(--display); font-size: 0.78rem; color: #ffd34d; display: flex; align-items: center; gap: 2px; }
.tw b img { width: 12px; height: 12px; }
.tw.on { border-color: #ffb02e; box-shadow: 0 0 14px rgba(255, 176, 46, 0.7); transform: translateY(-4px); }
.tw.poor { opacity: 0.5; }
.tw.poor b { color: #ff6b81; }
.dock-right { display: flex; gap: 6px; align-items: flex-end; }
.ability { position: relative; width: 56px; height: 64px; border-radius: 12px; border: 2px solid rgba(120, 180, 255, 0.4); background: linear-gradient(180deg, rgba(30, 50, 90, 0.95), rgba(12, 18, 36, 0.95)); color: #fff; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: inherit; }
.ability .ic { font-size: 1.4rem; line-height: 1; }
.ability small { font-size: 0.55rem; color: #bcd; margin-top: 3px; }
.ability .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0, 0, 0, 0.72) calc(var(--p, 0) * 1%), transparent 0); pointer-events: none; }
.ability.armed { border-color: #ffb02e; box-shadow: 0 0 16px rgba(255, 176, 46, 0.8); }
.ability:disabled { cursor: default; }
.ability.locked { opacity: 0.4; }
.wave-btn { min-width: 92px; height: 64px; border-radius: 14px; border: 2px solid #ffb02e; background: linear-gradient(180deg, #ffb02e, #d9561b); color: #1a0c00; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: inherit; box-shadow: 0 0 16px rgba(255, 140, 30, 0.55); padding: 0 8px; }
.wave-btn b { font-family: var(--display); font-size: 0.95rem; }
.wave-btn small { font-size: 0.58rem; font-weight: 800; opacity: 0.85; }
.wave-btn:disabled { background: rgba(40, 40, 60, 0.85); border-color: rgba(255, 255, 255, 0.15); color: #99a; box-shadow: none; cursor: default; }

.panel { position: absolute; z-index: 6; width: 220px; padding: 10px; border-radius: 14px; background: rgba(10, 12, 26, 0.94); border: 1px solid rgba(255, 176, 46, 0.5); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.8rem; }
.panel[hidden] { display: none; }
.panel h4 { margin: 0 0 6px; font-family: var(--display); font-size: 0.95rem; display: flex; justify-content: space-between; align-items: center; }
.panel h4 span { color: #ffd34d; font-size: 0.8rem; }
.panel .stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 6px; color: #cfd6ff; }
.panel .stats em { font-style: normal; color: #fff; font-weight: 800; }
.panel .stats em i { font-style: normal; color: #7dff3a; }
.panel .syn { margin: 4px 0 6px; padding: 5px 7px; border-radius: 8px; background: rgba(125, 255, 58, 0.1); border: 1px solid rgba(125, 255, 58, 0.35); color: #c9ffb0; font-size: 0.72rem; }
.panel .row { display: flex; gap: 5px; }
.panel button { flex: 1; padding: 8px 4px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(40, 46, 80, 0.9); color: #fff; font-weight: 800; font-size: 0.75rem; cursor: pointer; font-family: inherit; }
.panel button.up { background: linear-gradient(180deg, #4fd36b, #23843a); border-color: #7dff3a; }
.panel button.up:disabled { background: rgba(40, 46, 80, 0.9); border-color: rgba(255, 255, 255, 0.2); color: #889; }
.panel button.sell { background: rgba(120, 30, 40, 0.9); border-color: rgba(255, 90, 100, 0.6); }
.panel .mode { margin-top: 5px; width: 100%; }

.stars { font-size: 2.6rem; letter-spacing: 6px; color: #ffd34d; }
.stars .off { filter: grayscale(1); opacity: 0.25; }
.xp { color: var(--lime); font-weight: 800; font-family: var(--display); margin: 0; }
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 6, 15, 0.7); z-index: 10; }
.overlay[hidden] { display: none; }
.menu-card { width: min(420px, 100%); padding: 24px 20px; border-radius: 22px; text-align: center; background: var(--panel); border: 1px solid rgba(255, 176, 46, 0.4); box-shadow: 0 0 40px rgba(255, 176, 46, 0.15); display: flex; flex-direction: column; gap: 12px; animation: pop 0.25s ease-out; }
.menu-card h2 { margin: 0; font-size: 2rem; }
.menu-card .btn[hidden] { display: none; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }

@media (max-width: 560px) {
  .tw { width: 52px; }
  .tw img { width: 34px; height: 34px; }
  .tw small { display: none; }
  .ability { width: 46px; height: 56px; }
  .ability small { display: none; }
  .wave-btn { min-width: 70px; height: 56px; }
  .res { padding: 4px 8px; font-size: 0.9rem; }
  .hud-wave b { font-size: 0.9rem; }
  .dock { flex-direction: column; align-items: stretch; gap: 6px; }
  .dock-right { justify-content: flex-end; }
  .toast { bottom: 150px; }
}
/* short landscape phones: controls move to a right-hand column so the map gets the full height */
@media (max-height: 480px) and (orientation: landscape) {
  .dock { left: auto; top: 50px; width: 150px; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px; padding: 4px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 6px; background: linear-gradient(90deg, rgba(5, 6, 15, 0), rgba(5, 6, 15, 0.9) 25%); }
  .shop { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; overflow: visible; }
  .tw { width: auto; padding: 2px 1px; } .tw img { width: 26px; height: 26px; } .tw small { display: none; } .tw b { font-size: 0.68rem; }
  .tw.on { transform: none; }
  .dock-right { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .ability { width: auto; height: 40px; } .ability small { display: none; } .ability .ic { font-size: 1.1rem; }
  .wave-btn { grid-column: 1 / -1; height: 44px; min-width: 0; }
  .toast { bottom: 12px; }
}
.hud-wave { overflow: hidden; }
@media (max-width: 420px) { .hud-wave b { font-size: 0.8rem; } .hud { gap: 5px; } .res { padding: 3px 7px; font-size: 0.82rem; } .icon-btn { width: 36px; height: 36px; } }

.wave-btn.pulse { animation: wavepulse 1s ease-in-out infinite alternate; }
@keyframes wavepulse { to { transform: scale(1.07); box-shadow: 0 0 26px rgba(255, 160, 40, 0.95); } }
