/* Twin Tower Defense. Everything is under .ttd, so the game can sit inside a
   page that has its own styles (nt.cool's site template). The colour names
   match the site's; a page without them gets these defaults. */
.ttd {
  --bg: #07060b;
  --surface: #120e1a;
  --surface-2: #1c1528;
  --line: #2f2440;
  --text: #f5f1fb;
  --muted: #b3a9c4;
  --red: #ff0809;
  --cyan: #00e5ff;
  --green: #39ff14;
  --yellow: #ffe600;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* As wide as the page. The canvas takes the window's height less the HUD
     and controls, and the game zooms the board to fit; the city around it
     fills whatever shape is left. */
  width: 100%;
  margin: 0 auto;
  color: var(--text);
  font: 15px/1.4 var(--mono);
}
.ttd *, .ttd *::before, .ttd *::after { box-sizing: border-box; }
.ttd [hidden] { display: none !important; }
.ttd a { color: var(--cyan); }
.ttd button { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 8px 12px; cursor: pointer; touch-action: manipulation; }
.ttd button:hover:not(:disabled) { border-color: var(--muted); }
.ttd button:disabled { opacity: 0.4; cursor: default; }
.ttd button.on { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan) inset; }

/* Controls float over the city in the canvas's corners (ui.js). */
.ttd .topleft, .ttd .flow, .ttd .panel { position: absolute; z-index: 1; }
/* The counts in a row top left, each a small label over a big number, so
   they read at a glance mid-wave. */
.ttd .hud { --glass: rgba(12, 10, 18, 0.8); }
.ttd .stat { display: flex; flex-direction: column; padding: 6px 14px 8px; min-width: 96px;
  background: var(--glass, rgba(12, 10, 18, 0.8)); border: 1px solid var(--line); border-radius: 8px; }
.ttd .label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.ttd .stat b { font-size: 30px; line-height: 1.1; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ttd .stat.money b { color: var(--yellow); }
/* Money wherever it's shown (main.js cash()): dollar sign, yellow; red when
   you can't afford it. The build ring's canvas draws the same (menu.js). */
.ttd .cash { color: var(--yellow); font-weight: 700; font-variant-numeric: tabular-nums; }
.ttd .cash.short { color: #ff5a4e; }
.ttd button:disabled .cash { color: inherit; }
/* Top left: wave, money, score and the towers' health; the field-report
   badge under them. */
.ttd .topleft { left: 12px; top: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  max-width: calc(100% - 24px); }
.ttd .hud { display: flex; gap: 8px; align-items: stretch; }
.ttd .field { padding: 4px 10px; border-radius: 6px; font-size: 14px; font-weight: 600; letter-spacing: 0.03em; }
.ttd .field.handicap { background: rgba(178, 34, 52, 0.92); color: #fff; }
.ttd .field.perk { background: rgba(60, 59, 110, 0.97); color: #fff; box-shadow: 0 0 0 1px #8fa3ff inset; }
/* Score with its multiplier, and each tower's health as a bar. */
.ttd .stat.score { min-width: 150px; }
.ttd .mult { margin-left: 6px; font-size: 14px; font-weight: 700; letter-spacing: 0; color: var(--green); }
.ttd .mult.one { color: var(--muted); }
.ttd .towers { display: grid; align-content: center; gap: 6px; width: 210px; padding: 6px 12px; background: var(--glass); border: 1px solid var(--line); border-radius: 8px; }
.ttd .tower { display: grid; grid-template-columns: 52px 1fr 40px; align-items: center; gap: 8px; }
.ttd .tower b { font-size: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.ttd .tower .bar { height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.ttd .tower .bar i { display: block; height: 100%; width: 100%; background: var(--green); border-radius: 5px; transition: width 0.3s; }
.ttd .tower.low .bar i { background: #ffb020; }
.ttd .tower.low b { color: #ffb020; }
.ttd .tower.down .bar i { background: var(--red); }
.ttd .tower.down b { color: var(--red); font-size: 14px; }
/* Bottom right: the next wave, big, with speed, pause and full screen under it. */
.ttd .flow { right: 12px; bottom: 12px; display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 250px; }
.ttd .flow-row { display: flex; gap: 6px; }
.ttd .flow-row button { flex: 1; }
.ttd .flow button { padding: 8px 12px; background: rgba(28, 21, 40, 0.92); border-radius: 8px; }
.ttd .flow #next { padding: 12px; font-size: 17px; white-space: nowrap; font-weight: 700; border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan) inset; }
.ttd .flow #next:disabled { opacity: 0.6; border-color: var(--line); box-shadow: none; font-weight: 400; }
.ttd #fullscreen { flex: 0 0 auto; font-size: 18px; line-height: 1; }
/* Sound: mute (M) and the volume, a bar like the towers' health. */
.ttd #mute { flex: 0 0 auto; display: grid; place-items: center; padding: 6px 10px; }
.ttd #mute svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.ttd #mute .cone { fill: currentColor; }
.ttd #mute .cross { display: none; }
.ttd #mute.off { color: var(--muted); }
.ttd #mute.off .waves { display: none; }
.ttd #mute.off .cross { display: inline; stroke: var(--red); }
.ttd .volume { flex: 1; display: flex; align-items: center; gap: 10px; padding: 0 12px; min-width: 0;
  background: rgba(28, 21, 40, 0.92); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  --fill: var(--cyan); }
.ttd .volume.off { --fill: var(--muted); }
.ttd .volume input { flex: 1; min-width: 0; height: 22px; margin: 0; background: none; cursor: pointer;
  -webkit-appearance: none; appearance: none; touch-action: none; }
.ttd .volume input::-webkit-slider-runnable-track { height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, var(--fill) var(--v, 100%), rgba(255, 255, 255, 0.12) var(--v, 100%)); }
.ttd .volume input::-moz-range-track { height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); }
.ttd .volume input::-moz-range-progress { height: 10px; border-radius: 5px; background: var(--fill); }
.ttd .volume input::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px;
  margin-top: -3px; border-radius: 50%; background: var(--text); border: 2px solid var(--bg); }
.ttd .volume input::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--text);
  border: 2px solid var(--bg); }
.ttd .volume input:focus-visible { outline: none; }
.ttd .volume:has(input:focus-visible) { border-color: var(--cyan); }

/* OVERWATCH's radio panel: a field report every fifth wave (events.js). It
   interrupts: centred over a dimmed board, while the countdown runs on
   (shown on "Copy that"). */
.ttd .comms-wrap { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.7)); }
.ttd .comms { position: relative; width: min(900px, 100%); max-height: 100%; overflow: hidden;
  padding: 22px 28px 24px; border-radius: 12px; color: #e9eef2; font: 21px/1.45 var(--mono);
  background: rgba(10, 16, 12, 0.95); border: 1px solid #3d5a45; box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  animation: ttd-comms-in 0.35s ease-out; transition: opacity 0.3s, transform 0.3s; }
.ttd .comms.handicap { border-color: #b22234; box-shadow: 0 0 0 1px #b22234, 0 12px 48px rgba(0, 0, 0, 0.7); }
.ttd .comms.perk { border-color: #8fa3ff; box-shadow: 0 0 0 1px #8fa3ff, 0 12px 48px rgba(0, 0, 0, 0.7); }
@keyframes ttd-comms-in { from { opacity: 0; transform: scale(0.94); } }
.ttd .comms::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px);
  animation: ttd-static 0.25s steps(2) infinite; }
@keyframes ttd-static { to { background-position: 0 3px; } }
.ttd .comms.leaving { opacity: 0; transform: scale(0.96); }
.ttd .comms-head { display: flex; align-items: center; gap: 12px; font-size: 15px; letter-spacing: 0.14em; color: #9fc4a8; }
.ttd .comms-head .ch { margin-left: auto; opacity: 0.7; }
.ttd .comms-head .tx { color: #ff3b30; font-weight: 700; animation: ttd-blink 0.9s steps(2) infinite; }
@keyframes ttd-blink { 50% { opacity: 0.2; } }
/* The flag patch: blue canton with a few stars over thirteen stripes. */
.ttd .patch { width: 38px; height: 24px; flex: none; border: 1px solid rgba(255, 255, 255, 0.4); border-radius: 2px;
  background:
    radial-gradient(circle, #fff 0.6px, transparent 0.9px) 0 0 / 3px 3px,
    linear-gradient(#3c3b6e, #3c3b6e) 0 0 / 45% 54% no-repeat,
    repeating-linear-gradient(#b22234 0 1.15px, #fff 1.15px 2.3px);
  background-repeat: repeat, no-repeat, repeat; background-size: 11px 8px, 45% 54%, auto; }
.ttd .comms-kind { margin-top: 16px; font-size: 16px; letter-spacing: 0.16em; }
.ttd .comms.handicap .comms-kind { color: #ff6b6b; }
.ttd .comms.perk .comms-kind { color: #8fb4ff; }
.ttd .comms-title { margin-top: 4px; min-height: 1.2em; font-size: 38px; line-height: 1.2; font-weight: 800; letter-spacing: 0.02em; color: #fff; }
.ttd .comms-line { margin-top: 14px; min-height: 4.35em; color: #cfe3d4; }
.ttd .comms-foot { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ttd .comms-effect { padding: 8px 14px; border-radius: 8px; font-size: 20px; font-weight: 700; }
.ttd .comms-effect.wait, .ttd #comms-ok.wait { visibility: hidden; }
.ttd #comms-ok { position: relative; z-index: 1; padding: 12px 24px; font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 700; border-radius: 8px;
  background: #1f3a29; border-color: #6fbf85; }
.ttd #comms-ok:hover { border-color: #a9f0bb; }
.ttd .comms.handicap .comms-effect { background: rgba(178, 34, 52, 0.9); }
.ttd .comms.perk .comms-effect { background: rgba(60, 59, 110, 1); box-shadow: 0 0 0 1px #8fa3ff inset; }
@media (max-height: 520px), (max-width: 640px) {
  .ttd .comms { width: min(620px, 100%); padding: 10px 14px 12px; font-size: 14px; }
  .ttd .comms-head { font-size: 11px; }
  .ttd .comms-head .ch { display: none; }
  .ttd .comms-kind { margin-top: 6px; font-size: 11px; }
  .ttd .comms-title { font-size: 22px; }
  .ttd .comms-line { margin-top: 6px; min-height: 0; }
  .ttd .comms-foot { margin-top: 8px; }
  .ttd .comms-effect, .ttd #comms-ok { font-size: 14px; padding: 6px 12px; }
}

/* The stage fills the window, less the page's own header (--ttd-above;
   the standalone page sets it). Upright phones get a shorter box, since the
   board is limited by the width. In full screen, the whole screen. */
.ttd .stage { position: relative; border: 1px solid var(--line); background: #000; border-radius: 6px; overflow: hidden;
  height: max(280px, calc(100svh - var(--ttd-above, 0px))); }
@media (orientation: portrait) { .ttd .stage { height: clamp(280px, 90vw, calc(100svh - var(--ttd-above, 0px))); } }
.ttd:fullscreen { background: #000; }
.ttd:fullscreen .stage { height: 100vh; border: 0; border-radius: 0; }
.ttd canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.ttd .overlay { position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  background: rgba(7, 6, 11, 0.82); padding: 16px; }
.ttd .card { max-width: 440px; width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 18px 20px; max-height: 100%; overflow: auto; }
.ttd .card h2 { margin: 0 0 8px; font-size: 18px; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.04em; }
.ttd .card p, .ttd .card li { color: var(--muted); margin: 6px 0; }
.ttd .card strong { color: var(--text); }
.ttd .card .row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ttd .card input { font: inherit; flex: 1; min-width: 0; padding: 8px 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; }
.ttd .card .big { font-size: 28px; color: var(--yellow); margin: 4px 0; }
/* The cards' buttons: centred and big, easy to hit. */
.ttd .card .row { justify-content: center; gap: 10px; margin-top: 16px; }
.ttd .card .row button { min-width: 150px; padding: 13px 26px; font-size: 18px; font-weight: 700; border-radius: 8px; }
.ttd .card .row button.on { background: rgba(0, 229, 255, 0.14); }
.ttd .card .row button.on:hover { background: rgba(0, 229, 255, 0.24); }
.ttd .card form.row button { min-width: 0; padding: 8px 16px; font-size: 15px; }
/* The intro: a briefing, the same family as the leaderboard and game over. */
.ttd .intro-card { max-width: 520px; text-align: center; padding: 22px 26px 24px; border-color: #3d5a45;
  background: linear-gradient(180deg, rgba(57, 255, 20, 0.08), transparent 140px), var(--surface); }
.ttd .intro-card .kicker { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: #9fc4a8; }
.ttd .intro-card h2 { margin: 4px 0 14px; font-size: 24px; }
.ttd .card ul.brief { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; text-align: left; }
.ttd .card ul.brief li { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255, 255, 255, 0.03); line-height: 1.45; }
.ttd .card ul.brief b { color: var(--text); display: block; margin-bottom: 2px; }
.ttd .intro-card .keys { margin-top: 12px; }
.ttd .paused-card { max-width: 380px; text-align: center; }
/* A phone on its side: the briefing in three columns, so Play stays on screen. */
@media (max-height: 520px) {
  .ttd .overlay { padding: 8px; }
  .ttd .card { padding: 12px 14px; }
  .ttd .intro-card { max-width: 780px; padding: 12px 16px 14px; }
  .ttd .intro-card h2, .ttd .over-card h2, .ttd .scores-card h2 { margin: 2px 0 8px; font-size: 18px; }
  .ttd .card ul.brief { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .ttd .card ul.brief li { padding: 6px 8px; font-size: 12px; line-height: 1.35; }
  .ttd .intro-card .keys { display: none; }
  .ttd .card .row { margin-top: 10px; }
  .ttd .card .row button { min-width: 130px; padding: 9px 18px; font-size: 16px; }
  .ttd .final b { font-size: 34px; }
  .ttd .final-stats { margin: 8px 0 2px; }
}
/* The logo, in the canvas's top right corner over the city. */
.ttd .logo { position: absolute; z-index: 1; top: 12px; right: 16px; display: flex; flex-direction: column; align-items: flex-end;
  pointer-events: none; font-weight: 800; font-size: 40px; line-height: 0.95; letter-spacing: 0.04em; text-transform: uppercase;
  color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 18px rgba(0, 0, 0, 0.8); }
.ttd .logo .red { color: var(--red); font-size: 1.32em; letter-spacing: 0.06em; }
@media (max-width: 900px) { .ttd .logo { font-size: 26px; } }
@media (max-height: 520px) { .ttd .logo { top: 6px; right: 8px; font-size: 20px; } }
/* Game over: the score big and centred, wave and kills under it. */
.ttd .over-card { max-width: 480px; text-align: center; padding: 22px 24px; border-color: #4a1d2a;
  background: linear-gradient(180deg, rgba(178, 34, 52, 0.16), transparent 140px), var(--surface); }
.ttd .over-card .kicker { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: #ff6b6b; }
.ttd .over-card h2 { margin: 4px 0 14px; font-size: 20px; }
.ttd .final { display: flex; flex-direction: column; align-items: center; }
.ttd .final b { font-size: 52px; line-height: 1.05; color: var(--yellow); font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px rgba(255, 230, 0, 0.25); }
.ttd .final-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 4px; }
.ttd .final-stats > div { display: flex; flex-direction: column; padding: 8px; border: 1px solid var(--line);
  border-radius: 8px; background: rgba(255, 255, 255, 0.03); }
.ttd .final-stats b { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.ttd .over-card .note, .ttd .over-card .error { text-align: center; }
/* The leaderboard: its own screen; rank, name, wave and score in columns. */
.ttd .scores-card { max-width: 520px; text-align: center; padding: 22px 24px; border-color: #2c3b6e;
  background: linear-gradient(180deg, rgba(60, 59, 110, 0.35), transparent 140px), var(--surface); }
.ttd .scores-card .kicker { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: #8fb4ff; }
.ttd .scores-card h2 { margin: 4px 0 6px; font-size: 22px; }
.ttd .scores-card .note { text-align: center; }
.ttd .over-card .placed { color: var(--cyan); margin: 10px 0 0; }
.ttd .board-head, .ttd .board-list li { display: grid; grid-template-columns: 30px minmax(0, 1fr) 56px 92px;
  gap: 8px; align-items: center; }
.ttd .board-head { margin-top: 14px; padding: 0 10px 6px; border-bottom: 1px solid var(--line);
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.ttd .board-head span:nth-child(n+3), .ttd .board-list .wave, .ttd .board-list .score { text-align: right; }
.ttd .board-head span:nth-child(-n+2), .ttd .board-list .name { text-align: left; }
.ttd .card ol.board-list { list-style: none; padding: 0; margin: 6px 0 10px; display: grid; gap: 3px; }
.ttd .card .board-list li { margin: 0; padding: 7px 10px; border-radius: 6px; color: var(--text);
  background: rgba(255, 255, 255, 0.035); font-variant-numeric: tabular-nums; }
.ttd .board-list .rank { color: var(--muted); font-weight: 700; text-align: left; }
.ttd .board-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ttd .board-list .wave { color: var(--muted); }
.ttd .board-list .score { font-weight: 700; }
.ttd .board-list li.r1 .rank { color: #ffd34d; }
.ttd .board-list li.r2 .rank { color: #d7dde6; }
.ttd .board-list li.r3 .rank { color: #e0975a; }
.ttd .board-list li.r1 { background: linear-gradient(90deg, rgba(255, 211, 77, 0.14), rgba(255, 255, 255, 0.035)); }
.ttd .card .board-list li.me { background: rgba(0, 229, 255, 0.12); box-shadow: 0 0 0 1px var(--cyan) inset; }
.ttd .card .board-list li.me .name::after { content: " (you)"; color: var(--cyan); }
.ttd .card .board-list li.apart { margin-top: 10px; }
.ttd .card .board-list li.empty { display: block; text-align: center; color: var(--muted); background: none; }
.ttd .card .error { color: var(--red); min-height: 1.4em; margin: 6px 0 0; }
.ttd .card ol { padding-left: 2em; margin: 8px 0; }
.ttd .card .note { font-size: 12px; }

.ttd .toast { position: absolute; z-index: 2; left: 50%; top: 112px; transform: translateX(-50%); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 4px; padding: 6px 12px; font-size: 13px; pointer-events: none;
  transition: opacity 0.3s; opacity: 0; white-space: nowrap; }
.ttd .toast.show { opacity: 1; }

.ttd .build { display: flex; flex-wrap: wrap; gap: 6px; }
.ttd .build button { display: grid; text-align: left; gap: 0; padding: 6px 10px; min-width: 96px; }
.ttd .build button small { color: var(--muted); font-size: 12px; }
.ttd .build button .key { color: var(--muted); font-size: 11px; }
.ttd .build button.poor small { color: var(--red); }
/* What's selected or hovered, bottom left. */
.ttd .panel { left: 12px; bottom: 12px; max-width: min(420px, calc(50% - 24px)); padding: 8px 12px;
  background: rgba(12, 10, 18, 0.8); border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); font-size: 14px; pointer-events: none; }
.ttd .panel .stats { color: var(--text); }


@media (max-width: 640px) {
  .ttd .panel { display: none; }
  /* A phone upright: its own volume keys do; just mute, at the end of the row. */
  .ttd .volume { display: none; }
  .ttd .flow-row.sound { justify-content: flex-end; }
  .ttd .build button { min-width: 0; flex: 1; }
  .ttd .build button .key { display: none; }
}

/* Short screens (a phone on its side): smaller controls, so the board keeps
   the room. */
@media (max-height: 520px) {
  .ttd .topleft { top: 6px; left: 6px; gap: 4px; }
  .ttd .hud { gap: 4px; }
  .ttd .stat { padding: 3px 8px 4px; min-width: 64px; border-radius: 6px; }
  .ttd .label { font-size: 9px; }
  .ttd .stat b, .ttd .stat.score b { font-size: 20px; }
  .ttd .field { font-size: 11px; padding: 2px 8px; }
  .ttd .stat.score { min-width: 90px; }
  .ttd .towers { width: 140px; padding: 3px 8px; gap: 3px; border-radius: 6px; }
  .ttd .tower { grid-template-columns: 40px 1fr 26px; gap: 5px; }
  .ttd .tower b { font-size: 13px; }
  .ttd .tower .bar { height: 7px; }
  .ttd .flow { right: 6px; bottom: 6px; gap: 4px; width: 172px; }
  .ttd .toast { top: 72px; font-size: 12px; }
  .ttd .flow button { padding: 4px 6px; font-size: 12px; border-radius: 6px; }
  .ttd .flow #next { padding: 7px 6px; font-size: 13px; white-space: nowrap; }
  .ttd #mute { padding: 3px 6px; }
  .ttd #mute svg { width: 16px; height: 16px; }
  .ttd .volume { padding: 0 8px; gap: 6px; border-radius: 6px; }
  .ttd .volume .label { display: none; }
  .ttd .volume input { height: 18px; }
  .ttd .volume input::-webkit-slider-runnable-track { height: 7px; }
  .ttd .volume input::-webkit-slider-thumb { width: 13px; height: 13px; margin-top: -3px; }
  .ttd .panel { display: none; }
}
