:root {
  --ink: #1b2430;
  --paper: #ffffff;
  --paper-2: #f3f6fa;
  --line: #3b6cff;
  --felt: #dbe6f2;
  --felt-deep: #c5d4e6;
  --cinnabar: #e24b4b;
  --night: #eef3f8;
  --muted: #5c6b7a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: "Noto Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(59, 108, 255, 0.12), transparent 55%),
    var(--night);
  color: var(--ink);
}
button, input { font: inherit; font-size: 16px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--line); outline-offset: 2px; }
h1, h2, h3, .brand { font-family: "Noto Sans SC", sans-serif; font-weight: 700; }
.noscript { padding: 24px; }

#toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%) translateY(-12px);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
  z-index: 20;
  max-width: min(92vw, 420px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.home { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.ticket {
  width: min(460px, 100%);
  background: var(--paper);
  color: var(--ink);
  padding: 28px 22px 20px;
  position: relative;
  border-radius: 24px;
  box-shadow: 0 16px 40px rgba(27, 36, 48, 0.08);
}
.seal {
  position: absolute;
  right: 18px;
  top: 18px;
  width: 58px;
  height: 58px;
  border: 3px solid var(--cinnabar);
  color: var(--cinnabar);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "ZCOOL XiaoWei", serif;
  font-size: 30px;
  transform: rotate(12deg);
}
.eyebrow { letter-spacing: 0.18em; color: var(--cinnabar); margin: 0 0 4px; font-size: 13px; }
.ticket h1 { font-size: 56px; line-height: 1; margin: 0 0 8px; letter-spacing: 0.14em; }
.lede { margin: 0 64px 12px 0; line-height: 1.55; }
.steps { margin: 0 0 16px; padding: 0; list-style: none; display: grid; gap: 6px; }
.steps li { display: flex; gap: 8px; align-items: baseline; line-height: 1.45; }
.steps li::before {
  counter-increment: step;
  content: counter(step);
  width: 1.3em;
  height: 1.3em;
  border-radius: 50%;
  background: var(--ink);
  color: var(--line);
  display: grid;
  place-items: center;
  font-size: 12px;
  flex: none;
}
.steps { counter-reset: step; }
label { display: grid; gap: 4px; margin: 0 0 10px; font-size: 14px; }
.lbl { display: flex; gap: 6px; align-items: baseline; }
.opt { color: var(--muted); font-weight: 400; }
input {
  border: 1px solid #d9cbb3;
  background: #fffdf8;
  color: var(--ink);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
}
.actions-row { display: flex; gap: 8px; margin-top: 4px; }
.actions-row button, .side button, .topbar button, .modal button, .disconnect button, .lobby button {
  border-radius: 999px;
  border: 1px solid #d7c7aa;
  background: #fff;
  color: var(--ink);
  padding: 10px 16px;
  min-height: 44px;
}
button.primary { background: var(--cinnabar); color: #fff8f3; border-color: transparent; }
.form-error { min-height: 1.2em; color: var(--cinnabar); margin: 8px 0 0; }
#resume-wrap { margin: 8px 0 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 4;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e4ebf3;
}
.brand { font-size: 22px; letter-spacing: 0.04em; color: var(--ink); }
.room-chip, .turn-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #d5deea;
  border-radius: 999px;
  padding: 4px 8px 4px 12px;
  font-size: 14px;
}
.turn-chip { padding: 8px 12px; margin-left: auto; }
.topbar button { background: #fff; color: var(--ink); border-color: #d5deea; min-height: 36px; padding: 6px 12px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; padding: 14px; align-items: start; }
.board-wrap { width: 100%; }
.board { margin-inline: auto; }
.board {
  width: min(100%, 740px, calc(100dvh - 188px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: 3fr repeat(9, 1fr) 3fr;
  grid-template-rows: 3fr repeat(9, 1fr) 3fr;
  background: var(--felt);
  border: 8px solid #fff;
  border-radius: 28px;
  box-shadow: 0 18px 40px rgba(27, 36, 48, 0.08);
  container-type: inline-size;
  position: relative;
}
.center {
  grid-column: 2 / 11;
  grid-row: 2 / 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  text-align: center;
  padding: 8px;
  pointer-events: none;
}
.center .mark { font-size: clamp(28px, 6cqi, 48px); letter-spacing: 0.12em; color: #3b6cff; margin: 0; }
.dice-row { display: flex; gap: 8px; }
.die {
  width: clamp(36px, 7cqi, 52px);
  height: clamp(36px, 7cqi, 52px);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px;
  box-shadow: 0 6px 0 #c9b89a;
}
.die i { width: 7px; height: 7px; border-radius: 50%; background: transparent; justify-self: center; align-self: center; }
.die[data-pips*="1"] i:nth-child(5),
.die[data-pips*="2"] i:nth-child(1),
.die[data-pips*="2"] i:nth-child(9),
.die[data-pips*="3"] i:nth-child(1),
.die[data-pips*="3"] i:nth-child(5),
.die[data-pips*="3"] i:nth-child(9),
.die[data-pips*="4"] i:nth-child(1),
.die[data-pips*="4"] i:nth-child(3),
.die[data-pips*="4"] i:nth-child(7),
.die[data-pips*="4"] i:nth-child(9),
.die[data-pips*="5"] i:nth-child(1),
.die[data-pips*="5"] i:nth-child(3),
.die[data-pips*="5"] i:nth-child(5),
.die[data-pips*="5"] i:nth-child(7),
.die[data-pips*="5"] i:nth-child(9),
.die[data-pips*="6"] i:nth-child(1),
.die[data-pips*="6"] i:nth-child(3),
.die[data-pips*="6"] i:nth-child(4),
.die[data-pips*="6"] i:nth-child(6),
.die[data-pips*="6"] i:nth-child(7),
.die[data-pips*="6"] i:nth-child(9) { background: var(--ink); }
.die.rolling { animation: hop 0.35s ease; }
@keyframes hop { 50% { transform: translateY(-8px) rotate(8deg); } }
.center-note { margin: 0; font-size: clamp(12px, 2.4cqi, 16px); max-width: 26ch; line-height: 1.4; }
.winner-banner { margin: 0; color: var(--cinnabar); font-size: clamp(18px, 4cqi, 28px); }

.cell {
  position: relative;
  margin: 2px;
  border: 0;
  background: #f4f7fb;
  border-radius: 10px;
  color: var(--ink);
  min-width: 0;
  min-height: 0;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
}
.cell .fill {
  position: absolute;
  background: var(--owner);
  z-index: 0;
  pointer-events: none;
}
.cell[data-side="bottom"] .fill { top: 0; left: 0; right: 0; height: var(--fill); }
.cell[data-side="top"] .fill { bottom: 0; left: 0; right: 0; height: var(--fill); }
.cell[data-side="left"] .fill { top: 0; bottom: 0; right: 0; width: var(--fill); }
.cell[data-side="right"] .fill { top: 0; bottom: 0; left: 0; width: var(--fill); }
.cell[data-kind="go"] { background: #fff4d8; }
.cell[data-kind="jail"] { background: #efe8e1; }
.cell[data-kind="exchange"] { background: #fde8e8; }
.cell[data-kind="railroad"]:not(.owned) { background: #f6f3ef; }
.cell.mortgaged::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(-45deg, transparent, transparent 3px, rgba(27, 36, 48, 0.28) 3px, rgba(27, 36, 48, 0.28) 5px);
}
.cell.selected { outline: 2px solid var(--ink); outline-offset: -2px; }
.cell.here { filter: saturate(1.15); }
.cell .nm { font-size: clamp(8px, 2cqi, 13px); font-weight: 700; line-height: 1.05; text-align: center; word-break: break-all; z-index: 2; text-shadow: 0 0 2px #fff; }
.cell .sub { font-size: clamp(7px, 1.6cqi, 11px); color: #3a322b; font-weight: 700; z-index: 2; text-shadow: 0 0 2px #fff; }
.cell .pips { display: flex; gap: 2px; z-index: 2; min-height: 0; }
.cell .pips i { width: 6px; height: 6px; background: #2f9e6a; display: block; }
.cell .pips.hotel { color: var(--cinnabar); font-size: clamp(8px, 1.6cqi, 11px); font-weight: 700; }
.tokens { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; z-index: 2; }
.token {
  width: 1.15em;
  height: 1.15em;
  min-width: 12px;
  min-height: 12px;
  border-radius: 50%;
  color: white;
  font-size: clamp(8px, 1.7cqi, 12px);
  display: grid;
  place-items: center;
  border: 1px solid #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.token.turn { outline: 2px solid #241c16; }
.cell.mortgaged .nm { font-weight: 700; }

.inspect {
  width: min(100%, 740px);
  margin: 8px auto 0;
  background: #fff;
  border: 1px solid #e4ebf3;
  border-radius: 16px;
  padding: 8px 12px;
  min-height: 52px;
}
.inspect strong { color: var(--ink); }
.inspect p { margin: 4px 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

.side {
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 78px);
  position: sticky;
  top: 64px;
  min-height: 0;
  overflow: auto;
}
.side h2 { margin: 0; font-size: 22px; letter-spacing: 0.08em; }
.tabs { display: none; }
.pane { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#phase { background: var(--paper-2); border-radius: 12px; padding: 10px; line-height: 1.45; }
#phase p { margin: 0 0 6px; }
.action-grid { display: flex; flex-wrap: wrap; gap: 8px; }
#people, #log, #chat { overflow: auto; }
#people { max-height: 26vh; display: grid; gap: 8px; }
#log, #chat { max-height: 18vh; margin: 0; padding: 0; list-style: none; }
#log li, #chat li { margin: 0 0 6px; line-height: 1.4; }
.time { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.who { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.who b { font-size: 16px; }
.cash { font-variant-numeric: tabular-nums; font-weight: 700; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 12px; background: #efe4d2; border-radius: 999px; padding: 2px 6px; }
.badge.off { background: #f3d2cd; }
.props { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 12px; border-radius: 999px; padding: 2px 6px; background: #fff; border: 1px solid #e4d5bc; }
.player-card { border: 1px solid #e4d5bc; border-left-width: 6px; border-radius: 12px; padding: 8px; background: #fffdf8; }
.player-card.turn { background: #fff6d8; }
#chat-form { display: flex; gap: 6px; }
#chat-form input { flex: 1; }
.trade-card, .group { background: #fffdf8; border: 1px solid #e4d5bc; border-radius: 12px; padding: 8px; display: grid; gap: 8px; }
.rowline { display: flex; gap: 6px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.checks { display: grid; gap: 4px; }
.checks label { grid-template-columns: auto 1fr; align-items: center; margin: 0; }
.lobby {
  width: min(640px, 100%);
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 22px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}
.lobby h2 { margin: 0 0 6px; font-size: 36px; letter-spacing: 0.08em; }
.code-xl { font-size: 40px; letter-spacing: 0.24em; margin: 8px 0; font-variant-numeric: tabular-nums; }
.person { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eadfcd; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.settings { display: grid; gap: 8px; margin: 12px 0; padding: 12px; background: var(--paper-2); border-radius: 16px; }
.settings h3 { margin: 0; font-size: 16px; }
.setting-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.setting-grid label { margin: 0; }
.switches { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.switches label { display: flex; flex: none; gap: 6px; align-items: center; margin: 0; white-space: nowrap; }
.switches input { width: auto; }
.swatches, .avatars { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch, .avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #d5deea;
  padding: 0;
  min-height: 36px;
}
.swatch.on, .avatar-btn.on { box-shadow: 0 0 0 2px var(--ink); }
.avatar-btn { width: auto; border-radius: 999px; padding: 0 10px; background: #fff; }
#jail .delta { font-size: 36px; font-weight: 700; margin: 4px 0; }
.market {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background: rgba(27, 36, 48, 0.28);
  padding: 16px;
}
.market-card {
  width: min(360px, 100%);
  border-radius: 24px;
  background: #fff;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(27, 36, 48, 0.2);
  animation: pop 0.35s ease;
}
.market-card.up { box-shadow: 0 0 0 3px #1f9d57, 0 24px 60px rgba(31, 157, 87, 0.2); }
.market-card.down { box-shadow: 0 0 0 3px #d64545, 0 24px 60px rgba(214, 69, 69, 0.2); }
.market-card .code { letter-spacing: 0.2em; color: var(--muted); margin: 0; font-size: 13px; }
.market-card h3 { margin: 6px 0; font-size: 36px; }
.market-card .delta { font-size: 42px; margin: 0; font-variant-numeric: tabular-nums; }
.market-card.up .delta, .market-card.up h3 { color: #1f9d57; }
.market-card.down .delta, .market-card.down h3 { color: #d64545; }
.candles { display: flex; justify-content: center; align-items: flex-end; gap: 8px; height: 72px; margin: 8px 0 12px; }
.candles i { width: 14px; border-radius: 4px; display: block; }
.market-card.up .candles i { background: #1f9d57; }
.market-card.down .candles i { background: #d64545; }
.candles i:nth-child(1) { height: 28px; }
.candles i:nth-child(2) { height: 48px; }
.candles i:nth-child(3) { height: 36px; }
.candles i:nth-child(4) { height: 64px; }
@keyframes pop { from { transform: translateY(12px) scale(0.96); opacity: 0; } }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 14, 10, 0.62);
  display: grid;
  place-items: end center;
  z-index: 8;
  padding: 12px;
}
.overlay[hidden] { display: none; }
#liquidate { z-index: 14; place-items: center; }
.modal {
  width: min(520px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px 16px 12px 12px;
  padding: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.modal header { display: flex; justify-content: space-between; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--paper); }
.modal h3 { margin: 0; font-size: 28px; }
.prose p { line-height: 1.55; }
.disconnect {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 9;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  background: #3a201c;
  color: #fff6f2;
  border: 1px solid #e0c17a;
  border-radius: 14px;
  padding: 10px 12px;
}
.disconnect[hidden] { display: none; }

@media (max-width: 900px) {
  .layout { display: block; padding: 10px 10px 46vh; }
  .side {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-height: 44vh;
    border-radius: 16px 16px 0 0;
    z-index: 5;
    padding-bottom: calc(10px + var(--safe-bottom));
  }
  .tabs { display: flex; gap: 6px; }
  .tabs button { flex: 1; background: transparent; border-color: transparent; color: var(--muted); min-height: 36px; padding: 6px; }
  .tabs button.on { color: var(--ink); background: #fff; border-color: #e4d5bc; }
  .pane { display: none; overflow: auto; }
  .pane.on { display: flex; }
  #people, #log, #chat { max-height: none; }
  .topbar { flex-wrap: wrap; }
  .turn-chip { margin-left: 0; }
  .ticket h1 { font-size: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .die.rolling { animation: none; }
  #toast { transition: none; }
}
