:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --card2: #273549;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --board: #1d4ed8;
  --board-dark: #1e40af;
  --hole: #0f172a;
  --p1: #ef4444;
  --p2: #facc15;
  --p3: #3b82f6;
  --p4: #22c55e;
  --danger: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, #1e293b 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

#app { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 1em; }

/* ---------- connection dot ---------- */
#conn-dot {
  position: fixed; top: 10px; right: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #475569; z-index: 50; transition: background 0.3s;
}
#conn-dot.on { background: var(--p4); box-shadow: 0 0 8px var(--p4); }
#conn-dot.off { background: var(--p2); box-shadow: 0 0 8px var(--p2); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600;
  color: var(--text);
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
  border-color: #0369a1;
}
.btn.big { padding: 14px 28px; font-size: 17px; border-radius: 12px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #7f1d1d; }

/* ---------- lobby ---------- */
.logo {
  font-size: 44px; font-weight: 800; text-align: center; letter-spacing: -1px;
  margin-top: 40px;
}
.logo span { color: var(--accent); }
.tagline { text-align: center; color: var(--muted); margin: 8px 0 28px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type="text"] {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

.lobby-actions { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.lobby-actions .btn.primary { flex: 1 1 180px; }
.join-box { display: flex; gap: 8px; flex: 1 1 220px; }
.join-box input {
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 700;
  text-align: center;
  flex: 1 1 0;
  min-width: 0;
}
.hint { text-align: center; font-size: 13px; margin-top: 18px; line-height: 1.5; }

/* ---------- room top ---------- */
.room-top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.code-box { display: flex; align-items: center; gap: 14px; }
.code-row { display: flex; align-items: center; gap: 10px; }
.code {
  font-size: 34px; font-weight: 800; letter-spacing: 8px;
  color: var(--accent); font-family: ui-monospace, monospace;
}
.room-top-right { display: flex; align-items: center; gap: 10px; }
.you-badge { font-size: 13px; color: var(--muted); }
.you-badge b { color: var(--text); }

/* ---------- players ---------- */
.players { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.player-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  flex: 1 1 150px;
  min-width: 140px;
}
.player-chip.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,0.35); }
.player-chip.host .host-tag { display: inline-block; }
.host-tag {
  display: none; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: #0b1220;
  background: var(--accent); border-radius: 6px; padding: 2px 6px;
}
.player-chip .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-chip .dot {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.3), inset 0 3px 6px rgba(255,255,255,0.25);
}
.player-chip .conn { font-size: 11px; margin-left: auto; color: var(--muted); }
.player-chip .conn.off { color: var(--danger); }

/* ---------- waiting ---------- */
#waiting-actions { text-align: center; padding: 12px 0 8px; }

/* ---------- board ---------- */
#board-wrap { position: relative; }

#turn-bar-wrap {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
#turn-bar {
  flex: 1; height: 8px; border-radius: 99px;
  background: var(--card2); overflow: hidden;
}
#turn-fill {
  height: 100%; width: 100%;
  border-radius: 99px;
  transition: width 0.25s linear, background 0.3s;
}
#turn-label { font-size: 13px; white-space: nowrap; min-width: 110px; text-align: right; }

#board {
  position: relative;
  display: flex;
  gap: 6px;
  background: linear-gradient(180deg, var(--board) 0%, var(--board-dark) 100%);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45), inset 0 2px 0 rgba(255,255,255,0.15);
}

.col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 99px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.col:hover { background: rgba(255,255,255,0.07); }
.col.disabled { cursor: default; }
.col.disabled:hover { background: transparent; }

.cell {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--hole);
  box-shadow: inset 0 4px 8px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.12);
  transition: background 0.12s;
}
.cell.p1 { background: radial-gradient(circle at 35% 30%, #f87171, var(--p1) 55%, #b91c1c); box-shadow: inset 0 -4px 8px rgba(0,0,0,0.35); }
.cell.p2 { background: radial-gradient(circle at 35% 30%, #fde68a, var(--p2) 55%, #ca8a04); box-shadow: inset 0 -4px 8px rgba(0,0,0,0.35); }
.cell.p3 { background: radial-gradient(circle at 35% 30%, #93c5fd, var(--p3) 55%, #1d4ed8); box-shadow: inset 0 -4px 8px rgba(0,0,0,0.35); }
.cell.p4 { background: radial-gradient(circle at 35% 30%, #86efac, var(--p4) 55%, #15803d); box-shadow: inset 0 -4px 8px rgba(0,0,0,0.35); }
.cell.ghost { opacity: 0.45; }
.cell.winline {
  animation: winpulse 0.8s ease-in-out infinite alternate;
}
@keyframes winpulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.6); }
}

/* ---------- finished overlay ---------- */
#finished-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, 0.72);
  border-radius: 18px;
  backdrop-filter: blur(3px);
  z-index: 5;
}
.overlay-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  max-width: 90%;
}
#winner-text { font-size: 30px; font-weight: 800; margin-bottom: 6px; }
#winner-text .win-dot {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  vertical-align: -2px; margin-right: 8px;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.3);
}
#overlay-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: center; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  max-width: 90vw;
  animation: toastin 0.2s ease-out;
}
#toast.err { border-color: #7f1d1d; color: #fecaca; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 560px) {
  .code { font-size: 26px; letter-spacing: 5px; }
  #app { padding-top: 12px; }
  .logo { font-size: 34px; margin-top: 20px; }
  .player-chip { flex: 1 1 100%; }
}
