/* Tank Blitz — original top-down tank arcade game for HappyBiu. */

:root {
  color-scheme: light;
  --tb-bg: #eef2e8;
  --tb-bg-deep: #d7e2d2;
  --tb-surface: #fffdf4;
  --tb-surface-2: #e7eee2;
  --tb-ink: #1b241d;
  --tb-muted: #5e6b60;
  --tb-line: #1b241d;
  --tb-accent: #2f7d5b;
  --tb-accent-2: #e0a020;
  --tb-score: #2f7d5b;
  --tb-gold: #7a5200;
  --tb-danger: #d9533f;
  --tb-mint: #3fa87a;
  --tb-shadow: #1b241d;
  --tb-on-accent: #ffffff;
  --tb-on-gold: #141226;
  --tb-scrim: rgba(27, 36, 29, 0.55);
  --tb-floor: #f7f3e7;
  --tb-floor-2: #e9e4d3;
  --tb-brick: #b9583c;
  --tb-brick-dark: #7a3325;
  --tb-steel: #87918c;
  --tb-steel-light: #cbd3ce;
  --tb-water: #3a79a8;
  --tb-water-deep: #1d496b;
  --tb-grass: #3d8b55;
  --tb-grass-dark: #245d38;
  --tb-elite: #8a5bc7;
  --tb-font: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Segoe UI Mono",
    Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --tb-bg: #0a1410;
  --tb-bg-deep: #12241b;
  --tb-surface: #17291f;
  --tb-surface-2: #203a2b;
  --tb-ink: #eef7ef;
  --tb-muted: #a6b9aa;
  --tb-line: #eef7ef;
  --tb-accent: #46c98b;
  --tb-accent-2: #ffcf5a;
  --tb-score: #ffcf5a;
  --tb-gold: #ffcf5a;
  --tb-danger: #ff6b57;
  --tb-mint: #7be0b0;
  --tb-shadow: #020805;
  --tb-on-accent: #08100b;
  --tb-on-gold: #141226;
  --tb-scrim: rgba(2, 8, 5, 0.72);
  --tb-floor: #17291f;
  --tb-floor-2: #12241b;
  --tb-brick: #8c4634;
  --tb-brick-dark: #5c2c22;
  --tb-steel: #5d6b64;
  --tb-steel-light: #9aaba2;
  --tb-water: #205a82;
  --tb-water-deep: #123b59;
  --tb-grass: #256b43;
  --tb-grass-dark: #16452b;
  --tb-elite: #b18cff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--tb-bg);
}

body {
  font-family: var(--tb-font);
  color: var(--tb-ink);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: none;
  text-rendering: optimizeSpeed;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.u-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--tb-bg);
}

.tb-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-color: var(--tb-bg);
  background-image: url("./assets/tank-blitz-light.png");
  background-position: center;
  background-size: cover;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  opacity: 0.16;
}

[data-theme="dark"] .tb-bg {
  background-image: url("./assets/tank-blitz-dark.png");
  opacity: 0.24;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  outline: none;
  touch-action: none;
}

#game-canvas:focus-visible {
  outline: 3px solid var(--tb-accent-2);
  outline-offset: -3px;
}

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

.tb-hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px))
    calc(8px + env(safe-area-inset-right, 0px)) 0
    calc(8px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tb-hud__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.tb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 3px 5px;
  border: 2px solid var(--tb-line);
  background: var(--tb-surface);
  box-shadow: 3px 3px 0 var(--tb-shadow);
  white-space: nowrap;
}

.tb-chip strong {
  color: var(--tb-accent);
  font-size: 13px;
}

.tb-chip--accent strong {
  color: var(--tb-score);
}

.tb-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 3px solid var(--tb-line);
  border-radius: 0;
  background: var(--tb-surface);
  box-shadow: 4px 4px 0 var(--tb-shadow);
  pointer-events: auto;
}

.tb-icon-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 0 var(--tb-shadow);
}

.tb-icon-btn__bars {
  display: inline-grid;
  grid-template-columns: repeat(2, 6px);
  gap: 4px;
}

.tb-icon-btn__bars span {
  display: block;
  width: 6px;
  height: 16px;
  background: currentColor;
}

.tb-icon-btn[aria-pressed="true"] .tb-icon-btn__bars span {
  width: 6px;
  height: 12px;
  align-self: center;
}

.tb-icon-btn[aria-pressed="true"] .tb-icon-btn__bars span:first-child {
  clip-path: polygon(0 0, 100% 50%, 100% 50%, 0 100%);
}

/* Start card -------------------------------------------------------------- */

.tb-start {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
}

.tb-start[hidden] {
  display: none;
}

.tb-start__card {
  width: min(86vw, 350px);
  padding: 18px;
  border: 3px solid var(--tb-line);
  background: var(--tb-surface);
  box-shadow: 6px 6px 0 var(--tb-accent);
  text-align: center;
  pointer-events: auto;
}

.tb-start__card h1 {
  margin: 0 0 6px;
  color: var(--tb-accent);
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tb-start__card p {
  margin: 0 0 8px;
  color: var(--tb-muted);
  font-size: 16px;
  line-height: 1.45;
}

.tb-start__card .tb-start__seed {
  color: var(--tb-accent);
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 3px solid var(--tb-line);
  border-radius: 0;
  background: var(--tb-surface);
  box-shadow: 4px 4px 0 var(--tb-shadow);
  font-family: var(--tb-font);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tb-btn--primary {
  color: var(--tb-on-accent);
  background: var(--tb-accent);
}

.tb-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 0 var(--tb-shadow);
}

/* Level complete ---------------------------------------------------------- */

.tb-modal {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--tb-scrim);
}

.tb-modal[hidden] {
  display: none;
}

.tb-modal__card {
  width: min(86vw, 360px);
  padding: 18px;
  border: 3px solid var(--tb-line);
  background: var(--tb-surface);
  box-shadow: 6px 6px 0 var(--tb-accent-2);
  text-align: center;
}

.tb-modal__eyebrow {
  margin: 0 0 4px;
  color: var(--tb-accent);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tb-modal__card h2 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.1;
  text-transform: uppercase;
}

.tb-modal__score {
  margin: 6px 0 4px;
  color: var(--tb-accent);
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
}

.tb-modal__text {
  margin: 0 0 8px;
  color: var(--tb-muted);
  font-size: 16px;
}

.tb-modal__text strong {
  color: var(--tb-ink);
}

.tb-modal .tb-btn {
  margin-top: 8px;
}

/* Touch controls ---------------------------------------------------------- */

.tb-touch {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right, 0px));
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  z-index: 3;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.tb-stick {
  position: relative;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 3px solid var(--tb-line);
  border-radius: 0;
  background: var(--tb-surface);
  box-shadow: 4px 4px 0 var(--tb-shadow);
  pointer-events: auto;
  touch-action: none;
}

.tb-stick__cross,
.tb-stick__cross::before,
.tb-stick__cross::after {
  position: absolute;
  display: block;
  content: "";
  background: var(--tb-muted);
  opacity: 0.22;
}

.tb-stick__cross {
  top: 50%;
  left: 14px;
  right: 14px;
  height: 2px;
  transform: translateY(-50%);
}

.tb-stick__cross::before {
  top: -28px;
  left: 50%;
  width: 2px;
  height: 58px;
  transform: translateX(-50%);
}

.tb-stick__cross::after {
  display: none;
}

.tb-stick__knob {
  position: relative;
  z-index: 1;
  width: 30px;
  height: 30px;
  border: 3px solid var(--tb-line);
  border-radius: 0;
  background: var(--tb-accent);
  box-shadow: 3px 3px 0 var(--tb-shadow);
  pointer-events: none;
  will-change: transform;
}

.tb-fire {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 3px solid var(--tb-line);
  border-radius: 0;
  color: var(--tb-on-accent);
  background: var(--tb-accent-2);
  box-shadow: 4px 4px 0 var(--tb-shadow);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: auto;
}

.tb-fire:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 0 var(--tb-shadow);
}

@media (max-width: 720px), (hover: none), (pointer: coarse),
  (orientation: landscape) and (max-height: 520px) and (max-width: 850px) {
  .tb-touch {
    display: flex;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .tb-touch {
    top: 50%;
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: auto;
    left: auto;
    width: auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transform: translateY(-50%);
  }
}

#app[data-state="ready"] .tb-touch,
#app[data-state="levelComplete"] .tb-touch,
#app[data-state="over"] .tb-touch {
  display: none;
}

@media (max-width: 520px) {
  .tb-hud {
    flex-direction: column;
    align-items: stretch;
  }

  .tb-hud__group {
    justify-content: space-between;
  }
}

@media (max-width: 360px) {
  .tb-chip {
    padding: 2px 4px;
  }

  .tb-stick {
    width: 68px;
    height: 68px;
  }

  .tb-fire {
    width: 60px;
    height: 60px;
  }
}

/* Reduced motion ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .tb-btn,
  .tb-stick__knob,
  .tb-fire,
  .tb-icon-btn {
    transition: none;
  }
}
