* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #171310;
  --panel: #211a14;
  --panel2: #281f17;
  --line: #3a2e22;
  --text: #e9decb;
  --muted: #9a8a74;
  --gold: #d9a441;
  --red: #c05345;
  --black-chip: #8b93a1;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Heiti TC", sans-serif;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- 頂部 ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0));
  flex: none;
}

h1 { font-size: 19px; letter-spacing: 6px; font-weight: 700; }
.brand .sub {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 2.5px;
  color: var(--muted);
}

#hud { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* 回合狀態：浮動顯示在棋盤黑底右上角，不佔 header 空間 */
#turn {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 6;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid rgba(58, 46, 34, 0.9);
  border-radius: 999px;
  background: rgba(23, 18, 13, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  font-size: 14px;
}

/* 固定視角開關：浮動在棋盤黑底左上角，與回合徽章對稱。
   平時只顯示圖釘圖示，滑鼠 hover／鍵盤 focus 時以動畫展開文字標籤 */
#btnLock {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 8px;
  border-radius: 999px;
  background: rgba(23, 18, 13, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  border-color: rgba(58, 46, 34, 0.9);
  font-size: 14px;
  transition: gap 0.28s ease, padding 0.28s ease, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
#btnLock svg { flex: none; }
#btnLock .lbl {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  letter-spacing: 1px;
  transition: max-width 0.28s ease, opacity 0.2s ease;
}
#btnLock:hover, #btnLock:focus-visible {
  gap: 7px;
  padding: 8px 14px;
}
#btnLock:hover .lbl, #btnLock:focus-visible .lbl {
  max-width: 104px;
  opacity: 1;
}
#btnLock.on {
  color: var(--gold);
  border-color: rgba(217, 164, 65, 0.55);
  box-shadow: 0 0 16px rgba(217, 164, 65, 0.25);
}
#turnDot { width: 11px; height: 11px; border-radius: 50%; background: var(--red); box-shadow: 0 0 9px var(--red); }

/* 殺局標題比一般回合文字長，須為上游圖釘的展開標籤保留空間。 */
#app:is(.editor-active, .library-active) #turn { max-width: calc(100% - 78px); }
#app:is(.editor-active, .library-active) #turnDot { flex: none; }
#app:is(.editor-active, .library-active) #turnText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#app:is(.editor-active, .library-active) #btnLock:is(:hover, :focus-visible) ~ #turn {
  max-width: calc(100% - 180px);
}

button {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: #33281d; border-color: #4d3c2a; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
#btnEditor[aria-pressed="true"] {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}
#btnLibrary[aria-pressed="true"] {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}

/* 對弈模式選單：外觀與按鈕一致 */
#modeSel {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s;
}
#modeSel:hover { background: #33281d; border-color: #4d3c2a; }

.glyph-orientation-setting {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.glyph-orientation-setting select {
  max-width: 165px;
  padding: 7px 8px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.glyph-orientation-setting select:focus-visible { outline: 2px solid #f3ca70; outline-offset: 2px; }

.side-chooser {
  display: inline-flex;
  align-items: stretch;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel2);
}
.side-chooser[hidden] { display: none; }
.side-chooser legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.side-chooser input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.side-chooser label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}
.side-chooser label + input + label { border-left: 1px solid var(--line); }
.side-chooser input:checked + label {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  font-weight: 700;
}
.side-chooser input:focus-visible + label {
  outline: 2px solid #f3ca70;
  outline-offset: -3px;
}
.side-chooser input:disabled + label { opacity: 0.45; cursor: default; }

/* AI 思考中：回合指示燈呼吸閃爍 */
#turn.thinking #turnDot { animation: thinkpulse 1.1s ease-in-out infinite; }
@keyframes thinkpulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.72); }
}

#repoLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--muted);
  text-decoration: none;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#repoLink:hover { background: #33281d; border-color: #4d3c2a; color: var(--text); }
#repoLink svg { flex: none; }

/* 「更多」選單按鈕：僅小螢幕顯示；#hudMore 桌面版攤平成一般按鈕列 */
#btnMore { display: none; font-size: 17px; line-height: 1; letter-spacing: 0; padding: 7px 12px; }
#hudMore { display: contents; }
/* 玩法說明僅出現在小螢幕選單（桌面版左欄本來就有說明） */
#btnHelp { display: none; }
/* 「新對局」按鈕在小螢幕改用短標籤 */
.t-short { display: none; }

/* ---------- 主区域 ---------- */
main { flex: 1; display: flex; min-height: 0; }

#stage { flex: 1; min-width: 0; position: relative; }
#stage canvas { display: block; }

aside {
  width: 232px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px;
  background: var(--panel);
  overflow-y: auto;
}
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.game-teaching-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(101, 183, 164, 0.52);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(101, 183, 164, 0.14), rgba(40, 31, 23, 0.96));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}
.game-teaching-card h3 { color: #9adbc8; letter-spacing: 2px; }
.game-teaching-card strong { color: var(--text); font-size: 13px; line-height: 1.45; }
.game-teaching-card > p { color: #d9d1c4; font-size: 12px; line-height: 1.6; }
.game-teaching-moves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.game-teaching-moves div {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}
.game-teaching-moves dt { color: var(--muted); font-size: 10px; }
.game-teaching-moves dd {
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 11.5px;
}
.game-teaching-review-button {
  width: 100%;
  min-height: 44px;
  margin-top: 3px;
  color: #bfe9dd;
  border-color: rgba(101, 183, 164, 0.48);
  background: rgba(101, 183, 164, 0.09);
  font-weight: 700;
}
.game-teaching-review-button:hover:not(:disabled) {
  border-color: #65b7a4;
  background: rgba(101, 183, 164, 0.16);
}
.game-teaching-review-button:focus-visible {
  outline: 2px solid #9adbc8;
  outline-offset: 2px;
}
#btnTeachingMode[aria-pressed="true"] {
  color: #102a25;
  border-color: #65b7a4;
  background: linear-gradient(180deg, #afe5d5, #73c3af);
  font-weight: 700;
}
#app.editor-active #left,
#app.editor-active #right { display: none; }
#app.library-active #left,
#app.library-active #right,
#app.library-active #editorPanel { display: none; }
#app.game-record-active #left,
#app.game-record-active #right,
#app.game-record-active #editorPanel,
#app.game-record-active #libraryPanel { display: none; }

aside h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 8px;
}

.tray { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.chips { min-height: 26px; display: flex; flex-wrap: wrap; gap: 4px; }
.chips em { color: var(--muted); font-size: 13px; font-style: normal; }
.chip {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  background: radial-gradient(circle at 35% 30%, #eed6a8, #c08f52);
}
.chip.red { color: #b32c20; }
.chip.black { color: #26221d; }

.help { color: var(--muted); font-size: 12px; line-height: 1.75; }
.help p { margin-bottom: 4px; }

/* ---------- 殺局局面編輯器 ---------- */
#editorPanel {
  width: 284px;
  border-right: 1px solid var(--line);
  gap: 12px;
}

.photo-import-entry { display: flex; flex-direction: column; gap: 7px; }
.photo-import-button {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}
.photo-import-message {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
.photo-import-message.success { color: #b8dcaa; }
.photo-import-message.error { color: #e99a8e; }

#photoPanel {
  width: 320px;
  border-right: 1px solid var(--line);
  gap: 11px;
}
#photoPanel.calibration-active { width: min(430px, 38vw); }
#photoPanel.recognition-active { width: min(520px, 46vw); }
.photo-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.photo-heading h2 { font-size: 18px; letter-spacing: 3px; }
.photo-heading p { margin-top: 4px; color: var(--muted); font-size: 11.5px; }
.photo-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    var(--panel2);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px;
}
#photoPreviewImage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center;
  transition: transform 160ms ease;
  user-select: none;
  -webkit-user-drag: none;
}
.photo-view { display: flex; flex-direction: column; gap: 9px; }
.photo-transform-status {
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.photo-transform-actions,
.photo-file-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.photo-transform-actions button,
.photo-file-actions button { padding: 7px 6px; font-size: 11.5px; }
.photo-transform-actions #btnPhotoReset { grid-column: 1 / -1; }
.calibration-primary {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}
.calibration-summary,
.calibration-message,
.calibration-coordinate-note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.calibration-summary.confirmed,
.calibration-message.success { color: #b8dcaa; }
.calibration-message.error { color: #e99a8e; }
.calibration-instruction {
  color: var(--text);
  border-left: 3px solid var(--gold);
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.55;
}
.calibration-canvas-shell,
.calibration-rectified-shell {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d0b09;
}
#calibrationCornerCanvas,
#calibrationRectifiedCanvas {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
}
#calibrationCornerCanvas {
  cursor: crosshair;
  touch-action: none;
}
.calibration-corner-select {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.calibration-corner-select button,
.calibration-nudge button { padding: 7px 4px; font-size: 11px; }
.calibration-corner-select button.active {
  color: var(--gold);
  border-color: rgba(217, 164, 65, 0.7);
  background: rgba(217, 164, 65, 0.12);
}
.calibration-nudge {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.calibration-orientation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  color: var(--text);
  font-size: 12px;
}
.calibration-orientation legend { color: var(--muted); padding: 0 5px; }
.calibration-orientation input { accent-color: var(--gold); }
.calibration-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.calibration-actions button { padding: 8px 6px; font-size: 11.5px; }
.calibration-actions .calibration-primary:first-child,
.calibration-actions #btnCalibrationConfirm { grid-column: 1 / -1; }
.calibration-preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.calibration-preview-heading h3 { font-size: 13px; }
#calibrationOrientationBadge {
  color: var(--gold);
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 10px;
}
#recognitionCountBadge {
  color: var(--gold);
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 10px;
}
.recognition-instruction {
  color: var(--text);
  border-left: 3px solid var(--gold);
  padding: 7px 9px;
  font-size: 11.5px;
  line-height: 1.55;
}
.recognition-board-shell {
  position: relative;
  width: 100%;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d0b09;
}
#recognitionCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
}
.recognition-markers {
  position: absolute;
  inset: 18px;
}
.recognition-marker {
  position: absolute;
  width: 28px;
  height: 28px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 2px solid #f4ead6;
  border-radius: 50%;
  color: #f4ead6;
  background: rgba(28, 22, 17, 0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  touch-action: manipulation;
}
.recognition-marker.candidate-empty { border-style: solid; opacity: 0.74; }
.recognition-marker.candidate-occupied { border-width: 3px; }
.recognition-marker.candidate-uncertain { border-style: dashed; border-radius: 7px; }
.recognition-marker.suggested-red { color: #ffd5ce; border-color: #ef776a; }
.recognition-marker.suggested-black { color: #fff0c7; border-color: #c4b18b; }
.recognition-marker.reviewed {
  color: #241a0c;
  border-color: #fff0c7;
  background: #f0c463;
}
.recognition-marker.reviewed-empty {
  color: #f4ead6;
  background: rgba(50, 47, 43, 0.95);
}
.recognition-marker.selected {
  outline: 3px solid #fff;
  outline-offset: 2px;
  z-index: 2;
}
.recognition-marker.type-suggested {
  color: #241a0c;
  border-color: #f0c463;
  background: rgba(240, 196, 99, 0.88);
}
.recognition-marker.filtered { display: none; }
.recognition-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.recognition-stats span {
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--panel2);
  text-align: center;
  font-size: 10.5px;
}
.recognition-filter {
  color: var(--text);
  font-size: 11.5px;
}
.recognition-filter input { accent-color: var(--gold); }
.recognition-picker {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel2);
}
.recognition-picker-heading {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.recognition-picker-heading strong { color: var(--text); font-size: 12px; }
.recognition-picker-heading span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.piece-type-suggestion {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 9px;
  border: 1px solid rgba(217, 164, 65, 0.35);
  border-radius: 7px;
  background: rgba(217, 164, 65, 0.08);
}
.piece-type-suggestion-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.piece-type-suggestion-heading strong { color: var(--gold); font-size: 12px; }
.piece-type-suggestion-heading span,
.piece-type-suggestion > span { color: var(--text); font-size: 10.5px; }
.piece-type-suggestion small { color: var(--muted); font-size: 10px; line-height: 1.45; }
.recognition-choice-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}
.recognition-choice-actions button { min-width: 0; padding: 7px 4px; font-size: 10.5px; }
.recognition-empty-choice { padding: 7px; font-size: 11.5px; }
.recognition-palette {
  display: grid;
  grid-template-columns: 40px repeat(7, minmax(29px, 1fr));
  gap: 4px;
  align-items: center;
}
.recognition-palette span { color: var(--muted); font-size: 10.5px; }
.recognition-palette button {
  min-width: 0;
  min-height: 38px;
  padding: 6px 2px;
  border-radius: 50%;
  font-size: 11px;
}
.recognition-palette.red button { color: #ef776a; }
.recognition-palette.black button { color: #f4ead6; }
.recognition-palette.suggested {
  padding: 4px;
  border-radius: 7px;
  background: rgba(217, 164, 65, 0.1);
}
.recognition-picker button.active {
  color: #241a0c;
  border-color: #f0c463;
  background: #f0c463;
}
.recognition-bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.recognition-bulk-actions button { padding: 8px 6px; font-size: 11.5px; }
.recognition-bulk-actions #btnRecognitionRematch { grid-column: 1 / -1; }
.recognition-bulk-actions #btnRecognitionApply { grid-column: 1 / -1; }
.review-progress { display: flex; justify-content: space-between; gap: 8px; color: var(--gold); font-size: 14px; }
.review-empty-note, .review-marker-legend { color: var(--muted); font-size: 11px; line-height: 1.5; }
.review-target { display: flex; align-items: center; gap: 12px; min-width: 0; }
#recognitionTargetCanvas { width: 84px; height: 84px; flex: none; background: #0d0b09; border: 1px solid var(--gold); border-radius: 8px; }
.review-navigation { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 5px; }
.review-navigation button { min-width: 0; min-height: 38px; padding: 7px 3px; font-size: 11px; }
.recognition-empty-choice { min-height: 38px; }
.review-empty-actions { grid-template-columns: 1.4fr 1fr; }
.review-empty-actions button { min-height: 38px; }
.review-king-summary { color: #b8dcaa; font-size: 12px; line-height: 1.5; }
.review-king-summary.warning { color: #f0c463; }
.review-optional-assistance { color: var(--muted); font-size: 11px; line-height: 1.5; }
.review-optional-assistance summary { cursor: pointer; padding: 8px 0; }
.review-optional-assistance button { display: block; width: 100%; margin-top: 6px; }
.photo-privacy-note {
  color: var(--muted);
  border-left: 3px solid rgba(217, 164, 65, 0.45);
  padding: 7px 9px;
  font-size: 11px;
  line-height: 1.55;
}

.editor-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.editor-heading h2 { font-size: 18px; letter-spacing: 3px; }
.editor-heading h2:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.editor-heading p { margin-top: 4px; color: var(--muted); font-size: 11.5px; }
.editor-badge {
  flex: none;
  color: var(--gold);
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 999px;
  background: rgba(217, 164, 65, 0.08);
  padding: 4px 8px;
  font-size: 10px;
  letter-spacing: 1px;
}

.editor-section {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.editor-section h3 { margin-bottom: 8px; }
.piece-palette {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.editor-piece {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif TC", serif;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
  background: radial-gradient(circle at 35% 30%, #eed6a8, #c08f52);
  border-color: #6f4f2f;
}
.editor-piece.red { color: #b32c20; }
.editor-piece.black { color: #26221d; }
.editor-piece:hover { background: radial-gradient(circle at 35% 30%, #f6dfb4, #d3a05d); }
.editor-piece.active {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  box-shadow: 0 0 16px rgba(217, 164, 65, 0.45);
}

.editor-tools,
.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.editor-tools button,
.editor-actions button { padding: 7px 8px; font-size: 12.5px; }
.editor-tools button.active {
  color: var(--gold);
  border-color: rgba(217, 164, 65, 0.65);
  background: rgba(217, 164, 65, 0.09);
}
.editor-hint,
.editor-message {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}

.side-choice { display: flex; gap: 12px; flex-wrap: wrap; }
.side-choice legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
}
.side-choice label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  cursor: pointer;
}
.side-choice input { accent-color: var(--gold); }

.editor-actions .primary {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}
.editor-message {
  min-height: 38px;
  margin-top: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--line);
}
.editor-message.success { color: #b8dcaa; border-left-color: #77a966; }
.editor-message.error { color: #e99a8e; border-left-color: var(--red); }

/* ---------- 殺局答案錄製器 ---------- */
#editorPanel.recorder-active > :not(#recorderPanel) { display: none; }
.recorder-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.recorder-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.recorder-heading h2 { font-size: 17px; letter-spacing: 3px; }
.recorder-heading p { margin-top: 4px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
#recorderReady { display: flex; flex-direction: column; gap: 10px; }
.recorder-primary {
  color: #241a0c;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  font-weight: 700;
}
.recorder-primary:hover { background: linear-gradient(180deg, #f7d17a, #e2ad4a); }
.recorder-turn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12.5px;
}
#recorderTurnDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}
#recorderWorkspace { display: flex; flex-direction: column; gap: 9px; }
#recorderWorkspace h3 { margin: 0; }
#recorderLog {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 12.5px;
}
#recorderLog li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
}
.recorder-ply { color: var(--muted); font-variant-numeric: tabular-nums; }
#recorderEmpty { color: var(--muted); font-size: 12px; }
.recorder-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.recorder-actions button { padding: 7px 8px; font-size: 12.5px; }
.recorder-actions #btnPracticeStart { grid-column: 1 / -1; }
.recorder-actions #btnRecorderExit { grid-column: 1 / -1; }
.recorder-panel > .editor-message { margin-top: 0; }

.practice-workspace { display: flex; flex-direction: column; gap: 11px; }
.practice-stats {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.practice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.practice-actions button { padding: 8px; font-size: 12.5px; }
.practice-actions #btnPracticeHint { grid-column: 1 / -1; }
.practice-actions #btnPracticePuzzleExit { grid-column: 1 / -1; }
.practice-hint-message {
  min-width: 0;
  margin: 0;
  padding: 9px 10px;
  color: #d9edf0;
  background: rgba(105, 199, 212, 0.08);
  border: 1px solid rgba(105, 199, 212, 0.32);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.save-puzzle-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.save-puzzle-panel label { color: var(--muted); font-size: 11.5px; }
.save-puzzle-panel input,
.save-puzzle-panel textarea {
  width: 100%;
  color: var(--text);
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 9px;
  font: inherit;
  font-size: 12.5px;
  resize: vertical;
}
.save-puzzle-panel input:focus,
.save-puzzle-panel textarea:focus { outline: 1px solid var(--gold); border-color: var(--gold); }
.save-puzzle-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.save-puzzle-actions button { padding: 8px; font-size: 12.5px; }

/* ---------- 本機殺局庫 ---------- */
#libraryPanel {
  width: 340px;
  border-right: 1px solid var(--line);
  gap: 12px;
}
.library-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.library-heading h2 { font-size: 18px; letter-spacing: 3px; }
.library-heading p { margin-top: 4px; color: var(--muted); font-size: 11.5px; }
.library-transfer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.library-transfer-actions button { min-height: 38px; padding: 7px 8px; font-size: 12px; }
.library-transfer-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.library-transfer-status.success { color: #9fd68f; }
.library-transfer-status.error { color: #e99a8e; }
.library-import-preview {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  border: 1px solid rgba(217, 164, 65, 0.5);
  border-radius: 9px;
  background: rgba(217, 164, 65, 0.08);
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.library-import-preview-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.library-import-preview-actions button { min-height: 38px; padding: 7px 6px; font-size: 12px; }
.library-issues {
  color: #e99a8e;
  border-left: 3px solid var(--red);
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.5;
}
#libraryList { display: flex; flex-direction: column; gap: 8px; }
.library-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  padding: 10px;
}
.library-card h3 { color: var(--text); font-size: 14px; letter-spacing: 1px; margin-bottom: 5px; }
.library-card-meta { color: var(--muted); font-size: 11.5px; line-height: 1.6; }
.library-card-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; margin-top: 8px; }
.library-card-actions button { padding: 6px 4px; font-size: 11.5px; }
button.danger { color: #e99a8e; border-color: rgba(192, 83, 69, 0.55); }
#libraryEmpty { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.library-detail { display: flex; flex-direction: column; gap: 10px; }
.library-detail h3 { color: var(--text); font-size: 17px; letter-spacing: 2px; margin: 0; }
.library-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 12px; }
.library-detail dt { color: var(--muted); }
.library-detail dd { text-align: right; }
#libraryDetailNotes { color: var(--muted); font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.library-solution {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
}
.library-solution h4 { color: var(--muted); font-size: 11.5px; letter-spacing: 1px; margin-bottom: 6px; }
.library-solution ol { padding-left: 22px; color: var(--text); font-size: 12px; line-height: 1.7; }
.library-detail-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.library-detail-actions button { padding-left: 5px; padding-right: 5px; }

/* ---------- 已完成對局 / 唯讀複盤 ---------- */
#gameRecordPanel {
  width: 320px;
  border-right: 1px solid var(--line);
  gap: 12px;
}
.game-record-library-view,
.game-review-view,
.game-analysis-view {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.game-record-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.game-record-heading h2 { font-size: 18px; letter-spacing: 3px; }
.game-record-heading h2:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.game-record-heading p { margin-top: 4px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.game-record-library-list { display: flex; flex-direction: column; gap: 8px; }
.game-record-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
}
.game-record-card-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.game-record-card-heading strong { color: var(--text); font-size: 13px; }
.game-record-card-heading time { color: var(--muted); font-size: 10.5px; text-align: right; }
.game-record-card-meta { color: var(--muted); font-size: 11.5px; line-height: 1.55; }
.game-record-card-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.game-record-card-actions button { min-height: 40px; padding: 7px 9px; font-size: 12px; }
.game-record-empty,
.game-record-issues {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.6;
}
.game-record-issues { color: #e8b887; border-color: rgba(217, 164, 65, 0.45); }
.game-review-topbar { display: flex; justify-content: space-between; gap: 8px; }
.game-review-topbar button { padding: 7px 9px; font-size: 11.5px; }
.game-review-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  font-size: 11.5px;
}
.game-review-meta dt { color: var(--muted); }
.game-review-meta dd { color: var(--text); text-align: right; }
.game-review-status {
  min-height: 48px;
  padding: 9px 10px;
  border-left: 3px solid var(--gold);
  background: rgba(217, 164, 65, 0.08);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}
.game-review-navigation { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.game-review-navigation button {
  min-width: 0;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 3px;
  font-size: 14px;
}
.game-review-navigation button span { color: var(--muted); font-size: 10px; letter-spacing: 0; }
.game-review-moves {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  overflow: hidden;
}
.game-review-moves summary {
  cursor: pointer;
  padding: 10px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 1px;
}
#gameReviewMoveList {
  max-height: 34vh;
  overflow-y: auto;
  padding: 0 8px 9px;
  list-style: none;
}
#gameReviewMoveList li + li { margin-top: 4px; }
.game-review-move {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: 34px 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  text-align: left;
  font-size: 12px;
}
.game-review-move .ply { color: var(--muted); font-variant-numeric: tabular-nums; }
.game-review-move .side { font-weight: 700; }
.game-review-move .notation { min-width: 0; overflow-wrap: anywhere; }
.game-review-move .side.red { color: #ef776a; }
.game-review-move .side.black { color: #c8cbd0; }
.game-review-teaching-move-marker {
  padding: 2px 5px;
  border: 1px solid rgba(101, 183, 164, 0.68);
  border-radius: 999px;
  color: #bfe9dd;
  background: rgba(101, 183, 164, 0.12);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}
.game-review-move[aria-current="step"] {
  color: #241a0c;
  border-color: #f0c463;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  font-weight: 700;
}
.game-review-move[aria-current="step"] .ply,
.game-review-move[aria-current="step"] .side { color: #3a2511; }
.game-review-move[aria-current="step"] .game-review-teaching-move-marker {
  color: #241a0c;
  border-color: rgba(36, 26, 12, 0.58);
  background: rgba(255, 255, 255, 0.2);
}
#btnGameReviewDelete { width: 100%; min-height: 40px; }
.game-review-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.game-review-continue { min-height: 44px; width: 100%; border: 1px solid #b79c70; background: #443826; color: #fff1d5; border-radius: 8px; padding: 10px; cursor: pointer; }
.game-review-continue:disabled { opacity: .5; cursor: not-allowed; }
.game-review-continue-reason { font-size: 12px; line-height: 1.6; color: #bcb5a9; }
:is(#gameReviewContinuationDialog, #customPlayDialog) { margin: auto; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-sizing: border-box; overflow: auto; padding: 24px; border: 1px solid #827052; border-radius: 14px; background: #201e1b; color: #eee7dc; }
:is(#gameReviewContinuationDialog, #customPlayDialog)::backdrop { background: #000a; }
:is(#gameReviewContinuationDialog, #customPlayDialog) h2 { margin-top: 0; font-size: 20px; }
:is(#gameReviewContinuationDialog, #customPlayDialog) p { font-size: 13px; line-height: 1.7; }
:is(#gameReviewContinuationDialog, #customPlayDialog) label { display: block; margin: 14px 0 6px; }
:is(#gameReviewContinuationDialog, #customPlayDialog) select { width: 100%; min-height: 44px; padding: 8px; background: #302d28; color: inherit; border: 1px solid #827052; border-radius: 6px; }
.game-review-continuation-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.game-review-continuation-actions button { min-height: 44px; }
.game-review-continue:focus-visible, :is(#gameReviewContinuationDialog, #customPlayDialog) :focus-visible { outline: 2px solid #edc77d; outline-offset: 3px; }
.game-review-actions button { min-width: 0; min-height: 44px; padding: 7px 8px; font-size: 12px; }
.game-analysis-primary {
  min-height: 44px;
  color: #102a25;
  border-color: #65b7a4;
  background: linear-gradient(180deg, #9adbc8, #65b7a4);
  font-weight: 700;
}
.game-analysis-primary:hover:not(:disabled) { background: linear-gradient(180deg, #afe5d5, #73c3af); }
.game-review-ai-primary {
  color: #151d31;
  border-color: #8ea8e8;
  background: linear-gradient(180deg, #c5d3f4, #8ea8e8);
  font-weight: 700;
}
.game-review-ai-primary:hover:not(:disabled) { background: linear-gradient(180deg, #d6e0f8, #a2b8ed); }
.game-review-puzzle-primary {
  color: #2e210c;
  border-color: #d9a441;
  background: linear-gradient(180deg, #f0c463, #d9a441);
  font-weight: 700;
}
.game-review-puzzle-primary:hover:not(:disabled) { background: linear-gradient(180deg, #f6d17a, #e6b552); }
.game-review-ai-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(142, 168, 232, 0.45);
  border-left: 3px solid #8ea8e8;
  border-radius: 8px;
  background: rgba(142, 168, 232, 0.09);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.game-review-ai-panel strong { color: #dce6ff; }
.game-review-ai-panel span { color: var(--muted); }
.game-review-ai-panel.loading strong { color: #b9c9ef; }
.game-review-ai-panel.error {
  border-color: rgba(224, 125, 113, 0.5);
  border-left-color: #e07d71;
  background: rgba(224, 125, 113, 0.08);
}
.game-review-ai-panel.error strong { color: #f1b5ae; }
.game-review-evidence {
  min-width: 0;
  margin-top: 5px;
  padding-top: 9px;
  border-top: 1px solid rgba(142, 168, 232, 0.3);
}
.game-review-evidence-moves {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}
.game-review-evidence-moves > div {
  min-width: 0;
  padding: 6px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}
.game-review-evidence-moves dt {
  color: var(--muted);
  font-size: 11px;
}
.game-review-evidence-moves dd {
  margin: 1px 0 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.game-review-evidence-match {
  margin: 8px 0 0;
  color: #c8d7fb;
  font-weight: 700;
}
.game-review-evidence-facts h3 {
  margin: 8px 0 3px;
  color: #dce6ff;
  font-size: 12px;
}
.game-review-evidence-facts ul {
  margin: 0;
  padding-left: 19px;
  color: var(--text);
}
.game-review-evidence-facts li + li { margin-top: 2px; }
.game-review-teaching {
  margin-top: 9px;
  padding: 9px 10px;
  border: 1px solid rgba(101, 183, 164, 0.42);
  border-left: 3px solid #65b7a4;
  border-radius: 8px;
  background: rgba(101, 183, 164, 0.08);
  overflow-wrap: anywhere;
}
.game-review-teaching h3 {
  margin: 0 0 4px;
  color: #9adbc8;
  font-size: 11px;
  letter-spacing: 0.08em;
}
.game-review-teaching strong {
  display: block;
  color: #d8f1e9;
  font-size: 12px;
}
.game-review-teaching p {
  margin: 3px 0 0;
  color: var(--text);
  line-height: 1.55;
}
.game-review-teaching .game-review-coach-framing {
  color: #c9e8df;
}
.game-review-coach-button {
  width: 100%;
  min-height: 44px;
  margin-top: 9px;
  padding: 8px 10px;
  color: #102a25;
  border-color: #65b7a4;
  background: linear-gradient(180deg, #b7e5d8, #79c4b1);
  font-size: 12px;
  font-weight: 700;
}
.game-review-coach-profile label { display: block; margin-top: 10px; }
.game-review-coach-profile select {
  width: 100%; max-width: 100%; min-height: 44px; box-sizing: border-box;
  margin-top: 6px; padding: 8px; font: inherit;
  color: inherit; background: #252525; border: 1px solid #888; border-radius: 6px;
}
.game-review-coach-profile select:focus-visible { outline: 2px solid #e6b96b; outline-offset: 2px; }
.game-review-coach-profile p { font-size: 0.85em; }
.game-review-coach-button[aria-disabled="true"] {
  opacity: 0.65;
  cursor: progress;
}
.game-review-coach-button:hover:not([aria-disabled="true"]) {
  background: linear-gradient(180deg, #c9eee4, #8bd0be);
}
.game-review-coach-status {
  min-height: 0;
  color: var(--muted) !important;
  font-size: 11px;
}
.game-review-coach-status:empty { display: none; }
@media (max-width: 420px) {
  .game-review-evidence-moves { grid-template-columns: 1fr; }
  .game-review-teaching { padding: 8px; }
  .game-review-move {
    grid-template-columns: 28px 24px minmax(0, 1fr) auto;
    gap: 4px;
    padding-inline: 6px;
  }
  .game-review-teaching-move-marker { padding-inline: 4px; font-size: 9.5px; }
}
.game-analysis-badge { color: #9adbc8; border-color: rgba(101, 183, 164, 0.5); background: rgba(101, 183, 164, 0.1); }
.game-analysis-status {
  min-height: 54px;
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid #65b7a4;
  background: rgba(101, 183, 164, 0.09);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}
.game-analysis-status.terminal { color: #bce7da; }
.game-analysis-actions { display: grid; grid-template-columns: 1fr 1.55fr; gap: 7px; }
.game-analysis-actions button { min-height: 44px; padding: 7px 8px; font-size: 12px; }
#gameAnalysisMoveList {
  max-height: 34vh;
  overflow-y: auto;
  padding: 0 8px 9px;
  list-style: none;
}
#gameAnalysisMoveList li {
  display: grid;
  grid-template-columns: 34px 28px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 12px;
}
#gameAnalysisMoveList li + li { margin-top: 4px; }
#gameAnalysisMoveList li[aria-current="step"] { border: 1px solid rgba(101, 183, 164, 0.55); background: rgba(101, 183, 164, 0.12); }
#gameAnalysisMoveList .ply { color: var(--muted); font-variant-numeric: tabular-nums; }
#gameAnalysisMoveList .side { font-weight: 700; }
#gameAnalysisMoveList .side.red { color: #ef776a; }
#gameAnalysisMoveList .side.black { color: #c8cbd0; }

@media (prefers-reduced-motion: reduce) {
  .game-review-view *, .game-record-library-view *, .game-analysis-view * { scroll-behavior: auto !important; transition: none !important; }
}
.library-analytics {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}
.library-analytics h4 { margin: 0 0 8px; color: var(--text); font-size: 13px; }
#libraryAnalyticsStatus { margin: 0; color: var(--muted); font-size: 12px; }
#libraryAnalyticsSummary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
  margin: 0 0 9px;
  font-size: 12px;
}
#libraryAnalyticsSummary dt { color: var(--muted); }
#libraryAnalyticsSummary dd { text-align: right; }
#libraryRecentAttempts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
#btnLibraryExit { margin-top: auto; }

/* 左下角版權：字體與 .help 說明文字一致，水平置中 */
.copyright {
  margin-top: auto;
  padding-top: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}
.copyright a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
.copyright a:hover { color: var(--text); text-decoration-color: var(--text); }

#log {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
#log li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
}
#log li:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.side {
  width: 20px; height: 20px;
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.side.red { background: rgba(192, 83, 69, 0.2); color: #e08577; border: 1px solid rgba(192, 83, 69, 0.5); }
.side.black { background: rgba(139, 147, 161, 0.16); color: #aeb6c2; border: 1px solid rgba(139, 147, 161, 0.45); }
#logEmpty { color: var(--muted); font-size: 12.5px; line-height: 1.7; padding: 4px 2px; }

/* ---------- 將軍提示 ---------- */
#checkBanner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-size: 92px;
  font-weight: 900;
  letter-spacing: 18px;
  padding-left: 18px;
  color: #ffb454;
  text-shadow: 0 0 24px rgba(255, 120, 40, 0.75), 0 4px 22px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  animation: checkpop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
  z-index: 20;
}

@keyframes checkpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- 勝負覆蓋層 ---------- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.62);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  animation: fadein 0.25s ease both;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#confettiCv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.card {
  position: relative;
  width: min(92vw, 440px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 36px 30px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: cardin 0.32s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes cardin { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: none; } }

/* 勝利：金光；敗北：內斂 */
.card.win {
  border-color: rgba(217, 164, 65, 0.55);
  box-shadow:
    0 0 0 1px rgba(217, 164, 65, 0.18),
    0 24px 90px rgba(0, 0, 0, 0.65),
    0 0 80px rgba(217, 164, 65, 0.16);
}
.card.win h2 {
  background: linear-gradient(180deg, #ffe6a8, #f2c14e 55%, #c98f2e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 18px rgba(242, 193, 78, 0.35));
}
.card.lose h2 { color: var(--muted); }

#ovBadge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold);
  border: 1px solid rgba(217, 164, 65, 0.45);
  border-radius: 999px;
  padding: 4px 14px;
  margin-bottom: 14px;
  background: rgba(217, 164, 65, 0.08);
}

.card h2 {
  font-size: 38px;
  letter-spacing: 8px;
  padding-left: 8px;
  margin-bottom: 8px;
  color: var(--gold);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif TC", serif;
  font-weight: 900;
}

#ovStars { font-size: 24px; letter-spacing: 8px; padding-left: 8px; color: #504028; margin-bottom: 6px; }
#ovStars span { display: inline-block; }
#ovStars span.on {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(217, 164, 65, 0.65);
  animation: starpop 0.45s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}
@keyframes starpop {
  0% { opacity: 0; transform: scale(0.2) rotate(-40deg); }
  100% { opacity: 1; transform: none; }
}

#ovSub { color: var(--text); font-size: 14px; letter-spacing: 1px; margin-bottom: 18px; opacity: 0.85; }

#ovStats {
  display: flex;
  justify-content: center;
  gap: 26px;
  padding: 12px 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
#ovStats .stat b {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
#ovStats .stat span { font-size: 11px; letter-spacing: 3px; color: var(--muted); }
/* 全程零悔棋：純度勳章，金色高亮 */
#ovStats .stat b.pure {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(217, 164, 65, 0.55);
}

#ovReason { color: var(--muted); font-size: 13px; margin-bottom: 20px; letter-spacing: 2px; }

.ovBtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ovBtns button { font-size: 15px; padding: 10px 24px; }
.ovBtns .primary {
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  color: #241a0c;
  font-weight: 700;
}
.ovBtns .primary:hover { background: linear-gradient(180deg, #f7d17a, #e2ad4a); }

/* ---------- 提示浮層 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  max-width: 88vw;
  background: rgba(20, 15, 9, 0.92);
  border: 1px solid rgba(217, 164, 65, 0.5);
  color: var(--text);
  font-size: 13.5px;
  letter-spacing: 1px;
  padding: 10px 20px;
  border-radius: 999px;
  z-index: 40;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  animation: fadein 0.2s ease both;
}

.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ---------- 小螢幕 ---------- */
@media (max-width: 900px) {
  main { flex-direction: column; }
  /* 棋盤置頂居中，吃子列移到棋盤下方，說明收進選單 */
  #stage { order: 1; flex: 1; min-height: 0; }
  /* 殺局面板獨立配置，不改動上游浮動吃子托盤／說明選單。 */
  #app.editor-active #stage, #app.library-active #stage, #app.game-record-active #stage { min-height: 0; }
  #editorPanel {
    order: 2;
    width: 100%;
    max-height: 270px;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  #photoPanel {
    order: 1;
    width: 100%;
    max-height: none;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  #photoPanel.calibration-active { width: 100%; }
  #photoPanel.recognition-active { width: 100%; }
  #app.photo-active main {
    display: flex;
    overflow-x: hidden;
    overflow-y: auto;
  }
  #app.photo-active #stage {
    order: 2;
    flex: none;
    width: 100%;
    height: 390px;
    min-height: 390px;
  }
  #app.photo-active #editorPanel {
    order: 3;
    flex: none;
    max-height: none;
    overflow: visible;
  }
  .recognition-board-shell { padding: 17px; }
  .recognition-markers { inset: 17px; }
  .recognition-marker { width: 30px; height: 30px; font-size: 10.5px; }
  .recognition-palette { grid-template-columns: 36px repeat(7, minmax(27px, 1fr)); gap: 3px; }
  .piece-type-suggestion-heading { align-items: flex-start; }
  .recognition-choice-actions button { min-height: 36px; }
  #libraryPanel {
    order: 2;
    width: 100%;
    max-height: 320px;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  #gameRecordPanel {
    order: 2;
    width: 100%;
    max-height: 42dvh;
    border-right: none;
    border-top: 1px solid var(--line);
    padding: 12px;
  }
  #gameReviewMoveList, #gameAnalysisMoveList { max-height: 24dvh; }
  .game-record-card-actions button,
  .game-review-navigation button,
  .game-analysis-view .game-review-topbar button,
  .game-analysis-actions button,
  .game-review-actions button,
  #btnGameReviewDelete { min-height: 44px; }
  .library-transfer-actions button,
  .library-import-preview-actions button { min-height: 42px; }
  #right { display: none; }
  #right.teaching-visible {
    display: flex;
    order: 2;
    width: 100%;
    max-height: 238px;
    padding: 10px 10px max(58px, calc(env(safe-area-inset-bottom) + 48px));
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow-y: auto;
  }
  #right.teaching-visible > :not(#gameTeachingCard) { display: none; }
  #right.teaching-visible #gameTeachingCard { width: 100%; }
  h1 { font-size: 15px; letter-spacing: 3px; }
  .brand .sub { display: none; }

  header { padding: 6px 10px; gap: 8px; }
  #hud { gap: 6px; position: relative; }
  #turn { min-width: 0; padding: 6px 10px; font-size: 12.5px; gap: 6px; }
  #turnDot { width: 9px; height: 9px; }
  button, #modeSel { padding: 6px 10px; font-size: 12.5px; }
  .side-chooser label { min-height: 42px; padding: 0 10px; }
  #btnMore { display: inline-flex; align-items: center; justify-content: center; }
  .t-short { display: inline; }
  .t-full { display: none; }

  /* 次要按鈕收進「⋯」下拉選單 */
  #hudMore {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 168px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55);
    z-index: 60;
  }
  #hudMore.open { display: flex; }
  #hudMore > button, #hudMore > #repoLink {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    border-radius: 8px;
  }
  #hudMore > .glyph-orientation-setting { flex-direction: column; align-items: stretch; padding: 5px 4px; }
  #hudMore > .glyph-orientation-setting select { max-width: none; min-height: 38px; }
  #btnHelp { display: inline-flex; }

  /* 吃子托盤：浮動貼在棋盤底部黑邊上，指標事件穿透可繼續轉視角 */
  #left {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 6;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
    width: auto;
    max-height: none;
    padding: 0;
    background: transparent;
    border: none;
    pointer-events: none;
  }
  #left .tray {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: rgba(33, 26, 20, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
  #left .tray h3 { margin: 0; font-size: 11px; white-space: nowrap; }
  .chip { width: 22px; height: 22px; font-size: 13px; }
  .chips { min-height: 22px; }
  .chips em { font-size: 12px; }
  .help { display: none; }
  .copyright { display: none; }
  /* 從「⋯ → 玩法說明」展開成浮動說明面板 */
  #left.show-help {
    pointer-events: auto;
    flex-direction: column;
    background: rgba(23, 19, 16, 0.96);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    max-height: 48dvh;
    overflow-y: auto;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  #left.show-help .tray { pointer-events: auto; }
  #left.show-help .help { display: block; }

  #checkBanner { font-size: 54px; letter-spacing: 10px; padding-left: 10px; }
}

@media (max-width: 480px) {
  header { padding: 6px; gap: 6px; }
  #hud { gap: 5px; }
  h1 { font-size: 13px; letter-spacing: 1px; }
  button, #modeSel { padding: 5px 8px; font-size: 11.5px; letter-spacing: 0.5px; }
  #hud { flex: 1; }
  .side-chooser { flex-basis: 100%; justify-content: flex-end; border: 0; background: transparent; }
  .side-chooser label { min-height: 44px; border: 1px solid var(--line); background: var(--panel2); }
  .side-chooser input + label { border-radius: 8px 0 0 8px; }
  .side-chooser label + input + label { border-left: 0; border-radius: 0 8px 8px 0; }
  #turn { top: 9px; right: 9px; padding: 4px 10px; font-size: 11.5px; gap: 5px; }
  #turnDot { width: 8px; height: 8px; }
  #btnMore { padding: 5px 9px; font-size: 15px; }
}

#btnCustomPlay { margin-top: 10px; }
