  /* Layout: lacquered wooden board as the hero, a slim jade-grey side rail for players, clocks and the move log. */
  :root {
    --bg: #e3eae6;
    --surface: #f4f7f5;
    --ink: #17211d;
    --muted: #56665f;
    --line: #c6d2cb;
    --seal: #b0352a;
    --jade: #2c6a55;
    --wood: #e4b871;
    --wood-edge: #a8722f;
    --grid: #5b3616;
    --face: #f7e9c8;
    --rim: #b98a47;
    --red-ink: #b0261b;
    --black-ink: #1b2124;
    --red-text: #b0261b;
    --font-ui: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
    --font-piece: "Noto Serif SC", "Songti SC", "SimSun", serif;
    --font-seal: "Ma Shan Zheng", "Kaiti SC", "KaiTi", serif;
    --font-chess: "Noto Sans Symbols 2", "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", sans-serif;
    --sq-light: #ecd9b6;
    --sq-dark: #b5875a;
    --white-piece: #fbf7ee;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0f1513; --surface: #18211d; --ink: #e2eae5; --muted: #95a59d;
      --line: #2b3732; --seal: #dd5f4a; --jade: #6cbb9b; --red-text: #ef7d6b; color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #0f1513; --surface: #18211d; --ink: #e2eae5; --muted: #95a59d;
    --line: #2b3732; --seal: #dd5f4a; --jade: #6cbb9b; --red-text: #ef7d6b; color-scheme: dark;
  }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.5; }
  .app { max-width: 1060px; margin: 0 auto; padding-inline: 16px; padding-block: 16px 40px; display: grid; gap: 16px; }

  header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
  .seal { width: 48px; height: 48px; border-radius: 6px; background: var(--seal); color: #fff7ee; font-family: var(--font-seal); font-size: 22px; line-height: 1; display: grid; place-items: center; writing-mode: vertical-rl; letter-spacing: -2px; transform: rotate(-3deg); }
  .logo { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; }
  a.link { color: var(--muted); font-weight: 600; font-size: 14px; }
  h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
  h2 { margin: 0; font-size: 17px; font-weight: 700; text-wrap: balance; }
  .sub { margin: 0; color: var(--muted); font-size: 13px; }
  .who { color: var(--muted); font-size: 14px; }
  .who strong { color: var(--ink); }

  .card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 12px; align-content: start; min-width: 0; }
  .lobby { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .lobby .stack { display: grid; gap: 16px; min-width: 0; }
  @media (max-width: 760px) { .lobby { grid-template-columns: minmax(0, 1fr); } }
  .narrow { max-width: 420px; width: 100%; margin: 24px auto 0; }

  .field { display: grid; gap: 4px; }
  label, .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
  .check { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); font-weight: 400; }
  .check input { width: 18px; height: 18px; accent-color: var(--jade); }
  input[type="text"], input[type="password"], input[type="search"], select { font: inherit; width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
  .row { display: flex; flex-wrap: wrap; gap: 8px; }
  .seg { justify-self: start; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
  .seg button { border: 0; border-radius: 0; }
  .seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

  button { font: inherit; font-weight: 600; font-size: 14px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
  button:hover:not(:disabled) { border-color: var(--ink); }
  button:disabled { opacity: .45; cursor: not-allowed; }
  button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
  button.danger { color: var(--seal); border-color: var(--seal); }
  button.link { border: 0; background: none; padding: 4px 0; color: var(--muted); text-decoration: underline; }
  button:focus-visible, input:focus-visible, select:focus-visible, svg.board:focus-visible { outline: 3px solid var(--jade); outline-offset: 2px; }

  .rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
  .room { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
  .room .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .room .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
  .badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-right: 4px; white-space: nowrap; }
  .badge.on { border-color: var(--jade); color: var(--jade); }
  .empty { color: var(--muted); font-size: 14px; }
  #authError, #passError { color: var(--seal); }
  .game-row { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 2px; }
  .game-row .who-won { font-weight: 600; overflow-wrap: anywhere; }
  .game-row .meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

  .topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
  .topbar .grow { flex: 1 1 200px; min-width: 0; }
  .share { display: flex; gap: 8px; flex: 1 1 320px; min-width: 0; }
  .share input { flex: 1; min-width: 0; font-size: 13px; }

  .layout { display: grid; grid-template-columns: minmax(0, 620px) minmax(0, 1fr); gap: 20px; align-items: start; }
  @media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }
  .board-wrap { position: relative; width: 100%; max-width: 620px; margin-inline: auto; }
  svg.board { display: block; width: 100%; height: auto; max-width: 100%; border-radius: 10px; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer;
    background: radial-gradient(120% 90% at 30% 20%, #efc985 0%, var(--wood) 45%, #d6a259 100%);
    box-shadow: inset 0 0 0 3px var(--wood-edge), 0 14px 30px -14px rgba(40, 20, 0, .55); }
  .grid-line { stroke: var(--grid); stroke-width: 1.4; fill: none; }
  .grid-frame { stroke: var(--grid); stroke-width: 3; fill: none; }
  .river { font-family: var(--font-seal); font-size: 34px; fill: var(--grid); opacity: .75; }
  .file-no { font-family: var(--font-ui); font-size: 13px; fill: var(--grid); opacity: .7; text-anchor: middle; }
  .pc { transition: transform 220ms cubic-bezier(.3,.7,.3,1); }
  .pc .base { fill: var(--face); stroke: var(--rim); stroke-width: 2.5; }
  .pc .ring { fill: none; stroke-width: 1.6; }
  .pc text { font-family: var(--font-piece); font-size: 30px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
  .pc.red .ring { stroke: var(--red-ink); } .pc.red text { fill: var(--red-ink); }
  .pc.black .ring { stroke: var(--black-ink); } .pc.black text { fill: var(--black-ink); }
  .pc .shadow { fill: rgba(60, 30, 0, .35); }
  .pc.sel .base { stroke: var(--jade); stroke-width: 4; }
  .pc.checked .base { stroke: #d62d1d; stroke-width: 4; }
  .hint { fill: var(--jade); opacity: .8; pointer-events: none; }
  .hint-cap { fill: none; stroke: var(--jade); stroke-width: 3.5; pointer-events: none; }
  .last { fill: none; stroke: #2a6fb0; stroke-width: 2.5; stroke-dasharray: 6 4; pointer-events: none; }
  /* Chess board */
  svg.board[data-game="chess"] { background: var(--wood-edge); }
  .ch-frame { fill: var(--wood-edge); }
  .sq-l { fill: var(--sq-light); } .sq-d { fill: var(--sq-dark); }
  [data-game="chess"] .file-no { fill: var(--sq-light); opacity: .9; font-weight: 600; }
  .pc .cp { font-family: var(--font-chess); font-size: 50px; text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke-linejoin: round; }
  .pc.white .cp { fill: var(--white-piece); stroke: #2a211a; stroke-width: 1.6; }
  .pc.black .cp { fill: #1f1a17; stroke: #f3e7d0; stroke-width: 0.8; }
  .pc .sel-sq, .pc .chk { fill: transparent; }
  .pc.sel .sel-sq { fill: rgba(44, 106, 85, .45); }
  .pc.checked .chk { fill: rgba(214, 45, 29, .55); }
  .last-sq { fill: rgba(255, 214, 92, .38); pointer-events: none; }
  [data-game="chess"] .hint { fill: rgba(31, 26, 23, .35); opacity: 1; }
  [data-game="chess"] .hint-cap { stroke: rgba(31, 26, 23, .35); stroke-width: 6; }
  .promo { font-family: var(--font-chess); font-size: 34px; width: 64px; height: 64px; padding: 0; }
  .promo.first { color: var(--ink); } .promo.second { color: var(--ink); }
  @media (prefers-reduced-motion: reduce) { .pc { transition: none; } }

  .overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
  .result { pointer-events: auto; background: var(--surface); color: var(--ink); border-radius: 12px; padding: 20px 24px; text-align: center; box-shadow: 0 20px 40px -10px rgba(0,0,0,.45); display: grid; gap: 10px; max-width: 80%; }
  .result strong { font-size: 24px; text-wrap: balance; }

  aside { display: grid; gap: 14px; min-width: 0; }
  .players { display: grid; gap: 8px; }
  .player { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; border: 2px solid transparent; }
  .player.turn { border-color: var(--jade); background: color-mix(in srgb, var(--jade) 9%, transparent); }
  .disc { width: 40px; height: 40px; border-radius: 50%; background: var(--face); border: 2px solid var(--rim); display: grid; place-items: center; font-family: var(--font-piece); font-weight: 700; font-size: 21px; }
  .disc.xiangqi.first { color: var(--red-ink); } .disc.xiangqi.second { color: var(--black-ink); }
  .disc.chess { font-family: var(--font-chess); font-weight: 400; font-size: 24px; background: var(--sq-dark); }
  .disc.chess.first { color: var(--white-piece); -webkit-text-stroke: 1px #2a211a; }
  .disc.chess.second { color: #1f1a17; }
  .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pname .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: middle; }
  .pname .dot.on { background: var(--jade); }
  .caps { font-family: var(--font-piece); font-size: 14px; letter-spacing: 1px; min-height: 1em; overflow-wrap: anywhere; }
  .caps .first { color: var(--red-text); } .caps .second { color: var(--ink); }
  .caps.chess { font-family: var(--font-chess); font-size: 17px; }
  .pmeta { font-size: 12px; color: var(--muted); }
  .clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; padding: 2px 8px; border-radius: 6px; background: var(--bg); }
  .clock.low { color: var(--seal); }
  .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 2px 8px; border-radius: 999px; background: var(--ink); color: var(--surface); }
  .status { font-size: 20px; font-weight: 700; line-height: 1.3; text-wrap: balance; }
  .status.alert { color: var(--seal); }
  .note { color: var(--muted); font-size: 13px; margin: 0; }

  .log { max-height: 260px; overflow-y: auto; margin: 0; padding: 0; list-style: none; font-size: 14px; font-variant-numeric: tabular-nums; }
  .log li { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) minmax(0, 1fr); gap: 6px; padding: 4px 2px; border-bottom: 1px dashed var(--line); }
  .log li.only { display: block; color: var(--muted); font-size: 13px; }
  .log .n { color: var(--muted); }
  .log .r { color: var(--red-text); }

  dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--ink); width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 40px -10px rgba(0,0,0,.45); }
  dialog::backdrop { background: rgba(10, 15, 13, .55); }
  .dialog-body { padding: 20px; display: grid; gap: 12px; }
  .dialog-body .note { font-size: 14px; }
  .toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-weight: 600; max-width: calc(100% - 32px); z-index: 10; }
