:root {
  color-scheme: dark;
  --page-start: #130b08;
  --page-mid: #29120e;
  --page-end: #090809;
  --surface: #21150f;
  --surface-2: #322118;
  --surface-3: #422a1d;
  --text: #f7ead3;
  --muted: #dec7a5;
  --muted-2: #b99a70;
  --gold: #ffcf76;
  --gold-2: #f5a93d;
  --red: #c82232;
  --red-hi: #ff626d;
  --black: #171b22;
  --black-hi: #4f5864;
  --ink: #2d160b;
  --board: #e7b867;
  --board-hi: #ffe2a0;
  --board-frame: #6e331a;
  --wood-start: #6d3219;
  --wood-end: #25100a;
  --piece-hi: #f7e3a8;
  --piece-mid: #e8b765;
  --piece-low: #9d5a25;
  --focus: #80ddff;
  --shadow: 0 24px 80px #00000070;
  --radius: 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 8%, #c8223257, transparent 28rem),
    radial-gradient(circle at 92% 16%, #ffcf7633, transparent 25rem),
    linear-gradient(135deg, var(--page-start), var(--page-mid) 45%, var(--page-end));
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 4px solid var(--focus); outline-offset: 4px; }
[hidden] { display: none !important; }

.app-shell { width: min(1280px, calc(100% - 28px)); margin: 0 auto; padding: 26px 0 36px; }
.hero-card, .game-layout, .panel-card {
  border: 1px solid #f1d49e26;
  background: linear-gradient(145deg, #f1d49e1d, #f1d49e0a);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 20px;
  align-items: stretch;
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 28px);
  margin-bottom: 18px;
}
.hero-copy { min-width: 0; }
.eyebrow { color: var(--gold); font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; margin: 0 0 8px; }
h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 5rem); letter-spacing: -.06em; line-height: .96; }
.subtitle { color: var(--muted); max-width: 760px; margin: 12px 0 0; font-size: clamp(1rem, 1.7vw, 1.12rem); line-height: 1.55; }
.mode-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.mode-strip span, .toolbar-pill {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 34px; border-radius: 999px; padding: 7px 12px;
  color: #ffe6b6; background: #00000038; border: 1px solid #ffcf7638;
  font-weight: 850; font-size: .82rem; white-space: normal;
}
.status-card { min-width: 0; border-radius: 22px; background: #00000047; padding: 18px; display: grid; gap: 9px; align-content: start; overflow-wrap: anywhere; }
.badge { width: fit-content; max-width: 100%; border-radius: 999px; padding: 8px 13px; font-weight: 950; font-size: .82rem; overflow-wrap: anywhere; }
.badge.red { background: #c8223242; color: #ffd2d6; border: 1px solid #ff626d75; }
.badge.black { background: #141820e0; color: #ebf0f7; border: 1px solid #f1d49e40; }
.status-card strong { line-height: 1.35; }
.status-card small { color: var(--muted); line-height: 1.35; }

.game-layout { border-radius: var(--radius); padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.board-panel { display: grid; gap: 12px; place-items: center; min-width: 0; }
.board-toolbar { width: min(100%, 760px); display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.red-dot::before, .black-dot::before { content: ""; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.red-dot::before { background: var(--red-hi); box-shadow: 0 0 14px #ff626db3; }
.black-dot::before { background: #d8dce3; box-shadow: 0 0 14px #f1d49e6b; }
.board-wrap { width: min(100%, 760px); padding: clamp(14px, 3vw, 34px); border-radius: 32px; background: linear-gradient(160deg, var(--wood-start), var(--wood-end)); box-shadow: inset 0 0 0 1px #f1d49e2e, 0 16px 50px #0000007a; }
.xiangqi-board {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 9;
  background:
    radial-gradient(circle at 50% 46%, #fffadb3d, transparent 10rem),
    linear-gradient(135deg, var(--board-hi), var(--board));
  border-radius: 18px;
  color: var(--ink);
  box-shadow: inset 0 0 0 5px var(--board-frame), inset 0 0 0 9px #fff4c75c;
  touch-action: manipulation;
}
.board-lines, .piece-layer, .hint-layer { position: absolute; inset: 8.5%; }
.board-lines { width: 83%; height: 83%; overflow: visible; }
.grid-lines line, .palace-lines line { stroke: #2b190ddb; stroke-width: 4; stroke-linecap: round; }
.palace-lines line { stroke-width: 3; }
.river-text { font: 900 44px serif; fill: #50271085; letter-spacing: 18px; }
.piece-layer, .hint-layer { pointer-events: none; }
.piece, .move-hint { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; }
.piece {
  width: clamp(34px, 6.1vw, 64px); height: clamp(34px, 6.1vw, 64px); border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; font-weight: 950; font-size: clamp(1.12rem, 2.8vw, 2.05rem);
  border: 3px solid #4f2a11b3;
  background: radial-gradient(circle at 35% 25%, var(--piece-hi), var(--piece-mid) 62%, var(--piece-low));
  box-shadow: 0 7px 18px #2c140866, inset 0 0 0 3px #f1d49e57;
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
.piece:hover { transform: translate(-50%, -50%) scale(1.07); filter: brightness(1.05); }
.piece.red { color: var(--red); text-shadow: 0 1px 0 #f1d49e4d; }
.piece.black { color: var(--black); text-shadow: 0 1px 0 #f1d49e3d; }
.piece.selected { box-shadow: 0 0 0 6px #80ddff66, 0 10px 22px #00000061, inset 0 0 0 3px #f1d49e61; }
.piece.own-piece { outline: 2px solid #ffcf7685; outline-offset: 3px; }
.move-hint { width: clamp(18px, 3.7vw, 30px); height: clamp(18px, 3.7vw, 30px); border-radius: 50%; border: 0; background: #80ddffc7; box-shadow: 0 0 0 8px #80ddff2e; cursor: pointer; }

.side-panel { display: grid; gap: 14px; min-width: 0; }
.panel-card { border-radius: 24px; padding: 18px; background-color: #0000003d; overflow: hidden; }
.panel-card h2 { margin: 0 0 12px; font-size: 1rem; line-height: 1.25; }
.field-label { display: block; color: var(--muted); font-weight: 850; font-size: .84rem; margin-bottom: 8px; }
.control-input {
  width: 100%; min-width: 0; border: 1px solid #f1d49e33; border-radius: 14px; padding: 12px;
  background: #00000047; color: var(--text); font-weight: 850;
}
.control-input option { color: #17130f; }
.difficulty-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.difficulty-row strong { color: var(--gold); white-space: nowrap; }
.difficulty-slider { width: 100%; accent-color: var(--gold); margin: 8px 0 2px; }
.level-help, .hint-copy, .room-status { margin: 10px 0 0; color: var(--muted); line-height: 1.48; font-size: .94rem; overflow-wrap: anywhere; }
.engine-stats { display: block; margin-top: 2px; color: var(--muted); font-variant-numeric: tabular-nums; }
.button-row, .room-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button-row button, .room-actions button, .ghost-button {
  border: 0; border-radius: 14px; padding: 11px 14px; background: var(--gold); color: #261204; font-weight: 950; cursor: pointer;
  min-height: 42px;
}
.button-row button:hover, .room-actions button:hover, .ghost-button:hover { filter: brightness(1.06); }
.ghost-button { margin-top: 10px; width: 100%; background: transparent; color: var(--gold); border: 1px solid #ffcf7661; }
.ghost-button:disabled { opacity: .45; cursor: not-allowed; }
.room-code { flex: 1 1 110px; text-transform: uppercase; letter-spacing: .08em; text-align: center; }
.share-link { display: block; margin-top: 10px; color: #8ee7ff; overflow-wrap: anywhere; line-height: 1.35; }
.captured-list { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); min-height: 34px; align-items: center; }
.captured-piece { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #f1bd68; color: var(--ink); font-weight: 950; box-shadow: inset 0 0 0 2px #f1d49e47; }
.captured-piece.red { color: var(--red); }
.move-log { margin: 0; padding-left: 1.25rem; color: var(--muted); max-height: 230px; overflow: auto; line-height: 1.35; }
.move-log li { margin: 7px 0; overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .hero-card, .game-layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-card, .network-card { grid-column: span 1; }
}
@media (max-width: 680px) {
  .app-shell { width: min(100% - 16px, 520px); padding-top: 10px; }
  .hero-card, .game-layout { border-radius: 20px; padding: 12px; }
  .hero-card { gap: 12px; }
  h1 { font-size: clamp(2rem, 12vw, 3.4rem); }
  .status-card, .panel-card { border-radius: 18px; padding: 14px; }
  .side-panel { grid-template-columns: 1fr; }
  .board-wrap { padding: 13px; border-radius: 20px; }
  .xiangqi-board { border-radius: 12px; }
  .board-lines, .piece-layer, .hint-layer { inset: 9%; }
  .river-text { font-size: 36px; letter-spacing: 10px; }
  .piece { width: clamp(30px, 9vw, 43px); height: clamp(30px, 9vw, 43px); font-size: clamp(1rem, 5.6vw, 1.42rem); border-width: 2px; }
  .mode-strip span, .toolbar-pill { font-size: .78rem; min-height: 30px; padding: 6px 9px; }
  .room-actions { display: grid; grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .app-shell { width: calc(100% - 10px); }
  .hero-card, .game-layout { padding: 9px; }
  .board-wrap { padding: 10px; }
  .piece { width: 29px; height: 29px; font-size: 1rem; }
  .river-text { font-size: 29px; letter-spacing: 7px; }
}
