:root {
  --ink: #132033;
  --muted: #526176;
  --panel: #ffffff;
  --line: rgba(19, 32, 51, 0.14);
  --sky: #aee5ff;
  --field: #b9e47a;
  --trail: #f7df9e;
  --navy: #1a3f75;
  --blue: #2467e8;
  --red: #e84c50;
  --gold: #f4b83f;
  --green: #2f9e63;
  --shadow: 0 18px 45px rgba(19, 32, 51, 0.16);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--sky) 0%, #dff5ff 34%, #eff9d5 34%, #d7ef9d 100%);
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 850;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--red));
  box-shadow: 0 12px 24px rgba(36, 103, 232, 0.22);
  font-weight: 950;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--navy);
  font-weight: 750;
}

.topnav a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  text-decoration: none;
}

.topnav a:hover {
  text-decoration: underline;
}
.topnav .game-menu { border: 1px solid rgba(28, 57, 39, .16); border-radius: 999px; background: #fffdf7; color: #1c3927; padding: 8px 12px; font: inherit; font-weight: 800; cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.game-stage,
.control-panel {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
}

.game-stage {
  min-width: 0;
  padding: 14px;
}

.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 84px;
  padding: 0 4px 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 780px;
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  letter-spacing: 0;
}

.timer-box {
  display: grid;
  min-width: 130px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  text-align: right;
}

.timer-box span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.timer-box strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.45rem;
  line-height: 1;
}

.canvas-frame {
  position: relative;
  min-height: 500px;
  overflow: hidden;
  border: 3px solid #243b4f;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(174, 229, 255, 0.72), rgba(234, 249, 194, 0.74)),
    #eaf7c6;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 500px;
  background: #cdeef7;
}

.curtain,
.finish-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100% - 40px));
  padding: 18px;
  border: 2px solid rgba(19, 32, 51, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 24px 60px rgba(19, 32, 51, 0.22);
  text-align: center;
  transform: translate(-50%, -50%);
}

.curtain strong,
.finish-banner strong {
  font-size: 1.3rem;
}

.curtain span,
.finish-banner span {
  color: var(--muted);
}

.finish-banner[hidden],
.curtain[hidden] {
  display: none;
}

.mobile-controls {
  display: none;
  gap: 10px;
  padding-top: 12px;
}

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

.touch-player-row button,
.dpad button {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-weight: 850;
  font-size: 16px;
}

/* show the d-pad on ANY touch device (tablets in landscape are wider than 720px) */
@media (pointer: coarse) {
  .mobile-controls { display: grid; }
}

.touch-player-row button.active {
  color: white;
  background: var(--navy);
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  grid-template-rows: repeat(3, 66px);
  justify-content: center;
  gap: 8px;
}

.dpad button[data-touch-dir="n"] {
  grid-column: 2;
}

.dpad button[data-touch-dir="w"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad button[data-touch-dir="e"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad button[data-touch-dir="s"] {
  grid-column: 2;
  grid-row: 3;
}

.control-panel {
  align-self: start;
  padding: 14px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 9px;
}

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

.segmented button,
.primary-button,
.secondary-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 850;
}

.segmented button {
  color: var(--ink);
  background: #fffefa;
}

.segmented button.active {
  border-color: rgba(26, 63, 117, 0.9);
  color: white;
  background: var(--navy);
}

.primary-button {
  border-color: #17345e;
  color: white;
  background: linear-gradient(180deg, #2f73f0, #194b9c);
  box-shadow: 0 10px 20px rgba(36, 103, 232, 0.22);
}

.secondary-button {
  color: var(--ink);
  background: #fffefa;
}

.primary-button:hover,
.secondary-button:hover,
.segmented button:hover,
.touch-player-row button:hover,
.dpad button:hover {
  filter: brightness(0.98);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.full {
  width: 100%;
  margin-bottom: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  font-weight: 800;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.standings {
  display: grid;
  gap: 8px;
  min-height: 130px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.standings li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  font-size: 0.93rem;
  font-weight: 800;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(19, 32, 51, 0.18);
}

.standing-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.legend {
  display: grid;
  gap: 7px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 780;
}

.legend-row strong {
  color: var(--ink);
}

.online-panel {
  color: var(--muted);
}

.room-row {
  display: grid;
  grid-template-columns: 1fr 82px 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.room-row input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffefa;
  text-align: center;
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.online-status {
  min-height: 40px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 0 18px;
  }

  .panel-section {
    border-bottom: 0;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell,
  .topbar {
    width: min(100% - 18px, 1500px);
  }

  .game-stage,
  .control-panel {
    padding: 10px;
  }

  .score-strip {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 1.45rem;
  }

  .canvas-frame {
    min-height: 360px;
  }

  #gameCanvas {
    min-height: 360px;
  }

  .mobile-controls {
    display: grid;
    position: sticky;
    bottom: 8px;
    z-index: 4;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 254, 250, 0.96);
    box-shadow: 0 8px 22px rgba(16, 24, 38, 0.18);
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
