:root {
  --bg: #1c0f33;
  --bg2: #2a1650;
  --card: #2f1b57;
  --line: #4b3380;
  --text: #f5f0ff;
  --muted: #b9a8dd;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --danger: #f87171;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 50% -10%, #3b1f6e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; flex-direction: column; align-items: center; padding: 16px; gap: 16px; }
.screen.active { display: flex; }
#screen-home, #screen-lobby { justify-content: center; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

/* ---------- Home ---------- */
.brand { text-align: center; }
.brand h1 { margin: 8px 0 0; font-size: clamp(28px, 8vw, 40px); letter-spacing: -.5px; line-height: 1.1; }
.brand h1 small { display: block; font-size: .5em; font-weight: 600; color: var(--accent2); letter-spacing: 3px; text-transform: uppercase; margin-top: 4px; }
.tagline { color: var(--muted); margin: 6px 0 0; }
.logo { width: 64px; height: 64px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; transform: rotate(45deg); }
.logo span { border-radius: 8px; }
.logo span:nth-child(1) { background: #22c55e; }
.logo span:nth-child(2) { background: #ef4444; }
.logo span:nth-child(3) { background: #facc15; }
.logo span:nth-child(4) { background: #3b82f6; }

label { display: block; font-weight: 600; margin: 0 0 6px; font-size: 14px; color: var(--muted); }
input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 92, 246, .3); }
textarea {
  width: 100%;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: vertical;
  word-break: break-all;
}
.btn.wide { width: 100%; margin-top: 10px; }
.overlay-card.export-card { max-width: 560px; text-align: left; }
.export-card h2 { text-align: left; }
.export-card textarea { margin: 6px 0 4px; }
#pin-input { letter-spacing: 6px; font-variant-numeric: tabular-nums; text-align: center; min-width: 0; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.join-box { margin-top: 18px; }
.join-box .row { flex-wrap: nowrap; }
.join-box .btn { flex: 0 0 auto; }

.btn {
  font: inherit;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: #3a2270; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); border-color: transparent; color: #fff; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #b79cfb, #7c4ef0); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: 14px; }

.error { color: var(--danger); min-height: 1.4em; margin: 12px 0 0; font-size: 14px; }
.error.info { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.resume-box { margin-top: 18px; padding: 12px; border-radius: 12px; background: rgba(139, 92, 246, .15); border: 1px solid var(--accent); }
.resume-box p { margin: 0 0 10px; }

/* ---------- Lobby ---------- */
.lobby { text-align: center; }
.lobby h2 { font-size: 16px; margin: 22px 0 10px; text-align: left; }
.lobby p { margin: 6px 0; }
.pin {
  font-size: clamp(40px, 13vw, 56px);
  font-weight: 800;
  letter-spacing: 10px;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 12px;
  padding-left: 10px;
  color: #fff;
  text-shadow: 0 0 24px rgba(167, 139, 250, .6);
}
.mode-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.mode.selected { border-color: var(--accent2); background: #3a2270; }
.mode:disabled { cursor: default; }
.mode:disabled:not(.selected) { opacity: .45; }
.shape { width: 40px; height: 40px; background: conic-gradient(#ef4444 0 25%, #3b82f6 0 50%, #facc15 0 75%, #22c55e 0); }
.shape-4 { border-radius: 4px; }
.shape-5 {
  background: conic-gradient(#ef4444 0 20%, #3b82f6 0 40%, #facc15 0 60%, #22c55e 0 80%, #f97316 0);
  clip-path: polygon(50% 0, 100% 38%, 81% 100%, 19% 100%, 0 38%);
}
.shape-6 {
  background: conic-gradient(#ef4444 0 16.6%, #3b82f6 0 33.3%, #facc15 0 50%, #22c55e 0 66.6%, #f97316 0 83.3%, #a855f7 0);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

.lobby-players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.lobby-players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.badge { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 2px 6px; border-radius: 6px; background: var(--line); }
.badge.host { background: #facc15; color: #422006; }
.badge.you { background: var(--accent); }
.badge.away { background: #64748b; }
.badge.rank { background: #facc15; color: #422006; }
.kick { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.kick:hover { color: var(--danger); background: rgba(248, 113, 113, .12); }
#btn-start { margin-top: 8px; min-width: 160px; }
#btn-leave-lobby { margin-top: 8px; }

/* ---------- Game ---------- */
/* ---------- Game: arena (players | board | chat) ---------- */
#screen-game { padding: 0; }
.arena { width: 100%; flex: 1; display: grid; grid-template-columns: 1fr; gap: 0; min-height: 100vh; min-height: 100dvh; }
.side-left, .side-right { background: #160b2b; display: flex; flex-direction: column; min-width: 0; }
/* Above the board: its big drop-shadow filter otherwise swallows touches meant for
   the sidebars (the players bar wouldn't swipe on the 5/6-player boards). */
.side-left, .side-right { position: relative; z-index: 5; }
.side-left { padding: 10px 8px; gap: 8px; }
.side-brand { font-weight: 800; font-size: 15px; padding: 2px 6px 4px; letter-spacing: -.2px; }
.side-brand small { display: block; font-size: 10px; color: var(--accent2); letter-spacing: 2.5px; text-transform: uppercase; }
.game-clock-wrap { display: flex; align-items: center; gap: 6px; padding: 2px 6px; color: var(--muted); font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.game-clock-wrap svg { width: 16px; height: 16px; }
.game-clock { color: var(--text); }
.game-clock.stopped { color: var(--muted); }
.pavatar-pic, .pavatar-pic .avatar-svg { width: 100%; height: 100%; display: block; border-radius: 9px; }
.players-handle { display: none; }
.side-actions { display: flex; margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); }
.icon-btn { flex: 1; display: grid; place-items: center; height: 52px; border: 0; background: transparent; color: var(--text); cursor: pointer; border-radius: 10px; }
.icon-btn:hover { background: rgba(255, 255, 255, .06); }
.icon-btn svg { width: 26px; height: 26px; }
#btn-sound .mute { display: none; }
#btn-sound.muted .waves { display: none; }
#btn-sound.muted .mute { display: inline; }
.arena-main { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px; min-width: 0; }

.game-layout { width: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.game-main { display: flex; flex-direction: column; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.player-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.player-panel h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
@media (min-width: 900px) {
  .game-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
  .game-layout .sb-side { position: sticky; top: 16px; }
  .game-layout .player-list { flex-direction: column; overflow: visible; }
  .game-layout .prow { width: auto; }
}

/* Player rows */
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.prow {
  --c: #888;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  border: 2px solid transparent;
  transition: border-color .25s, box-shadow .25s, background .25s;
}
.prow.active { border-color: #60a5fa; background: rgba(96, 165, 250, .08); box-shadow: 0 0 12px rgba(96, 165, 250, .35); }
.prow.away { opacity: .55; }
.pavatar { position: relative; flex: none; width: 46px; height: 46px; border-radius: 9px; overflow: visible; }
.pavatar .avatar-svg { width: 100%; height: 100%; display: block; border-radius: 9px; }
.crown { position: absolute; top: -7px; left: -5px; width: 18px; height: 13px; background: #facc15; clip-path: polygon(0 100%, 0 20%, 25% 55%, 50% 0, 75% 55%, 100% 20%, 100% 100%); filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .4)); }
.pinfo { flex: 1; min-width: 0; }
.prow-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.pawn-icon { width: 13px; height: 17px; flex: none; }
.prow .pname { font-size: 15px; font-weight: 800; }
.pct { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.pmeta { display: flex; flex-wrap: wrap; column-gap: 5px; row-gap: 0; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; min-width: 0; }
.pmeta b { color: var(--text); }
.pmeta .sep { opacity: .5; }
.pbar { height: 3px; margin-top: 5px; border-radius: 2px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--c); border-radius: 2px; transition: width .6s cubic-bezier(.2, .8, .3, 1); }
.prow .badge { flex: none; font-size: 10px; padding: 1px 5px; }

/* Board with seat overlays */
.board-wrap { position: relative; width: 100%; max-width: min(760px, calc(100vh - 220px)); min-width: 280px; container-type: inline-size; }
.seat-layer { position: absolute; inset: 0; pointer-events: none; }
.seat-avatar, .seat-die { position: absolute; transform: translate(-50%, -50%); }
.seat-avatar {
  --c: #888;
  width: calc(var(--cell) * 1.75);
  height: calc(var(--cell) * 1.75);
  border-radius: calc(var(--cell) * .3);
  padding: calc(var(--cell) * .09);
  background: #2a1650;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
  transition: transform .25s, box-shadow .25s;
}
.seat-pic, .seat-pic .avatar-svg { width: 100%; height: 100%; display: block; border-radius: calc(var(--cell) * .22); }
.seat-avatar.active { transform: translate(-50%, -50%) scale(1.08); box-shadow: 0 0 0 calc(var(--cell) * .05) var(--c), 0 0 calc(var(--cell) * .6) var(--c); }
.seat-avatar.away .seat-pic, .seat-avatar.afk .seat-pic { filter: grayscale(1) brightness(.7); }
.seat-avatar.afk::after { content: "afk"; position: absolute; left: 50%; bottom: calc(var(--cell) * -.25); transform: translateX(-50%); font: 800 calc(var(--cell) * .28)/1.4 system-ui, sans-serif; text-transform: uppercase; background: #f59e0b; color: #1f1235; padding: 0 .5em; border-radius: 999px; }
.afk-banner { background: #f59e0b; }
.seat-avatar.bot .seat-pic { filter: grayscale(.85) hue-rotate(180deg) brightness(.85); }
.seat-avatar.bot::after { content: "🤖 bot"; position: absolute; left: 50%; bottom: calc(var(--cell) * -.25); transform: translateX(-50%); font: 800 calc(var(--cell) * .28)/1.4 system-ui, sans-serif; text-transform: uppercase; white-space: nowrap; background: #38bdf8; color: #0c1a2b; padding: 0 .5em; border-radius: 999px; }
.badge.bot { background: #38bdf8; color: #0c1a2b; }
.badge.afk { background: #f59e0b; color: #1f1235; }
.bot-btn { position: absolute; right: -6px; bottom: -6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #160b2b; background: #2f1b57; cursor: pointer; font-size: 11px; line-height: 1; padding: 0; display: grid; place-items: center; transition: transform .15s, background .15s; }
.bot-btn:hover, .bot-btn:focus-visible { transform: scale(1.2); background: #38bdf8; }
.seat-avatar.away::after { content: "away"; position: absolute; left: 50%; bottom: calc(var(--cell) * -.25); transform: translateX(-50%); font: 800 calc(var(--cell) * .28)/1.4 system-ui, sans-serif; text-transform: uppercase; background: #64748b; color: #fff; padding: 0 .5em; border-radius: 999px; }
.ring { position: absolute; inset: calc(var(--cell) * -.08); width: calc(100% + var(--cell) * .16); height: calc(100% + var(--cell) * .16); overflow: visible; opacity: 0; }
.ring rect { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; }
.seat-avatar.timing .ring { opacity: 1; }
.seat-die { --die: calc(var(--cell) * 1.4); width: var(--die); height: var(--die); display: grid; place-items: center; pointer-events: auto; }
.seat-die .die.mini { position: relative; inset: auto; width: 78%; height: 78%; font-size: calc(var(--die) * .78); opacity: .55; }
.seat-die .dice { font-size: var(--die); }

.status-bar { width: 100%; max-width: 760px; text-align: center; min-height: 3em; }
.status-bar .turn-text { font-size: 17px; }
.status-bar .note-text { margin: 2px 0 0; }

/* Chat */
.side-right { padding: 10px; gap: 8px; max-height: 340px; }
.chat-head { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.chat-head .chat-count { margin-left: auto; }
.chat-unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 12px; line-height: 20px; text-align: center; }
.chat-chevron { display: none; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-135deg) translate(-2px, -2px); transition: transform .25s; }
.side-right.open .chat-chevron { transform: rotate(45deg); }
.chat-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
.chat-count { font-size: 13px; color: var(--muted); background: rgba(255, 255, 255, .06); padding: 3px 10px; border-radius: 999px; }
.chat-log { list-style: none; margin: 0; padding: 0 2px; flex: 1 1 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 5px; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; min-height: 120px; }
.chat-log .sys { color: var(--muted); font-weight: 600; }
.chat-log .sys b { color: var(--text); }
.chat-log .who { font-weight: 800; margin-right: 4px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { font-size: 14px; padding: 9px 12px; border-radius: 10px; }

@media (min-width: 1100px) {
  .arena { grid-template-columns: 230px minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
  /* Each column scrolls on its own: a long chat or many players never push the board. */
  .side-right { max-height: none; min-height: 0; overflow: hidden; }
  .side-right .chat-log { min-height: 0; }
  .side-left { min-height: 0; overflow: hidden; }
  .side-left .player-list { flex: 0 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
  .side-left .side-actions { flex: none; }
  .arena-main { justify-content: center; overflow: hidden; }
  .arena .board-wrap { width: auto; height: calc(100dvh - 120px); max-width: 100%; aspect-ratio: var(--board-ratio, 1); }
}
@media (max-width: 1099px) {
  .arena { grid-template-rows: auto 1fr; align-content: start; }
  .side-left { order: 0; }
  .arena-main { order: 1; }
  .side-right { order: 2; }
  /* Players bar: swipe sideways; pull the handle down to see everyone in a grid */
  .side-brand, .game-clock-wrap { display: inline-flex; }
  .side-left { display: block; padding: 8px 8px 0; }
  .side-brand { display: inline-block; vertical-align: middle; margin-right: 8px; }
  .game-clock-wrap { vertical-align: middle; background: rgba(255, 255, 255, .06); border-radius: 999px; padding: 3px 10px; }
  .player-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    margin-top: 8px;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    touch-action: pan-x;
  }
  .player-list::-webkit-scrollbar { display: none; }
  .player-list.more-right { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .player-list.more-left { -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%); mask-image: linear-gradient(90deg, transparent, #000 15%); }
  .player-list.more-left.more-right { -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); }
  .prow { flex: 0 0 auto; width: 192px; gap: 7px; padding: 6px 7px; background: rgba(255, 255, 255, .04); scroll-snap-align: start; }
  .prow .pavatar { width: 38px; height: 38px; }
  .prow .pname { font-size: 14px; }
  .pmeta { gap: 4px; font-size: 10.5px; }
  .side-left.expanded .player-list { flex-wrap: wrap; overflow: visible; touch-action: auto; -webkit-mask-image: none; mask-image: none; }
  .side-left.expanded .prow { width: calc(50% - 3px); }
  .players-handle {
    display: block;
    width: 100%;
    height: 22px;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: grab;
    touch-action: none;
  }
  .players-handle span { display: block; width: 44px; height: 5px; margin: 0 auto; border-radius: 3px; background: rgba(255, 255, 255, .3); transition: background .15s, width .15s; }
  .players-handle:hover span, .players-handle:focus-visible span { background: rgba(255, 255, 255, .55); width: 56px; }
  .side-actions { margin-top: 0; border-top: 0; position: absolute; top: 8px; right: 8px; }
  .side-left { position: relative; }
  .icon-btn { width: 40px; height: 36px; flex: none; }
  .icon-btn svg { width: 20px; height: 20px; }
  .arena-main { padding: 8px 6px; }
  .arena .board-wrap { max-width: min(760px, calc(100dvh - 190px)); }
  .seat-die { --die: calc(var(--cell) * 1.85); }   /* phones: bigger, easier to tap */

  /* Chat: a bar at the bottom, tap to slide it up over the board */
  #screen-game { padding-bottom: 56px; }
  .side-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: 52px;
    max-height: none;
    padding: 0 12px;
    border-radius: 16px 16px 0 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
    transition: height .25s ease;
    overflow: hidden;
  }
  .side-right.open { height: min(65dvh, 480px); padding-bottom: 10px; }
  .side-right:not(.open) .chat-log, .side-right:not(.open) .chat-form { display: none; }
  .chat-head { flex: none; height: 52px; cursor: pointer; user-select: none; }
  .chat-chevron { display: inline-block; }
  .toast { bottom: 68px; }
}

.dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--c); display: inline-block; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25); }

.pause-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 760px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #facc15;
  color: #422006;
  font-weight: 700;
}
.pause-banner p { margin: 0; flex: 1 1 200px; }
.pause-banner .btn { background: #422006; color: #fef9c3; border-color: transparent; }
.pause-icon { width: 14px; height: 16px; flex: none; border-left: 5px solid currentColor; border-right: 5px solid currentColor; }

.board { width: 100%; height: auto; display: block; overflow: visible; filter: drop-shadow(0 18px 40px rgba(0, 0, 0, .45)); }
.board.board-4 { border-radius: 2.2%; overflow: hidden; }
.board.board-4 .board-bg { stroke: none; }
.board-bg { fill: #ffffff; stroke: #1f1235; stroke-width: 1.2; stroke-linejoin: round; }
.wedge { stroke: rgba(0, 0, 0, .25); stroke-width: .3; }
.wedge-inner { stroke: rgba(0, 0, 0, .2); stroke-width: .3; }
.base.inactive { opacity: .4; filter: grayscale(.6); }
.spot { fill: rgba(0, 0, 0, .18); stroke: rgba(255, 255, 255, .15); stroke-width: .4; }
.cell { stroke: #c8c2d6; stroke-width: .35; }
.star { fill: #fff; stroke: rgba(0, 0, 0, .2); stroke-width: .3; pointer-events: none; }
.temp-star { pointer-events: none; animation: temp-star-in .35s ease-out; transform-box: fill-box; transform-origin: center; }
.temp-cell { opacity: .75; stroke: rgba(0, 0, 0, .25); stroke-width: .35; }
.temp-star-shape { stroke-width: .5; opacity: .95; }
@keyframes temp-star-in { from { transform: scale(.2); opacity: 0; } }
.arrow { stroke: rgba(0, 0, 0, .2); stroke-width: .2; pointer-events: none; }
.tri { stroke: #1f1235; stroke-width: .4; }
.center-outline { fill: none; stroke: #1f1235; stroke-width: .9; stroke-linejoin: round; }

.token { transition: transform .14s ease-out; cursor: default; }
.token-inner { transform-box: fill-box; transform-origin: 50% 100%; }
/* path preview */
.preview { pointer-events: none; }
.preview-line { fill: none; stroke-width: .9; stroke-dasharray: 1.4 1.4; stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.preview-dot { stroke: #fff; stroke-width: .4; animation: dot-in .25s ease-out backwards; transform-box: fill-box; transform-origin: center; }
@keyframes dot-in { from { transform: scale(0); opacity: 0; } }
.preview-target { fill: rgba(255, 255, 255, .55); stroke-width: .9; stroke-dasharray: 2 1.2; animation: target-spin 3s linear infinite, target-pulse .9s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.preview-target.capture { fill: rgba(220, 38, 38, .25); stroke-width: 1.2; }
@keyframes target-spin { to { rotate: 360deg; } }
@keyframes target-pulse { from { scale: .9; } to { scale: 1.08; } }
.preview-ghost { opacity: .45; }
.token.threatened .pawn-hop { animation: threatened .35s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes threatened { from { transform: rotate(-9deg); } to { transform: rotate(9deg); } }
.pawn-shadow { fill: rgba(0, 0, 0, .35); transform-box: fill-box; transform-origin: center; }
.pawn-hop { transform-box: fill-box; transform-origin: 50% 100%; }
.token.knocked .pawn-hop { animation: knocked .75s ease-in-out; transform-origin: center; }
@keyframes knocked {
  0% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-25deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}
.pawn-halo { fill: none; stroke: #fff; stroke-width: .7; opacity: 0; }
.pawn-gloss { fill: #fff; opacity: .75; pointer-events: none; }
.token.movable { cursor: pointer; }
.token.movable .pawn-halo { opacity: 1; animation: halo .7s ease-in-out infinite alternate; }
.token.movable .token-inner { animation: bob .7s ease-in-out infinite alternate; }
@keyframes halo { from { stroke-width: .5; opacity: .5; } to { stroke-width: 1.1; opacity: 1; } }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-1.6px); } }

.controls { display: flex; align-items: center; gap: 16px; width: 100%; max-width: 520px; }
.status { flex: 1; min-width: 0; }
.turn-text { margin: 0; font-weight: 800; font-size: 18px; }
.note-text { margin: 2px 0 6px; font-size: 14px; min-height: 1.4em; }
.timer { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .1); overflow: hidden; }
#timer-bar { height: 100%; width: 0; border-radius: 3px; }

/* Dice: a flat face; JS flicks through faces while it's thrown. */
.dice {
  --c: #888;
  --size: .74em;
  font-size: 84px; /* everything below scales with this */
  flex: none;
  width: 1em;
  height: 1em;
  padding: 0;
  border: 0;
  background: none;
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dice:disabled { cursor: default; }
.dice:focus-visible { outline: 2px solid var(--accent2); outline-offset: 4px; border-radius: 16px; }
.dice-shadow {
  position: absolute;
  left: 50%;
  bottom: .02em;
  width: .64em;
  height: .12em;
  margin-left: -.32em;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  filter: blur(.035em);
}
.dice-jump { position: absolute; left: 50%; top: 50%; width: var(--size); height: var(--size); margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2); }
.die {
  position: absolute;
  inset: 0;
  padding: .11em;
  border-radius: .17em;
  background: radial-gradient(circle at 30% 25%, #ffffff, #ece8f4 70%, #d6d0e4);
  border: max(2px, .036em) solid var(--c);
  box-shadow: inset 0 -.05em 0 rgba(0, 0, 0, .12), 0 .05em 0 rgba(0, 0, 0, .25);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  transition: border-color .3s;
}
.pip { width: .13em; height: .13em; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #4b3a6b, #1f1235); visibility: hidden; }
.die[data-value="1"] .pip:nth-child(5),
.die[data-value="2"] .pip:nth-child(3), .die[data-value="2"] .pip:nth-child(7),
.die[data-value="3"] .pip:nth-child(3), .die[data-value="3"] .pip:nth-child(5), .die[data-value="3"] .pip:nth-child(7),
.die[data-value="4"] .pip:nth-child(1), .die[data-value="4"] .pip:nth-child(3), .die[data-value="4"] .pip:nth-child(7), .die[data-value="4"] .pip:nth-child(9),
.die[data-value="5"] .pip:nth-child(1), .die[data-value="5"] .pip:nth-child(3), .die[data-value="5"] .pip:nth-child(5), .die[data-value="5"] .pip:nth-child(7), .die[data-value="5"] .pip:nth-child(9),
.die[data-value="6"] .pip:nth-child(1), .die[data-value="6"] .pip:nth-child(3), .die[data-value="6"] .pip:nth-child(4), .die[data-value="6"] .pip:nth-child(6), .die[data-value="6"] .pip:nth-child(7), .die[data-value="6"] .pip:nth-child(9) { visibility: visible; }
.die[data-value="1"] .pip:nth-child(5) { width: .2em; height: .2em; background: radial-gradient(circle at 35% 30%, #f87171, #b91c1c); }

/* your turn: the dice breathes and glows in your color */
.dice.ready .dice-jump { animation: ready 1.1s ease-in-out infinite; }
.dice.ready .die { box-shadow: inset 0 -.05em 0 rgba(0, 0, 0, .12), 0 .05em 0 rgba(0, 0, 0, .25), 0 0 .22em var(--c); }
.dice.ready:hover .dice-jump { animation-play-state: paused; transform: translateY(-.05em) scale(1.05); }
@keyframes ready { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-.06em) scale(1.04); } }

/* the throw: up, bounce, settle */
.dice.rolling .dice-jump { animation: throw var(--roll, .65s) cubic-bezier(.3, .6, .4, 1); }
.dice.rolling .dice-shadow { animation: throw-shadow var(--roll, .65s) cubic-bezier(.3, .6, .4, 1); }
@keyframes throw {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-.55em) scale(1.12); }
  58% { transform: translateY(0) scale(1); }
  72% { transform: translateY(-.14em) scale(1.03); }
  86% { transform: translateY(0) scale(1); }
  93% { transform: translateY(-.04em); }
  100% { transform: translateY(0); }
}
@keyframes throw-shadow {
  0%, 58%, 86%, 100% { transform: scale(1); opacity: 1; }
  30% { transform: scale(.45); opacity: .35; }
  72% { transform: scale(.8); opacity: .75; }
}
.dice.rolling .die { animation: tumble var(--roll, .65s) cubic-bezier(.2, .7, .3, 1); }
@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  30% { transform: rotate(400deg) scale(.9, 1.05); }
  58% { transform: rotate(640deg) scale(1.1, .88); }
  72% { transform: rotate(700deg) scale(1); }
  86% { transform: rotate(714deg) scale(1.05, .95); }
  100% { transform: rotate(720deg) scale(1); }
}
.dice.landed .die { animation: land-flash .5s ease-out; }
@keyframes land-flash { from { box-shadow: inset 0 -.05em 0 rgba(0, 0, 0, .12), 0 .05em 0 rgba(0, 0, 0, .25), 0 0 0 0 var(--c); } to { box-shadow: inset 0 -.05em 0 rgba(0, 0, 0, .12), 0 .05em 0 rgba(0, 0, 0, .25), 0 0 0 .2em transparent; } }

.leave-game { margin-top: auto; }

/* ---------- Overlay / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 4, 22, .7); display: grid; place-items: center; padding: 16px; z-index: 10; backdrop-filter: blur(3px); }
.overlay-card { text-align: center; }
.overlay-card h2 { margin-top: 0; }
#overlay-sub { margin: -6px 0 14px; }
#overlay-sub:empty { display: none; }
.overlay-card:has(.scoreboard) { max-width: 640px; }
.overlay-board { overflow-x: auto; margin: 0 -6px; }
.overlay-board:empty { display: none; }
.scoreboard { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-variant-numeric: tabular-nums; }
.scoreboard th { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 800; padding: 0 8px; text-align: center; }
.scoreboard th:nth-child(2) { text-align: left; }
.scoreboard td { background: var(--bg); padding: 8px; text-align: center; font-weight: 700; white-space: nowrap; }
.scoreboard td:first-child { border-radius: 10px 0 0 10px; font-size: 18px; width: 36px; box-shadow: inset 4px 0 0 var(--c); }
.scoreboard td:last-child { border-radius: 0 10px 10px 0; }
.scoreboard tr.winner td { background: rgba(250, 204, 21, .14); }
.scoreboard td:nth-child(2) { text-align: left; }
.sb-player { display: flex; align-items: center; gap: 6px; }
.score-face { flex: none; width: 34px; height: 34px; margin-right: 2px; }
.score-face .avatar-svg { width: 100%; height: 100%; display: block; border-radius: 7px; }
.sb-name { display: inline-block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 30px);
  background: #fff;
  color: #1f1235;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .token, .token.moving { transition: none; }
  .token.movable .token-inner, .token.movable .pawn-halo, .dice.ready .dice-jump, .dice.rolling .dice-jump, .token.knocked .pawn-hop { animation: none; }
  .dice.rolling .die { animation: none; }
}

/* ---------- Sandbox (/test) ---------- */

/* ---------- Mobile game-over scoreboard ---------- */
@media (max-width: 600px) {
  #overlay {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    overflow-y: auto;
    place-items: center;
  }
  .overlay-card:has(.scoreboard) {
    width: 100%;
    max-width: 480px;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 20px 14px 16px;
    border-radius: 22px;
    text-align: left;
    overscroll-behavior: contain;
  }
  .overlay-card:has(.scoreboard) h2 {
    margin: 0;
    text-align: center;
    font-size: 26px;
    letter-spacing: -.5px;
  }
  .overlay-card:has(.scoreboard) #overlay-sub {
    margin: 4px 0 16px;
    text-align: center;
    font-size: 12px;
  }
  .overlay-board {
    overflow: visible;
    margin: 0;
  }
  .scoreboard {
    display: block;
    width: 100%;
    border-spacing: 0;
  }
  .scoreboard thead { display: none; }
  .scoreboard tbody {
    display: grid;
    gap: 9px;
  }
  .scoreboard tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg);
  }
  .scoreboard td {
    min-width: 0;
    padding: 7px 3px 9px;
    background: transparent;
    white-space: normal;
    font-size: 13px;
    line-height: 1.2;
  }
  .scoreboard td:first-child {
    grid-column: 1;
    grid-row: 1;
    width: auto;
    border-radius: 0;
    box-shadow: none;
    align-self: center;
    font-size: 17px;
  }
  .scoreboard td:nth-child(2) {
    grid-column: 2 / 5;
    grid-row: 1;
    min-width: 0;
    padding: 9px 8px 7px 2px;
    text-align: left;
  }
  .sb-player { gap: 7px; min-width: 0; }
  .score-face { width: 32px; height: 32px; }
  .sb-name { max-width: none; min-width: 0; font-size: 14px; }
  .scoreboard td:nth-child(n+3) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-top: 1px solid var(--line);
    font-size: 14px;
  }
  .scoreboard td:nth-child(n+3)::before {
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .7px;
    text-transform: uppercase;
  }
  .scoreboard td:nth-child(3)::before { content: "Time"; }
  .scoreboard td:nth-child(4)::before { content: "Captures"; }
  .scoreboard td:nth-child(5)::before { content: "Captured"; }
  .scoreboard td:nth-child(6)::before { content: "Sixes"; }
  .scoreboard tr.winner {
    border-color: rgba(250, 204, 21, .5);
    box-shadow: 0 0 0 1px rgba(250, 204, 21, .08);
  }
  .scoreboard tr.winner td { background: rgba(250, 204, 21, .08); }
  .overlay-card:has(.scoreboard) #overlay-text {
    margin: 12px 0;
    text-align: center;
    font-size: 13px;
  }
  .overlay-card:has(.scoreboard) .row.center {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
  }
  .overlay-card:has(.scoreboard) .row.center .btn {
    min-width: 0;
    padding: 11px 8px;
    font-size: 13px;
  }
  .overlay-card:has(.scoreboard) #btn-home {
    grid-column: 1 / -1;
  }
}

.sb-header { width: 100%; max-width: 1180px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sb-header h1 { margin: 0; font-size: 22px; }
.sb-header h1 small { color: var(--accent2); font-size: .6em; letter-spacing: 2px; text-transform: uppercase; margin-left: 6px; }
.sb-side { display: flex; flex-direction: column; gap: 12px; }
.sb-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.sb-card h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
.sb-field { margin-bottom: 12px; }
.sb-field:last-child { margin-bottom: 0; }
.sb-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg-btn { font: inherit; font-weight: 700; min-width: 40px; padding: 6px 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.seg-btn.selected { border-color: var(--accent2); background: #3a2270; }
.sb-toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: center; width: 100%; }
.sb-inline { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; color: var(--muted); }
.sb-inline select { font: inherit; font-weight: 700; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.sb-toggle { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; color: var(--text); cursor: pointer; }
.sb-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.sb-hint { margin: 0; padding: 8px 12px; border-radius: 10px; background: rgba(34, 211, 238, .15); border: 1px solid #22d3ee; color: #cffafe; font-size: 14px; max-width: 760px; }
.sb-faces { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sb-face { min-width: 38px; padding: 6px 0; }
.sb-log-card { width: 100%; max-width: 760px; }
.sb-code-actions { margin-top: 8px; }
.sb-log { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow: auto; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.sb-log li:first-child { color: var(--text); }
.board.placing .token { pointer-events: none; }
.board.placing .cell, .board.placing .base, .board.placing .tri { cursor: crosshair; }
.token.selected .pawn-halo { opacity: 1; stroke: #22d3ee; stroke-width: 1.2; }
