:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #617084;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(24, 33, 47, 0.14);
  --sky: #8ad7ff;
  --sun: #ffd04b;
  --grass: #2faf7f;
  --clay: #f57b51;
  --blue: #3468d8;
  --shadow: 0 18px 50px rgba(24, 33, 47, 0.16);
  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, #d9f3ff 0%, #f8fbff 52%, #e9f7ee 100%);
}

button {
  font: inherit;
}

.app {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar,
.scoreboard,
.help {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 18px;
}

.play-area {
  min-width: 0;
}

.topbar {
  min-height: 72px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.3rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.mode-button,
.icon-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.mode-button {
  padding: 0 12px;
  white-space: nowrap;
}

.mode-button.active {
  color: #fff;
  background: var(--blue);
}

.icon-button {
  width: 44px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.mode-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.scoreboard {
  margin: 18px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.score-block {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 10px;
  min-width: 128px;
}

.score-block.right-side {
  justify-content: end;
}

.team-label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-block strong {
  display: grid;
  place-items: center;
  width: 54px;
  height: 42px;
  border-radius: 7px;
  color: #fff;
  background: var(--ink);
  font-size: 1.7rem;
  line-height: 1;
}

.left-side strong {
  background: var(--clay);
}

.right-side strong {
  background: var(--blue);
}

.status {
  min-width: 190px;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  width: min(100%, calc((100vh - 230px) * 16 / 9));
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(24, 33, 47, 0.18);
  border-radius: 8px;
  background: var(--sky);
  box-shadow: 0 24px 70px rgba(24, 33, 47, 0.2);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 16 / 9;
  touch-action: none;
}

.help {
  margin-top: 16px;
  color: var(--muted);
  font-weight: 700;
  flex-wrap: wrap;
}

.help > div {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.key {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(24, 33, 47, 0.2);
  border-bottom-width: 3px;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 900;
}

.help-text {
  margin-right: 8px;
}

.side-panel {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 18px;
}

.panel-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.online {
  background: var(--grass);
}

.inline-form,
.room-actions {
  display: grid;
  gap: 8px;
}

.inline-form label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input {
  min-width: 0;
  height: 40px;
  border: 1px solid rgba(24, 33, 47, 0.18);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-weight: 800;
}

.side-panel button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 12px;
  color: #fff;
  background: var(--blue);
  font-weight: 900;
  cursor: pointer;
}

.side-panel button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

#readyButton {
  background: var(--clay);
}

.room-code-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}

.room-code-line strong {
  color: var(--ink);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
}

.panel-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.45;
}

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

.ranking-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(24, 33, 47, 0.1);
}

.ranking-list li:last-child {
  border-bottom: 0;
}

.rank-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.rank-name {
  min-width: 0;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.rank-rating {
  font-weight: 950;
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1160px);
    padding-top: 14px;
  }

  .topbar,
  .scoreboard {
    align-items: stretch;
    flex-direction: column;
  }

  .controls,
  .scoreboard {
    width: 100%;
  }

  .segmented {
    flex: 1;
  }

  .scoreboard {
    gap: 10px;
  }

  .score-block,
  .score-block.right-side {
    width: 100%;
    grid-template-columns: 1fr auto;
    justify-content: stretch;
  }

  .status {
    order: -1;
    min-width: 0;
  }

  .stage-wrap {
    width: 100%;
  }

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

@media (max-height: 760px) and (min-width: 721px) {
  .app {
    padding-top: 12px;
  }

  .topbar {
    min-height: 60px;
  }

  h1 {
    font-size: clamp(2rem, 5vw, 3.3rem);
  }

  .scoreboard {
    margin: 10px 0 12px;
    padding: 10px 12px;
  }

  .help {
    margin-top: 10px;
  }
}
