:root {
  color-scheme: dark;
  --ink: #08131c;
  --ink-soft: #102735;
  --panel: rgba(8, 19, 28, 0.88);
  --line: rgba(239, 255, 246, 0.16);
  --paper: #f7fff1;
  --lime: #a2ef3c;
  --green: #49c86e;
  --cyan: #42daf5;
  --pink: #ff5ea8;
  --yellow: #ffdf54;
  --coral: #ff7a59;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--paper);
  background:
    linear-gradient(135deg, #061017 0 28%, transparent 28% 100%),
    linear-gradient(315deg, #173322 0 25%, transparent 25% 100%),
    #0c202b;
  font-family: "Trebuchet MS", "Arial Black", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 8px;
}

.arena {
  position: relative;
  width: min(calc(100vw - 16px), calc((100svh - 16px) * 16 / 9), 1760px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  isolation: isolate;
  border: 4px solid #03090e;
  background: #76cf3e;
  box-shadow:
    0 26px 72px var(--shadow),
    0 0 0 1px rgba(247, 255, 241, 0.16);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.hud {
  position: absolute;
  inset: 18px 18px auto;
  z-index: 2;
  display: grid;
  grid-template-columns: 116px minmax(150px, auto) 1fr 52px;
  align-items: start;
  gap: 12px;
  pointer-events: none;
}

.hud[hidden] {
  display: none;
}

.hud-timer,
.tagger-hud,
.score-hud {
  min-height: 58px;
  border: 2px solid rgba(3, 9, 14, 0.7);
  background: rgba(8, 19, 28, 0.72);
  box-shadow: 0 5px 0 rgba(3, 9, 14, 0.35);
  backdrop-filter: blur(5px);
}

.hud-timer {
  display: grid;
  align-content: center;
  padding: 7px 14px;
  border-radius: 8px;
}

.hud-label {
  color: rgba(247, 255, 241, 0.68);
  font-size: 12px;
  text-transform: uppercase;
}

#timerValue {
  color: var(--yellow);
  font-size: 30px;
  line-height: 30px;
}

.tagger-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 166px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 17px;
  text-transform: uppercase;
}

.tagger-chip,
.score-chip {
  --player: var(--paper);
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 3px solid #031018;
  border-radius: 3px;
  color: #031018;
  background: var(--player);
  box-shadow: inset -5px -4px rgba(3, 16, 24, 0.16);
  font-size: 14px;
  font-weight: 900;
}

.score-hud {
  justify-self: end;
  display: flex;
  min-width: 0;
  gap: 7px;
  align-items: center;
  justify-content: flex-end;
  padding: 9px;
  border-radius: 8px;
}

.score-entry {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 70px;
  height: 38px;
  padding: 3px 8px 3px 3px;
  border: 1px solid rgba(247, 255, 241, 0.15);
  border-radius: 7px;
  background: rgba(247, 255, 241, 0.08);
  font-weight: 900;
}

.score-chip {
  width: 30px;
  height: 30px;
  border-width: 2px;
  font-size: 12px;
}

.icon-button {
  display: inline-grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 2px solid rgba(3, 9, 14, 0.82);
  border-radius: 8px;
  background: rgba(247, 255, 241, 0.13);
  box-shadow: inset 0 1px rgba(247, 255, 241, 0.18), 0 5px 0 rgba(3, 9, 14, 0.32);
  cursor: pointer;
}

.icon-button svg,
.start-button svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.hud .icon-button {
  color: var(--paper);
  pointer-events: auto;
  justify-self: end;
  background: rgba(8, 19, 28, 0.72);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(180deg, rgba(4, 12, 17, 0.06), rgba(4, 12, 17, 0.36));
}

.overlay[hidden] {
  display: none;
}

.menu-panel,
.dialog-panel {
  width: min(760px, 100%);
  border: 4px solid #03090e;
  border-radius: 8px;
  background: var(--panel);
  box-shadow:
    0 14px 0 rgba(3, 9, 14, 0.32),
    inset 0 0 0 2px rgba(247, 255, 241, 0.09);
}

.menu-panel {
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 26px;
}

.menu-overlay {
  background:
    linear-gradient(128deg, rgba(3, 10, 18, 0.2), rgba(7, 19, 19, 0.08)),
    rgba(8, 14, 24, 0.28);
}

.menu-overlay .menu-panel {
  width: min(1080px, 100%);
  border: 0;
  background: transparent;
  box-shadow: none;
  gap: 24px;
  padding: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--paper);
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 68px;
  line-height: 68px;
  text-align: center;
  text-shadow:
    0 5px #03090e,
    -3px 0 #03090e,
    3px 0 #03090e;
}

.menu-overlay h1 {
  font-size: 116px;
  line-height: 112px;
  text-shadow:
    0 11px #061216,
    -7px 0 #061216,
    7px 0 #061216,
    0 -5px #061216;
}

.player-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.menu-overlay .player-grid {
  width: min(980px, 100%);
  gap: 38px;
}

.player-slot {
  --player: var(--paper);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  grid-template-rows: 23px 18px;
  min-height: 74px;
  gap: 0 9px;
  align-items: center;
  padding: 12px;
  border: 3px solid #03090e;
  border-radius: 8px;
  color: var(--paper);
  background: rgba(247, 255, 241, 0.11);
  box-shadow: 0 5px 0 rgba(3, 9, 14, 0.35);
  cursor: pointer;
  text-align: left;
}

.menu-overlay .player-slot {
  min-height: 108px;
  grid-template-columns: 44px minmax(0, 1fr);
  align-content: center;
  border: 5px solid #07120d;
  border-radius: 4px;
  background: rgba(18, 55, 16, 0.94);
  box-shadow:
    0 0 0 6px #eff5e8,
    8px 8px 0 #07120d;
  cursor: default;
}

.player-slot[data-player="0"] {
  --player: var(--cyan);
}

.player-slot[data-player="1"] {
  --player: var(--coral);
}

.player-slot[data-player="2"] {
  --player: var(--yellow);
}

.player-slot[data-player="3"] {
  --player: var(--pink);
}

.player-slot[aria-pressed="false"] {
  opacity: 0.5;
  filter: saturate(0.45);
}

.player-mark {
  grid-row: span 2;
  width: 42px;
  height: 48px;
  border: 3px solid #03090e;
  border-radius: 3px;
  background:
    radial-gradient(circle at 32% 42%, #03090e 0 3px, transparent 4px),
    radial-gradient(circle at 68% 42%, #03090e 0 3px, transparent 4px),
    var(--player);
  box-shadow: inset -7px -8px rgba(3, 9, 14, 0.14);
}

.player-slot strong {
  min-width: 0;
  overflow: hidden;
  font-size: 23px;
  line-height: 23px;
  text-overflow: ellipsis;
}

.player-slot small {
  min-width: 0;
  overflow: hidden;
  color: rgba(247, 255, 241, 0.72);
  font-size: 12px;
  font-weight: 900;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-list {
  display: grid;
  justify-items: center;
  gap: 0;
  width: min(720px, 100%);
}

.menu-choice {
  position: relative;
  min-height: 52px;
  border: 0;
  color: #f7fff1;
  background: transparent;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 39px;
  line-height: 48px;
  text-transform: uppercase;
  text-shadow:
    0 4px #061216,
    -2px 0 #061216,
    2px 0 #061216;
}

.menu-choice.is-selected {
  color: #fff28a;
}

.menu-choice.is-selected::before,
.menu-choice.is-selected::after {
  position: absolute;
  top: 0;
  color: #f7fff1;
  text-shadow: 0 4px #061216;
}

.menu-choice.is-selected::before {
  left: -42px;
  content: ">";
}

.menu-choice.is-selected::after {
  right: -42px;
  content: "<";
}

.menu-command,
.menu-toggle,
.menu-list .start-button {
  display: inline-flex;
  width: auto;
  height: auto;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 10px;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
}

.menu-setting {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
}

.menu-setting .stepper {
  gap: 2px;
}

.menu-setting .stepper strong {
  width: auto;
  min-width: 72px;
  height: auto;
  border: 0;
  color: inherit;
  background: transparent;
  font-size: inherit;
  line-height: inherit;
}

.menu-setting .icon-button {
  width: 42px;
  height: 48px;
  border: 0;
  color: inherit;
  background: transparent;
  box-shadow: none;
}

.menu-setting .icon-button svg {
  width: 36px;
  height: 36px;
}

.menu-toggle strong {
  min-width: 78px;
}

.menu-list .start-button {
  color: inherit;
  background: transparent;
  font-size: 39px;
  line-height: 48px;
  text-transform: uppercase;
}

.settings-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.setting-row,
.toggle {
  min-height: 64px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 255, 241, 0.08);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.stepper,
.segments {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stepper strong {
  display: grid;
  width: 46px;
  height: 42px;
  place-items: center;
  border: 2px solid #03090e;
  border-radius: 7px;
  color: #031018;
  background: var(--lime);
  font-size: 25px;
}

.stepper .icon-button {
  width: 42px;
  height: 42px;
  border-width: 2px;
  box-shadow: none;
  background: rgba(247, 255, 241, 0.14);
}

.stepper .icon-button svg {
  width: 23px;
  height: 23px;
}

.segments button,
.dialog-actions button {
  min-width: 52px;
  height: 42px;
  border: 2px solid #03090e;
  border-radius: 7px;
  color: var(--paper);
  background: rgba(247, 255, 241, 0.12);
  box-shadow: inset 0 1px rgba(247, 255, 241, 0.14);
  cursor: pointer;
  font-weight: 900;
}

.segments .is-selected {
  color: #031018;
  background: var(--yellow);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
}

.toggle input {
  appearance: none;
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 28px;
  margin: 0;
  align-items: center;
  padding: 3px;
  border: 2px solid #03090e;
  border-radius: 8px;
  background: rgba(247, 255, 241, 0.25);
  cursor: pointer;
}

.toggle input::before {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 1px 0 #03090e;
  content: "";
  transition: transform 120ms ease, background 120ms ease;
}

.toggle input:checked {
  background: var(--green);
}

.toggle input:checked::before {
  background: #031018;
  transform: translateX(14px);
}

.start-button {
  display: inline-flex;
  width: min(228px, 100%);
  height: 68px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 3px solid #03090e;
  border-radius: 8px;
  color: #031018;
  background: var(--lime);
  box-shadow: 0 8px 0 rgba(3, 9, 14, 0.44), inset 0 2px rgba(247, 255, 241, 0.35);
  cursor: pointer;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 30px;
  text-transform: uppercase;
}

.start-button:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.45;
}

.compact-overlay {
  z-index: 4;
  background: rgba(4, 12, 17, 0.58);
}

.dialog-panel {
  display: grid;
  width: min(440px, 100%);
  justify-items: center;
  gap: 20px;
  padding: 28px;
  text-align: center;
}

.dialog-panel h2 {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 48px;
  line-height: 50px;
  text-shadow: 0 4px #03090e;
  text-transform: uppercase;
}

.result-panel p {
  min-height: 32px;
  font-size: 24px;
  font-weight: 900;
  text-transform: uppercase;
}

.dialog-actions {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}

.dialog-actions button {
  min-width: 118px;
  padding: 0 14px;
}

button:hover,
.toggle:hover {
  filter: brightness(1.08);
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid var(--cyan);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .app {
    padding: 4px;
  }

  .arena {
    width: min(calc(100vw - 8px), calc((100svh - 8px) * 16 / 9));
  }

  .overlay {
    padding: 12px;
  }

  .menu-panel {
    gap: 10px;
    padding: 14px;
  }

  h1 {
    font-size: 43px;
    line-height: 46px;
  }

  .menu-overlay h1 {
    font-size: 76px;
    line-height: 76px;
  }

  .menu-overlay .player-grid {
    gap: 16px;
  }

  .menu-overlay .player-slot {
    min-height: 76px;
  }

  .menu-choice,
  .menu-list .start-button {
    min-height: 40px;
    font-size: 28px;
    line-height: 38px;
  }

  .menu-choice.is-selected::before {
    left: -28px;
  }

  .menu-choice.is-selected::after {
    right: -28px;
  }

  .player-slot {
    grid-template-columns: 34px minmax(0, 1fr);
    min-height: 58px;
    gap: 0 6px;
    padding: 7px;
  }

  .player-mark {
    width: 34px;
    height: 40px;
  }

  .player-slot strong {
    font-size: 17px;
    line-height: 19px;
  }

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

  .setting-row,
  .toggle {
    min-height: 50px;
    padding: 5px 7px;
    font-size: 12px;
  }

  .toggle {
    gap: 6px;
  }

  .stepper strong,
  .stepper .icon-button,
  .segments button {
    width: 33px;
    min-width: 33px;
    height: 34px;
  }

  .stepper strong {
    font-size: 18px;
  }

  .start-button {
    height: 54px;
    font-size: 22px;
  }

  .hud {
    inset: 8px 8px auto;
    grid-template-columns: 82px minmax(118px, auto) 1fr 42px;
    gap: 6px;
  }

  .hud-timer,
  .tagger-hud,
  .score-hud {
    min-height: 46px;
  }

  .hud-timer,
  .tagger-hud {
    padding: 5px 7px;
  }

  #timerValue {
    font-size: 22px;
    line-height: 22px;
  }

  .tagger-hud {
    min-width: 118px;
    gap: 5px;
    font-size: 12px;
  }

  .score-hud {
    gap: 4px;
    padding: 4px;
  }

  .score-entry {
    min-width: 50px;
    height: 34px;
    gap: 3px;
    padding-right: 5px;
    font-size: 12px;
  }

  .tagger-chip {
    width: 29px;
    height: 29px;
    font-size: 11px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 620px), (max-height: 520px) {
  .player-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .setting-row:nth-child(2) {
    grid-column: span 2;
  }

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

  .menu-overlay h1 {
    font-size: 54px;
    line-height: 56px;
  }

  .menu-overlay .player-slot {
    min-height: 58px;
  }

  .menu-choice,
  .menu-list .start-button {
    min-height: 32px;
    font-size: 21px;
    line-height: 30px;
  }

  .menu-setting .icon-button {
    width: 28px;
    height: 32px;
  }

  .menu-setting .icon-button svg {
    width: 26px;
    height: 26px;
  }

  .score-hud {
    display: none;
  }

  .hud {
    grid-template-columns: 82px minmax(118px, 1fr) 42px;
  }
}

@media (max-aspect-ratio: 4 / 3) {
  body {
    overflow: auto;
  }

  .arena {
    width: calc(100vw - 16px);
    height: calc(100svh - 16px);
    aspect-ratio: auto;
  }

  #gameCanvas {
    object-fit: contain;
  }

  .overlay {
    overflow: auto;
  }

  .menu-panel,
  .dialog-panel {
    margin: auto;
  }
}
