/* 海拉尔棋 · 塞尔达风格界面（森林神殿 / 羊皮纸 / 金色符文） */

:root {
  --ink: #f2ead6;
  --ink-dim: #c3bda7;
  --muted: #8f9a8c;
  --gold: #d8b65f;
  --gold-bright: #f3d98e;
  --gold-line: rgba(216, 182, 95, 0.34);
  --teal: #6fe3c0;
  --teal-dim: rgba(111, 227, 192, 0.24);
  --panel: rgba(10, 27, 22, 0.82);
  --panel-solid: #0d231c;
  --bg-deep: #050e0b;
  --bg-mid: #0a1c16;
  --danger: #e2705a;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --serif: "Palatino Linotype", "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  background:
    radial-gradient(120% 80% at 50% -10%, #12362b 0%, #0a1d17 42%, var(--bg-deep) 100%) fixed,
    var(--bg-deep);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body.is-fullscreen {
  background: #06110d;
}

/* ---------- 背景光晕与雾气 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.backdrop .glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.5;
}

.backdrop .g1 {
  width: 62vmax;
  height: 62vmax;
  left: -20vmax;
  top: -24vmax;
  background: radial-gradient(circle, rgba(63, 168, 132, 0.5), transparent 66%);
  animation: drift-a 26s ease-in-out infinite alternate;
}

.backdrop .g2 {
  width: 54vmax;
  height: 54vmax;
  right: -18vmax;
  bottom: -22vmax;
  background: radial-gradient(circle, rgba(180, 143, 66, 0.34), transparent 68%);
  animation: drift-b 32s ease-in-out infinite alternate;
}

.backdrop .mist {
  position: absolute;
  left: -50%;
  width: 200%;
  height: 30vh;
  background: radial-gradient(ellipse at center, rgba(126, 214, 178, 0.1), transparent 70%);
  filter: blur(18px);
}

.backdrop .m1 { top: 18%; animation: mist-a 38s linear infinite; }
.backdrop .m2 { top: 58%; animation: mist-b 46s linear infinite; opacity: 0.7; }

@keyframes drift-a { to { transform: translate3d(6vmax, 4vmax, 0) scale(1.12); } }
@keyframes drift-b { to { transform: translate3d(-5vmax, -5vmax, 0) scale(1.08); } }
@keyframes mist-a { from { transform: translateX(-8%); } to { transform: translateX(8%); } }
@keyframes mist-b { from { transform: translateX(6%); } to { transform: translateX(-6%); } }

/* ---------- 顶栏 ---------- */
.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 12px 6px;
}

.topbar .home {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  color: var(--gold-bright);
  background: linear-gradient(160deg, rgba(24, 54, 44, 0.9), rgba(10, 26, 21, 0.9));
  border: 1px solid var(--gold-line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.topbar .home svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.topbar .home:active { transform: translateY(1px); }

.brand {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 2px;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.15;
  color: #f6ecd2;
  text-shadow: 0 0 18px rgba(216, 182, 95, 0.28);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  margin: 1px 0 0;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: rgba(216, 182, 95, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 13px;
  border: 1px solid var(--gold-line);
  background: linear-gradient(160deg, rgba(24, 54, 44, 0.9), rgba(10, 26, 21, 0.9));
  color: var(--gold-bright);
  font: 700 12px/1 var(--sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .ico-on { fill: currentColor; stroke-width: 1.6; }
.icon-btn.off .ico-on { display: none; }
.icon-btn:not(.off) .ico-off { display: none; }

.icon-btn:active { transform: translateY(1px) scale(0.97); }

.icon-btn:focus-visible,
.btn:focus-visible,
.seg button:focus-visible,
.coach-toggle:focus-visible,
.coach-arrow:focus-visible,
.promo-grid button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.fs-btn .fs-exit { display: none; }
.fs-btn.is-fs .fs-enter { display: none; }
.fs-btn.is-fs .fs-exit { display: block; }

/* ---------- 主体 ---------- */
.wrap {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
  padding: 4px 12px calc(22px + var(--safe-b));
}

.board-area {
  width: 100%;
  min-width: 0;
}

.board-wrap {
  position: relative;
  width: 100%;
}

.side-panel {
  display: contents;
}

/* 窄屏时把对局信息放回棋盘上方，其余功能仍排在棋盘下方 */
.hud {
  order: -1;
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 6px 2px 10px;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid rgba(216, 182, 95, 0.22);
  background: rgba(9, 25, 20, 0.7);
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.hud-chip.moves span {
  color: var(--muted);
  font-weight: 500;
}

.hud-chip.moves b {
  color: var(--gold-bright);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.hud-chip.turn {
  background: linear-gradient(160deg, rgba(31, 70, 55, 0.9), rgba(12, 34, 27, 0.9));
  color: #eaf5e4;
}

.hud-chip.turn.b {
  background: linear-gradient(160deg, rgba(20, 44, 50, 0.92), rgba(9, 24, 27, 0.92));
  color: #cfe4e4;
}

.hud-chip.turn.w::before,
.hud-chip.turn.b::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.hud-chip.turn.w::before {
  background: #f4ead2;
  box-shadow: 0 0 8px rgba(244, 234, 210, 0.9);
}

.hud-chip.turn.b::before {
  background: #3d5a4d;
  box-shadow: 0 0 8px rgba(111, 227, 192, 0.55);
}

.hud-chip.side {
  margin-left: auto;
  color: rgba(216, 182, 95, 0.85);
  background: rgba(9, 25, 20, 0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34%;
}

/* ---------- 棋盘舞台 ---------- */
.board-wrap {
  position: relative;
}

.alert {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -10px);
  padding: 7px 16px;
  border-radius: 999px;
  background: linear-gradient(160deg, rgba(120, 34, 26, 0.95), rgba(74, 18, 14, 0.95));
  border: 1px solid rgba(255, 176, 140, 0.55);
  color: #ffe8da;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 26px rgba(80, 10, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.alert.show {
  opacity: 1;
  transform: translate(-50%, 0);
  animation: alert-pulse 1.5s ease-in-out infinite;
}

@keyframes alert-pulse {
  0%, 100% { box-shadow: 0 10px 26px rgba(80, 10, 0, 0.45); }
  50% { box-shadow: 0 10px 30px rgba(228, 106, 78, 0.5); }
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #1a3d31 0%, #0d241d 46%, #071510 100%);
  border: 1px solid rgba(216, 182, 95, 0.26);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    0 0 0 4px rgba(9, 24, 19, 0.55),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 236, 190, 0.07), inset 0 0 42px rgba(0, 0, 0, 0.42);
}

.stage .scene {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.stage .scene canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

.turn-glow {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(90% 70% at 50% 100%, rgba(216, 182, 95, 0.16), transparent 62%);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.turn-glow.on { opacity: 1; }

.loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 40%, rgba(18, 48, 38, 0.96), rgba(5, 14, 11, 0.98));
  color: rgba(233, 224, 196, 0.86);
  font-size: 13px;
  letter-spacing: 0.12em;
  transition: opacity 0.45s ease, visibility 0.45s;
}

.loading.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading p { margin: 0; }

.rune-spin {
  position: relative;
  width: 58px;
  height: 58px;
}

.rune-spin i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
}

.rune-spin i:nth-child(1) {
  border-top-color: var(--gold-bright);
  animation: spin 2.4s linear infinite;
}

.rune-spin i:nth-child(2) {
  inset: 8px;
  border-right-color: var(--teal);
  animation: spin 1.7s linear infinite reverse;
}

.rune-spin i:nth-child(3) {
  inset: 17px;
  border-bottom-color: rgba(216, 182, 95, 0.8);
  animation: spin 1.2s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 状态文字 */
.status {
  min-height: 22px;
  margin: 12px 4px 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #e6ddc4;
  letter-spacing: 0.02em;
}

/* ---------- 走法小课堂 ---------- */
.coach {
  margin: 0 0 10px;
  padding: 9px 11px 10px;
  border-radius: 14px;
  border: 1px solid rgba(111, 227, 192, 0.26);
  background: linear-gradient(160deg, rgba(26, 64, 51, 0.78), rgba(8, 22, 18, 0.82));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.coach-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.coach-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--teal);
}

.coach-toggle {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(111, 227, 192, 0.3);
  background: rgba(8, 25, 20, 0.72);
  color: #dff5ea;
  font: 600 10.5px/1.2 var(--sans);
  white-space: nowrap;
  cursor: pointer;
}

.coach-toggle.off {
  color: var(--muted);
  border-color: rgba(143, 154, 140, 0.3);
}

.coach-toggle:disabled {
  opacity: 0.5;
  cursor: default;
}

.coach-text {
  margin: 5px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: #e9e1ca;
}

.coach-lesson {
  border-color: rgba(214, 178, 88, 0.3);
  background: linear-gradient(160deg, rgba(58, 48, 22, 0.7), rgba(18, 16, 8, 0.82));
}

.coach-lesson .coach-title {
  color: var(--gold);
}

.coach-nav {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}

.coach-arrow {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 7px;
  border: 1px solid rgba(214, 178, 88, 0.36);
  background: rgba(20, 16, 8, 0.7);
  color: #f0dfa8;
  font: 700 14px/1 var(--sans);
  cursor: pointer;
}

.coach-arrow:active {
  transform: translateY(1px);
}

.coach-count {
  min-width: 26px;
  text-align: center;
  font: 600 10.5px/1 var(--sans);
  color: var(--muted);
}

.coach-lesson-title {
  margin: 7px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: #f3e7bd;
}

/* ---------- 控制按钮 ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  margin-bottom: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--gold-line);
  background: linear-gradient(165deg, rgba(28, 60, 49, 0.92), rgba(9, 25, 20, 0.94));
  color: #eee6cf;
  font: 600 13.5px/1.2 var(--sans);
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}

.btn:active { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.38;
  cursor: default;
  box-shadow: none;
}

.btn.save-btn.off {
  color: var(--muted);
  border-color: rgba(143, 154, 140, 0.28);
}

.btn.primary {
  background: linear-gradient(165deg, #e2c274, #b8913e);
  border-color: rgba(255, 240, 190, 0.7);
  color: #22190a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 22px rgba(184, 145, 62, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn.ghost {
  background: transparent;
  border-color: rgba(216, 182, 95, 0.25);
  color: var(--ink-dim);
  box-shadow: none;
}

/* ---------- 模式与难度 ---------- */
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 13px;
  border: 1px solid rgba(216, 182, 95, 0.2);
  background: rgba(7, 20, 16, 0.66);
}

.seg button {
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-dim);
  font: 600 13px/1 var(--sans);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.seg button.on {
  background: linear-gradient(160deg, rgba(53, 104, 82, 0.95), rgba(24, 56, 44, 0.95));
  color: #f5efd9;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 10px rgba(0, 0, 0, 0.3);
}

.seg.level {
  margin-left: auto;
}

.seg.level.muted {
  opacity: 0.42;
}

/* ---------- 走子记录 ---------- */
.moves {
  border-radius: 16px;
  border: 1px solid rgba(216, 182, 95, 0.2);
  background: rgba(8, 22, 18, 0.72);
  overflow: hidden;
}

.moves summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
}

.moves summary::-webkit-details-marker { display: none; }

.moves summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}

.moves[open] summary::before { transform: rotate(45deg); }

.moves ul {
  max-height: 172px;
  margin: 0;
  padding: 0 14px 12px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.moves li {
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  color: #e4dcc5;
  border-top: 1px solid rgba(216, 182, 95, 0.1);
  font-variant-numeric: tabular-nums;
}

.moves li:first-child { border-top: 0; }

.moves li b {
  color: rgba(216, 182, 95, 0.8);
  font-weight: 600;
}

.moves li.empty {
  display: block;
  color: var(--muted);
  padding: 6px 0 8px;
  border-top: 0;
}

/* ---------- 提示 ---------- */
.hint {
  margin: 11px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: rgba(143, 154, 140, 0.85);
  letter-spacing: 0.04em;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(22px + var(--safe-b));
  transform: translate(-50%, 10px);
  max-width: 84vw;
  padding: 9px 17px;
  border-radius: 999px;
  background: rgba(10, 26, 21, 0.94);
  border: 1px solid var(--gold-line);
  color: #f2ead6;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 9, 7, 0.72);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s;
}

.modal.show {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  width: min(92vw, 380px);
  padding: 22px 20px 20px;
  border-radius: 22px;
  border: 1px solid rgba(216, 182, 95, 0.4);
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(31, 72, 58, 0.55), transparent 60%),
    linear-gradient(170deg, #102b23, #081813 78%);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  text-align: center;
  transform: translateY(10px) scale(0.98);
  transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.modal.show .modal-card {
  transform: translateY(0) scale(1);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #f8efd6;
}

.modal-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-dim);
}

.promo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promo-grid button {
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 11px 0 9px;
  border-radius: 14px;
  border: 1px solid rgba(216, 182, 95, 0.28);
  background: linear-gradient(165deg, rgba(30, 64, 52, 0.9), rgba(9, 25, 20, 0.94));
  color: var(--ink);
  font: 600 12px/1 var(--sans);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}

.promo-grid button:active { transform: scale(0.96); }
.promo-grid button:hover { border-color: rgba(243, 217, 142, 0.7); }

.promo-glyph {
  font-size: 30px;
  line-height: 1;
  color: var(--gold-bright);
  text-shadow: 0 0 14px rgba(216, 182, 95, 0.5);
}

.result-card { padding-top: 20px; }

.result-icon {
  display: grid;
  place-items: center;
  height: 84px;
  margin-bottom: 4px;
}

.result-icon svg {
  width: 82px;
  height: 82px;
  filter: drop-shadow(0 6px 18px rgba(216, 182, 95, 0.3));
}

.result-card p {
  margin: 2px 0 18px;
  font-size: 14px;
  color: var(--ink-dim);
  line-height: 1.6;
}

.result-actions {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.result-actions .btn { min-height: 46px; }

@media (max-width: 400px) {
  .brand h1 { font-size: 17px; }
  .wrap { padding-left: 9px; padding-right: 9px; }
  .controls { gap: 6px; }
  .btn { font-size: 12.5px; padding: 0 8px; }
  .seg button { padding: 0 12px; }
  .hud-chip { padding: 0 9px; font-size: 11.5px; }
  .hud-chip.side { max-width: 30%; }
}

@media (max-width: 340px) {
  .icon-btn, .topbar .home { width: 36px; height: 36px; border-radius: 11px; }
  .brand p { display: none; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .save-btn { grid-column: 1 / -1; }
  .seg.level { margin-left: 0; }
}

/* ---------- 横屏 / 宽屏：棋盘主区 + 右侧功能栏 ---------- */
@media (min-width: 760px) and (min-aspect-ratio: 6 / 5) {
  .topbar {
    max-width: 1560px;
  }

  .wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(216px, 20vw, 280px);
    align-items: center;
    gap: 18px;
    max-width: 1560px;
    padding: 2px 16px calc(14px + var(--safe-b));
  }

  .board-area {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
  }

  /* 棋盘高度约占视口 90%，同时受宽度和顶栏剩余空间限制 */
  .board-wrap {
    width: min(100%, 90dvh, calc(100dvh - 76px));
    margin: 0 auto;
  }

  .side-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(90dvh, calc(100dvh - 76px));
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .side-panel .hud {
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
  }

  .side-panel .hud-chip {
    height: 28px;
    padding: 0 9px;
    font-size: 11.5px;
  }

  .side-panel .hud-chip.side {
    margin-left: 0;
    max-width: 100%;
  }

  .side-panel .status {
    min-height: 0;
    margin: 0;
    text-align: left;
  }

  .side-panel .coach {
    margin: 0;
  }

  .side-panel .controls {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin: 0;
  }

  .side-panel .controls .save-btn {
    grid-column: 1 / -1;
  }

  .side-panel .btn {
    min-height: 42px;
  }

  .side-panel .modes {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 7px;
    margin: 0;
  }

  .side-panel .seg {
    width: 100%;
  }

  .side-panel .seg button {
    flex: 1;
    padding: 0 8px;
  }

  .side-panel .seg.level {
    margin-left: 0;
  }

  .side-panel .moves {
    margin: 0;
  }

  .side-panel .moves ul {
    max-height: min(26vh, 230px);
  }

  .side-panel .hint {
    margin: 0;
    text-align: left;
    line-height: 1.45;
  }
}

/* 全屏时保持同样的「棋盘 + 侧栏」结构，让棋盘尽量占满高度 */
body.is-fullscreen .stage {
  max-height: none;
  margin: 0;
}

body.is-fullscreen .wrap {
  max-width: 1560px;
}

body.is-fullscreen .board-wrap {
  width: min(100%, 90dvh, calc(100dvh - 76px));
  margin: 0 auto;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
