:root {
  color-scheme: dark;
  --paper: #13231f;
  --surface: #1c3029;
  --surface-raised: #243b32;
  --ink: #f6f0e2;
  --muted: #b9c7bb;
  --line: #3b5349;
  --accent: #e9c47d;
  --accent-strong: #f5d99e;
  --accent-ink: #262515;
  --light-square: #eadbb9;
  --dark-square: #70907b;
  font-family: ui-sans-serif, system-ui, "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 25% 0%, #294337 0%, transparent 58%), var(--paper);
}
a { color: inherit; }
button, input, select { font: inherit; }
button:not(:disabled) { cursor: pointer; }
button:disabled { opacity: .55; }
:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

.site-header {
  border-bottom: 1px solid #334a40;
  background: #15251f;
}
.header-inner {
  display: flex;
  max-width: 1200px;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: auto;
  padding: 10px 26px;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fbefd3;
  font-family: "Songti TC", "Noto Serif TC", ui-serif, Georgia, serif;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: .065em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark img { flex: none; }
.navigation {
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid #334a40;
  border-radius: 12px;
  background: #101e19;
}
.navigation a {
  display: grid;
  min-height: 38px;
  place-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 670;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.navigation a:hover { background: var(--surface); color: var(--ink); }
.navigation a[aria-current] { background: #30483a; color: #fae4b1; }
.account { min-width: 0; text-align: right; }
.account-controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.account-controls .button { min-height: 40px; padding: 5px 11px; font-size: 14px; white-space: nowrap; }
#account-name { min-width: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
#account-status { color: var(--muted); font-size: 13px; }

.shell {
  width: min(100%, 1120px, calc(clamp(410px, 100svh - 289px, 700px) + 428px));
  margin: 0 auto;
  padding: clamp(22px, 4vh, 40px) 24px 38px;
}
.intro { margin-bottom: clamp(16px, 2.8vh, 25px); }
h1 {
  color: #fff0d3;
  font-family: "Songti TC", "Noto Serif TC", ui-serif, Georgia, serif;
  font-size: clamp(35px, 5.4vw, 57px);
  font-weight: 750;
  letter-spacing: -.025em;
  line-height: 1.12;
}
.intro p { margin-top: 9px; color: var(--muted); font-size: 16px; line-height: 1.5; }
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(286px, 337px);
  align-items: start;
  gap: clamp(16px, 2.8vw, 28px);
}
.controls { display: grid; gap: 14px; min-width: 0; }

.board-frame {
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #20352d;
  box-shadow: 0 12px 28px #08161069;
}
.board-bar, .board-foot {
  display: flex;
  min-height: 51px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 3px;
  font-size: 14px;
}
.board-bar { font-weight: 710; }
.board-indicators, .board-metrics { display: flex; align-items: center; gap: 8px; }
.board-indicators { min-width: 0; flex-wrap: wrap; }
.board-metrics { color: var(--muted); font-size: 13px; white-space: nowrap; }
.board-metrics strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.board-metrics #timer { font-size: 18px; }
.board-metrics .urgent { color: #ffad95; }
.board-state {
  padding: 4px 9px;
  border: 1px solid #536962;
  border-radius: 20px;
  background: #2c4138;
  color: #e1e9df;
  font-size: 13px;
}
.board-state[data-turn="player"] { border-color: #867441; background: #473d24; color: #ffe6a8; }
.board-foot { min-height: 60px; padding-block: 8px; }
.board-player { display: grid; gap: 3px; min-width: 0; color: var(--ink); font-weight: 700; }
#board-last-move { color: var(--muted); font-size: 13px; font-weight: 500; }
#board-last-move:empty { display: none; }
.board-actions { display: grid; grid-template-columns: auto auto; gap: 6px; }
.board-actions .button { min-height: 44px; padding-inline: 12px; font-size: 14px; }
.assistant-hint-text { grid-column: 1 / -1; color: var(--accent-strong); font-size: 14px; text-align: center; }
.board-stage { position: relative; isolation: isolate; }
.board {
  display: grid;
  grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 7px;
  container-type: inline-size;
  touch-action: manipulation;
}
.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--light-square);
  color: #426052;
  -webkit-tap-highlight-color: transparent;
}
.square:not(:disabled) { cursor: default; }
.square.dark { background: var(--dark-square); color: #10291e; }
.square.selectable, .square.target { cursor: pointer; }
.square.last { background: #dbbd76; }
.square.dark.last { background: #b49658; }
.square.selected { background: #e5c26e; box-shadow: inset 0 0 0 3px #755119; }
.square:focus-visible { z-index: 2; outline-color: #53350f; outline-offset: -4px; }
.square.in-check { background: #d88a77; }
.square.target::after {
  position: absolute;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #11392e6e;
  content: "";
}
.square.target.occupied::after { width: 87%; border: 4px solid #11392e7a; background: transparent; }
@media (hover: hover) {
  .square.selectable:not(.selected):hover, .square.target:hover { box-shadow: inset 0 0 0 3px #2c6049b0; }
}
.piece {
  z-index: 1;
  color: #1c2925;
  font-family: "Apple Symbols", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  font-size: 10.4cqw;
  line-height: 1;
  pointer-events: none;
}
.piece.white { color: #fff7e4; -webkit-text-stroke: 1px #343c32; text-shadow: 0 2px 1px #202a2477; }
.coord { position: absolute; z-index: 2; font-size: clamp(9px, 1.85cqw, 12px); font-weight: 760; pointer-events: none; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { right: 3px; bottom: 1px; }
.assistant-arrow { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; }
.board-overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; border-radius: 7px; background: #192e2675; pointer-events: none; }
.board-overlay span { padding: 10px 17px; border: 1px solid #667b66; border-radius: 8px; background: #1c342a; color: #fff4d9; font-weight: 720; text-align: center; }

.control-card, .ranking {
  min-width: 0;
  padding: clamp(18px, 2.6vw, 26px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 10px 24px #0816103d;
}
.control-card h2, .ranking h2, dialog h2 { color: #fff2d6; font-size: 22px; line-height: 1.3; }
.status-text { margin-top: 10px; color: var(--muted); line-height: 1.55; overflow-wrap: anywhere; }
.game-status { color: #e6e9d9; }
.actions, .field-group { display: grid; gap: 10px; margin-top: 19px; }
.field-group { gap: 7px; }
.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 740;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover:not(:disabled) { background: var(--accent-strong); }
.secondary { border-color: #536b5d; background: #2a4135; color: #f7efdc; }
.secondary:hover:not(:disabled) { background: #395346; }
.quiet { background: transparent; color: var(--muted); }
.quiet:hover:not(:disabled) { background: #31483d; }
.support-text { margin-top: 16px; color: var(--muted); font-size: 14px; line-height: 1.48; }
.support-text a { text-underline-offset: 3px; }
.support-text a:hover { color: var(--accent-strong); }
.room-card, .copilot-evaluation, .replay-analysis {
  padding: 13px 14px;
  margin-top: 16px;
  border: 1px solid #445d50;
  border-radius: 10px;
  background: #132820;
}
.room-card { display: grid; gap: 4px; }
.room-card span { color: var(--muted); font-size: 14px; font-weight: 720; }
.room-card strong { color: var(--accent-strong); font-size: 24px; font-variant-numeric: tabular-nums; letter-spacing: .1em; }
.join-form { display: grid; gap: 7px; margin-top: 8px; }
label { font-size: 14px; font-weight: 710; }
.input-row { display: flex; gap: 8px; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid #61766a;
  border-radius: 8px;
  background: #12251e;
  color: var(--ink);
}
input::placeholder { color: #9dad9e; }
.input-row button { flex-shrink: 0; }
#room-code { text-transform: uppercase; }
.copilot-evaluation-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 7px; }
.copilot-evaluation-heading h3 { font-size: 15px; }
#copilot-balance { color: var(--accent-strong); font-size: 14px; font-weight: 700; }
.copilot-rate-bar { display: flex; height: 14px; margin-top: 12px; border: 1px solid #768c79; border-radius: 5px; background: #748b7e; overflow: hidden; }
.copilot-rate-bar span { flex-basis: 0; }
.copilot-rate-bar span:nth-child(1) { background: #f6e5bc; }
.copilot-rate-bar span:nth-child(2) { background: #819b88; }
.copilot-rate-bar span:nth-child(3) { background: #121c18; }
.copilot-rate-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.copilot-rate-values span { display: grid; gap: 3px; }
.copilot-rate-values span:nth-child(2) { text-align: center; }
.copilot-rate-values span:nth-child(3) { text-align: right; }
.copilot-rate-values strong { color: var(--ink); font-size: clamp(17px, 2vw, 21px); line-height: 1.2; }
.check-control { display: flex; align-items: center; gap: 8px; margin-top: 14px; min-height: 30px; }
.check-control input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
.coach-explanation { color: #e7eddf; font-size: 14px; line-height: 1.65; }
.coach-explanation:not(:empty) { margin-top: 12px; }
.history-rows { display: grid; gap: 8px; padding: 0; margin: 13px 0 0; list-style: none; }
.history-rows li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; }
.history-rows li p { margin-top: 4px; color: var(--muted); font-size: 14px; }
.history-rows li button { flex: none; }
.replay-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#history-ply { min-height: 33px; padding: 0; accent-color: var(--accent); }
.replay-analysis { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.replay-analysis strong { color: var(--accent-strong); font-size: 18px; }
.replay-analysis p:empty { display: none; }
.replay-analysis .support-text { margin: 0; }
.ranking-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ranking-toolbar .button { flex: none; }
table { width: 100%; margin-top: 16px; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
th, td { padding: 12px 9px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
th { color: var(--muted); font-size: 14px; }
td:nth-child(3) { color: #fae4ad; font-weight: 750; }
.ranking-cta { margin-top: 22px; }
dialog {
  width: min(360px, calc(100% - 28px));
  padding: 22px;
  border: 1px solid #566d60;
  border-radius: 15px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: #07150eb8; }
.promotions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; }
.account-fields { display: grid; gap: 8px; margin-top: 16px; }
.account-fields label:not(:first-child) { margin-top: 4px; }

@media (max-width: 820px) {
  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 14px;
    padding: 9px 15px 10px;
  }
  .navigation {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1px;
  }
  .navigation a { min-height: 44px; padding: 5px 4px; white-space: normal; }
}
@media (max-width: 700px) {
  .shell { max-width: 550px; padding: 19px 12px 30px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .board-frame { padding: 0 8px; }
  .board-bar { min-height: 42px; }
  .board-foot { min-height: 43px; }
  .board-actions { width: 100%; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 410px) {
  .header-inner { padding-inline: 10px; }
  .wordmark { gap: 7px; font-size: 20px; }
  .wordmark img { width: 37px; height: 37px; }
  .navigation a { font-size: 13px; }
  .board-bar { font-size: 13px; }
  .board-metrics { gap: 5px; }
  .board-metrics #timer { font-size: 16px; }
  .board-state { padding-inline: 6px; }
  th, td { padding-inline: 4px; }
  .ranking-toolbar h2 { font-size: 18px; }
  .ranking-toolbar .button { padding-inline: 8px; font-size: 14px; }
}
