@font-face {
  font-family: "Quan Co";
  src: url("../assets/quan-co.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: block;
}

:root {
  color-scheme: dark;
  --ink: #151b16;
  --panel: #20271f;
  --panel-inset: #182019;
  --edge: #394136;
  --text: #eee8da;
  --muted: #b6b5a4;
  --gold: #dcb880;
  --gold-soft: #bb975f;
  --red: #db7762;
  --red-dark: #8f251c;
  --black-dark: #202b23;
  --serif: Georgia, "Times New Roman", serif;
  --ui: "Segoe UI", system-ui, sans-serif;
  --cjk: "Quan Co", "Noto Serif CJK TC", "Songti TC", SimSun, serif;
  --duration: 180ms;
  font-family: var(--ui);
  font-size: 15px;
  color: var(--text);
  background: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 46% 16%, #2a3023 0%, #1b221b 50%, #141914 100%);
}
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
.board-svg:focus-visible, .board-point:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: inline-block;
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.topbar {
  border-bottom: 1px solid #ffffff12;
  background: #121812c9;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  width: min(calc(100% - 64px), 1210px);
  margin-inline: auto;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid #d38565;
  border-radius: 7px;
  background: #a44432;
  color: #f8dec0;
  box-shadow: inset 0 0 0 2px #5b221c65;
}
.brand-mark .icon { width: 22px; height: 22px; }
.topbar-tools { display: flex; gap: 5px; }
.utility {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.utility:hover { background: #ffffff0a; color: var(--text); }
.utility[aria-pressed="true"] { color: var(--gold); }
.help-button { border-color: var(--edge); color: var(--text); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(190px, 220px) minmax(390px, 570px) minmax(225px, 272px);
  justify-content: center;
  align-items: start;
  gap: 26px;
  width: min(calc(100% - 64px), 1210px);
  margin: 22px auto 28px;
}
.mode-panel { padding-top: 13px; }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .15em;
  line-height: 1.45;
  text-transform: uppercase;
}
.mini-diamond {
  width: 6px;
  height: 6px;
  rotate: 45deg;
  background: var(--gold);
}
.mode-intro h1 {
  margin: 9px 0 7px;
  color: #f6ecda;
  font-family: var(--serif);
  font-size: clamp(40px, 4vw, 57px);
  font-weight: 500;
  letter-spacing: -.06em;
  line-height: 1.1;
}
.mode-intro > p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}
.mode-list { display: grid; gap: 9px; margin-top: 23px; }
.mode-button {
  position: relative;
  display: grid;
  grid-template-columns: 35px minmax(0, 1fr) 12px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 63px;
  padding: 9px;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: #242d23;
  text-align: left;
  transition: background var(--duration), border-color var(--duration);
}
.mode-button:hover { background: #2d382b; border-color: #6d725c; }
.mode-button[aria-pressed="true"] {
  border-color: #b6915d;
  background: linear-gradient(120deg, #514631, #2b3226 85%);
}
.mode-button[aria-pressed="true"]::before {
  position: absolute;
  top: 17px;
  bottom: 17px;
  left: -1px;
  width: 2px;
  border-radius: 2px;
  background: var(--gold);
  content: "";
}
.mode-icon {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid #d5bb8534;
  border-radius: 7px;
  color: var(--gold);
  background: #161d166b;
}
.mode-copy { display: grid; gap: 2px; min-width: 0; }
.mode-copy strong { font-size: 13px; font-weight: 700; }
.mode-copy small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.mode-arrow { width: 12px; height: 16px; color: var(--gold-soft); }
.mode-caption {
  display: flex;
  gap: 9px;
  align-items: start;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #ffffff16;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.mode-caption p { margin: 0; }
.mode-caption-icon { color: var(--gold); font-size: 15px; line-height: 1.2; }

.board-column {
  display: grid;
  gap: 8px;
  width: min(100%, clamp(385px, calc((100svh - 180px) * .891), 570px));
  min-width: 0;
  justify-self: center;
}
.board-column.flipped #red-player { order: -1; }
.board-column.flipped #black-player { order: 1; }
.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 36px;
  padding: 3px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
}
.player-row.active, .player-row.is-active {
  border-color: #e3b98137;
  background: #d0ad7520;
}
.player-seal {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  padding-bottom: 1px;
  border: 1px solid #c4aa76;
  border-radius: 50%;
  background: #e5c895;
  color: var(--black-dark);
  font-family: var(--cjk);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
}
.red .player-seal { color: var(--red-dark); }
.player-name {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-side {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 4px 8px;
  border: 1px solid #d7ddc52b;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.red .player-side { border-color: #e28e7436; color: #ef9b87; }
.board-mount {
  width: 100%;
  aspect-ratio: 900 / 1010;
  border-radius: 2.7% / 2.4%;
  background: #eac58a url("../assets/board.svg") center / 100% 100% no-repeat;
  box-shadow: 0 2px 0 #4b2b1c, 0 8px 0 #2c2419, 0 21px 40px #0008;
  isolation: isolate;
}
.board-svg, .board-mount > svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.board-point { cursor: pointer; fill: transparent; }
.board-point:focus-visible { stroke: #9c582f; stroke-width: 4; }
.piece { --piece-ink: var(--black-dark); cursor: pointer; }
.piece.red, .piece.r { --piece-ink: var(--red-dark); }
.piece-shadow { fill: #5b351c; opacity: .33; }
.piece-face { fill: url("#piece-ivory") #f1d9a6; stroke: #996035; stroke-width: 2.5; }
.piece-outer-ring, .piece-inner-ring { fill: none; stroke: var(--piece-ink); pointer-events: none; }
.piece-outer-ring { stroke-width: 2.4; }
.piece-inner-ring { stroke-width: 1.1; opacity: .75; }
.piece-glyph {
  fill: var(--piece-ink);
  font-family: var(--cjk);
  font-size: 46px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.piece.selected .piece-face { stroke: #995016; stroke-width: 5; }
.piece.checked .piece-face { stroke: #ae332b; stroke-width: 5; stroke-dasharray: 8 4; }
.target-dot { fill: #344d32; opacity: .78; pointer-events: none; }
.capture-target { r: 42px; fill: none; stroke: #3a633a; stroke-width: 5; stroke-dasharray: 7 5; pointer-events: none; }
.last-mark { fill: none; stroke: #9e552d; stroke-width: 4; opacity: .88; pointer-events: none; }
.river-label {
  fill: #785133;
  opacity: .86;
  font-family: var(--cjk);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 9px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.match-panel {
  min-width: 0;
  margin-top: 4px;
  padding: 16px;
  border: 1px solid var(--edge);
  border-radius: 11px;
  background: linear-gradient(150deg, #262f25, var(--panel) 65%);
  box-shadow: 0 10px 25px #080b082e;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}
.panel-heading h2 {
  margin: 0;
  color: var(--text);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -.025em;
  line-height: 1.2;
}
.mode-pill {
  padding: 4px 7px;
  border: 1px solid #e2bc7d31;
  border-radius: 5px;
  color: var(--gold);
  font-size: 10px;
  line-height: 1.3;
  text-align: center;
}
.turn-box {
  min-height: 78px;
  margin-top: 15px;
  padding: 11px 12px;
  border: 1px solid #ffffff12;
  border-left: 2px solid var(--red);
  border-radius: 7px;
  background: var(--panel-inset);
}
.turn-box.black, .turn-box[data-turn="b"] { border-left-color: var(--gold); }
.turn-line { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.turn-dot, .seat-dot {
  display: block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--red);
}
.turn-box.black .turn-dot, .turn-box[data-turn="b"] .turn-dot { background: var(--gold); }
.turn-box p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.turn-box .connection-status { color: var(--gold); }
.match-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.action-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  min-height: 54px;
  padding: 5px 2px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: #ffffff06;
  font-size: 11px;
  white-space: nowrap;
}
.action-button .icon { color: var(--gold); width: 18px; height: 18px; }
.action-button:not(:disabled):hover, .action-button[aria-pressed="true"] { border-color: #a88d61; background: #e6c58a17; }
.move-facts {
  display: grid;
  gap: 7px;
  margin: 14px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid #ffffff14;
  font-size: 12px;
}
.move-facts > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.move-facts dt { flex: 0 0 auto; color: var(--muted); }
.move-facts dd { margin: 0; min-width: 0; color: var(--text); font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.history-section, .capture-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid #ffffff14; }
.match-panel h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; color: var(--text); font-size: 13px; font-weight: 700; }
.match-panel h3 .icon { width: 15px; height: 15px; color: var(--gold); }
.history-list {
  min-height: 91px;
  max-height: 153px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #8a795a transparent;
  margin: 0;
  padding: 7px 8px;
  border: 1px solid #ffffff10;
  border-radius: 7px;
  background: #151c16;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  list-style: none;
}
.history-list:empty { padding: 10px; }
.history-list:empty::before { content: "Chưa có nước đi."; }
.history-list li {
  display: grid;
  grid-template-columns: 19px 22px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  overflow-wrap: anywhere;
}
.history-list li + li { border-top: 1px solid #ffffff12; }
.history-list li:last-child { color: var(--text); }
.history-list .empty-history { display: block; color: var(--muted); }
.history-number { color: var(--gold-soft); font-size: 10px; font-variant-numeric: tabular-nums; }
.history-piece {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border: 1px solid #9b6c41;
  border-radius: 50%;
  background: #e9cc95;
  color: var(--black-dark);
  font-family: var(--cjk);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}
.history-piece.red { color: var(--red-dark); }
.capture-row { display: grid; grid-template-columns: 32px 1fr; gap: 6px; align-items: center; min-height: 28px; }
.capture-row > span { color: var(--muted); font-size: 11px; }
.capture-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-width: 0;
  color: var(--gold);
  font-family: var(--cjk);
  font-size: 16px;
  font-weight: 700;
}
.capture-pieces:empty::before { content: "—"; color: var(--muted); font-family: var(--ui); font-size: 11px; }
.capture-piece {
  display: grid;
  place-items: center;
  min-width: 23px;
  height: 23px;
  padding: 0 3px 1px;
  border: 1px solid #9b6c41;
  border-radius: 50%;
  background: #e9cc95;
  color: var(--black-dark);
  line-height: 1;
}
.capture-piece.red, .capture-piece.r { color: var(--red-dark); }
.minor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
}
.text-button {
  min-height: 39px;
  padding: 4px 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.text-button .icon { width: 14px; height: 14px; }
.text-button:not(:disabled):hover { color: var(--text); background: #ffffff09; }
#online-actions .text-button { color: var(--gold); }

.game-dialog {
  width: min(calc(100% - 28px), 450px);
  max-height: calc(100svh - 30px);
  padding: 0;
  border: 1px solid #a99264;
  border-radius: 12px;
  background: #232c22;
  color: var(--text);
  box-shadow: 0 24px 65px #000a;
}
.game-dialog::backdrop { background: #0d120ecb; }
.dialog-inner { position: relative; padding: 23px; }
.dialog-inner > h2 {
  margin: 5px 36px 15px 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(27px, 5vw, 36px);
  line-height: 1.12;
}
.dialog-close {
  position: absolute;
  top: 9px;
  right: 9px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}
.dialog-close:hover { background: #ffffff11; color: var(--text); }
.dialog-form { display: grid; gap: 7px; min-width: 0; }
.dialog-form h3 { margin: 0 0 2px; color: var(--gold); font-size: 16px; }
.dialog-form label { color: var(--muted); font-size: 13px; }
.dialog-form input, .dialog-form select {
  width: 100%;
  min-height: 44px;
  margin-bottom: 4px;
  padding: 8px 10px;
  border: 1px solid #62705b;
  border-radius: 6px;
  background: #171f17;
  color: var(--text);
  font-size: 16px;
}
.dialog-form input::placeholder { color: #a4a89a; }
.primary-button, .secondary-button {
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid #9a8053;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
}
.primary-button { background: #e2bd81; color: #23190f; }
.primary-button:not(:disabled):hover { background: #f1cf99; }
.secondary-button { background: #31382b; color: var(--text); }
.secondary-button:not(:disabled):hover { background: #424a36; }
.online-dialog { width: min(calc(100% - 28px), 595px); }
.online-forms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.online-forms form { padding: 12px; border: 1px solid var(--edge); border-radius: 8px; }
.dialog-note { margin: 10px 0; color: var(--muted); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.dialog-note:empty { display: none; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.room-code {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border: 1px solid #b4915e54;
  border-radius: 7px;
  background: var(--panel-inset);
}
.room-code > span { color: var(--muted); font-size: 12px; }
.room-code > strong { margin-right: auto; color: var(--gold); font-size: 18px; letter-spacing: .08em; }
.invite-link {
  width: 100%;
  min-height: 44px;
  margin-top: 9px;
  padding: 8px 10px;
  border: 1px solid #62705b;
  border-radius: 6px;
  background: var(--panel-inset);
  color: var(--text);
  font-size: 14px;
}
.room-seats { display: grid; gap: 6px; margin-top: 12px; }
.room-seat {
  display: grid;
  grid-template-columns: 8px 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 41px;
  padding: 6px 10px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  font-size: 13px;
}
.room-seat strong { overflow-wrap: anywhere; }
.seat-dot.black { background: var(--gold); }
.help-list { padding-left: 18px; margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.help-list li + li { margin-top: 8px; }

@media (max-width: 1100px) {
  .topbar-inner, .game-layout { width: min(calc(100% - 40px), 880px); }
  .game-layout { grid-template-columns: minmax(0, 1fr) minmax(222px, 250px); gap: 18px 20px; }
  .mode-panel { grid-column: 1 / -1; display: flex; align-items: center; gap: 20px; padding-top: 0; }
  .mode-intro { flex: 0 0 auto; }
  .mode-intro h1 { font-size: 38px; margin-top: 5px; }
  .mode-intro > p { display: none; }
  .mode-list { flex: 1 1 auto; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 0; }
  .mode-button { grid-template-columns: 29px minmax(0, 1fr); gap: 7px; min-height: 57px; padding: 7px; }
  .mode-icon { width: 29px; height: 29px; }
  .mode-icon .icon { width: 17px; height: 17px; }
  .mode-arrow, .mode-caption { display: none; }
  .mode-copy strong { font-size: 12px; }
  .mode-copy small { font-size: 10px; }
  .board-column { width: 100%; }
}

@media (max-width: 660px) {
  .topbar-inner, .game-layout { width: calc(100% - 24px); }
  .topbar-inner { min-height: 55px; gap: 6px; }
  .brand { font-size: 19px; gap: 7px; }
  .brand-mark { width: 29px; height: 29px; }
  .brand-mark .icon { width: 18px; height: 18px; }
  .topbar-tools { gap: 1px; }
  .utility { padding: 8px; }
  .utility span { display: none; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 13px; }
  .mode-panel { display: grid; gap: 10px; }
  .mode-intro { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
  .mode-intro .eyebrow { order: 1; font-size: 9px; letter-spacing: .1em; }
  .mode-intro h1 { margin: 0; font-size: clamp(31px, 8vw, 43px); }
  .mode-list { width: 100%; }
  .mode-button { grid-template-columns: 24px minmax(0, 1fr); min-height: 48px; padding: 5px; gap: 5px; }
  .mode-icon { width: 24px; height: 24px; border-radius: 5px; }
  .mode-icon .icon { width: 15px; height: 15px; }
  .mode-copy strong { font-size: 11px; line-height: 1.25; }
  .mode-copy small { display: none; }
  .board-column { width: min(100%, 515px); gap: 6px; }
  .player-row { min-height: 34px; padding-block: 2px; }
  .player-seal { width: 25px; height: 25px; flex-basis: 25px; font-size: 15px; }
  .match-panel { margin-top: 0; padding: 13px; }
  .match-actions { gap: 7px; }
  .action-button, .text-button { min-height: 44px; }
  .action-button { display: flex; justify-content: center; align-items: center; gap: 6px; }
  .history-list { min-height: 56px; max-height: 132px; }
}

@media (max-width: 440px) {
  .dialog-inner { padding: 18px; }
  .online-forms { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .online-forms form { padding: 10px; }
}

html.reduced-motion, html[data-reduced-motion="true"] { --duration: 0ms; }
@media (prefers-reduced-motion: reduce) {
  :root { --duration: 0ms; scroll-behavior: auto; }
}
