:root {
  --bg: #14151f;
  --panel: #1f2130;
  --panel-2: #2a2d40;
  --border: #3a3e58;
  --text: #e8e9f2;
  --muted: #8b8fa8;
  --accent: #ffd84a;
  --green: #3fbf5f;
  --blue: #3fa4ff;
  --red: #e0533d;
  --font: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

button {
  font-family: var(--font);
  font-weight: bold;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
}
/* Hover only on devices that really hover; touch browsers keep :hover stuck after a tap. */
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled) { border-color: var(--accent); }
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:active:not(:disabled) { border-bottom-width: 2px; margin-top: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.danger { border-color: #6e3a3a; }
button.small { padding: 5px 8px; font-size: 11px; }
html, body, button, #game, summary { touch-action: manipulation; } /* no double-tap zoom on phones */

.hidden { display: none !important; }
.short { display: none; } /* compact button labels, swapped in on phones */
.muted { color: var(--muted); font-size: 12px; }

/* ---------- HUD ---------- */

.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 4px solid var(--border);
}
.hud h1 { margin: 0; font-size: 18px; color: var(--accent); letter-spacing: 2px; }
.hud-stats { display: flex; gap: 16px; }
.stat { color: var(--muted); font-size: 12px; }
.stat span { color: var(--text); font-size: 18px; font-weight: bold; margin-left: 4px; }
.stat.coins span { color: var(--accent); }
.stat.base span { color: #7fb2ff; }

.phase {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 14px;
  border: 3px solid var(--border);
  background: #000;
  min-width: 220px;
}
.phase #phase-label { font-weight: bold; font-size: 16px; }
.phase #phase-timer { font-size: 26px; font-weight: bold; margin-left: auto; }
.phase.build { border-color: var(--blue); }
.phase.build #phase-label { color: var(--blue); }
.phase.combat { border-color: var(--red); }
.phase.combat #phase-label { color: var(--red); }
.phase.urgent #phase-timer { color: var(--accent); animation: blink 0.5s steps(1) infinite; }

.hud-buttons { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 1360px) {
  .hud { gap: 10px; }
  .hud h1 { font-size: 14px; letter-spacing: 1px; }
  .hud-stats { gap: 10px; }
  .phase { min-width: 190px; }
  .speed > span { display: none; }
  .hud-buttons { gap: 6px; }
  .hud-buttons button { padding: 8px 9px; }
}

/* ---------- Layout (desktop) ----------
   Map on the left, sized to fit the window height; towers + selected tower in a
   bar under the map; heart rate, tank and keys in a column on the right. */

:root { --hud-h: 72px; --under-map-h: 124px; }

.layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
}
.col-main {
  flex: 0 1 auto;
  min-width: 0;
  /* map is 16:10; leave room for header, under-map bar and padding */
  width: max(520px, min(100%, calc((100vh - var(--hud-h) - var(--under-map-h) - 56px) * 1.6)));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.col-side {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.under-map {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 12px;
  min-height: var(--under-map-h);
}
.canvas-wrap { position: relative; width: 100%; }
#game {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 4px solid var(--border);
  background: #000;
  cursor: crosshair;
}
.map-viewport { overflow: hidden; position: relative; touch-action: pan-x pan-y; }
.map-viewport.zoomed { touch-action: none; }
#game { transform-origin: 0 0; }
.zoom-controls { position: absolute; left: 4px; bottom: 4px; display: flex; gap: 4px; z-index: 5; }
.zoom-controls button { width: 34px; height: 28px; padding: 0; font-size: 11px; background: rgba(20, 21, 31, 0.85); }

/* Phase-driven controls. */
body:not(.phase-combat) #tank-modes, body:not(.phase-combat) .battle-speed { display: none; }
body.phase-combat .towers-card { display: none; }
body.phase-combat .selected-card { display: none !important; }
.battle-speed { display: none; align-items: center; gap: 6px; }
body.phase-combat .battle-speed { display: flex; }
.battle-speed button { flex: 1; min-height: 40px; font-size: 14px; }
.battle-speed span { min-width: 40px; text-align: center; font-size: 18px; font-weight: bold; color: var(--accent); }
body.phase-combat .tank-modes button { min-height: 48px; font-size: 16px; }

/* Single-line toast pinned to the top of the map. */
.message {
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: auto;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 10px;
  background: rgba(10, 10, 20, 0.85);
  border: 2px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}
.message:empty { display: none; }
.message.msg-warn, .message.msg-breach { color: var(--red); }
.message.msg-coins { color: var(--accent); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 20, 0.6);
  z-index: 6;
}
.overlay .panel {
  background: var(--panel);
  border: 4px solid var(--accent);
  padding: 20px 32px;
  text-align: center;
}
.overlay h2 { margin: 0 0 8px; color: var(--accent); font-size: 28px; letter-spacing: 3px; }
.overlay.lost .panel { border-color: var(--red); }
.overlay.lost h2 { color: var(--red); }

/* ---------- Cards ---------- */

.card {
  background: var(--panel);
  border: 3px solid var(--border);
  padding: 10px 12px;
}
.card h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); letter-spacing: 2px; }

.hr-readout { display: flex; align-items: baseline; gap: 6px; }
.hr-readout #hr-value { font-size: 40px; font-weight: bold; }
.hr-readout small { color: var(--muted); }
.zone-preview { margin: 12px 0 6px; }
.setup-note { color: var(--muted); font-size: 12px; }
.heart { color: var(--red); font-size: 26px; display: inline-block; }
.heart.beat { animation: beat 0.15s steps(2) 1; }

#hr-slider { width: 100%; margin: 8px 0 4px; accent-color: var(--red); cursor: pointer; }

.zone-wrap { position: relative; height: 30px; margin: 2px 0 6px; }
.zone-bar { position: relative; height: 10px; background: #000; }
.zone-bar div { position: absolute; top: 0; height: 100%; transition: left 0.35s, width 0.35s; }
.zone-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 18px;
  margin-left: -2px;
  background: #fff;
  box-shadow: 0 0 0 2px #000;
  transition: left 0.15s;
}
.zone-labels span {
  position: absolute;
  top: 13px;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  transition: left 0.35s;
}
.zone-labels.shifted span { color: var(--accent); font-weight: bold; }

.speed { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.speed-buttons { display: flex; padding-left: 2px; }
/* Segmented control: full borders, overlapped by their width; selected one drawn on top. */
.speed-buttons button { position: relative; padding: 6px 8px; font-size: 12px; margin-left: -2px; }
@media (hover: hover) and (pointer: fine) {
  .speed-buttons button:hover:not(:disabled) { z-index: 1; }
}
.speed-buttons button.selected { z-index: 2; border-color: var(--accent); background: #3a3520; color: var(--accent); }

.power-badge {
  text-align: center;
  font-weight: bold;
  font-size: 20px;
  padding: 6px;
  letter-spacing: 3px;
  border: 3px solid currentColor;
  background: #000;
}
.power-badge.overdrive { animation: blink 0.25s steps(1) infinite; }
.power-desc { margin: 6px 0 4px; font-size: 12px; color: var(--muted); min-height: 30px; }

.towers-card { container-type: inline-size; }
.tower-buttons { display: flex; gap: 8px; }
.tower-buttons .tower-btn { flex: 1 1 0; min-width: 0; }
.tower-btn {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 6px 8px;
}
.tower-btn.selected { border-color: var(--accent); background: #3a3520; }
.tower-btn.offline .swatch { opacity: 0.35; }
.tower-btn .swatch { width: 24px; height: 24px; border: 3px solid #1d1f2a; }
.tower-btn .name { font-size: 13px; }
.tower-btn .blurb { display: block; font-size: 10px; color: var(--muted); font-weight: normal; }
.tower-btn .cost { color: var(--accent); }
/* Narrow tower bar: drop the description, then the key hint (full text stays in the tooltip). */
@container (max-width: 560px) { .tower-btn .blurb { display: none; } }
@container (max-width: 440px) {
  .tower-btn .key { display: none; }
  .tower-btn { grid-template-columns: 16px 1fr auto; gap: 6px; padding: 6px; }
  .tower-btn .swatch { width: 16px; height: 16px; border-width: 2px; }
  .tower-btn .name, .tower-btn .cost { font-size: 12px; }
}

.sel-close { display: none; float: right; padding: 0 8px; font-size: 16px; line-height: 1.2; border-bottom-width: 2px; }
.sel-name { font-weight: bold; font-size: 14px; margin-bottom: 2px; }
.sel-stats { font-size: 11px; color: var(--muted); line-height: 1.4; margin-bottom: 6px; }
.sel-buttons { display: flex; gap: 6px; }
.sel-buttons button { flex: 1; padding: 5px 6px; font-size: 11px; }

.hr-boost { margin-left: auto; font-size: 12px; color: var(--accent); text-align: right; line-height: 1.3; }

.tank-level { color: var(--accent); margin-left: 4px; }
.tank-bar {
  position: relative;
  height: 20px;
  background: #0d0e16;
  border: 3px solid #20232f;
}
.tank-fill { height: 100%; width: 0; background: #c9a83a; }
.tank-fill.releasing { background: var(--accent); animation: blink 0.3s steps(1) infinite; }
.tank-amount {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 11px;
  line-height: 14px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.tank-status { font-size: 11px; color: var(--muted); margin: 6px 0; min-height: 14px; }
.tank-status.releasing { color: var(--accent); }
.tank-status.empty { color: var(--red); }
.tank-status.charging, .tank-status.full { color: #ff5a3c; }
.tank-modes { display: flex; gap: 4px; margin-bottom: 6px; }
.tank-modes button { flex: 1; padding: 5px 2px; font-size: 11px; line-height: 1.2; }
.tank-modes button small { display: block; font-weight: normal; color: var(--muted); font-size: 10px; }
.tank-modes button.selected { border-color: var(--accent); background: var(--accent); color: #14151f; }
.tank-modes button.selected small { color: #14151f; }
.tank-upgrade { width: 100%; }

.zones-wrap { margin-bottom: 10px; font-size: 11px; }
.zones-wrap summary { cursor: pointer; color: var(--muted); }
.zones-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding: 8px; background: #000; border: 2px solid var(--border); }
.zones-form label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.zone-name { min-width: 76px; font-weight: bold; }
.zones-form input {
  width: 56px;
  padding: 3px 4px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid var(--border);
}
.zones-form input:focus { outline: none; border-color: var(--accent); }
.zones-maxhr { display: flex; align-items: center; gap: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
.zones-maxhr label .zone-name { min-width: 0; }
.zones-error { color: var(--red); min-height: 13px; }
.zones-buttons { display: flex; gap: 6px; }
.zones-buttons button { flex: 1; }

.help p { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.6; }
.help b { color: var(--text); }

/* ---------- Info sheet ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 8, 16, 0.75);
}
.modal-panel {
  width: min(680px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 4px solid var(--accent);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 3px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; letter-spacing: 3px; color: var(--accent); }
.modal-head button { padding: 2px 10px; font-size: 18px; line-height: 1.2; }
.confirm-panel { width: min(380px, 100%); }
.confirm-body { padding: 14px; font-size: 13px; line-height: 1.5; }
.confirm-body p { margin: 0 0 14px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions button { flex: 1; padding: 12px; }
.mode-body button { display: block; width: 100%; min-height: 56px; margin-bottom: 10px; font-size: 18px; letter-spacing: 2px; }
.mode-body p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.mode-body .mode-ble-status { margin: 0 0 14px; min-height: 1.5em; overflow-wrap: anywhere; }
.mode-body .mode-ble-status:empty { display: none; }
.mode-body .mode-ble { font-size: 16px; }
.mode-body #mode-continue { border-color: var(--accent); background: #3a3520; color: var(--accent); margin-bottom: 4px; }
.mode-body .mode-continue-info { margin: 0 0 10px; text-align: center; overflow-wrap: anywhere; }
.resume-count { margin: 0 0 6px; color: var(--text); font-size: 48px; font-weight: bold; }
#resume-overlay { cursor: pointer; }
.mode-body .mode-hint { margin: 0 0 8px; }
.mode-body .mode-hint.hidden { display: none; }
.mode-ble-state { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12px; overflow-wrap: anywhere; }
.ble-dot { flex: none; width: 12px; height: 12px; background: var(--muted); }
.ble-dot.off { background: var(--muted); }
.ble-dot.connecting { background: var(--accent); }
.ble-dot.on { background: var(--green); }
.ble-dot.error { background: var(--red); }
.mode-divider { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; color: var(--muted); font-size: 11px; letter-spacing: 2px; }
.mode-divider::before, .mode-divider::after { content: ''; flex: 1; min-width: 0; border-top: 2px solid var(--border); }
.mode-divider span { text-align: center; }
.mode-body { overflow-y: auto; }
.auth-section { margin-top: 14px; padding-top: 12px; border-top: 2px solid var(--border); }
.mode-body .auth-label { display: block; margin: 0 0 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.auth-section input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 4px 0 10px;
  padding: 12px;
  min-height: 44px;
  font-family: var(--font);
  font-size: 16px; /* 16px+ stops iOS Safari zooming on focus */
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid var(--border);
  color-scheme: dark;
}
.auth-section input::placeholder { color: var(--muted); opacity: 1; }
.auth-section input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 216, 74, 0.25);
}
.mode-body .auth-section button { min-height: 44px; font-size: 14px; margin-bottom: 6px; }
.mode-body .auth-status { min-height: 1.5em; margin: 0; overflow-wrap: anywhere; }
.setup-body { overflow-y: auto; }
.setup-field { display: block; margin-bottom: 12px; }
.setup-field input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 12px;
  min-height: 44px;
  font-family: var(--font);
  font-size: 16px; /* 16px+ stops iOS Safari zooming on focus */
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid var(--border);
  color-scheme: dark;
}
.setup-field input::placeholder { color: var(--muted); opacity: 1; }
.setup-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 216, 74, 0.25);
}

/* ---------- Session summary ---------- */

.summary-panel { width: min(420px, 100%); }
.summary-body { overflow-y: auto; padding: 14px; font-size: 12px; }
.summary-brand { color: var(--muted); font-size: 11px; letter-spacing: 3px; }
.summary-date { color: var(--muted); font-size: 11px; margin-bottom: 12px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.summary-stat { background: var(--panel-2); border: 2px solid var(--border); padding: 8px; min-width: 0; }
.summary-stat b { display: block; font-size: 22px; color: var(--text); overflow-wrap: anywhere; }
.summary-stat span, .summary-note { color: var(--muted); font-size: 10px; letter-spacing: 1px; }
.summary-section { margin: 0 0 6px; font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.summary-zone { display: grid; grid-template-columns: 82px 1fr 64px; gap: 6px; align-items: center; margin-bottom: 5px; }
.summary-zone .bar { height: 10px; background: var(--panel-2); border: 1px solid var(--border); }
.summary-zone .bar i { display: block; height: 100%; }
.summary-zone em { font-style: normal; text-align: right; color: var(--muted); }
.summary-speeds { color: var(--text); margin: 0 0 12px; overflow-wrap: anywhere; }
.summary-actions { padding: 0 14px 14px; }
.summary-actions button { width: 100%; min-height: 44px; }
.setup-field small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.setup-section { margin: 4px 0 6px; font-size: 12px; color: var(--muted); }
.hr-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.hr-tabs button { flex: 1; min-width: 0; min-height: 44px; padding: 6px 4px; font-size: 14px; }
.hr-tabs button.selected { border-color: var(--accent); background: #3a3520; color: var(--accent); }
.setup-zones { display: flex; gap: 8px; }
.setup-zones .setup-field { flex: 1; min-width: 0; }
.setup-body .zones-error { min-height: 16px; margin-bottom: 8px; }
.info-content { overflow-y: auto; padding: 12px 14px 14px; font-size: 12px; line-height: 1.5; }
.info-content h3 { margin: 14px 0 6px; font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.info-content h3:first-child { margin-top: 0; }
.info-content p { margin: 0 0 6px; }
.info-content ul { margin: 0; padding-left: 18px; }
.info-content b { color: var(--text); }
.info-content .dim { color: var(--muted); }
.info-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.info-table th { text-align: left; font-weight: normal; color: var(--muted); padding: 2px 6px 4px 0; }
.info-table td { padding: 5px 6px 5px 0; border-top: 1px solid var(--border); vertical-align: top; }
.info-table td.num { white-space: nowrap; }
.info-table .desc { color: var(--muted); }
.info-table td .desc { margin-top: 2px; font-size: 10px; }
.info-sprite {
  display: inline-block;
  position: relative;
  vertical-align: middle;
  margin-right: 6px;
  border: 2px solid #1b1b24;
}
.info-sprite::after {
  content: '';
  position: absolute;
  top: 20%;
  right: 15%;
  width: 25%;
  height: 25%;
  background: #fff;
  box-shadow: -140% 0 0 #fff;
}
.info-swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: middle; border: 2px solid #1d1f2a; }

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes beat { 50% { transform: scale(1.3); } }

/* Short desktop windows: drop the least important side-panel content. */
@media (min-width: 901px) and (max-height: 760px) {
  .help, .power-desc { display: none; }
}

/* ---------- Phone / narrow screens ----------
   One column in workout order: map, compact heart rate, tank, towers. */

@media (max-width: 900px) {
  :root { --gap: 8px; }
  body { font-size: 13px; }

  .hud {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "stats phase" "speed buttons";
    gap: 6px 8px;
    padding: 6px 8px;
    border-bottom-width: 3px;
  }
  .hud h1 { display: none; }
  .hud-stats { grid-area: stats; gap: 10px; align-self: center; }
  .stat { font-size: 10px; }
  .stat span { font-size: 15px; margin-left: 2px; }
  .phase { grid-area: phase; min-width: 0; padding: 3px 8px; gap: 8px; border-width: 2px; }
  .phase #phase-label { font-size: 11px; }
  .phase #phase-timer { font-size: 18px; }
  .speed { grid-area: speed; }
  .speed > span { display: none; }
  .speed-buttons button { padding: 5px 5px; font-size: 11px; }
  .hud-buttons { grid-area: buttons; margin-left: 0; gap: 4px; justify-self: end; }
  .hud-buttons button { padding: 5px 6px; font-size: 11px; }
  .long { display: none; }
  .short { display: inline; }
  .modal { padding: 8px; align-items: stretch; }
  .info-content { padding: 10px; }

  .layout { flex-direction: column; align-items: stretch; gap: var(--gap); padding: var(--gap); max-width: 640px; margin: 0 auto; }
  .col-main, .col-side, .under-map { display: contents; }
  .board { order: 1; }
  .towers-card { order: 2; }
  .hr-card { order: 3; }
  .tank-card { order: 4; }
  .battle-speed { order: 4; }
  .selected-card { order: 5; }
  .help { display: none; }

  #game { border-width: 3px; }
  .overlay h2 { font-size: 20px; }
  .overlay .panel { padding: 12px 18px; }
  .message { top: 6px; font-size: 11px; }

  .card { padding: 8px; border-width: 2px; }
  .card h3 { margin-bottom: 6px; font-size: 10px; }

  /* Heart rate: bpm on the left, connect / zones / log on the right. The zone bar
     already shows which zone you're in, so the power badge is hidden. */
  .hr-card { display: grid; grid-template-columns: 1fr auto auto; column-gap: 10px; align-items: center; }
  .hr-card > * { grid-column: 1 / -1; }
  .hr-card h3, .hr-card .power-badge, .power-desc { display: none; }
  .hr-card .hr-readout { grid-column: 1; grid-row: 1 / 3; flex-wrap: wrap; column-gap: 4px; row-gap: 0; }
  .hr-readout #hr-value { font-size: 30px; }
  .heart { font-size: 20px; }
  .hr-boost { flex-basis: 100%; margin-left: 0; text-align: left; font-size: 10px; }
  .hr-boost br { display: none; }
  .hr-card #ble-btn {
    grid-column: 2; grid-row: 1 / 3;
    max-width: 130px; padding: 5px 8px; font-size: 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .hr-card .zones-wrap { grid-column: 3; grid-row: 1; margin: 0; }
  .hr-card summary { white-space: nowrap; }
  /* An opened panel drops below and takes the full width. */
  .hr-card details[open] { grid-column: 1 / -1; grid-row: auto; margin-top: 6px; }
  #hr-slider { margin: 6px 0 2px; }
  body.hr-live #hr-slider { display: none; }
  .zone-wrap { margin-top: 8px; margin-bottom: 0; height: 26px; }

  /* Tank: title + upgrade on one row, bar, one-line status, single-line modes. */
  .tank-card { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: center; }
  .tank-card > * { grid-column: 1 / -1; }
  .tank-card h3 { grid-column: 1; grid-row: 1; margin: 0; }
  .tank-card .tank-upgrade { grid-column: 2; grid-row: 1; width: auto; padding: 3px 6px; font-size: 10px; }
  .tank-card .tank-bar { margin-top: 6px; height: 16px; border-width: 2px; }
  .tank-amount { line-height: 12px; font-size: 10px; }
  .tank-card .tank-status { display: none; }
  .tank-modes { margin: 6px 0 0; }
  .tank-modes button { padding: 5px 2px; }
  body.phase-combat .tank-modes button { min-height: 64px; font-size: 18px; border-width: 3px; }
  .battle-speed button { min-height: 56px; font-size: 14px; padding: 4px; }
  .tank-modes button small { display: none; }

  /* Towers: three compact buttons in a row. */
  .tower-btn { grid-template-columns: 18px 1fr; grid-template-rows: auto auto; gap: 2px 6px; padding: 6px; }
  .tower-btn .swatch { width: 16px; height: 16px; border-width: 2px; grid-row: 1 / 3; }
  .tower-btn { min-height: 56px; }
  .tower-btn .name { font-size: 14px; }
  .tower-btn .blurb, .tower-btn .key, .towers-card h3 { display: none; }
  .tower-btn .cost { font-size: 14px; }

  /* Selected tower: a bottom sheet that only shows when a tower is picked. */
  .selected-card:not(.has-selection) { display: none; }
  .selected-card.has-selection {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 20;
    border-color: var(--accent);
    box-shadow: 0 -4px 0 rgba(0, 0, 0, 0.5);
  }
  .sel-close { display: inline-block; }
}
