:root {
  color-scheme: light;
  --ink: #162126;
  --muted: #64727b;
  --line: #c9d5dc;
  --panel: #ffffff;
  --shell: #eef3f5;
  --sea: #b9e6e1;
  --sea-deep: #55a7a0;
  --blue: #2864c7;
  --red: #c04758;
  --gold: #d59a18;
  --violet: #7259b6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--shell);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

.game-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(420px, 1fr) minmax(260px, 320px);
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 14px;
}

.topbar,
.room-panel,
.map-panel,
.turn-panel,
.log-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(240px, 320px);
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.brand-block h1,
.room-panel h2,
.turn-panel h2,
.log-panel h2 {
  margin: 0;
  font-weight: 750;
  line-height: 1.05;
}

.brand-block h1 {
  font-size: 26px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.primary-actions,
.join-form,
.button-grid,
.share-row,
.seat-strip {
  display: flex;
  gap: 8px;
}

.join-form input,
.share-row input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #f8fbfc;
}

.command,
.icon-command {
  min-height: 38px;
  border: 1px solid #aebdc5;
  border-radius: 6px;
  background: #f8fbfc;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.command:hover:not(:disabled),
.icon-command:hover:not(:disabled) {
  border-color: var(--sea-deep);
  background: #edf9f7;
}

.command.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.command.accent {
  border-color: var(--sea-deep);
  background: var(--sea-deep);
  color: #ffffff;
}

.command.secondary {
  border-color: var(--violet);
  color: var(--violet);
}

.command.danger {
  border-color: var(--red);
  background: var(--red);
  color: #ffffff;
}

.command.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.wide {
  width: 100%;
}

.room-panel,
.turn-panel,
.log-panel {
  padding: 14px;
}

.room-panel {
  grid-column: 1;
  grid-row: 2;
}

.map-panel {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 10px;
}

.turn-panel {
  grid-column: 3;
  grid-row: 2;
}

.log-panel {
  grid-column: 1 / -1;
  grid-row: 3;
  max-height: 210px;
  overflow: auto;
}

.status-line {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 24px;
  color: var(--muted);
}

.status-line.error {
  color: var(--red);
  font-weight: 700;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metric-grid div,
.selected-readout {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fbfc;
}

.metric-grid span,
.selected-readout span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-grid strong,
.selected-readout strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.team-blue {
  color: var(--blue);
}

.team-red {
  color: var(--red);
}

.seat-strip {
  margin: 12px 0;
}

.seat {
  flex: 1;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.seat.filled {
  border-style: solid;
  color: #ffffff;
}

.seat.blue {
  background: var(--blue);
}

.seat.red {
  background: var(--red);
}

.map-grid {
  width: min(100%, 76vh);
  max-width: 780px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: repeat(12, minmax(0, 1fr));
  gap: 3px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid rgba(22, 33, 38, 0.18);
  border-radius: 4px;
  background: rgba(185, 230, 225, 0.84);
  color: rgba(22, 33, 38, 0.74);
  padding: 0;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.cell.path-heat {
  background: rgba(213, 154, 24, calc(0.18 + var(--heat)));
}

.cell.island {
  background: #424b4f;
  color: #ffffff;
}

.cell.own-route {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(40, 100, 199, 0.32);
}

.cell.own-position {
  background: var(--blue);
  color: #ffffff;
}

.cell.legal-move {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 3px var(--gold);
}

.cell.opponent-endpoint::after {
  content: "";
  position: absolute;
  width: 42%;
  height: 42%;
  border: 2px solid var(--red);
  border-radius: 50%;
}

.cell.selected {
  outline: 3px solid var(--violet);
  outline-offset: -3px;
}

.panel-copy {
  margin: 12px 0;
  color: var(--muted);
  line-height: 1.4;
}

.selected-readout {
  margin: 12px 0;
}

.button-grid {
  flex-direction: column;
}

.compass {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". n ."
    "w . e"
    ". s .";
  gap: 8px;
  margin: 12px 0;
}

.compass-N {
  grid-area: n;
}

.compass-W {
  grid-area: w;
}

.compass-E {
  grid-area: e;
}

.compass-S {
  grid-area: s;
}

#public-log {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

#public-log li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fbfc;
  line-height: 1.35;
}

#public-log span {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  min-height: 24px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--ink);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.empty-log {
  color: var(--muted);
}

@media (max-width: 1080px) {
  .game-shell {
    grid-template-columns: minmax(240px, 320px) 1fr;
  }

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

  .map-panel {
    grid-column: 2;
  }

  .turn-panel {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .log-panel {
    grid-row: 4;
  }

  .status-line {
    grid-row: 5;
  }
}

@media (max-width: 760px) {
  .game-shell {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .room-panel,
  .map-panel,
  .turn-panel,
  .log-panel,
  .status-line {
    grid-column: 1;
    grid-row: auto;
  }

  .primary-actions,
  .join-form {
    flex-wrap: wrap;
  }

  .primary-actions .command,
  .join-form .command {
    flex: 1;
  }

  .map-grid {
    width: 100%;
    gap: 2px;
  }

  .cell {
    font-size: 9px;
  }

  #public-log {
    grid-template-columns: 1fr;
  }
}
