:root {
  --bg: #f0e4cf;
  --surface: rgba(255, 250, 239, .94);
  --text: #2e231a;
  --muted: #786c61;
  --accent: #7b4d25;
  --accent-2: #b88043;
  --border: #b99c76;
  --cell: #efe1c8;
  --cell-dark: #d4b98f;
  --shadow: 0 10px 28px rgba(57, 38, 20, .16);
  --yellow: #e6b92e;
  --green: #3b9b62;
  --blue: #3f75cc;
  --red: #c94a48;
}

body.theme-yard {
  --bg: #c8ccd0;
  --surface: rgba(247, 247, 244, .95);
  --text: #202428;
  --muted: #5f666b;
  --accent: #316b4d;
  --accent-2: #4f8e69;
  --border: #788087;
  --cell: #d7d9d9;
  --cell-dark: #aeb2b3;
  --shadow: 0 10px 26px rgba(25, 30, 32, .18);
}

body.theme-prison {
  --bg: #272927;
  --surface: rgba(55, 55, 50, .96);
  --text: #eee7d6;
  --muted: #b7b0a1;
  --accent: #a58a5a;
  --accent-2: #d0b276;
  --border: #777164;
  --cell: #68665d;
  --cell-dark: #474840;
  --shadow: 0 12px 30px rgba(0, 0, 0, .36);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, color-mix(in srgb, var(--bg), white 15%), var(--bg));
  color: var(--text);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.screen { min-height: 100vh; padding: 20px; }
.centered { width: min(440px, calc(100% - 32px)); min-height: auto; margin: 9vh auto; text-align: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 20px; }
.logo-mark { width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 14px; display: grid; place-items: center; font-size: 40px; font-weight: 900; color: white; background: var(--accent); transform: rotate(-4deg); }
.stack { display: grid; gap: 12px; }
input, select { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; padding: 12px 14px; outline: none; }
input:focus, select:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 72%); }
button { border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 750; }
button:disabled { opacity: .48; cursor: not-allowed; }
.primary { background: var(--accent); color: white; }
.secondary { background: var(--accent-2); color: #fff; }
.danger { background: #a92929; color: #fff; animation: pulse 1.2s infinite alternate; }
.ghost, .icon-btn { background: transparent; color: var(--text); border: 1px solid var(--border); }
.icon-btn { padding: 5px 9px; margin-left: 6px; }
@keyframes pulse { to { transform: scale(1.025); } }

.topbar { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.topbar select { width: auto; min-width: 160px; }
.topbar .muted { margin-left: 10px; }
.home-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; max-width: 1100px; margin: 7vh auto 0; }
.home-grid article { display: grid; gap: 13px; align-content: start; }
.rules-card details { border-top: 1px solid var(--border); padding-top: 10px; }
.room-code-wrap { display: flex; align-items: center; }

.game-layout { display: grid; grid-template-columns: minmax(210px, 270px) minmax(500px, 1fr) minmax(230px, 320px); gap: 16px; align-items: start; }
.side-panel, .actions-panel { position: sticky; top: 14px; max-height: calc(100vh - 100px); overflow: auto; }
.players-list { display: grid; gap: 8px; margin: 12px 0; }
.player-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 9px; padding: 9px; border-radius: 10px; background: color-mix(in srgb, var(--surface), var(--cell-dark) 22%); }
.player-row.current { outline: 2px solid var(--accent); }
.color-dot { width: 13px; height: 13px; border-radius: 50%; }
.turn-panel { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; display: grid; gap: 10px; }
.turn-title { font-weight: 850; }
.dice-row { display: flex; gap: 10px; min-height: 54px; }
.die { width: 54px; height: 54px; border-radius: 12px; background: #fff; color: #171717; border: 2px solid var(--border); display: grid; place-items: center; font-size: 27px; font-weight: 900; box-shadow: 0 5px 12px rgba(0,0,0,.12); }
.die.used { opacity: .35; filter: grayscale(1); }
.claim-countdown { text-align: center; font-weight: 800; color: #b32626; }

.board-area { position: relative; min-width: 0; }
.board { width: min(82vh, 820px, 100%); aspect-ratio: 1; margin: 0 auto; display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); gap: 2px; padding: 10px; background: color-mix(in srgb, var(--cell-dark), black 8%); border: 5px solid var(--accent); border-radius: 22px; box-shadow: var(--shadow); position: relative; }
.cell { position: relative; border-radius: 5px; background: var(--cell); border: 1px solid color-mix(in srgb, var(--border), transparent 15%); display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: visible; }
.cell.track::after { content: attr(data-number); position: absolute; top: 1px; left: 3px; font-size: clamp(6px, .7vw, 10px); opacity: .52; }
.cell.start-yellow { background: color-mix(in srgb, var(--yellow), white 38%); }
.cell.start-green { background: color-mix(in srgb, var(--green), white 42%); }
.cell.start-blue { background: color-mix(in srgb, var(--blue), white 42%); }
.cell.start-red { background: color-mix(in srgb, var(--red), white 42%); }
.cell.home-yellow { background: color-mix(in srgb, var(--yellow), white 36%); }
.cell.home-green { background: color-mix(in srgb, var(--green), white 40%); }
.cell.home-blue { background: color-mix(in srgb, var(--blue), white 40%); }
.cell.home-red { background: color-mix(in srgb, var(--red), white 40%); }
.cell.mast { background: repeating-linear-gradient(45deg, var(--cell-dark), var(--cell-dark) 5px, var(--cell) 5px, var(--cell) 10px); outline: 2px solid var(--accent); }
.cell.pocket { border-radius: 40%; background: var(--cell-dark); border: 2px dashed var(--accent); }
.cell.bur { background: #252525; color: white; border-radius: 50%; border: 3px solid #9a8360; font-size: clamp(8px, 1.2vw, 15px); font-weight: 900; }
.cell.center-arrow { background: transparent; border: 0; color: var(--accent); font-size: clamp(12px, 2vw, 25px); font-weight: 900; }
.pieces { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 1px; z-index: 3; width: 100%; height: 100%; padding: 3px; }
.piece { width: clamp(10px, 2.15vw, 24px); height: clamp(10px, 2.15vw, 24px); border-radius: 50% 50% 45% 45%; border: 2px solid rgba(255,255,255,.86); box-shadow: 0 2px 4px rgba(0,0,0,.35); display: grid; place-items: center; color: white; font-size: clamp(5px, .8vw, 10px); font-weight: 900; }
.piece.yellow { background: var(--yellow); color: #3a2c00; }
.piece.green { background: var(--green); }
.piece.blue { background: var(--blue); }
.piece.red { background: var(--red); }
.bases { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(82vh, 820px, 100%); margin: 10px auto 0; }
.base-box { border-radius: 12px; padding: 8px; background: var(--surface); border: 1px solid var(--border); min-height: 58px; }
.base-box strong { font-size: 12px; }
.base-pieces { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }

.actions { display: grid; gap: 8px; margin-bottom: 18px; }
.action-button { text-align: left; background: color-mix(in srgb, var(--surface), var(--accent) 12%); color: var(--text); border: 1px solid var(--border); }
.action-button:hover { transform: translateY(-1px); border-color: var(--accent); }
.events { display: grid; gap: 7px; font-size: 13px; }
.event { padding: 7px 8px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--surface), var(--cell-dark) 20%); border-radius: 5px; }
.toast { position: fixed; z-index: 999; left: 50%; top: 18px; transform: translateX(-50%); max-width: min(92vw, 560px); padding: 12px 18px; border-radius: 12px; color: white; background: #292929; box-shadow: var(--shadow); }

@media (max-width: 1100px) {
  .game-layout { grid-template-columns: 220px minmax(430px, 1fr); }
  .actions-panel { grid-column: 1 / -1; position: static; max-height: none; }
  .actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .screen { padding: 8px; }
  .home-grid, .game-layout { grid-template-columns: 1fr; }
  .home-grid { margin-top: 16px; }
  .side-panel, .actions-panel { position: static; max-height: none; }
  .board { width: 100%; padding: 5px; gap: 1px; border-width: 3px; border-radius: 14px; }
  .room-topbar { flex-wrap: wrap; }
  .room-topbar select { min-width: 130px; }
  .actions { grid-template-columns: 1fr; }
  .bases { grid-template-columns: repeat(2, 1fr); }
  .piece { border-width: 1px; }
}
