:root {
  --bg: #f6f4ee;
  --surface: #fffdfa;
  --surface-muted: #f0eee7;
  --ink: #20231f;
  --ink-soft: #4d534c;
  --muted: #81857d;
  --faint: #a8a99f;
  --line: #dedbd1;
  --line-strong: #c8c4b8;
  --accent: #a94630;
  --accent-soft: #f4e8e3;
  --jade: #3f6254;
  --jade-soft: #e8efea;
  --danger: #a33f2b;
  --radius: 10px;
  --font-sans: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Microsoft YaHei", "SimSun", serif;
  --font-mono: "SFMono-Regular", "Cascadia Mono", "Consolas", monospace;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: none;
}

h1,
h2,
h3,
p,
figure,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.3;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg,
canvas,
img {
  display: block;
  max-width: 100%;
}

ol,
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 999;
  transform: translateY(-150%);
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--surface);
  background: var(--ink);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------- basic controls */

.primary,
.secondary,
.danger,
.small,
.icon-button,
.text-button,
.nav-btn,
.close-button,
.game-card,
.preset span,
.segmented span,
.promotion-options button,
.import-dropzone {
  touch-action: manipulation;
}

.primary,
.secondary,
.danger {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  line-height: 1.2;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.primary {
  color: var(--surface);
  background: var(--ink);
}

.primary:hover {
  background: #111410;
}

.secondary {
  border-color: var(--line-strong);
  color: var(--ink-soft);
  background: transparent;
}

.secondary:hover {
  border-color: var(--ink-soft);
  background: var(--surface);
}

.danger {
  border-color: var(--line-strong);
  color: var(--danger);
  background: transparent;
}

.danger:hover {
  border-color: var(--danger);
}

.small {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 12px;
}

.primary.small,
.secondary.small,
.danger.small {
  border-radius: 7px;
}

.text-button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
  line-height: 1.4;
}

.text-button:hover {
  color: var(--ink);
  border-bottom-color: var(--line-strong);
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--ink);
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.icon-button-primary {
  border-color: var(--ink);
  color: var(--surface);
  background: var(--ink);
}

.icon-button-primary:hover:not(:disabled) {
  color: var(--surface);
  background: #111410;
}

button:disabled {
  cursor: wait;
}

/* --------------------------------------------------------------- structure */

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

body[data-view="room"] .topbar {
  display: none;
}

body[data-view="room"] main {
  min-height: 100vh;
}

.topbar-inner {
  display: flex;
  width: min(100% - 48px, 1120px);
  height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-inline: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  height: 40px;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.16em;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn {
  display: inline-flex;
  height: 34px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.nav-btn:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

main {
  min-height: calc(100vh - 56px);
}

.view {
  width: min(100% - 48px, 1120px);
  margin-inline: auto;
}

/* -------------------------------------------------------------------- home */

.home-view {
  display: flex;
  min-height: calc(100vh - 56px);
  align-items: flex-start;
  justify-content: center;
  padding: clamp(28px, 7vh, 76px) 0 40px;
}

.home {
  width: min(100%, 620px);
}

.home h1 {
  margin-bottom: 18px;
  font-size: clamp(26px, 4vw, 34px);
  letter-spacing: 0.02em;
}

.panel {
  display: grid;
  gap: 22px;
  padding: clamp(18px, 4vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.field > legend,
.field > .label {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.field > .label .muted,
.muted {
  color: var(--faint);
  font-size: 10px;
  font-weight: 400;
}

.field input[type="text"],
.field input[type="number"],
.custom-time input,
#import-paste {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 140ms ease, background 140ms ease;
}

.field input::placeholder,
#import-paste::placeholder {
  color: var(--faint);
}

.field input:focus,
.custom-time input:focus,
#import-paste:focus {
  border-color: var(--ink-soft);
  background: #fff;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}

.game-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.game-card {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 13px;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.game-card:hover {
  border-color: var(--line-strong);
}

.game-card.is-selected {
  border-color: var(--ink);
  color: var(--surface);
  background: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 32px;
  place-items: center;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.segmented input:checked + span {
  color: var(--ink);
  background: var(--surface);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
}

.time-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset {
  display: inline-flex;
}

.preset input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.preset span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 10px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
}

.preset input:checked + span {
  border-color: var(--ink);
  color: var(--surface);
  background: var(--ink);
}

.preset input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.custom-time {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 2px;
}

.inline-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.inline-input {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.inline-input input {
  height: 36px;
  padding-inline: 8px;
}

.hint {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.6;
}

.hint:empty {
  display: none;
}

.panel > .primary {
  width: 100%;
}

.form-error {
  min-height: 0;
  margin-top: -8px;
  color: var(--accent);
  font-size: 11px;
  line-height: 1.6;
}

.form-error:empty {
  display: none;
}

.home-note {
  margin-top: 14px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.7;
  text-align: center;
}

/* -------------------------------------------------------------------- room */

.room-view {
  --board-size: 590px;
  --aside-size: 310px;
  padding: 18px 0 48px;
}

.room-view[data-game-type="xiangqi"] {
  --board-size: 540px;
}

.room-view[data-game-type="go"] {
  --board-size: 610px;
}

.room {
  width: min(100% - 48px, 1120px);
  margin-inline: auto;
}

.room-head {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.room-head-left,
.room-head-right {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.back-link {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 17px;
}

.back-link:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

.room-game-label {
  flex: 0 0 auto;
  font-family: var(--font-serif);
  font-size: 14px;
}

.room-id {
  overflow: hidden;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-pill,
.status-pill {
  display: inline-flex;
  height: 24px;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
}

.connection-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--faint);
}

.connection-pill.is-online {
  color: var(--jade);
  border-color: rgba(63, 98, 84, 0.25);
}

.connection-pill.is-online .connection-dot {
  background: var(--jade);
}

.connection-pill.is-reconnecting {
  color: var(--accent);
  border-color: rgba(169, 70, 48, 0.25);
}

.connection-pill.is-reconnecting .connection-dot {
  background: var(--accent);
}

.connection-pill.is-local {
  color: var(--jade);
  border-color: rgba(63, 98, 84, 0.2);
}

.status-pill--waiting {
  color: var(--accent);
  border-color: rgba(169, 70, 48, 0.24);
}

.status-pill--playing {
  color: var(--jade);
  border-color: rgba(63, 98, 84, 0.24);
}

.status-pill--finished,
.status-pill--local {
  color: var(--ink-soft);
}

.room-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-size);
  gap: clamp(24px, 4vw, 44px);
  align-items: start;
}

.room-view.aside-empty .room-layout {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.room-view.aside-empty .room-aside {
  display: none;
}

.room-view.aside-empty .board-column {
  width: 100%;
}

.board-column {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
}

.player-strip,
.board-frame,
.board-hint,
.undo-bar,
.live-actions,
.invite-zone,
.replay-panel {
  width: min(100%, var(--board-size));
}

.player-strip {
  display: flex;
  min-height: 50px;
  align-items: center;
  gap: 9px;
  padding: 6px 0;
}

.player-identity {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
}

.player-name {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-sub {
  display: flex;
  min-height: 16px;
  align-items: center;
  gap: 6px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.4;
}

.player-strip.is-turn .player-name {
  color: var(--ink);
}

.player-strip.is-turn .player-name::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 2px;
}

.player-strip.is-empty {
  opacity: 0.55;
}

.presence-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
}

.presence-dot.is-online {
  background: var(--jade);
}

.side-swatch {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid rgba(35, 35, 28, 0.18);
  border-radius: 50%;
}

.side-swatch--red {
  background: #aa442d;
}

.side-swatch--black {
  background: #2b2e28;
}

.side-swatch--white {
  border-color: var(--line-strong);
  background: #f8f3e8;
}

.side-swatch--go-black {
  background: #242722;
}

.side-swatch--go-white {
  border-color: var(--line-strong);
  background: #f5eee1;
}

.player-clock {
  display: flex;
  min-width: 76px;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.player-clock strong {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.3;
}

.player-clock small {
  color: var(--faint);
  font-size: 9px;
  line-height: 1.3;
}

.player-clock.is-low strong,
.player-clock.is-low small {
  color: var(--accent);
}

.board-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(97, 76, 44, 0.42);
  border-radius: 5px;
  background: #d6bd93;
  box-shadow: 0 8px 24px rgba(60, 46, 25, 0.08);
}

.board-frame[data-board="xiangqi"] {
  aspect-ratio: 9 / 10;
}

#board-canvas {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  outline: none;
  touch-action: manipulation;
}

.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(247, 244, 236, 0.88);
  text-align: center;
  backdrop-filter: blur(2px);
}

.board-overlay p {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 20px;
}

.board-hint {
  min-height: 40px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}

.undo-bar {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(169, 70, 48, 0.28);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--accent-soft);
  font-size: 11px;
}

.undo-bar #undo-message {
  min-width: 0;
}

.undo-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.undo-actions .small {
  min-height: 30px;
  padding: 4px 10px;
}

.live-actions {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.invite-zone {
  display: flex;
  min-height: 34px;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-top: 2px;
}

.invite {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.invite input {
  width: auto;
  min-width: 0;
  height: 34px;
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 9px;
  color: var(--muted);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 9px;
  outline: none;
}

.invite .small {
  flex: 0 0 auto;
  white-space: nowrap;
}

.replay-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.replay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.replay-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.replay-controls .icon-button {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.replay-progress {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

.replay-slider {
  width: 100%;
  height: 18px;
  margin-top: 7px;
  accent-color: var(--ink);
  cursor: pointer;
}

.replay-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line-strong);
}

.replay-slider::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--surface);
  -webkit-appearance: none;
  appearance: none;
}

/* ------------------------------------------------------------------- aside */

.room-aside {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}

.result-card {
  color: var(--surface);
  border-color: var(--ink);
  background: var(--ink);
}

.result-card .card-head h2,
.result-card .text-button {
  color: var(--surface);
}

.result-card .text-button:hover {
  border-bottom-color: rgba(255, 255, 255, 0.4);
}

.result-title {
  margin-top: 4px;
  font-family: var(--font-serif);
  font-size: 21px;
  line-height: 1.4;
}

.result-detail {
  margin-top: 4px;
  color: rgba(255, 253, 250, 0.64);
  font-size: 11px;
  line-height: 1.7;
}

.result-detail:empty {
  display: none;
}

.result-card .text-button {
  margin-top: 10px;
  color: rgba(255, 253, 250, 0.7);
}

.card-head {
  display: flex;
  min-height: 24px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.card-head h2 {
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.card-count,
.tag-badge {
  color: var(--faint);
  font-size: 9px;
  line-height: 1.4;
}

.tag-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 6px;
}

.move-list {
  display: flex;
  max-height: 220px;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.move-list:empty {
  display: none;
}

.move-row {
  display: grid;
  grid-template-columns: 22px 6px minmax(0, 1fr) auto;
  min-height: 28px;
  align-items: center;
  gap: 7px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 2px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 11px;
  text-align: left;
}

.move-row:last-child {
  border-bottom: 0;
}

button.move-row {
  width: 100%;
  cursor: pointer;
}

button.move-row:hover {
  background: var(--surface-muted);
}

.move-row.is-current {
  background: var(--surface-muted);
}

.move-number {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 9px;
  text-align: right;
}

.move-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
}

.move-dot--seat-0 {
  background: var(--accent);
}

.move-dot--seat-1 {
  background: var(--ink-soft);
}

.room-view[data-game-type="go"] .move-dot--seat-0 {
  background: #242722;
}

.room-view[data-game-type="go"] .move-dot--seat-1 {
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.room-view[data-game-type="chess"] .move-dot--seat-0 {
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.room-view[data-game-type="chess"] .move-dot--seat-1 {
  background: var(--ink-soft);
}

.move-notation {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-tag {
  padding: 0 5px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 8px;
  line-height: 1.8;
  white-space: nowrap;
}

.move-tag--brilliant {
  color: #79510c;
  background: #f1dfb8;
}

.move-tag--good {
  color: var(--jade);
  background: var(--jade-soft);
}

.move-tag--best {
  color: var(--ink);
  background: var(--surface-muted);
  font-weight: 600;
}

.move-tag--correct {
  color: var(--muted);
  background: var(--surface-muted);
}

.move-tag--inaccuracy {
  color: #82631e;
  background: #f3ead6;
}

.move-tag--mistake {
  color: #a1542e;
  background: #f4e2d4;
}

.move-tag--blunder {
  color: var(--surface);
  background: var(--accent);
}

.empty {
  padding: 8px 0 2px;
  color: var(--faint);
  font-size: 10px;
}

.undo-log {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.undo-log:empty {
  display: none;
}

.undo-log li {
  color: var(--faint);
  font-size: 9px;
  line-height: 1.6;
}

.undo-log li::before {
  content: "↩ ";
  color: var(--accent);
}

.review-summary {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
}

.review-summary:empty {
  display: none;
}

.review-current {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.review-current-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.review-move-label {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 9px;
}

.review-tag {
  padding: 0 5px;
  border-radius: 999px;
  color: var(--jade);
  background: var(--jade-soft);
  font-size: 8px;
  line-height: 1.8;
}

.review-tag--brilliant {
  color: #79510c;
  background: #f1dfb8;
}

.review-tag--good {
  color: var(--jade);
  background: var(--jade-soft);
}

.review-tag--best {
  color: var(--ink);
  background: var(--surface-muted);
  font-weight: 600;
}

.review-tag--correct {
  color: var(--muted);
  background: var(--surface-muted);
}

.review-tag--inaccuracy {
  color: #82631e;
  background: #f3ead6;
}

.review-tag--mistake {
  color: #a1542e;
  background: #f4e2d4;
}

.review-tag--blunder {
  color: var(--surface);
  background: var(--accent);
}

.review-comment,
.review-empty {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
}

.review-disclaimer {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 8px;
  line-height: 1.6;
}

/* ------------------------------------------------------------------ states */

.state-view {
  display: grid;
  min-height: calc(100vh - 56px);
  place-items: center;
  padding: 32px 24px;
}

.state {
  width: min(100%, 420px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.state h1 {
  margin-bottom: 8px;
  font-size: 25px;
}

.state p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.state-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

/* ------------------------------------------------------------------ modals */

.modal {
  width: min(100% - 32px, 540px);
  max-height: min(88svh, 760px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 16px 50px rgba(30, 28, 22, 0.16);
}

.modal::backdrop {
  background: rgba(31, 30, 25, 0.35);
}

.modal-small {
  width: min(100% - 32px, 400px);
}

.modal-inner {
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-head h2 {
  font-size: 21px;
}

.close-button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
}

.close-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.modal-text {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}

.modal-actions:last-child {
  justify-content: flex-end;
}

.modal-actions .primary,
.modal-actions .secondary {
  min-height: 38px;
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.promotion-options button {
  display: flex;
  min-height: 84px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
}

.promotion-options button:hover {
  border-color: var(--ink);
}

.promotion-options button span {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
  font-size: 27px;
  line-height: 1.1;
}

#promotion-cancel {
  margin-top: 12px;
}

#import-paste {
  height: auto;
  min-height: 82px;
  margin-top: 10px;
  padding: 8px 10px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.5;
}

.import-dropzone {
  display: flex;
  min-height: 104px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--faint);
  background: var(--surface-muted);
  font-size: 10px;
  cursor: pointer;
}

.import-dropzone strong {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

.import-dropzone:hover,
.import-dropzone.is-drag {
  border-color: var(--accent);
}

.import-error {
  min-height: 16px;
  margin-top: 6px;
  color: var(--accent);
  font-size: 10px;
  line-height: 1.6;
}

/* ------------------------------------------------------------------ toasts */

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  width: min(100% - 32px, 320px);
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 8px 11px;
  border-radius: 6px;
  color: var(--surface);
  background: var(--ink);
  font-size: 11px;
  line-height: 1.6;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 150ms ease, transform 150ms ease;
  pointer-events: auto;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--error {
  background: var(--danger);
}

.toast--success {
  background: var(--jade);
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 980px) {
  .room-view {
    --board-size: 540px;
    --aside-size: 280px;
  }

  .room-view[data-game-type="xiangqi"] {
    --board-size: 500px;
  }

  .room-view[data-game-type="go"] {
    --board-size: 560px;
  }
}

@media (max-width: 820px) {
  .topbar-inner,
  .view,
  .room {
    width: min(100% - 32px, 680px);
  }

  .home-view {
    padding-top: 28px;
  }

  .room-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .room-view,
  .room-view[data-game-type="xiangqi"],
  .room-view[data-game-type="go"] {
    --board-size: 620px;
  }

  .room-aside {
    width: min(100%, var(--board-size));
    margin-inline: auto;
  }

  .board-column {
    width: 100%;
  }

  .card {
    padding: 12px 14px;
  }

  .move-list {
    max-height: 190px;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 14px;
  }

  .topbar-inner {
    width: calc(100% - 24px);
    height: 52px;
  }

  .brand {
    font-size: 17px;
  }

  .nav-btn {
    height: 32px;
    padding-inline: 8px;
    font-size: 11px;
  }

  .home-view {
    min-height: auto;
    padding: 24px 0 28px;
  }

  .home {
    width: 100%;
  }

  .home h1 {
    margin-bottom: 14px;
    font-size: 25px;
  }

  .panel {
    gap: 18px;
    padding: 16px;
  }

  .form-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .field input[type="text"],
  .field input[type="number"],
  .custom-time input {
    height: 42px;
    font-size: 16px;
  }

  .game-picker {
    gap: 5px;
  }

  .game-card {
    min-height: 42px;
    padding: 8px 5px;
    font-size: 12px;
  }

  .time-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .preset span {
    width: 100%;
    min-height: 38px;
    justify-content: center;
    padding: 7px 8px;
  }

  .custom-time {
    gap: 8px;
  }

  .home-note {
    margin-top: 12px;
    font-size: 9px;
    text-align: left;
  }

  .room-view {
    padding: 10px 0 calc(24px + env(safe-area-inset-bottom));
  }

  .room {
    width: calc(100% - 24px);
  }

  .room-head {
    min-height: 34px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .room-head-left,
  .room-head-right {
    gap: 6px;
  }

  .room-id {
    display: none;
  }

  .room-game-label {
    font-size: 13px;
  }

  .back-link {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  .connection-pill {
    display: none;
  }

  .status-pill {
    height: 22px;
    padding-inline: 7px;
    font-size: 9px;
  }

  .room-layout {
    gap: 14px;
  }

  .player-strip {
    min-height: 46px;
    gap: 8px;
    padding: 4px 0;
  }

  .player-name {
    font-size: 13px;
  }

  .player-sub {
    gap: 5px;
    font-size: 9px;
  }

  .side-swatch {
    width: 21px;
    height: 21px;
  }

  .player-clock {
    min-width: 68px;
  }

  .player-clock strong {
    font-size: 16px;
  }

  .player-clock small {
    font-size: 8px;
  }

  .board-hint {
    min-height: 34px;
    margin-top: 8px;
    font-size: 10px;
    line-height: 1.55;
    text-align: left;
  }

  .text-button {
    min-height: 36px;
    font-size: 11px;
  }

  .undo-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 9px 10px;
    font-size: 10px;
  }

  .undo-actions {
    margin-left: auto;
  }

  .undo-actions .small {
    min-height: 34px;
  }

  .live-actions {
    justify-content: flex-start;
    gap: 6px;
    min-height: 38px;
    margin-top: 0;
  }

  .live-actions .small {
    min-height: 36px;
  }

  .invite-zone {
    min-height: 34px;
    margin-top: 0;
  }

  .invite {
    margin-top: 0;
  }

  .invite input {
    height: 36px;
    font-size: 8px;
  }

  .invite .small {
    min-height: 36px;
    flex: 0 0 auto;
  }

  .board-overlay {
    gap: 10px;
    padding: 16px;
  }

  .board-overlay p {
    font-size: 18px;
  }

  .replay-panel {
    margin-top: 8px;
    padding: 9px;
  }

  .replay-row {
    gap: 8px;
  }

  .replay-controls {
    gap: 4px;
  }

  .replay-controls .icon-button {
    width: 32px;
    height: 32px;
  }

  .replay-progress {
    font-size: 9px;
  }

  .room-aside {
    gap: 8px;
  }

  .card {
    padding: 12px;
  }

  .card-head {
    min-height: 22px;
    margin-bottom: 6px;
  }

  .result-title {
    font-size: 19px;
  }

  .result-detail {
    font-size: 10px;
  }

  .move-list {
    max-height: 175px;
  }

  .move-row {
    min-height: 30px;
  }

  .review-summary,
  .review-comment,
  .review-empty {
    font-size: 9.5px;
  }

  .modal {
    width: calc(100% - 20px);
    max-height: 88svh;
    border-radius: 10px;
  }

  .modal-inner {
    padding: 16px;
  }

  .modal-head h2 {
    font-size: 19px;
  }

  .modal-text {
    font-size: 10px;
  }

  .promotion-options {
    gap: 5px;
  }

  .promotion-options button {
    min-height: 74px;
    font-size: 11px;
  }

  .promotion-options button span {
    font-size: 23px;
  }

  .state-view {
    padding: 24px 12px;
  }

  .state {
    padding: 20px;
  }

  .toast-region {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100% - 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
