* { box-sizing: border-box; }

:root {
  --wood: #e8c98f;
  --wood-line: #8a5a2b;
  --ink: #2b2016;
  --red: #c0392b;
  --panel: #1f1b16;
  --panel-2: #2a241c;
  --gold: #d4a24c;
  --text: #e8dfd2;
  --font-scale: 1;
  --muted: #b9ab96;
  --muted-2: #c9bda9;
  --muted-3: #8c806f;
  --input-bg: #15110c;
  --btn-bg: #33291d;
  --btn-hover: #453723;
  --danger: #ff9b8f;
  --n-red: #ff8b7e;
  --n-black: #cfd6dd;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible {
  outline: 3px solid #2c6fb5; outline-offset: 2px;
}
canvas:focus-visible { outline: 3px solid #2c6fb5; outline-offset: 2px; }

/* 高对比度主题：覆盖变量与原先的字面量颜色 */
body.hc {
  --wood: #ffffff;
  --wood-line: #000000;
  --ink: #000000;
  --red: #a00000;
  --panel: #000000;
  --panel-2: #0a0a0a;
  --gold: #ffd400;
  --text: #ffffff;
  --muted: #ffffff;
  --muted-2: #ffffff;
  --muted-3: #e0e0e0;
  --input-bg: #000000;
  --btn-bg: #000000;
  --btn-hover: #222222;
  --danger: #ff6666;
  --n-red: #ff8888;
  --n-black: #ffffff;
  background: #000000;
}
body.hc .header p, body.hc .player-tag { color: var(--muted); }
body.hc .clock.low { color: #ff6666; border-color: #ff6666; }
body.hc .notation li.red .txt { color: var(--n-red); }
body.hc .notation li.black .txt { color: var(--n-black); }
body.hc .notation li.variation { color: var(--muted-2); }
body.hc .notation li.empty { color: var(--muted-3); }
body.hc .tips { color: var(--muted-3); }
body.hc .muted { color: var(--muted-2); }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: radial-gradient(circle at 50% 0%, #3a3023 0%, #17130e 70%);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  user-select: none;
  -webkit-user-select: none;
}

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}
.header .logo {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--wood);
  color: var(--red);
  font-size: 30px;
  font-weight: 700;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.header h1 { margin: 0; font-size: calc(26px * var(--font-scale)); letter-spacing: 4px; color: var(--gold); }
.header p { margin: 4px 0 0; font-size: calc(13px * var(--font-scale)); color: var(--muted); letter-spacing: 1px; }

.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}
.board-section { flex: 0 0 auto; }
.canvas-wrap {
  background: var(--wood);
  padding: 0;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5), inset 0 0 0 2px rgba(0,0,0,.15);
  overflow: hidden;
}
canvas {
  display: block; width: 100%; max-width: 470px; height: auto;
  cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.player-row {
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.player-tag {
  text-align: center;
  font-size: calc(14px * var(--font-scale));
  letter-spacing: 2px;
  color: var(--muted);
  padding: 6px 0;
}
.player-tag.active { color: var(--gold); font-weight: 700; }
#eval-chart {
  display: block; width: 100%; height: 96px; max-width: none; max-height: none;
  border: 1px solid rgba(212,162,76,.3); border-radius: 6px;
  background: rgba(0,0,0,.25); cursor: crosshair; touch-action: manipulation;
}
.clock {
  font-variant-numeric: tabular-nums; font-size: calc(15px * var(--font-scale)); font-weight: 700;
  color: var(--gold); min-width: 72px; text-align: center;
  padding: 3px 8px; border: 1px solid rgba(212,162,76,.3);
  border-radius: 6px; background: rgba(0,0,0,.25);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.clock.low {
  color: #ff8b7e; border-color: rgba(192,57,43,.6);
  animation: clockPulse 1s infinite alternate;
}
@keyframes clockPulse { from { opacity: 1; } to { opacity: .55; } }

.panel {
  flex: 1 1 auto;
  min-width: 260px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(212,162,76,.25);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.status {
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(212,162,76,.3);
  color: var(--gold);
  font-size: calc(16px * var(--font-scale));
  font-weight: 700;
  letter-spacing: 1px;
}
.group { display: flex; flex-direction: column; gap: 10px; }
.group.grow { flex: 1; min-height: 140px; }
.group-title {
  font-size: calc(13px * var(--font-scale));
  color: var(--muted-2);
  border-bottom: 1px dashed rgba(212,162,76,.25);
  padding-bottom: 6px;
  display: flex; justify-content: space-between;
}
.muted { color: var(--muted-3); font-weight: normal; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: calc(14px * var(--font-scale)); }
.field span { color: var(--muted-2); }
select, input[type=text] {
  flex: 1; max-width: 160px; min-width: 0;
  background: var(--input-bg); color: var(--text);
  border: 1px solid rgba(212,162,76,.35);
  border-radius: 6px; padding: 7px 8px; font-size: calc(14px * var(--font-scale));
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
input[type=text] { letter-spacing: 2px; text-transform: uppercase; }
#net-status { font-size: calc(13px * var(--font-scale)); letter-spacing: 0; font-weight: 400; }
textarea {
  width: 100%; resize: vertical;
  background: var(--input-bg); color: var(--text);
  border: 1px solid rgba(212,162,76,.35);
  border-radius: 6px; padding: 8px; font-size: calc(13px * var(--font-scale));
  font-family: inherit; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
textarea:disabled { opacity: .45; }
.btn.active { background: var(--gold); color: #241a0e; font-weight: 700; border-color: var(--gold); }
.notation li .cmt { color: var(--muted-3); font-style: italic; font-size: calc(12px * var(--font-scale)); margin-left: 4px; }
.buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.buttons.four { grid-template-columns: repeat(4, 1fr); }
.btn {
  background: var(--btn-bg); color: var(--text);
  border: 1px solid rgba(212,162,76,.3);
  border-radius: 6px; padding: 9px 6px; font-size: calc(14px * var(--font-scale));
  cursor: pointer; transition: .15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--btn-hover); border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--btn-bg); border-color: rgba(212,162,76,.3); }
.btn.primary { background: var(--gold); color: #241a0e; font-weight: 700; border-color: var(--gold); }
.btn.primary:hover { background: var(--gold); }
.btn.danger { color: var(--danger); border-color: rgba(192,57,43,.5); }

.notation {
  list-style: none; margin: 0; padding: 0;
  max-height: 190px; overflow-y: auto;
  font-size: calc(14px * var(--font-scale));
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px;
}
.notation li {
  padding: 5px 8px; border-radius: 4px;
  background: rgba(255,255,255,.03);
  display: flex; gap: 6px; align-items: center;
}
.notation li .no { color: var(--muted-3); font-size: calc(12px * var(--font-scale)); min-width: 20px; }
.notation li.red .txt { color: var(--n-red); }
.notation li.black .txt { color: var(--n-black); }
.notation li.latest { background: rgba(212,162,76,.15); }
.notation li.reviewing { box-shadow: inset 0 0 0 1px var(--gold); }
.notation li.variation {
  grid-column: 1 / -1; color: var(--muted-2); font-size: calc(13px * var(--font-scale));
  border-left: 2px solid rgba(212,162,76,.45); margin-left: 6px;
}
.notation li.variation .no { color: #6f6558; }
.notation.tree { grid-template-columns: 1fr; }
.notation li.empty { grid-column: 1 / -1; color: var(--muted-3); justify-content: center; }

.tips { font-size: calc(12px * var(--font-scale)); color: var(--muted-3); line-height: 1.6; border-top: 1px dashed rgba(212,162,76,.2); padding-top: 10px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 10;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel-2); border: 1px solid var(--gold);
  border-radius: 10px; padding: 24px; text-align: center; min-width: 260px;
}
.modal-box h3 { margin: 0 0 8px; color: var(--gold); }
.modal-box p { color: var(--muted-2); margin: 0 0 18px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }

/* ---------- 竖屏 / 窄屏：堆叠布局，按钮适合触控 ---------- */
@media (max-width: 820px) {
  .app { padding: 12px 10px 24px; }
  .layout { flex-direction: column; align-items: center; gap: 12px; }
  .panel { width: 100%; max-width: 470px; min-width: 0; padding: 14px; gap: 14px; }
  .header h1 { font-size: calc(22px * var(--font-scale)); }

  .btn { min-height: 44px; font-size: calc(14px * var(--font-scale)); }
  .buttons { gap: 6px; }
  .buttons.four { grid-template-columns: repeat(2, 1fr); }

  .player-tag { font-size: calc(12px * var(--font-scale)); padding: 4px 0; }
  .clock { font-size: calc(13px * var(--font-scale)); min-width: 60px; padding: 2px 6px; }
  .status { padding: 9px; font-size: calc(14px * var(--font-scale)); }
  .notation { max-height: 150px; }

  /* 棋盘按视口高度自适应，固有比例 564:624 保证点击坐标换算不变 */
  canvas {
    width: auto; height: auto;
    max-width: min(470px, 100%);
    max-height: calc(100vh - 200px);
  }
}
@supports (height: 100dvh) {
  @media (max-width: 820px) and (orientation: portrait) {
    canvas { max-height: calc(100dvh - 200px); }
  }
}
@media (max-width: 380px) {
  .notation { grid-template-columns: 1fr; }
}

/* ---------- 横屏低高度：左右布局，棋盘按高度最大化 ---------- */
@media (orientation: landscape) and (max-height: 620px) {
  .app { padding: 6px 10px; max-width: none; }
  .header { display: none; }
  .layout { flex-direction: row; align-items: stretch; gap: 10px; width: 100%; }

  canvas {
    width: auto; height: auto;
    max-width: min(60vw, 720px); max-height: calc(100vh - 16px);
  }

  .panel {
    flex: 1 1 auto; min-width: 0; max-width: none;
    max-height: calc(100vh - 16px); overflow-y: auto;
    padding: 10px; gap: 8px;
  }
  .status { padding: 6px 8px; font-size: calc(13px * var(--font-scale)); }
  .group { gap: 6px; }
  .tips { display: none; }
  .player-row { gap: 8px; }
  .player-tag, .clock { font-size: calc(12px * var(--font-scale)); padding: 2px 6px; }
  .clock { min-width: 60px; }
  .notation { max-height: 110px; }
  .btn { min-height: 40px; padding: 7px 4px; }
}
@supports (height: 100dvh) {
  @media (orientation: landscape) and (max-height: 620px) {
    canvas { max-height: calc(100dvh - 16px); }
    .panel { max-height: calc(100dvh - 16px); }
  }
}
