:root {
  color-scheme: dark;
  --bg: #121417;
  --panel: #1d2328;
  --panel-strong: #252d33;
  --text: #f5f3ea;
  --muted: #aeb8b2;
  --line: #37434b;
  --green: #61c47c;
  --teal: #4db7b5;
  --gold: #f0c75e;
  --coral: #f06f5d;
  --ink: #0b0d0e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--green);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  min-height: 40px;
  padding: 0 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

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

.start-screen,
.lobby-screen {
  width: min(680px, 100%);
  display: grid;
  gap: 24px;
}

.lobby-screen {
  width: min(980px, 100%);
}

.brand-block {
  display: grid;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 3rem;
  letter-spacing: 0;
  line-height: 1;
}

.notice {
  margin: 0;
  color: var(--muted);
  max-width: 56ch;
}

.join-form,
.lobby-panel {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.lobby-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.lobby-header strong {
  min-width: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 18px;
  text-align: center;
  font-size: 1.25rem;
}

.lobby-body {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.8fr);
  gap: 12px;
}

.lobby-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.lobby-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lobby-status {
  margin: 0;
  color: var(--muted);
}

.lobby-players {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.lobby-players li {
  display: flex;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ink);
  padding: 10px 12px;
}

.lobby-players li.self {
  border-color: var(--teal);
}

.join-form label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.form-hint,
.join-error {
  margin: 0;
  font-size: 0.82rem;
}

.form-hint {
  color: var(--muted);
}

.join-error {
  color: var(--coral);
  font-weight: 750;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.join-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ink);
  color: var(--text);
  min-height: 44px;
  padding: 0 12px;
}

.game-screen {
  width: min(1180px, 100%);
  display: grid;
  gap: 12px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(7, minmax(86px, 1fr)) minmax(148px, auto);
  gap: 8px;
  align-items: stretch;
}

.hud-group,
.hud-actions {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.hud-group {
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 8px 10px;
}

.hud-group.hot {
  border-color: color-mix(in srgb, var(--gold), var(--line) 45%);
}

.hud-group.danger {
  border-color: var(--coral);
  background: color-mix(in srgb, var(--coral), var(--panel) 78%);
}

.hud-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  font-size: 1rem;
  line-height: 1.1;
}

.hud-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.hud-actions {
  min-width: 120px;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 800;
}

.hud-actions button {
  min-width: 64px;
  padding: 0 12px;
}

.hud-actions span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-message {
  grid-column: 1 / -1;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--muted);
  display: flex;
  align-items: center;
  padding: 7px 10px;
  font-size: 0.9rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-surface {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #88c8db;
  aspect-ratio: 16 / 9;
  min-height: 300px;
}

.corner-timer {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  display: grid;
  gap: 1px;
  min-width: 86px;
  border: 1px solid rgba(245, 243, 234, 0.22);
  border-radius: 8px;
  background: rgba(11, 13, 14, 0.78);
  padding: 7px 10px;
  box-shadow: 0 8px 24px rgba(11, 13, 14, 0.24);
}

.corner-timer span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.corner-timer strong {
  font-size: 1.35rem;
  line-height: 1;
}

.corner-timer.danger {
  border-color: var(--coral);
  background: color-mix(in srgb, var(--coral), rgba(11, 13, 14, 0.78) 82%);
}

.time-popups {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.time-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  color: var(--gold);
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 var(--ink), 0 0 12px rgba(240, 199, 94, 0.62);
  animation: time-popup-rise 920ms ease-out forwards;
}

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

.opponent-panel {
  display: grid;
  gap: 2px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 10px;
}

.opponent-panel.danger {
  border-color: var(--coral);
}

.opponent-panel strong,
.opponent-panel span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opponent-panel span {
  color: var(--muted);
  font-size: 0.82rem;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.status-overlay {
  position: absolute;
  inset: auto 18px 18px 18px;
  display: grid;
  gap: 10px;
  align-items: baseline;
  border: 1px solid rgba(245, 243, 234, 0.18);
  border-radius: 8px;
  background: rgba(11, 13, 14, 0.78);
  padding: 14px 16px;
  backdrop-filter: blur(6px);
}

.status-overlay.victory {
  border-color: rgba(240, 199, 94, 0.62);
  background: rgba(22, 25, 22, 0.84);
}

.status-overlay.defeat {
  border-color: rgba(240, 111, 93, 0.55);
}

.result-emblem {
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.status-overlay.defeat .result-emblem {
  color: var(--coral);
  font-size: 1.8rem;
  text-transform: none;
}

.status-overlay strong {
  font-size: 1.1rem;
}

.status-overlay span {
  color: var(--muted);
}

.result-placements {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-placements:empty {
  display: none;
}

.result-placements li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  gap: 12px;
  border: 1px solid rgba(245, 243, 234, 0.14);
  border-radius: 6px;
  padding: 8px 10px;
}

.result-placements li.self {
  border-color: var(--teal);
}

.result-placements strong,
.result-placements span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-overlay button {
  justify-self: start;
}

@keyframes time-popup-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -150%) scale(1.1);
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

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

  .hud-actions {
    grid-column: 1 / -1;
  }

  .join-row {
    grid-template-columns: 1fr;
  }

  .lobby-body {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2.25rem;
  }
}
