/* Tower Defense: HUD on top, the map canvas in the middle, the build dock below (portrait) or beside it (landscape) */
.td { display: flex; flex-direction: column; color: #dfe9ff; --td-hud: 44px; --td-line: #1c2b4a; --td-panel: #0b1328; --td-acc: #55d6ff; --td-warm: #ffd166; --td-bad: #ff6b81; }
.td-stage { position: relative; display: grid; grid-template: "hud" var(--td-hud) "field" minmax(0, 1fr) "dock" auto / minmax(0, 1fr); width: 100%; height: min(84vh, 740px); min-height: 520px;
  background: #04060f; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.td-stage.td-wide { grid-template: "hud dock" var(--td-hud) "field dock" minmax(0, 1fr) / minmax(0, 1fr) clamp(212px, 27%, 292px); }
@media (max-width: 600px) { .td-stage { height: min(88vh, 800px); min-height: 480px; } }
.td-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.td button { font: inherit; color: inherit; cursor: pointer; }
.td button:focus-visible, #td-canvas:focus-visible { outline: 2px solid var(--td-acc); outline-offset: 2px; }
.td kbd { font-family: inherit; font-size: 9.5px; font-weight: 700; line-height: 1; color: #9db7dd; background: rgba(22, 33, 58, .92); border-radius: 3px; padding: 2px 3px; }
@media (hover: none) and (pointer: coarse) { .td-stage kbd { display: none; } }

/* HUD */
.td-hud { grid-area: hud; display: flex; align-items: center; gap: 12px; padding: 0 6px 0 12px; background: linear-gradient(#0b1328, #080e1f); border-bottom: 1px solid var(--td-line); min-width: 0; z-index: 3; }
.td-stat { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 0 1 auto; overflow: hidden; font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-stat svg { width: 18px; height: 18px; flex: none; }
.td-stat b { font-size: 17px; font-weight: 800; color: #fff; display: inline-block; transition: transform .18s cubic-bezier(.3, 1.6, .5, 1), color .18s; }
.td-stat b.td-pop { transform: scale(1.25); }
.td-lives svg { color: var(--td-bad); } .td-lives b.td-pop { color: var(--td-bad); }
.td-coins svg { color: var(--td-warm); } .td-coins b { color: var(--td-warm); }
.td-k { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #8aa3c4; }
.td-score b { font-size: 15px; color: #cfe3ff; }
.td-sp { flex: 1 1 auto; }
.td-tool { flex: none; width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .06); color: #cfe3ff; font-weight: 800; font-size: 14px; }
.td-tool:hover { background: rgba(255, 255, 255, .12); }
.td-tool svg { width: 20px; height: 20px; }
.td-speed { width: 44px; color: var(--td-acc); }
.td-speed.is-fast { background: rgba(85, 214, 255, .18); }
#td-pause .pl { display: none; } #td-pause.is-paused .pl { display: block; } #td-pause.is-paused .pz { display: none; }
#td-pause.is-paused { background: rgba(255, 209, 102, .2); color: var(--td-warm); }
#td-sound .off { display: none; } #td-sound[aria-pressed="true"] .off { display: block; } #td-sound[aria-pressed="true"] .on { display: none; }
@media (max-width: 430px) { .td-hud { gap: 6px; padding: 0 4px 0 8px; } .td-score, .td-wave .td-k { display: none; } .td-stat b { font-size: 16px; } .td-tool { width: 34px; } .td-speed { width: 40px; } .td-tool + .td-tool { margin-left: -2px; } }
@media (hover: none) and (pointer: coarse) { .td-tool { width: 40px; height: 40px; } .td-speed { width: 46px; } }
@media (hover: none) and (pointer: coarse) and (max-width: 430px) { .td-tool, .td-speed { width: 40px; } }
@media (max-width: 380px) { .td-hud { gap: 4px; padding: 0 3px 0 6px; } .td-stat { gap: 4px; } .td-stat svg { width: 16px; height: 16px; } .td-stat b { font-size: 15px; } }

/* field */
.td-field { grid-area: field; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#td-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline-offset: -3px; touch-action: none; }
.td-banner { position: absolute; left: 50%; top: 14%; transform: translate(-50%, 0); padding: 8px 22px; border-radius: 999px; background: rgba(6, 10, 24, .82); border: 1px solid var(--td-line); font-weight: 800; font-size: 18px; letter-spacing: .04em; white-space: nowrap; pointer-events: none; opacity: 0; }
.td-banner.is-on { animation: td-banner 2.2s ease both; }
.td-banner.is-boss { color: var(--td-bad); border-color: rgba(255, 107, 129, .5); }
@keyframes td-banner { 0% { opacity: 0; transform: translate(-50%, -8px) scale(.94); } 12%, 75% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -6px); } }

/* dock */
.td-dock { grid-area: dock; display: flex; flex-direction: column; gap: 6px; padding: 7px 8px 8px; background: #080e1f; border-top: 1px solid var(--td-line); min-width: 0; min-height: 0; z-index: 2; }
.td-wide .td-dock { border-top: 0; border-left: 1px solid var(--td-line); padding: 8px; gap: 8px; overflow-y: auto; }
.td-next { display: flex; align-items: stretch; gap: 6px; min-width: 0; }
.td-wide .td-next { flex-wrap: wrap; }
.td-preview { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 0 2px; }
.td-preview::-webkit-scrollbar { display: none; }
.td-wide .td-preview { flex: 1 1 100%; flex-wrap: wrap; min-height: 40px; align-content: center; }
.td-pv-k { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #8aa3c4; margin-right: 2px; white-space: nowrap; }
.td-chip { flex: none; display: inline-flex; align-items: center; gap: 1px; height: 30px; padding: 0 6px 0 2px; border: 1px solid var(--td-line); border-radius: 999px; background: #0b1328; font-size: 12px; font-weight: 700; color: #cfe3ff; }
.td-chip canvas { width: 24px; height: 24px; }
.td-chip.is-boss { border-color: rgba(255, 107, 129, .6); color: #ffc2cc; }
.td-chip.is-new { border-color: rgba(255, 209, 102, .7); }
.td-call { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 104px; min-height: 44px; padding: 3px 12px; border: 0; border-radius: 12px; background: linear-gradient(#63dcff, #2fb4e6); color: #04121d; font-weight: 800; font-size: 13.5px; line-height: 1.15; }
.td-wide .td-call { flex: 1 1 auto; }
.td-call i { font-style: normal; font-size: 11px; font-weight: 700; opacity: .8; }
.td-call i:empty { display: none; }
.td-call:disabled { background: #16213a; color: #7f97bb; cursor: default; }
.td-call.is-pulse { animation: td-pulse 1.4s ease-in-out infinite; }
@keyframes td-pulse { 50% { box-shadow: 0 0 0 5px rgba(85, 214, 255, .22); } }
.td-powers { display: flex; gap: 6px; flex: none; }
.td-power { position: relative; width: 44px; min-height: 44px; display: grid; place-items: center; padding: 0; border: 1px solid var(--td-line); border-radius: 12px; background: #0b1328; color: #ffb37a; overflow: hidden; }
#td-p-cryo { color: #8fdcff; }
.td-power svg { width: 22px; height: 22px; position: relative; z-index: 1; }
.td-power i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(4, 6, 15, .78); }
.td-power kbd { position: absolute; right: 2px; top: 2px; z-index: 1; }
.td-power.is-cool { color: #5d7396; cursor: default; }
.td-power.is-on { border-color: var(--td-warm); box-shadow: 0 0 0 2px rgba(255, 209, 102, .3); }
.td-info { min-height: 32px; font-size: 12.5px; line-height: 1.3; color: #a9bfdf; display: flex; align-items: center; gap: 6px; padding: 0 2px; }
.td-info b { color: #fff; } .td-info em { font-style: normal; color: var(--td-warm); font-weight: 700; }
.td-wide .td-info { min-height: 50px; align-items: flex-start; }
.td-shop { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; margin: 0 -3px; }
.td-wide .td-shop { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0; }
@media (max-width: 370px) { .td-stage:not(.td-wide) .td-shop { gap: 1px; margin: 0 -6px; } }
.td-buy { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; min-height: 52px; padding: 2px 0 3px; border: 1px solid var(--td-line); border-radius: 11px; background: #0b1328; }
.td-buy canvas { width: 32px; height: 32px; }
.td-buy span { font-size: 11.5px; font-weight: 800; color: var(--td-warm); font-variant-numeric: tabular-nums; line-height: 1; }
.td-buy kbd { position: absolute; left: 2px; top: 2px; }
.td-buy:hover { border-color: #33507f; }
.td-buy.is-on { border-color: var(--td-acc); background: #10203c; box-shadow: 0 0 0 2px rgba(85, 214, 255, .25); }
.td-buy.is-poor canvas { opacity: .42; } .td-buy.is-poor span { color: #b0647a; }

/* selected tower */
.td-tower { display: flex; flex-direction: column; gap: 6px; }
.td-tower[hidden] { display: none; }
.td-th { display: flex; align-items: center; gap: 8px; }
.td-th canvas { width: 34px; height: 34px; flex: none; }
.td-th div { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
.td-th b { display: block; font-size: 14px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-th small { display: block; font-size: 11.5px; color: #8aa3c4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-x { flex: none; width: 40px; height: 40px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .07); font-size: 20px; line-height: 1; }
.td-ups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.td-ups.is-one { grid-template-columns: minmax(0, 1fr); }
.td-up { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-height: 52px; padding: 5px 8px; text-align: left; border: 1px solid #2a4675; border-radius: 11px; background: #0e1a33; line-height: 1.2; }
.td-up b { font-size: 12.5px; color: #fff; padding-right: 40px; }
.td-up small { font-size: 11px; color: #9db7dd; }
.td-up span { position: absolute; right: 7px; top: 5px; font-size: 12px; font-weight: 800; color: var(--td-warm); }
.td-up.is-poor { opacity: .55; } .td-up.is-poor span { color: #d98a9a; }
.td-up.is-max { border-style: dashed; color: #8aa3c4; cursor: default; align-items: center; justify-content: center; }
.td-acts { display: flex; gap: 6px; }
.td-act { flex: 1 1 0; min-height: 40px; padding: 4px 8px; border: 1px solid var(--td-line); border-radius: 11px; background: #0b1328; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.td-act em { font-style: normal; color: var(--td-acc); } .td-sell em { color: var(--td-warm); }

/* panels */
.td-overlay { position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(4, 6, 15, .8); backdrop-filter: blur(3px); }
.td-overlay[hidden] { display: none; }
.td-panel { width: min(100%, 600px); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 20px 20px 18px; border: 1px solid var(--td-line); border-radius: 18px; background: linear-gradient(#0d1730, #080e1f); text-align: center; animation: td-in .22s ease both; user-select: none; }
.td-panel.is-wide { width: min(100%, 760px); }
@keyframes td-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.td-panel h2 { margin: 0 0 4px; font-size: clamp(24px, 5vw, 34px); font-weight: 900; letter-spacing: -.01em; color: #fff; }
.td-panel h2 span { color: var(--td-acc); }
.td-panel h3 { margin: 14px 0 6px; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: #8aa3c4; text-align: left; }
.td-panel p { margin: 0 0 12px; color: #a9bfdf; font-size: 14px; line-height: 1.45; }
.td-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
/* long panels (maps, how to play) scroll; their Back button stays in reach at the bottom */
.td-panel.is-wide > .td-btns:last-child { position: sticky; bottom: 0; z-index: 2; margin: 12px -8px -10px; padding: 16px 8px 12px; background: linear-gradient(rgba(8, 14, 31, 0), #080e1f 34%); }
.td-btn { min-height: 44px; padding: 8px 18px; border: 1px solid #2a4675; border-radius: 12px; background: #0e1a33; font-weight: 800; font-size: 14.5px; }
.td-btn:hover { border-color: #3d63a3; }
.td-btn.is-main { border: 0; background: linear-gradient(#63dcff, #2fb4e6); color: #04121d; font-size: 16px; padding: 10px 28px; min-width: 150px; }
.td-btn small { display: block; font-size: 11px; font-weight: 700; opacity: .75; }
.td-seg { display: inline-flex; padding: 3px; gap: 3px; border: 1px solid var(--td-line); border-radius: 12px; background: #070c1b; }
.td-seg button { min-height: 38px; padding: 4px 14px; border: 0; border-radius: 9px; background: transparent; color: #9db7dd; font-weight: 800; font-size: 13px; }
.td-seg button[aria-pressed="true"] { background: #1a2d52; color: #fff; }
.td-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; margin: 8px 0; }
.td-row > span { font-size: 12px; font-weight: 700; color: #8aa3c4; letter-spacing: .08em; text-transform: uppercase; }
.td-art { display: block; width: min(100%, 420px); height: auto; aspect-ratio: 21 / 8; margin: 6px auto 10px; border-radius: 12px; border: 1px solid var(--td-line); }
.td-stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.td-stars svg { width: 15px; height: 15px; color: #2a3b5e; } .td-stars svg.is-on { color: var(--td-warm); }
.td-stars.is-big svg { width: 44px; height: 44px; } .td-stars.is-big svg.is-on { animation: td-star .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.td-stars.is-big svg:nth-child(2) { animation-delay: .18s; } .td-stars.is-big svg:nth-child(3) { animation-delay: .36s; }
@keyframes td-star { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
.td-nums { display: flex; justify-content: center; gap: 22px; margin: 10px 0 2px; }
.td-nums div { display: flex; flex-direction: column; } .td-nums b { font-size: 22px; color: #fff; font-variant-numeric: tabular-nums; } .td-nums span { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #8aa3c4; }
.td-nums .is-best b { color: var(--td-warm); }
.td-maps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.td-map { position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 6px 6px 7px; border: 1px solid var(--td-line); border-radius: 12px; background: #0b1328; text-align: left; }
.td-map canvas { width: 100%; height: auto; aspect-ratio: 14 / 9; border-radius: 7px; display: block; }
.td-map b { font-size: 12.5px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-map small { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: #8aa3c4; }
.td-map:hover:not(:disabled) { border-color: var(--td-acc); }
.td-map:disabled { cursor: default; } .td-map:disabled canvas { opacity: .3; filter: grayscale(1); } .td-map:disabled b { color: #6f86aa; }
.td-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; text-align: left; }
@media (max-width: 520px) { .td-list { grid-template-columns: minmax(0, 1fr); } .td-panel { padding: 16px 12px 14px; } .td-maps { gap: 6px; } }
.td-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--td-line); border-radius: 11px; background: #0b1328; }
.td-item canvas { width: 36px; height: 36px; flex: none; }
.td-item b { display: block; font-size: 13px; color: #fff; } .td-item small { display: block; font-size: 11.5px; line-height: 1.3; color: #9db7dd; }
.td-steps { margin: 0 0 4px; padding: 0 0 0 20px; text-align: left; color: #c3d5f0; font-size: 13.5px; line-height: 1.5; }
.td-toast { position: absolute; left: 50%; top: calc(var(--td-hud) + 10px); transform: translateX(-50%); z-index: 5; max-width: min(92%, 460px); padding: 8px 14px; border: 1px solid #2a4675; border-radius: 12px; background: rgba(8, 14, 31, .95); font-size: 13px; font-weight: 600; color: #dfe9ff; text-align: center; pointer-events: none; animation: td-in .2s ease both; }
.td-toast[hidden] { display: none; }
.td-help .hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .td-help .hint-kb { display: none; } .td-help .hint-touch { display: inline; } }

/* short landscape screens (phones on their side) */
@media (max-height: 460px) and (orientation: landscape) {
  .td { --td-hud: 40px; }
  .td-wide .td-dock { padding: 6px; gap: 5px; }
  .td-buy { min-height: 46px; } .td-buy canvas { width: 28px; height: 28px; }
  .td-wide .td-info { min-height: 32px; font-size: 11.5px; }
  .td-up { min-height: 46px; } .td-panel { padding: 12px 14px; } .td-art { display: none; }
}

/* full screen */
.stage.is-immersive .stage-body > .td { min-height: 0; }
.stage.is-immersive .td-stage { flex: 1 1 auto; height: auto; max-height: none; min-height: 0; }
.stage.is-immersive .td-help { display: none; }
@media (prefers-reduced-motion: reduce) { .td-panel, .td-toast, .td-banner.is-on, .td-call.is-pulse, .td-stars.is-big svg.is-on { animation: none; } .td-banner.is-on { opacity: 1; } .td-stat b { transition: none; } }

/* the dock keeps one height in the stacked layout, so the map never jumps when a tower is picked */
@media (max-width: 600px) { .td-stage { height: min(92vh, 820px); height: min(92dvh, 820px); } }
.td-stage:not(.td-wide) .td-dock { height: 170px; }
.td-stage:not(.td-wide) .td-info { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.td-stage:not(.td-wide) .td-dock.is-tower > .td-next, .td-stage:not(.td-wide) .td-dock.is-tower > .td-info, .td-stage:not(.td-wide) .td-dock.is-tower > .td-shop { display: none; }
.td-stage:not(.td-wide) .td-tower { flex: 1 1 auto; min-height: 0; }
.td-stage:not(.td-wide) .td-ups { flex: 1 1 auto; min-height: 0; }
.td-stage:not(.td-wide) .td-up { min-height: 0; overflow: hidden; }
.td-wide .td-dock.is-tower > .td-info { display: none; }
.td-wide .td-tower { padding-top: 8px; border-top: 1px solid var(--td-line); }
.td-wide .td-ups { grid-template-columns: minmax(0, 1fr); }
.td-up kbd { position: absolute; right: 7px; bottom: 5px; }
.td-chip { cursor: pointer; position: relative; }
/* the chip stays small to look at, but its touch target is a full 40 px tall */
.td-chip::after { content: ''; position: absolute; left: -3px; right: -3px; top: -6px; bottom: -6px; }
.td-info canvas { width: 30px; height: 30px; flex: none; }
.td-info span { min-width: 0; }
.td-ach { color: #cfe3ff !important; font-weight: 600; }
.td-sub { font-size: 12.5px !important; color: #8aa3c4 !important; margin-bottom: 4px !important; }
.td-map i { position: absolute; left: 10px; top: 10px; font-style: normal; font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: rgba(4, 6, 15, .8); color: #9db7dd; }
.td-keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; text-align: left; font-size: 12.5px; color: #c3d5f0; }
.td-keys kbd { margin-right: 4px; }
@media (max-width: 520px) { .td-keys { grid-template-columns: minmax(0, 1fr); } }
@media (max-height: 560px) and (orientation: landscape) {
  .td-stage { height: 96vh; height: 96dvh; min-height: 300px; }
  .td-wide .td-ups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .td-wide .td-dock.is-tower > .td-shop { display: none; }
}
