:root {
  color-scheme: dark;
  --bg: #101312;
  --panel: #171d1b;
  --line: #31403b;
  --text: #f4fff9;
  --muted: #a8b8b0;
  --player: #1ee8a3;
  --cpu: #ff4e88;
  --amber: #ffd166;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 209, 102, 0.12), rgba(30, 232, 163, 0.06)),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22302c;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 40px;
  padding: 0 16px;
}

button:hover {
  background: #2b3b36;
}

button.active,
.start-button {
  background: var(--player);
  border-color: rgba(255, 255, 255, 0.6);
  color: #07110e;
}

button.active:hover,
.start-button:hover {
  background: #7dffd8;
}

.shell {
  align-items: center;
  display: flex;
  min-height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.game-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: min(100dvh - 16px, 760px);
  margin: 0 auto;
  max-width: 1040px;
  padding: 16px;
  position: relative;
  width: min(100%, 1040px);
}

.title-screen {
  align-items: stretch;
  background:
    linear-gradient(90deg, rgba(10, 14, 12, 0.18), rgba(10, 14, 12, 0.85)),
    url("./assets/title-character.png") center / cover;
  border-radius: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  inset: 16px;
  overflow: hidden;
  position: absolute;
  z-index: 3;
}

.title-screen img {
  height: 100%;
  object-fit: cover;
  object-position: center;
  width: 100%;
}

.title-copy {
  align-content: center;
  background: rgba(10, 14, 12, 0.82);
  display: grid;
  gap: 16px;
  padding: 28px;
}

.kicker {
  color: var(--amber);
  font-size: 12px;
  font-weight: 950;
  margin: 0;
}

.title-copy h1 {
  color: var(--text);
  font-size: clamp(48px, 9vw, 92px);
  line-height: 0.88;
  margin: 0;
}

.tagline {
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

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

.player-count {
  min-width: 0;
  padding: 0 8px;
}

.start-button {
  min-height: 52px;
}

.music-toggle {
  background: #16241f;
}

.hud,
.controls {
  align-items: center;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
}

.kill-board {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
}

.kill-counter {
  align-items: center;
  background: #0e1311;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 10px;
}

.kill-counter.player {
  border-color: rgba(30, 232, 163, 0.45);
}

.kill-counter.cpu {
  border-color: rgba(255, 78, 136, 0.45);
}

.kill-counter span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kill-counter strong {
  color: var(--amber);
  font-size: 18px;
  font-weight: 950;
}

.meter {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
}

.meter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.meter strong {
  font-size: 22px;
}

.meter.player {
  border-color: rgba(30, 232, 163, 0.45);
}

.meter.cpu {
  border-color: rgba(255, 78, 136, 0.45);
}

.timer {
  background: #0e1311;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--amber);
  font-size: clamp(24px, 5vw, 40px);
  font-weight: 950;
  line-height: 1;
  min-width: 128px;
  padding: 10px 16px;
  text-align: center;
}

canvas {
  background: #242a28;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  height: 100%;
  image-rendering: auto;
  min-height: 0;
  touch-action: none;
  width: 100%;
}

.touch-controls {
  display: none;
  inset: auto 24px 82px 24px;
  pointer-events: none;
  position: absolute;
  z-index: 2;
}

.touch-stick {
  background: rgba(14, 19, 17, 0.62);
  border: 2px solid rgba(244, 255, 249, 0.38);
  border-radius: 999px;
  height: 112px;
  pointer-events: auto;
  position: relative;
  touch-action: none;
  width: 112px;
}

.touch-stick span {
  background: rgba(30, 232, 163, 0.86);
  border: 2px solid rgba(244, 255, 249, 0.72);
  border-radius: 999px;
  height: 46px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 46px;
}

.touch-fire {
  align-self: end;
  background: rgba(255, 78, 136, 0.9);
  border: 2px solid rgba(244, 255, 249, 0.72);
  border-radius: 999px;
  color: var(--text);
  height: 96px;
  justify-self: end;
  min-height: 0;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  width: 96px;
}

.ink-bar {
  background: #0e1311;
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 24px;
  overflow: hidden;
}

.ink-bar span {
  background: linear-gradient(90deg, var(--player), #88ffe0);
  display: block;
  height: 100%;
  transition: width 100ms linear;
  width: 100%;
}

.controls {
  grid-template-columns: 1fr auto auto;
}

.result {
  align-items: center;
  background: rgba(10, 14, 12, 0.9);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  inset: 16px;
  justify-items: center;
  padding: 24px;
  position: absolute;
  text-align: center;
}

.result h1 {
  font-size: clamp(36px, 8vw, 72px);
  line-height: 0.95;
  margin: 0;
}

.result p {
  color: var(--muted);
  font-size: 16px;
  margin: 0;
  max-width: 520px;
}

.hidden {
  display: none;
}

@media (max-width: 680px) {
  .shell {
    padding: 8px;
  }

  .game-panel {
    gap: 8px;
    padding: 8px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

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

  .timer {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
  }

  .title-screen {
    grid-template-columns: 1fr;
    inset: 8px;
  }

  .title-screen img {
    display: none;
  }

  .title-copy {
    background: rgba(10, 14, 12, 0.72);
    padding: 18px;
  }

  .player-select {
    grid-template-columns: 1fr;
  }
}

@media (pointer: coarse) {
  button {
    min-height: 44px;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: 112px 1fr 96px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .shell {
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .game-panel {
    gap: 4px;
    height: calc(100dvh - 8px);
    padding: 6px;
    width: 100%;
  }

  .hud {
    gap: 6px;
    grid-template-columns: 1fr auto 1fr;
  }

  .meter {
    min-height: 30px;
    padding: 0 8px;
  }

  .meter span {
    font-size: 10px;
  }

  .meter strong {
    font-size: 16px;
  }

  .timer {
    font-size: 22px;
    min-width: 92px;
    padding: 5px 8px;
  }

  .kill-board {
    gap: 4px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .kill-counter {
    min-height: 24px;
    padding: 0 6px;
  }

  .kill-counter span {
    font-size: 9px;
  }

  .kill-counter strong {
    font-size: 13px;
  }

  .controls {
    gap: 6px;
  }

  .ink-bar {
    height: 16px;
  }

  .controls button {
    font-size: 12px;
    min-height: 30px;
    padding: 0 10px;
  }

  .title-screen {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    inset: 6px;
  }

  .title-copy {
    gap: 8px;
    padding: 16px;
  }

  .title-copy h1 {
    font-size: clamp(40px, 8vw, 64px);
  }

  .tagline {
    font-size: 13px;
  }

  .player-select {
    gap: 6px;
  }

  .player-count,
  .start-button {
    font-size: 12px;
    min-height: 38px;
  }

  .touch-controls {
    inset: auto max(14px, env(safe-area-inset-right)) 44px max(14px, env(safe-area-inset-left));
    grid-template-columns: 92px 1fr 82px;
  }

  .touch-stick {
    height: 92px;
    width: 92px;
  }

  .touch-stick span {
    height: 38px;
    width: 38px;
  }

  .touch-fire {
    font-size: 13px;
    height: 82px;
    width: 82px;
  }
}
