:root {
  --bg: #1d2433;
  --bg-2: #262f42;
  --card: #2d3850;
  --text: #eef1f7;
  --muted: #9aa5bd;
  --red: #e5484d;
  --red-dark: #a8262b;
  --blue: #3e8ef7;
  --blue-dark: #1f5bb5;
  --white: #f7f7f2;
  --cell-light: #d9b98c;
  --cell-dark: #c9a676;
  --board-frame: #7a5a35;
  --highlight: rgba(80, 220, 120, 0.45);
  --highlight-strong: rgba(80, 220, 120, 0.62);
  --select: #ffd84d;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%) fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.logo {
  margin: 0 0 4px;
  font-size: 2.6rem;
  letter-spacing: 0.04em;
}
.logo::before {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-right: 0.3em;
  border-radius: 50%;
  background: var(--white);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  vertical-align: 0.05em;
}

.tagline, .muted { color: var(--muted); }
.tagline { margin: 0 0 22px; }

form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
label { font-weight: 600; font-size: 0.95rem; }

input[type="text"] {
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input[type="text"]:focus { border-color: var(--blue); }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 12px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; }

.error { color: #ff8b8f; margin: 12px 0 0; }

.rules {
  margin-top: 22px;
  text-align: left;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.rules summary { cursor: pointer; color: var(--text); font-weight: 600; }
.rules ol { padding-left: 1.2em; }

/* Lobby */
.spinner {
  width: 48px;
  height: 48px;
  margin: 4px auto 16px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--white);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-text { font-size: 1.1rem; }

/* Game */
#screen-game {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.players {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
#player-opp { flex-direction: row-reverse; text-align: right; }

.player.active {
  border-color: var(--pcolor);
  background: color-mix(in srgb, var(--pcolor) 28%, var(--card));
  box-shadow: 0 0 18px color-mix(in srgb, var(--pcolor) 45%, transparent);
}
.player.away { opacity: 0.5; }

.player.red { --pcolor: var(--red); }
.player.blue { --pcolor: var(--blue); }

.swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--pcolor);
}

.pname {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dots { flex: none; display: inline-flex; gap: 4px; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--pcolor);
  opacity: 0.55;
}
.dot.won { background: var(--pcolor); opacity: 1; }

.vs { color: var(--muted); font-size: 0.85rem; font-weight: 600; }

.meta { margin: 0; font-size: 0.85rem; }

.status {
  min-height: 1.6em;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}
.status.mine { color: var(--select); }
.status.win { color: #7ee2a0; }
.status.lose { color: #ff8b8f; }

.substatus { margin: 0; min-height: 1.3em; text-align: center; font-size: 0.95rem; }

.board-wrap {
  width: min(94vw, 62vh, 520px);
  width: min(94vw, 62dvh, 520px);
  aspect-ratio: 1 / 1;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--board-frame);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(0, 0, 0, 0.25);
  position: relative;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  position: relative;
  border-radius: 6px;
  background: var(--cell-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.cell.alt { background: var(--cell-dark); }

/* Tint each player's baseline with their colour. */
.cell.base-red { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--red) 55%, transparent); }
.cell.base-blue { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--blue) 55%, transparent); }

.cell.last::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.cell.clickable { cursor: pointer; }

.cell.valid::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--highlight);
  box-shadow: inset 0 0 0 3px rgba(40, 170, 80, 0.8);
  transition: background 0.12s ease, transform 0.12s ease;
  pointer-events: none;
}
@media (any-hover: hover) {
  .cell.valid:hover::after {
    background: var(--highlight-strong);
    box-shadow: inset 0 0 0 4px rgba(30, 150, 70, 1);
  }
  .cell.selectable:hover .piece { transform: scale(1.06); }
}

.piece {
  position: relative;
  z-index: 1;
  width: 74%;
  height: 74%;
  border-radius: 50%;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.35), inset 0 -5px 0 rgba(0, 0, 0, 0.18), inset 0 4px 6px rgba(255, 255, 255, 0.25);
}
.piece.red { background: var(--red); }
.piece.blue { background: var(--blue); }
.piece.bobail { background: var(--white); }

.piece.selected {
  transform: scale(1.08);
  box-shadow: 0 0 0 4px var(--select), 0 6px 12px rgba(0, 0, 0, 0.45);
}
.piece.arrived { animation: pop 0.25s ease-out; }
@keyframes pop {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.actions { min-height: 48px; display: flex; align-items: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #111827;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.95rem;
  z-index: 10;
}

@media (max-width: 420px) {
  .player { padding: 8px; gap: 6px; }
  .pname { font-size: 0.92rem; }
  .dot { width: 8px; height: 8px; }
  .status { font-size: 1.05rem; }
  .card { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
