:root {
  color-scheme: dark;
  --page: #070b14;
  --page-2: #111827;
  --panel: rgba(15, 23, 42, 0.9);
  --panel-solid: #111827;
  --line: rgba(148, 163, 184, 0.26);
  --ink: #f8fafc;
  --muted: #a9b4c6;
  --red: #ff4d46;
  --blue: #3ba4ff;
  --gold: #facc15;
  --green: #5ee65d;
  --violet: #a855f7;
  --cyan: #38bdf8;
  --radius: 8px;
  --hud-height: clamp(54px, 7vh, 72px);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  overscroll-behavior: none;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 16% 12%, rgba(168, 85, 247, 0.24), transparent 30%),
    radial-gradient(circle at 82% 86%, rgba(56, 189, 248, 0.18), transparent 34%),
    linear-gradient(135deg, #070b14 0%, #101729 52%, #131126 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

.tta-shell {
  width: min(100vw, 1680px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  padding: 0;
  overflow: hidden;
}

.tta-hud {
  position: absolute;
  top: clamp(8px, 1vw, 14px);
  left: clamp(8px, 1vw, 14px);
  right: clamp(8px, 1vw, 14px);
  z-index: 6;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(156px, 220px) minmax(220px, 1fr) minmax(156px, 220px) auto;
  align-items: stretch;
  gap: clamp(7px, 1vw, 12px);
  pointer-events: none;
}

.hud-card,
.hud-actions,
.stage-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 46%),
    rgba(12, 18, 34, 0.72);
  backdrop-filter: blur(8px);
  box-shadow:
    0 18px 34px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.hud-card {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: clamp(8px, 1vw, 14px);
  overflow: hidden;
}

.hud-card-player {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr auto;
  column-gap: 12px;
}

.hud-card-player strong {
  grid-row: 1 / 4;
  align-self: center;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 0.9;
}

.hud-card-p1 {
  grid-column: 1;
  border-color: rgba(255, 77, 70, 0.42);
}

.hud-card-p2 {
  grid-column: 3;
  border-color: rgba(59, 164, 255, 0.42);
}

.hud-card-p1 strong,
.hud-card-p1 .hud-kicker {
  color: var(--red);
}

.hud-card-p2 strong,
.hud-card-p2 .hud-kicker {
  color: var(--blue);
}

.hud-card-center {
  grid-column: 2;
  place-items: center;
  gap: 2px;
  text-align: center;
}

.hud-card-center strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(17px, 2.25vw, 28px);
  font-weight: 900;
  line-height: 0.95;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-kicker,
.hud-card small {
  min-width: 0;
  overflow: hidden;
  font-size: clamp(10px, 1.2vw, 12px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.15;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud-card small {
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}

.health-pips {
  display: flex;
  gap: 5px;
  min-height: 13px;
}

.health-pips span {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.1);
}

.hud-card-p1 .health-pips span.is-full {
  border-color: var(--red);
  background: var(--red);
  box-shadow: 0 0 10px rgba(255, 77, 70, 0.42);
}

.hud-card-p2 .health-pips span.is-full {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 0 10px rgba(59, 164, 255, 0.42);
}

.hud-actions {
  grid-column: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  pointer-events: auto;
}

.hud-card {
  pointer-events: none;
}

.icon-button,
.play-button,
.secondary-button,
.mode-button,
.touch-button {
  border: 0;
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.icon-button {
  width: clamp(40px, 4.6vw, 56px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.28), transparent 52%),
    linear-gradient(180deg, #1e293b, #0f172a);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 -8px 16px rgba(0, 0, 0, 0.24);
}

body[data-game-state="playing"] .hud-card-center {
  display: none;
}

body[data-game-state="playing"] .tta-hud {
  top: 10px;
  left: 10px;
  right: 10px;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: start;
}

body[data-game-state="playing"] .hud-card-player,
body[data-game-state="playing"] .hud-actions {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 46%),
    rgba(5, 8, 18, 0.42);
}

body[data-game-state="playing"] .hud-card-player {
  width: 96px;
  min-height: 40px;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr;
  align-items: center;
  column-gap: 7px;
  padding: 6px 8px;
  opacity: 0.82;
}

body[data-game-state="playing"] .hud-card-player strong {
  grid-row: auto;
  font-size: 25px;
}

body[data-game-state="playing"] .hud-card-player .hud-kicker,
body[data-game-state="playing"] .hud-card-player small {
  display: none;
}

body[data-game-state="playing"] .health-pips {
  align-self: center;
  gap: 4px;
}

body[data-game-state="playing"] .health-pips span {
  width: 9px;
  height: 9px;
}

body[data-game-state="playing"] .hud-actions {
  padding: 5px;
  gap: 5px;
  opacity: 0.72;
}

body[data-game-state="playing"] .hud-actions .icon-button {
  width: 38px;
}

.icon-button svg {
  width: 62%;
  height: 62%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.icon-button[aria-pressed="true"] {
  color: var(--gold);
}

.stage-shell {
  position: relative;
  min-height: 0;
  aspect-ratio: 16 / 9;
  width: min(100%, calc(100vh * 16 / 9));
  width: min(100%, calc(100dvh * 16 / 9));
  justify-self: center;
  align-self: center;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.68), rgba(6, 11, 22, 0.96) 74%),
    #0b1020;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.screen-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vw, 30px);
  background:
    radial-gradient(circle at 50% 48%, rgba(168, 85, 247, 0.2), transparent 46%),
    rgba(5, 8, 18, 0.62);
  backdrop-filter: blur(5px) saturate(0.98);
}

.screen-overlay[hidden] {
  display: none;
}

.menu-panel {
  width: min(650px, 100%);
  max-height: 100%;
  display: grid;
  gap: clamp(10px, 1.6vw, 16px);
  overflow: auto;
  padding: clamp(18px, 3.2vw, 32px);
  text-align: center;
  border: 1px solid rgba(148, 163, 184, 0.36);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 0%, rgba(168, 85, 247, 0.18), transparent 46%),
    linear-gradient(180deg, rgba(17, 24, 39, 0.96), rgba(7, 11, 20, 0.98));
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tank-mark {
  position: relative;
  width: 78px;
  height: 54px;
  justify-self: center;
  border-radius: 18px 18px 12px 12px;
  background:
    linear-gradient(90deg, transparent 0 9px, rgba(0, 0, 0, 0.52) 9px 15px, transparent 15px 63px, rgba(0, 0, 0, 0.52) 63px 69px, transparent 69px),
    linear-gradient(180deg, #ef4444, #991b1b);
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.08),
    0 18px 36px rgba(239, 68, 68, 0.22);
}

.tank-mark::before,
.tank-mark::after {
  content: "";
  position: absolute;
}

.tank-mark::before {
  left: 24px;
  top: 12px;
  width: 27px;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff8a80, #b91c1c);
  box-shadow: inset 0 0 0 3px rgba(127, 29, 29, 0.58);
}

.tank-mark::after {
  left: 48px;
  top: 24px;
  width: 34px;
  height: 8px;
  border-radius: 999px;
  background: #fed7aa;
  box-shadow: 0 0 14px rgba(251, 146, 60, 0.34);
}

.menu-panel h1 {
  margin: 0;
  color: #fff7ed;
  font-size: clamp(40px, 7vw, 76px);
  font-weight: 950;
  letter-spacing: 0;
  line-height: 0.92;
}

.menu-panel p {
  max-width: 560px;
  margin: 0 auto;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 700;
  line-height: 1.35;
}

.mode-switch,
.menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-button,
.secondary-button {
  min-height: 44px;
  padding: 0 14px;
  color: rgba(248, 250, 252, 0.84);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent),
    rgba(30, 41, 59, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
}

.mode-button.is-selected {
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0%, rgba(168, 85, 247, 0.38), transparent 58%),
    linear-gradient(180deg, #6d28d9, #4c1d95);
  box-shadow:
    0 0 22px rgba(168, 85, 247, 0.26),
    inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.record-grid span {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.76);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.record-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(18px, 2.6vw, 25px);
}

.menu-copy {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.62);
  text-align: left;
}

.menu-copy strong {
  color: var(--gold);
  font-size: 13px;
  text-transform: uppercase;
}

.menu-copy span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
}

.play-button {
  min-height: 54px;
  padding: 0 18px;
  background:
    radial-gradient(circle at 50% 0%, rgba(250, 204, 21, 0.34), transparent 56%),
    linear-gradient(180deg, #a855f7, #7c3aed 66%, #581c87);
  box-shadow:
    0 16px 32px rgba(124, 58, 237, 0.32),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    inset 0 -8px 18px rgba(0, 0, 0, 0.24);
  font-size: 18px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: clamp(14px, 2.2vw, 24px);
  z-index: 3;
  width: min(520px, calc(100% - 28px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(250, 204, 21, 0.36);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.9);
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.34);
}

.toast[hidden] {
  display: none;
}

.touch-controls {
  position: fixed;
  left: 0;
  right: auto;
  bottom: 8px;
  z-index: 8;
  width: 100vw;
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  padding: 0 14px;
  pointer-events: none;
}

.touch-controls.is-active {
  display: flex;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 8px;
  pointer-events: auto;
}

.touch-button {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.22), transparent 54%),
    rgba(15, 23, 42, 0.78);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34);
  pointer-events: auto;
  touch-action: none;
}

.touch-button svg {
  width: 56%;
  height: 56%;
  fill: currentColor;
}

.touch-button.is-held {
  border-color: var(--violet);
  background:
    radial-gradient(circle at 50% 0%, rgba(168, 85, 247, 0.42), transparent 54%),
    rgba(76, 29, 149, 0.82);
}

.touch-up {
  grid-column: 2;
  grid-row: 1;
}

.touch-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-down {
  grid-column: 2;
  grid-row: 2;
}

.touch-right {
  grid-column: 3;
  grid-row: 2;
}

.touch-fire {
  width: 78px;
  height: 78px;
  border-radius: 999px;
  border-color: rgba(250, 204, 21, 0.34);
  color: var(--gold);
  text-transform: uppercase;
}

.icon-button:hover,
.play-button:hover,
.secondary-button:hover,
.mode-button:hover,
.touch-button:hover {
  filter: brightness(1.12);
}

.icon-button:focus-visible,
.play-button:focus-visible,
.secondary-button:focus-visible,
.mode-button:focus-visible,
.touch-button:focus-visible,
#game:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

@media (pointer: coarse) {
  .tta-shell {
    padding-bottom: 98px;
  }
}

@media (min-width: 861px) and (hover: hover) {
  .touch-controls.is-active {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --hud-height: auto;
  }

  .tta-shell {
    grid-template-rows: minmax(0, 1fr);
  }

  .tta-hud {
    top: 8px;
    left: 8px;
    right: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 6px;
  }

  .hud-card-center {
    grid-column: 1 / -1;
    order: -1;
    min-height: 58px;
    padding-right: 102px;
  }

  .hud-card-center strong {
    font-size: clamp(20px, 7vw, 30px);
  }

  .hud-card-p1,
  .hud-card-p2,
  .hud-actions {
    grid-column: auto;
  }

  .hud-actions {
    min-height: 0;
    padding: 4px;
    gap: 4px;
  }

  .hud-actions .icon-button {
    width: 32px;
  }

  .hud-card-player strong {
    font-size: clamp(28px, 8vw, 40px);
  }

  .hud-card-player {
    column-gap: 8px;
    padding: 8px;
  }

  body[data-game-state="playing"] .hud-card-player {
    min-height: 44px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 1fr;
    align-items: center;
    column-gap: 7px;
    padding: 6px 7px;
  }

  body[data-game-state="playing"] .hud-card-player strong {
    grid-row: auto;
    font-size: clamp(24px, 7vw, 30px);
  }

  body[data-game-state="playing"] .hud-card-player .hud-kicker,
  body[data-game-state="playing"] .hud-card-player small {
    display: none;
  }

  body[data-game-state="playing"] .health-pips {
    align-self: center;
    gap: 3px;
  }

  body[data-game-state="playing"] .health-pips span {
    width: 9px;
    height: 9px;
  }

  .stage-shell {
    width: 100%;
    align-self: center;
  }

  .touch-controls {
    max-width: 100vw;
    padding: 0 12px;
  }

  .menu-panel {
    width: min(420px, 100%);
    padding: 18px;
  }

  .menu-panel h1 {
    font-size: clamp(38px, 12vw, 54px);
  }

  .record-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-height: 760px) and (min-width: 761px) and (orientation: landscape) {
  .tta-shell {
    grid-template-rows: minmax(0, 1fr);
  }

  .hud-card {
    padding: 7px 9px;
  }

  .hud-card-center strong {
    font-size: clamp(20px, 3vw, 28px);
  }

  .hud-card-player strong {
    font-size: clamp(28px, 4vw, 40px);
  }

  .icon-button {
    width: 44px;
  }

  .screen-overlay {
    padding: 10px;
  }

  .menu-panel {
    width: min(720px, 100%);
    max-height: 100%;
    grid-template-columns: minmax(220px, 0.9fr) minmax(260px, 1.1fr);
    text-align: left;
    padding: 14px;
    gap: 9px 12px;
  }

  .tank-mark {
    width: 58px;
    height: 40px;
    justify-self: start;
  }

  .tank-mark,
  .menu-panel h1,
  .menu-panel p {
    grid-column: 1;
  }

  .mode-switch,
  .record-grid,
  .menu-copy,
  .menu-actions {
    grid-column: 2;
  }

  .menu-panel h1 {
    font-size: clamp(32px, 5.4vw, 48px);
  }

  .menu-panel p,
  .menu-copy span {
    font-size: 12px;
  }

  .record-grid span {
    padding: 7px 6px;
  }

  .play-button,
  .secondary-button,
  .mode-button {
    min-height: 40px;
  }
}
