:root {
  --bg: #0f1724;
  --card: #182233;
  --ink: #f4f7fb;
  --muted: #9aa8bc;
  --line: #2a3a51;
  --red: #ef4444;
  --green: #22c55e;
  --yellow: #eab308;
  --blue: #3b82f6;
  --path: #f7f4ea;
  --safe: #fff7cc;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at top, #1e2d45, var(--bg) 55%);
  color: var(--ink);
}

.hidden { display: none !important; }
#app { min-height: 100dvh; }

.screen {
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.setup-card {
  width: min(460px, 100%);
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.brand-icon { width: 64px; height: 64px; border-radius: 16px; }
.brand h1 { margin: 0; font-size: 2rem; letter-spacing: 0.04em; }
.brand p { margin: 4px 0 0; color: var(--muted); }

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field > span { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #101926;
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 1rem;
}
input:focus { outline: 2px solid #4f8cff; }

.color-picks, .segmented, .other-names { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick, .segmented button {
  border: 0;
  cursor: pointer;
  border-radius: 14px;
}
.color-pick {
  width: 54px;
  height: 54px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.18);
}
.color-pick.active { outline: 3px solid #fff; outline-offset: 2px; }
.color-pick[data-color="red"] { background: var(--red); }
.color-pick[data-color="green"] { background: var(--green); }
.color-pick[data-color="yellow"] { background: var(--yellow); }
.color-pick[data-color="blue"] { background: var(--blue); }

.segmented button {
  flex: 1;
  min-width: 56px;
  padding: 11px 10px;
  background: #101926;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
}
.segmented button.active { background: #2554d6; border-color: #2554d6; }

.other-names { display: grid; }
.other-names .field { margin-bottom: 8px; }

.remote-box {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 8px;
}
.check {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 12px;
}
.split-actions { display: flex; gap: 8px; }
.split-actions .primary { margin-top: 0; }
.split-actions .ghost { margin-top: 0; }
.hint { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.auth-form { margin-top: 16px; }
.auth-error { color: #fda4a4; font-size: 0.9rem; }
.account-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #101926;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.account-bar .ghost { width: auto; margin: 0; padding: 8px 12px; }
#account-kind { display: block; margin-top: 2px; }
.lobby-players { display: grid; gap: 8px; margin: 16px 0; }
.lobby-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #101926;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.online-banner {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.icon-btn.live { box-shadow: 0 0 0 2px #22c55e; }
.icon-btn.muted { opacity: 0.55; }
.talking { box-shadow: 0 0 0 2px #22c55e; }

.primary, .ghost {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.primary { background: linear-gradient(180deg, #3d7bff, #2554d6); color: #fff; margin-top: 8px; }
.ghost { margin-top: 10px; background: transparent; color: var(--ink); border: 1px solid var(--line); }

#game {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}
#game.hidden { display: none !important; }

.game-bar, .player-strip, .game-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}
.game-bar { justify-content: space-between; }
.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 1.2rem;
  cursor: pointer;
}
.turn-status {
  flex: 1;
  text-align: center;
  font-weight: 700;
}

.player-strip { justify-content: center; flex-wrap: wrap; }
.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.player-chip.current { box-shadow: 0 0 0 2px #fff; animation: turnglow 1.2s ease-in-out infinite; }
.player-chip.mine { outline: 1px dashed #9aa8bc; }
.player-chip.offline { opacity: 0.55; }
.player-chip .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}
.presence {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}
.presence.on { background: #22c55e; }
.player-chip .homes { color: var(--muted); }
@keyframes turnglow {
  50% { box-shadow: 0 0 0 3px #fde047; }
}

.board-wrap { display: grid; place-items: center; flex: 1; }
.board {
  --size: min(92vw, 68vh, 560px);
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  background: #1b140f;
  border: 6px solid #1b140f;
  border-radius: 18px;
  position: relative;
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
}
.cell.path { background: var(--path); }
.cell.yard-red { background: var(--red); }
.cell.yard-green { background: var(--green); }
.cell.yard-yellow { background: var(--yellow); }
.cell.yard-blue { background: var(--blue); }
.cell.yard-inner { filter: brightness(1.12); }
.cell.home-red { background: #fca5a5; }
.cell.home-green { background: #86efac; }
.cell.home-yellow { background: #fde047; }
.cell.home-blue { background: #93c5fd; }
.cell.start-red { background: var(--red); }
.cell.start-green { background: var(--green); }
.cell.start-yellow { background: var(--yellow); }
.cell.start-blue { background: var(--blue); }
.cell.star::after {
  content: "★";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.7em;
  color: #b45309;
  pointer-events: none;
}
.cell.center { background: #fff; }
.cell.center-red { background: var(--red); }
.cell.center-green { background: var(--green); }
.cell.center-yellow { background: var(--yellow); }
.cell.center-blue { background: var(--blue); }

.yard-spot {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.08);
}

.token {
  position: absolute;
  width: 68%;
  height: 68%;
  left: 16%;
  top: 16%;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  z-index: 3;
  cursor: default;
  transition: transform 0.15s ease;
}
.token.stacked { transform: translate(12%, -12%); }
.token.movable {
  cursor: pointer;
  animation: pulse 0.9s ease-in-out infinite;
}
.token.walking { z-index: 6; animation: hop 0.12s ease; }
.cell.preview {
  box-shadow: inset 0 0 0 2px #2554d6;
}
.token.red { background: radial-gradient(circle at 30% 30%, #fda4a4, var(--red)); }
.token.green { background: radial-gradient(circle at 30% 30%, #86efac, var(--green)); }
.token.yellow { background: radial-gradient(circle at 30% 30%, #fde68a, var(--yellow)); }
.token.blue { background: radial-gradient(circle at 30% 30%, #93c5fd, var(--blue)); }

@keyframes pulse {
  50% { transform: scale(1.18); }
}

.game-footer { justify-content: space-between; }
.message {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  min-height: 64px;
  display: grid;
  align-items: center;
}
.dice {
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: #111;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 8px;
}
.dice:disabled { opacity: 0.55; cursor: default; }
.dice.your-turn:not(:disabled) { animation: turnglow 1s ease-in-out infinite; }
.dice.rolling .dice-face { animation: shake 0.45s linear; }
.dice-face {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
}
.pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #111;
  margin: auto;
}
@keyframes shake {
  25% { transform: rotate(-18deg); }
  50% { transform: rotate(16deg); }
  75% { transform: rotate(-10deg); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 16, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal-card {
  width: min(380px, 100%);
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  border: 1px solid var(--line);
}
.modal-card h2 { margin-top: 0; }

.link-btn {
  display: grid;
  place-items: center;
  text-decoration: none;
  text-align: center;
}
.chat-box {
  margin: 12px 0;
  background: #101926;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.chat-log {
  max-height: 140px;
  overflow: auto;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
}
.chat-line .who { color: var(--muted); font-weight: 700; margin-right: 6px; }
.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.chat-form input { flex: 1; margin: 0; }
.chat-form button {
  border: 0;
  border-radius: 12px;
  background: #2554d6;
  color: #fff;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
}
.game-chat { margin: 0; }
.turn-status.yours { color: #fde047; }
@keyframes hop {
  50% { transform: translateY(-18%); }
}

@media (max-width: 420px) {
  .setup-card { padding: 18px; }
  .brand-icon { width: 52px; height: 52px; }
  .dice { width: 64px; height: 64px; }
}
