:root {
  --bg: #0d1020;
  --panel: #161a31;
  --cell: #1f2546;
  --cell-hover: #2a3160;
  --line: #2b3260;
  --text: #eef0ff;
  --muted: #9aa0c8;
  --p0: #f6a822;
  --p1: #2ec4b6;
  --p2: #ef476f;
  --p3: #a274f2;
  --accent: #f6a822;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 30% 20%, #1a1f42 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 90%, #241434 0%, transparent 60%),
    var(--bg);
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vw, 40px);
  padding: clamp(12px, 3vw, 32px);
}

#stage {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  --size: min(calc(100vh - 48px), calc(100vw - 360px), 640px);
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(var(--n, 7), 1fr);
  gap: calc(var(--size) / 90);
  padding: calc(var(--size) / 40);
  background: linear-gradient(160deg, #1b2042, #12162c);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.cell {
  position: relative;
  border: 0;
  border-radius: 22%;
  background: var(--cell);
  padding: 0;
  cursor: default;
  transition: background 120ms ease;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 180ms ease, transform 220ms cubic-bezier(.2, 1.4, .4, 1);
}

#board.playable .cell.empty { cursor: pointer; }
#board.playable .cell.empty:hover { background: var(--cell-hover); }
#board.playable .cell.empty:hover::after { opacity: 0.25; transform: scale(0.8); background: var(--me, #fff); }

.cell.p0::after, .cell.p1::after, .cell.p2::after, .cell.p3::after { opacity: 1; transform: scale(1); }
.cell.p0::after { background: radial-gradient(circle at 35% 30%, #fff3d0, var(--p0) 45%, #a8660a); box-shadow: 0 0 18px rgba(246, 168, 34, 0.55); }
.cell.p1::after { background: radial-gradient(circle at 35% 30%, #d6fffb, var(--p1) 45%, #157a71); box-shadow: 0 0 18px rgba(46, 196, 182, 0.55); }
.cell.p2::after { background: radial-gradient(circle at 35% 30%, #ffe0e8, var(--p2) 45%, #a01d43); box-shadow: 0 0 18px rgba(239, 71, 111, 0.55); }
.cell.p3::after { background: radial-gradient(circle at 35% 30%, #efe3ff, var(--p3) 45%, #5b2fa8); box-shadow: 0 0 18px rgba(162, 116, 242, 0.55); }

.cell.last { outline: 2px solid rgba(255, 255, 255, 0.35); outline-offset: -2px; }
.cell.win { background: #343c74; animation: glow 1.1s ease-in-out infinite alternate; }

@keyframes glow {
  from { box-shadow: 0 0 0 rgba(255, 255, 255, 0); }
  to { box-shadow: 0 0 22px rgba(255, 255, 255, 0.35); }
}

#panel {
  flex: 0 1 300px;
  min-width: 240px;
  max-width: 320px;
  background: rgba(22, 26, 49, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  max-height: 100%;
  overflow: auto;
}

h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--p0), var(--p2) 55%, var(--p3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 8px; }

.lede { margin: 6px 0 18px; color: var(--muted); }

button, select, input {
  font: inherit;
  color: var(--text);
  background: #262c55;
  border: 1px solid #343b70;
  border-radius: 10px;
  padding: 10px 14px;
}

button { cursor: pointer; transition: background 120ms ease, transform 80ms ease; }
button:hover:not(:disabled) { background: #30376a; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1b1300; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #ffb93d; }
button.ghost { background: transparent; }

.online, .local { display: flex; flex-direction: column; gap: 10px; }
.local { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.row { display: flex; gap: 10px; }
.row button { flex: 1; }
.join { display: flex; gap: 10px; margin: 0; }
.join input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.2em; font-weight: 600; }
.join input::placeholder { letter-spacing: normal; font-weight: 400; text-transform: none; color: var(--muted); }

.note { color: var(--muted); font-size: 14px; margin: 10px 0 0; word-break: break-all; }
.error { color: #ff8fa8; font-size: 14px; margin: 12px 0 0; }

.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.code { font-size: 28px; font-weight: 700; letter-spacing: 0.18em; }

.room-head[hidden] ~ .seats { margin-top: 0; }
.seats { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seats li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #1d2244;
  border: 1px solid transparent;
}
.seats li.turn { border-color: var(--seat); background: #252b55; }
.seats li.away { opacity: 0.5; }
.seats .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--seat); box-shadow: 0 0 10px var(--seat); flex: 0 0 auto; }
.seats .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seats .tag { font-size: 12px; color: var(--muted); }
.seats .score { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.status { margin: 18px 0 0; font-size: 18px; font-weight: 600; min-height: 1.4em; }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.wins ol { margin: 0; padding-left: 20px; color: var(--muted); }
.wins li { margin: 3px 0; }
.wins b { color: var(--text); font-weight: 600; }

@media (max-width: 720px), (max-aspect-ratio: 1/1) {
  html, body { overflow: auto; }
  #app { flex-direction: column; height: auto; min-height: 100%; }
  #board { --size: min(calc(100vw - 32px), 560px); }
  #panel { flex: none; width: min(100%, 560px); max-width: none; }
}
