:root {
  color-scheme: light;
  --bg: #f3ede2;
  --paper: #fffdf8;
  --line: #e4dccd;
  --fg: #2a2520;
  --muted: #7a7064;
  --accent: #e2574c;
  --road: #e8dfcf;
  font-family: ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); line-height: 1.45; min-height: 100vh; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
button {
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 14px; cursor: pointer;
  transition: transform .1s, background .15s, border-color .15s;
}
button:hover:not(:disabled) { border-color: #cbbfa8; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #cf4439; border-color: #cf4439; }
input { background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 12px; width: 100%; min-width: 0; }
input:focus { outline: 2px solid #f0a097; outline-offset: -1px; }
kbd { font: 11px ui-monospace, monospace; opacity: .7; margin-left: 6px; }
.ghost { color: var(--muted); text-decoration: none; font-size: .9rem; }

/* Landing */
.landing { max-width: 580px; margin: 0 auto; padding: clamp(32px, 8vh, 90px) 16px 64px; }
.home { color: var(--muted); text-decoration: none; font-size: .9rem; }
.landing h1 { font-size: clamp(2.4rem, 8vw, 3.4rem); letter-spacing: -.03em; margin: 10px 0 6px; }
.lede { color: var(--muted); font-size: 1.08rem; margin: 0 0 28px; }
.card { background: var(--paper); border: 1.5px solid var(--line); border-radius: 18px; padding: 20px; display: grid; gap: 10px; }
.card label { font-size: .85rem; color: var(--muted); }
.card .primary { padding: 12px; font-size: 1.05rem; }
.hint { margin: 0; font-size: .85rem; color: var(--muted); }
.join { display: flex; gap: 8px; margin: 14px 0 36px; }
.how h2 { font-size: 1rem; margin: 0 0 8px; }
.how ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; color: #4a4239; }

/* Game layout */
.game {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start;
  max-width: 1400px; margin: 0 auto; padding: 16px;
}
.board-wrap { position: relative; background: #dcebd3; border-radius: 22px; padding: 10px; box-shadow: inset 0 0 0 2px #c9dcbf; }
#board { display: block; width: 100%; height: auto; }
#board .sp { cursor: default; }
#board .sp circle { transition: r .2s; }
#board .token { transition: transform .2s ease-in-out; }
#board .token.active circle { stroke: #2a2520; stroke-width: 3.5; }
#board .label { font-size: 13px; font-weight: 700; fill: #3b342c; paint-order: stroke; stroke: #dcebd3; stroke-width: 4px; }
#board .lane-label { font-size: 12px; font-weight: 700; fill: #5a6b52; paint-order: stroke; stroke: #dcebd3; stroke-width: 4px; }

.event-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 32px)); background: var(--paper); border-radius: 20px; padding: 20px 22px;
  box-shadow: 0 18px 50px rgba(60, 40, 20, .25), 0 0 0 3px var(--who, var(--accent)); text-align: center; cursor: pointer;
  animation: pop .28s cubic-bezier(.2, 1.4, .4, 1);
}
.event-card .emoji { font-size: 44px; line-height: 1.1; }
.event-card h3 { margin: 6px 0 8px; font-size: 1.1rem; }
.event-card p { margin: 3px 0; color: #4a4239; font-size: .93rem; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }

.panel {
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 20px; padding: 16px;
  display: grid; gap: 14px; position: sticky; top: calc(16px + env(safe-area-inset-top, 0px));
  max-height: calc(100vh - 32px); overflow-y: auto;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.title { font-weight: 800; font-size: 1.25rem; color: var(--fg); text-decoration: none; letter-spacing: -.02em; }
.conn { font-size: .75rem; color: var(--muted); }
.conn.bad { color: #d9822b; }

.players { display: grid; gap: 8px; }
.player { border: 1.5px solid var(--line); border-radius: 14px; padding: 9px 11px; display: grid; gap: 3px; font-size: .88rem; background: #fff; }
.player.active { border-color: var(--seat); box-shadow: 0 0 0 2px var(--seat) inset; }
.player .top { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .95rem; }
.player .chip { width: 14px; height: 14px; border-radius: 50%; background: var(--seat); border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--seat); flex: none; }
.player .money { margin-left: auto; font-variant-numeric: tabular-nums; }
.player .sub { color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.player .you { color: var(--muted); font-weight: 400; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #c9c0b1; flex: none; }
.dot.on { background: #2fb36d; }

.action { background: #faf5ec; border-radius: 16px; padding: 12px; display: grid; gap: 10px; }
.spinner-row { display: flex; gap: 12px; align-items: center; }
#spinner { width: 104px; height: 111px; flex: none; }
#spinner .wheel { transition: transform 1.7s cubic-bezier(.15, .7, .15, 1); }
.action-main { display: grid; gap: 8px; flex: 1; min-width: 0; }
.prompt { margin: 0; font-size: .95rem; }
.prompt b { font-weight: 700; }
.options { display: grid; gap: 8px; }
.options:empty { display: none; }
.opt {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 4px 10px; text-align: left; padding: 10px 12px; background: #fff;
}
.opt .e { font-size: 24px; grid-row: span 2; text-align: center; }
.opt .l { font-weight: 700; }
.opt .c { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.opt .d { grid-column: 2 / 4; color: var(--muted); font-size: .84rem; }
.opt:not(:disabled):hover { border-color: var(--accent); }

.invite { display: flex; gap: 8px; }
.invite input { font-size: .85rem; color: var(--muted); }

.results table { width: 100%; border-collapse: collapse; font-size: .86rem; font-variant-numeric: tabular-nums; }
.results th, .results td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--muted); font-weight: 600; font-size: .78rem; }
.results .win td { font-weight: 800; }
.results .banner { font-size: 1.3rem; font-weight: 800; margin: 0 0 8px; }

.log-wrap h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .86rem; color: #4a4239; max-height: 220px; overflow-y: auto; }
.log li:first-child { color: var(--fg); font-weight: 600; }
.you-row { display: grid; gap: 6px; }
.you-row label { font-size: .8rem; color: var(--muted); }
.panel-foot { display: flex; justify-content: space-between; align-items: start; gap: 12px; border-top: 1px solid var(--line); padding-top: 10px; font-size: .88rem; color: #4a4239; }
.panel-foot summary { cursor: pointer; color: var(--fg); }
.panel-foot p { margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #2a2520; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100vw - 32px); z-index: 10;
}

@media (max-width: 980px) {
  .game { grid-template-columns: 1fr; padding: 10px; }
  .panel { position: static; max-height: none; }
  .board-wrap { padding: 4px; border-radius: 16px; }
}
