:root {
  color-scheme: light;
  --ink: #202220;
  --muted: #7b817e;
  --mist: #e8f0f1;
  --mist-deep: #d6e5e7;
  --paper: #f7f4ed;
  --gold: #c6a84e;
  --gold-deep: #9b843f;
  --red: #a8433b;
  --red-soft: #f4e8e4;
  --line: rgba(52, 58, 54, 0.13);
  --shadow: 0 24px 70px rgba(47, 60, 59, 0.13);
  --panel: rgba(247, 249, 247, 0.58);
  --selector: rgba(104, 119, 116, 0.09);
  --dialog: rgba(249, 247, 241, 0.97);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--mist);
  color: var(--ink);
  touch-action: pan-x pan-y;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 8% 2%, rgba(255, 255, 255, 0.95), transparent 29rem),
    radial-gradient(circle at 94% 96%, rgba(198, 168, 78, 0.08), transparent 27rem),
    var(--mist);
}

button,
a {
  color: inherit;
  font: inherit;
}

button {
  touch-action: manipulation;
}

svg,
a {
  -webkit-user-drag: none;
  user-drag: none;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(198, 168, 78, 0.65);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  margin-bottom: 14px;
}

.brand {
  display: inline-flex;
  gap: 13px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: flex;
  width: 42px;
  height: 37px;
  align-items: center;
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  top: 5px;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(45, 49, 46, 0.32);
  border-radius: 50%;
  background: #f4efe5;
  box-shadow: 0 4px 8px rgba(42, 48, 44, 0.12);
  content: "";
}

.brand-mark::before { left: 0; }
.brand-mark::after { right: 0; border-color: rgba(168, 67, 59, 0.38); }

.brand-mark i {
  position: relative;
  z-index: 1;
  width: 24px;
  color: #353a36;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  text-align: center;
}

.brand-mark i + i {
  margin-left: -6px;
  color: var(--red);
}

.brand strong {
  display: block;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.05;
}

.brand small,
.turn-card small,
.section-heading small,
.result-card > small,
.help-card > small,
.confirm-card > small {
  display: block;
  margin-top: 5px;
  color: var(--gold-deep);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: 0 8px 20px rgba(51, 61, 60, 0.05);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
}

.icon-button:active { transform: scale(0.94); }

.icon-button svg,
.tool-button svg,
.note-icon svg,
.primary-button svg,
.confirm-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button svg { width: 21px; height: 21px; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(500px, 1fr) 320px;
  gap: clamp(28px, 5vw, 70px);
  align-items: center;
}

.board-column { min-width: 0; }

.board-frame {
  position: relative;
  width: min(100%, calc((100svh - 162px) * 0.9));
  margin: 0 auto;
  padding: clamp(9px, 1.2vw, 15px);
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow), 0 0 0 1px rgba(110, 130, 128, 0.04);
}

.board-frame::after {
  position: absolute;
  inset: -13px;
  z-index: -1;
  border-radius: 18px;
  background: rgba(211, 230, 233, 0.72);
  content: "";
}

.board-surface {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 10;
  border-radius: 4px;
  background:
    repeating-linear-gradient(88deg, transparent 0, transparent 27px, rgba(85, 66, 40, 0.02) 28px, transparent 30px),
    repeating-linear-gradient(2deg, transparent 0, transparent 41px, rgba(92, 69, 38, 0.02) 42px, transparent 45px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.35), transparent 45%),
    #e5ddcf;
  box-shadow: inset 0 0 50px rgba(91, 75, 53, 0.08);
}

.board-surface::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 45% 40%, transparent 48%, rgba(87, 70, 48, 0.06) 120%);
  content: "";
}

#board {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

.mobile-status { display: none; }

.board-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-top: 16px;
}

.tool-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 13px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #555b58;
  font-size: 13px;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.tool-button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.52); color: var(--ink); }
.tool-button:active:not(:disabled) { transform: scale(0.97); }
.tool-button:disabled { opacity: 0.3; cursor: default; }
.tool-button svg { width: 21px; height: 21px; }
.tool-divider { width: 1px; height: 22px; background: rgba(65, 72, 68, 0.13); }

.control-panel {
  padding: 31px 28px 26px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(51, 65, 63, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.turn-card { display: flex; gap: 17px; align-items: center; }

.turn-piece,
.mobile-turn-piece,
.result-seal {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid #333734;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 26%, #fffdf6 0, #eee5d5 72%, #d0c3ad 100%);
  color: #303531;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-weight: 700;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.42), 0 7px 13px rgba(40, 45, 42, 0.19);
}

.turn-piece { width: 54px; height: 54px; font-size: 27px; }
.turn-piece.is-red,
.mobile-turn-piece.is-red,
.result-seal.is-red { border-color: var(--red); color: var(--red); }
.turn-piece.is-check { animation: check-pulse 950ms ease-in-out infinite; }

.turn-card h1 {
  margin: 4px 0 2px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(26px, 3vw, 32px);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.12;
}

.turn-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.rule {
  height: 1px;
  margin: 25px 0 23px;
  background: linear-gradient(90deg, var(--gold) 0 38px, var(--line) 38px 100%);
}

.rule--soft { margin: 20px 0; background: var(--line); }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 3px 0 0;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 19px;
  font-weight: 600;
}

.section-heading small { margin: 0; }
.round-label { color: #8e9490; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 10px; white-space: nowrap; }

.player-row { display: grid; gap: 8px; }

.player-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 59px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--selector);
  color: var(--muted);
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.player-card.is-active {
  border-color: rgba(57, 64, 59, 0.12);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  box-shadow: 0 5px 14px rgba(53, 64, 62, 0.06);
}

.player-card.is-active.is-red { border-color: rgba(168, 67, 59, 0.2); }
.player-piece { display: grid; place-items: center; width: 34px; height: 34px; border: 1.5px solid currentColor; border-radius: 50%; font-family: "Songti SC", "STSong", serif; font-size: 18px; font-weight: 700; }
.player-card.is-red .player-piece { color: var(--red); }
.player-card span:nth-child(2) small,
.player-card span:nth-child(2) strong { display: block; }
.player-card span:nth-child(2) small { margin-bottom: 2px; color: var(--gold-deep); font-size: 7px; font-weight: 700; letter-spacing: 0.14em; }
.player-card span:nth-child(2) strong { font-family: "Songti SC", "STSong", serif; font-size: 15px; }
.player-card b { font-size: 9px; font-weight: 600; }
.player-card.is-check b { color: var(--red); }

.gentle-note {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 17px;
  padding: 13px 14px;
  border: 1px solid rgba(198, 168, 78, 0.2);
  border-radius: 14px;
  background: rgba(229, 207, 130, 0.13);
  transition: border-color 180ms ease, background 180ms ease;
}

.gentle-note.is-warning { border-color: rgba(168, 67, 59, 0.26); background: rgba(168, 67, 59, 0.07); }
.note-icon { display: grid; flex: 0 0 auto; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: rgba(229, 207, 130, 0.28); color: var(--gold-deep); }
.gentle-note.is-warning .note-icon { background: rgba(168, 67, 59, 0.12); color: var(--red); }
.note-icon svg { width: 19px; height: 19px; }
.gentle-note p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.gentle-note strong { color: #414542; font-size: 12px; font-weight: 600; }

.mini-rules { display: grid; gap: 12px; }
.mini-rules > div { display: flex; gap: 10px; align-items: center; }
.mini-rules i { display: grid; flex: 0 0 auto; place-items: center; width: 25px; height: 25px; border: 1px solid rgba(198, 168, 78, 0.26); border-radius: 50%; color: var(--gold-deep); font-family: Georgia, serif; font-size: 11px; font-style: normal; }
.mini-rules strong,
.mini-rules small { display: block; }
.mini-rules strong { margin-bottom: 2px; color: #515652; font-size: 11px; font-weight: 600; }
.mini-rules small { color: var(--muted); font-size: 9px; line-height: 1.4; }

.dialog-backdrop[hidden] { display: none; }
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(35, 42, 39, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fade-in 180ms ease both;
}

.result-card,
.help-card,
.confirm-card {
  position: relative;
  width: min(390px, 100%);
  max-height: calc(100dvh - 44px);
  padding: 42px 36px 31px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 26px;
  background: var(--dialog);
  box-shadow: 0 35px 90px rgba(29, 36, 33, 0.22);
  text-align: center;
  animation: card-in 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  overscroll-behavior: contain;
}

.help-card { width: min(430px, 100%); }
.dialog-close { position: absolute; top: 14px; right: 14px; display: grid; place-items: center; width: 38px; height: 38px; padding: 0 0 3px; border: 0; border-radius: 50%; background: rgba(79, 87, 82, 0.07); color: #606662; font-family: Arial, sans-serif; font-size: 25px; font-weight: 300; cursor: pointer; }
.result-seal { width: 74px; height: 74px; margin: 0 auto 23px; border-width: 3px; font-size: 39px; }
.result-card h2,
.help-card h2,
.confirm-card h2 { margin: 9px 0; font-family: "Songti SC", "STSong", "SimSun", serif; font-size: 34px; font-weight: 600; letter-spacing: 0.04em; }
.result-card > p,
.confirm-card > p { margin: 0 auto 26px; color: var(--muted); font-size: 14px; line-height: 1.7; }

.primary-button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 53px; gap: 8px; border: 0; border-radius: 16px; background: #dbc477; color: #373329; font-weight: 600; cursor: pointer; box-shadow: 0 9px 22px rgba(168, 139, 51, 0.18); transition: transform 150ms ease, background 150ms ease; }
.primary-button:hover { background: #e3cb7d; transform: translateY(-1px); }
.primary-button:active { transform: scale(0.98); }
.primary-button svg { width: 18px; height: 18px; }
.text-button { margin-top: 13px; padding: 8px 15px; border: 0; background: transparent; color: #747a76; font-size: 13px; cursor: pointer; }

.help-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 24px 0 18px; text-align: left; }
.help-list p { display: flex; gap: 9px; align-items: center; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.48); }
.help-list b { display: grid; flex: 0 0 auto; place-items: center; width: 28px; height: 28px; border: 1px solid var(--red); border-radius: 50%; color: var(--red); font-family: "Songti SC", "STSong", serif; font-size: 15px; }
.help-list span { color: var(--muted); font-size: 10px; line-height: 1.45; }
.help-summary { margin: 0 0 22px; color: #555b57; font-size: 12px; line-height: 1.7; }
.confirm-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 50%; background: rgba(229, 207, 130, 0.28); color: var(--gold-deep); }
.confirm-icon svg { width: 27px; height: 27px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.97); } }
@keyframes check-pulse { 50% { box-shadow: inset 0 0 0 3px rgba(255,255,255,.42), 0 0 0 8px rgba(168,67,59,.12), 0 7px 13px rgba(40,45,42,.19); } }

@media (orientation: landscape) and (pointer: coarse) {
  html,
  body { position: fixed; inset: 0; width: 100%; height: 100dvh; min-height: 0; overflow: hidden; overscroll-behavior: none; touch-action: none; }
  .app-shell { height: 100dvh; min-height: 0; overflow: hidden; }
  .board-frame { width: min(100%, calc((100dvh - 165px) * 0.9)); }
}

@media (max-width: 900px) {
  .app-shell { padding-right: max(22px, env(safe-area-inset-right)); padding-left: max(22px, env(safe-area-inset-left)); }
  .game-layout { grid-template-columns: 1fr; gap: 32px; }
  .board-frame { width: min(100%, 620px); }
  .control-panel { width: min(620px, 100%); margin: 0 auto 20px; }
  .turn-card,
  .control-panel > .rule:first-of-type { display: none; }
  .mobile-status { display: flex; gap: 10px; align-items: center; justify-content: center; min-height: 40px; margin-bottom: 9px; font-family: "Songti SC", "STSong", serif; font-size: 18px; font-weight: 600; }
  .mobile-turn-piece { width: 27px; height: 27px; border-width: 1.5px; font-size: 14px; box-shadow: 0 3px 7px rgba(40, 45, 42, 0.14); }
}

@media (orientation: landscape) and (pointer: coarse) and (min-width: 600px) and (max-width: 900px) {
  .app-shell { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 48px; margin-bottom: 4px; }
  .brand strong { font-size: 18px; }
  .brand small { font-size: 7px; }
  .brand-mark { transform: scale(.82); transform-origin: left center; margin-right: -5px; }
  .icon-button { width: 38px; height: 38px; }
  .game-layout { grid-template-columns: minmax(250px, 1fr) 292px; gap: 24px; align-items: center; }
  .mobile-status { display: none; }
  .board-frame { width: min(100%, calc((100dvh - 111px) * .9)); padding: 7px; }
  .board-tools { margin-top: 5px; }
  .tool-button { min-height: 35px; padding: 4px 9px; font-size: 11px; }
  .control-panel { width: 100%; max-height: calc(100dvh - 68px); margin: 0; padding: 18px 19px; overflow: hidden; }
  .match-section .section-heading { margin-bottom: 8px; }
  .section-heading h2 { font-size: 16px; }
  .player-row { grid-template-columns: 1fr 1fr; }
  .player-card { grid-template-columns: 30px 1fr; min-height: 50px; padding: 7px 8px; }
  .player-card b { display: none; }
  .player-piece { width: 29px; height: 29px; font-size: 15px; }
  .gentle-note { margin-top: 10px; padding: 9px 11px; }
  .rule--soft { margin: 11px 0; }
  .mini-rules { gap: 7px; }
  .mini-rules > div:nth-child(3) { display: none; }
}

@media (max-width: 520px) {
  .app-shell { padding-top: max(12px, env(safe-area-inset-top)); padding-right: max(13px, env(safe-area-inset-right)); padding-left: max(13px, env(safe-area-inset-left)); }
  .topbar { min-height: 58px; margin-bottom: 7px; }
  .brand strong { font-size: 19px; }
  .brand small { font-size: 7px; }
  .brand-mark { transform: scale(.86); transform-origin: left center; margin-right: -4px; }
  .icon-button { width: 42px; height: 42px; }
  .game-layout { gap: 28px; }
  .board-frame { padding: 7px; border-radius: 7px; }
  .board-frame::after { inset: -7px; border-radius: 12px; }
  .board-tools { margin-top: 11px; }
  .control-panel { padding: 23px 18px 21px; border-radius: 18px; }
  .result-card,
  .help-card,
  .confirm-card { padding: 40px 23px 26px; }
  .help-list { grid-template-columns: 1fr; }
}

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