:root {
  --bg: #302e2b;
  --panel: #262421;
  --panel-2: #3a3835;
  --text: #f1f0ee;
  --muted: #a9a7a3;
  --accent: #81b64c;
  --accent-dark: #5d8a32;
  --danger: #e0574f;
  --light: #ebecd0;
  --dark: #739552;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", "Microsoft JhengHei", sans-serif;
  display: flex;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 30px; margin: 0 0 8px; }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); }
p { margin: 6px 0; }
.muted { color: var(--muted); }

/* 側邊選單 */
.sidebar {
  width: 180px;
  flex: none;
  background: var(--panel);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar a { padding: 10px 12px; border-radius: 6px; font-weight: 600; display: flex; gap: 10px; }
.sidebar a i { font-style: normal; }
.sidebar a:hover, .sidebar a.active { background: var(--panel-2); }
.sidebar .logo { font-size: 24px; align-items: center; margin-bottom: 8px; }
.sidebar .logo span { color: var(--accent); }
.sound-toggle { margin-top: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 8px; }
.sidebar .source-link { font-size: 12px; font-weight: 400; color: var(--muted); justify-content: center; }

main { flex: 1; min-width: 0; padding: 20px; }

/* 按鈕與輸入框 */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); box-shadow: 0 3px 0 var(--accent-dark); }
.btn.danger { background: var(--danger); }
.btn.big { font-size: 19px; padding: 13px; width: 100%; }
.btn.selected { outline: 2px solid var(--accent); background: #4b4945; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
input, textarea, select {
  background: #1f1e1b;
  color: var(--text);
  border: 1px solid #55534f;
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 90px; font-family: Consolas, monospace; font-size: 13px; }

/* 首頁 */
.home { max-width: 900px; margin: 0 auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 24px; }
.card { background: var(--panel); border-radius: 10px; padding: 22px; display: block; border: 2px solid transparent; }
a.card:hover { border-color: var(--accent); }
.card .icon { font-size: 40px; }
.games { margin-top: 28px; }
.game-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.game-row .grow { flex: 1; min-width: 0; }

/* 對局版面 */
.game-layout { display: flex; gap: 20px; justify-content: center; align-items: flex-start; }
.board-col { flex: 0 1 auto; width: min(calc(100vh - 132px), calc(100vw - 600px)); min-width: 360px; }
.panel {
  width: 370px;
  flex: none;
  background: var(--panel);
  border-radius: 10px;
  padding: 16px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.player-bar { display: flex; align-items: center; gap: 10px; height: 46px; }
.player-bar .name { font-weight: 700; }
.player-bar .sub { color: var(--muted); font-size: 13px; }
.player-bar .captured { font-size: 15px; color: var(--muted); letter-spacing: -2px; }
.player-bar .clock {
  margin-left: auto;
  font: 700 24px Consolas, monospace;
  background: #4b4945;
  color: #bbb;
  padding: 3px 14px;
  border-radius: 5px;
}
.player-bar .clock.running { background: #fff; color: #222; }
.player-bar .clock.low { background: var(--danger); color: #fff; }
.avatar { font-size: 26px; width: 38px; height: 38px; display: grid; place-items: center; background: var(--panel-2); border-radius: 6px; }

.board-row { display: flex; gap: 8px; }
.board-row .board { flex: 1; }
.eval-bar { width: 24px; background: #403e3b; border-radius: 4px; position: relative; overflow: hidden; flex: none; }
.eval-bar .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #f4f4f4; transition: height .35s; }
.eval-bar.flipped .fill { bottom: auto; top: 0; }
.eval-bar .num { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-size: 10px; font-weight: 700; color: #333; z-index: 1; }
.eval-bar .num.top { bottom: auto; top: 3px; }
.eval-bar .num.on-dark { color: #eee; }

/* 棋盤 */
.board { position: relative; aspect-ratio: 1; user-select: none; touch-action: none; container-type: inline-size; }
.board .squares { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); border-radius: 4px; overflow: hidden; }
.sq { position: relative; background: var(--light); }
.sq.dark { background: var(--dark); }
.sq::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: rgba(255, 255, 40, .45); }
.sq.selected::before { background: rgba(255, 255, 40, .55); }
.sq.check::before { background: radial-gradient(circle, rgba(255, 0, 0, .85) 25%, transparent 75%); }
.sq.hint::after { content: ""; position: absolute; inset: 34%; border-radius: 50%; background: rgba(0, 0, 0, .2); }
.sq.hint.capture::after { inset: 0; background: transparent; border: .9cqw solid rgba(0, 0, 0, .2); }
.sq .coord { position: absolute; font-size: max(9px, 2cqw); font-weight: 700; color: var(--dark); pointer-events: none; }
.sq.dark .coord { color: var(--light); }
.sq .coord.rank { top: 1px; left: 3px; }
.sq .coord.file { bottom: 0; right: 3px; }
.piece { position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; pointer-events: none; z-index: 2; }
.piece.moving { transition: transform .18s ease; z-index: 3; }
.piece.dragging { z-index: 6; }
.board.movable { cursor: pointer; }
.board svg.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.badge {
  position: absolute;
  z-index: 5;
  width: 5.6cqw;
  height: 5.6cqw;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.8cqw;
  font-weight: 800;
  color: #fff;
  transform: translate(-60%, -40%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .5);
  pointer-events: none;
}
.promotion { position: absolute; inset: 0; z-index: 10; background: rgba(0, 0, 0, .55); display: grid; place-items: center; }
.promotion div { background: #fff; border-radius: 8px; display: flex; padding: 6px; width: 70%; }
.promotion button { flex: 1; aspect-ratio: 1; background: none; border: 0; border-radius: 6px; cursor: pointer; padding: 0; }
.promotion button:hover { background: #cde3b8; }

/* 走法列表 */
.move-list { background: #1f1e1b; border-radius: 8px; padding: 6px; max-height: 260px; min-height: 80px; overflow-y: auto; margin: 12px 0; }
.move-row { display: grid; grid-template-columns: 40px 1fr 1fr; align-items: center; }
.move-row:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.move-row > span { color: var(--muted); padding-left: 6px; }
.move-row button { background: none; border: 0; color: var(--text); font: 600 14px inherit; text-align: left; padding: 3px 8px; border-radius: 4px; display: flex; align-items: center; gap: 6px; }
.move-row button.clickable { cursor: pointer; }
.move-row button.current { background: #55534f; }
.dot { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; flex: none; }

.status { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-weight: 600; }
.status.over { background: var(--accent-dark); }
.status.warn { background: #8a5a22; }

.bot-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.bot-card { display: flex; gap: 8px; align-items: center; text-align: left; }
.bot-card span:first-child { font-size: 26px; }
.bot-card small { display: block; color: var(--muted); font-weight: 400; }

.chat-log { background: #1f1e1b; border-radius: 8px; padding: 8px 10px; height: 120px; overflow-y: auto; margin-bottom: 8px; font-size: 14px; overflow-wrap: anywhere; }
.room-code { font: 800 38px Consolas, monospace; letter-spacing: 6px; text-align: center; background: #1f1e1b; border-radius: 8px; padding: 10px; }

/* 回顧 */
.progress { height: 10px; background: #1f1e1b; border-radius: 5px; overflow: hidden; margin: 14px 0; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.accuracy { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.accuracy div { border-radius: 8px; padding: 8px; text-align: center; background: #eee; color: #222; }
.accuracy div.black { background: #1a1917; color: #eee; }
.accuracy b { display: block; font-size: 26px; }
.counts { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.counts td { padding: 2px 4px; text-align: center; }
.counts td:nth-child(2) { text-align: left; }
.counts .label { display: flex; align-items: center; gap: 8px; justify-content: flex-start; }
.graph { width: 100%; height: 90px; display: block; background: #403e3b; border-radius: 6px; cursor: pointer; margin: 12px 0; }
.comment { background: var(--panel-2); border-radius: 8px; padding: 12px; min-height: 108px; }
.comment .head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.comment .head .score { margin-left: auto; font: 700 14px Consolas, monospace; background: #1f1e1b; padding: 2px 8px; border-radius: 4px; }
.nav-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: .96; }

/* 窄螢幕與手機 */
@media (max-width: 960px) {
  .game-layout { flex-direction: column; align-items: center; }
  .board-col { width: 100%; max-width: 640px; min-width: 0; }
  .panel { width: 100%; max-width: 640px; max-height: none; }
}
@media (max-width: 700px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; padding: 6px; z-index: 20; justify-content: space-between; }
  .sidebar a { padding: 6px 8px; font-size: 12px; flex-direction: column; align-items: center; gap: 0; }
  .sidebar .logo { font-size: 18px; margin: 0; justify-content: center; }
  .sound-toggle { margin: 0; font-size: 0; }
  .sound-toggle::first-letter { font-size: 18px; }
  main { padding: 10px; }
}
