/* =========================================================
   Louie 的围棋道场 · 克制、聚焦
   中性暖灰底 + 一个强调色（墨绿）；红色只用于警示
   ========================================================= */
:root {
  --bg: #e9e6e0;
  --surface: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #a1a1a6;
  --sep: #e4e1dc;
  --accent: #2e6b55;
  --accent-soft: #e7f0eb;
  --red: #c4463a;
  --red-soft: #fbeceb;
  --toolbar-h: 60px;
  --side-w: 260px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
.hidden { display: none !important; }

/* ---------------- 工具栏 ---------------- */
.toolbar {
  flex-shrink: 0;
  height: calc(var(--toolbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sep);
  background: rgba(246, 244, 240, 0.95);
}
.title-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.home-portal-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--sep);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.home-portal-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.home-portal-link:hover { background: rgba(0,0,0,0.04); color: var(--ink); border-color: rgba(0,0,0,0.15); }
.title { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.status { font-size: 13px; color: var(--ink-2); font-weight: 500; white-space: nowrap; text-align: center; }
.status b { color: var(--ink); font-weight: 600; }
.tools { display: flex; justify-content: flex-end; gap: 2px; }
.tool {
  width: 56px; height: 46px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); font-size: 10.5px; font-weight: 500;
  transition: background .15s;
}
.tool:hover { background: rgba(0, 0, 0, 0.04); }
.tool:active, .tool.pressed { background: rgba(0, 0, 0, 0.07); }
.tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tool svg .dot { fill: currentColor; }
.tool.on { color: var(--accent); }
.tool:disabled { opacity: 0.35; cursor: default; }

/* ---------------- 主体 ---------------- */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 24px max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.spacer { flex: 0 1 var(--side-w); min-width: 0; align-self: stretch; }
.board-area { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
#board {
  display: block;
  touch-action: none;
  cursor: pointer;
  border-radius: 5px;
  /* 棋盘像一块实木：贴地的接触阴影 + 远处的柔和投影 */
  box-shadow: 0 2px 3px rgba(40, 24, 6, 0.30), 0 18px 36px rgba(40, 24, 6, 0.28), 0 40px 80px rgba(40, 24, 6, 0.12);
}

/* ---------------- 侧栏 ---------------- */
.side { width: var(--side-w); flex-shrink: 0; display: flex; flex-direction: column; }
.player { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; transition: background .2s, box-shadow .2s; }
.player.turn { background: var(--surface); box-shadow: 0 0 0 1px var(--sep), 0 1px 2px rgba(0, 0, 0, 0.05); }
.avatar {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 50%;
  background: #ebe8e2; position: relative;
  display: grid; place-items: center;
}
.face { font-size: 21px; line-height: 1; }
.mark { font-family: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif; font-weight: 700; color: #3a3530; font-size: 19px; }
#b-face { font-size: 15px; font-weight: 600; color: #555; }
.badge-stone { position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--bg); }
.player.turn .badge-stone { border-color: var(--surface); }
.side .avatar { background: #f3f1ec; }
.badge-stone.b { background: radial-gradient(circle at 35% 30%, #5a5a5a, #111 70%); }
.badge-stone.w { background: radial-gradient(circle at 35% 30%, #fff, #d6d1c8 85%); }
.pinfo { min-width: 0; }
.pname { font-size: 15px; font-weight: 600; white-space: nowrap; }
.player.turn .pname::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 8px; vertical-align: middle; }
.psub { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; white-space: nowrap; }

.hint {
  margin: 10px 14px; padding: 9px 12px; min-height: 40px;
  border-radius: 10px; font-size: 13px; line-height: 1.45; color: var(--ink-3);
  transition: background .2s, color .2s;
}
.hint.alert { background: var(--red-soft); color: var(--red); font-weight: 500; }
.hint.good { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.hint.note { color: var(--ink-2); }
.hint.key { background: var(--red-soft); color: var(--ink); }

.side-actions { margin: 14px 14px 0; display: flex; flex-direction: column; gap: 8px; }
.btn {
  height: 38px; border-radius: 8px; width: 100%;
  border: 1px solid var(--sep); background: var(--surface);
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
  transition: transform .1s, background .15s;
}
.btn:hover { background: #fbfaf8; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2a6450; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-right: 4px; vertical-align: -2px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.btn-row .btn { padding: 0 6px; white-space: nowrap; }
.btn.ghost { border: none; background: none; box-shadow: none; color: var(--ink-2); }

/* 复盘进度条（浮在棋盘下沿） */
.replay {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.12);
  font-size: 12.5px; color: var(--ink-2);
  white-space: nowrap;
}
.replay input[type=range] { width: 220px; accent-color: var(--accent); }
.rp-track { position: relative; display: flex; align-items: center; }
.rp-marks { position: absolute; inset: 0; pointer-events: none; }
.rp-mark {
  position: absolute; top: 50%; width: 16px; height: 16px; margin: 7px 0 0 -8px; padding: 0;
  border: 0; background: transparent; cursor: pointer; pointer-events: auto;
}
.rp-mark::after { content: ''; position: absolute; left: 5px; top: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--red); }
.rp { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; }
.rp:hover { background: rgba(0, 0, 0, 0.05); }
.rp svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rp-count { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.rp-text { padding: 5px 10px; border-radius: 6px; color: var(--accent); font-weight: 600; }
.rp-text:hover { background: var(--accent-soft); }

/* ---------------- 更多菜单 ---------------- */
.menu {
  position: fixed; z-index: 50;
  top: calc(var(--toolbar-h) + env(safe-area-inset-top) - 4px);
  right: max(14px, env(safe-area-inset-right));
  width: 256px; padding: 6px;
  background: rgba(255, 255, 255, 0.98); border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.16);
  font-size: 13.5px;
}
.mi { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.mi:hover { background: rgba(0, 0, 0, 0.04); }
.mi.static { cursor: default; }
.mi.static:hover { background: none; }
.mi .sub { color: var(--ink-3); font-size: 12.5px; }
.mi.danger { color: var(--red); }
.mi:disabled { opacity: 0.35; cursor: default; }
.msep { height: 1px; background: var(--sep); margin: 5px 8px; }

/* 开关 */
.switch {
  -webkit-appearance: none; appearance: none; flex-shrink: 0;
  width: 36px; height: 21px; border-radius: 11px; margin: 0;
  background: #d6d3ce; position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: left .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 17px; }

/* ---------------- 面板 ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(30, 28, 25, 0.28);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#eye-sheet { z-index: 90; } /* 护眼面板永远在最上层 */
.overlay.show { display: flex; animation: fade .16s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(440px, 100%);
  max-height: calc(100dvh - 40px); overflow-y: auto;
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 24px 60px rgba(0, 0, 0, 0.22);
  padding: 22px 24px 20px;
  animation: pop .2s cubic-bezier(.2, .9, .3, 1.1);
}
.sheet.small { width: min(380px, 100%); }
.sheet.center { text-align: center; }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } }
.sheet h2 { margin: 0 0 16px; font-size: 17px; font-weight: 600; text-align: center; }
.field { margin-bottom: 16px; }
.flabel { font-size: 12px; color: var(--ink-2); font-weight: 500; margin-bottom: 8px; display: flex; justify-content: space-between; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #efede9; border-radius: 8px; padding: 2px; }
.seg button { padding: 7px 0; border-radius: 6px; font-size: 12.5px; color: var(--ink-2); }
.seg button.sel { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.opps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opps button { border: 1px solid var(--sep); border-radius: 10px; padding: 10px 4px 8px; font-size: 12.5px; font-weight: 500; text-align: center; }
.opps .e { display: grid; place-items: center; width: 40px; height: 40px; margin: 0 auto 6px; border-radius: 50%; background: #efece6; font-size: 20px; }
.opps button.sel .e { background: var(--accent-soft); color: var(--accent); }
.opps small { display: block; color: var(--ink-3); font-size: 11px; margin-top: 1px; font-weight: 400; }
.opps button.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; color: var(--accent); }
.opps button:disabled { opacity: 0.4; cursor: default; }
.auto { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px; border-radius: 10px; background: #f7f6f3; cursor: pointer; }
.auto .t { font-size: 13px; font-weight: 600; }
.auto .d { font-size: 12px; color: var(--ink-2); margin-top: 3px; line-height: 1.5; }
.sheet-note { font-size: 12px; color: var(--ink-3); text-align: center; margin: -4px 0 12px; min-height: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }

.result { position: relative; text-align: center; width: min(360px, 100%); padding-top: 26px; }
.sheet .x {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-3); display: grid; place-items: center; cursor: pointer;
}
.sheet .x:hover { background: #efede9; color: var(--ink); }
.sheet .x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.result .big { font-size: 30px; font-weight: 700; letter-spacing: 0.5px; }
.result .margin { font-size: 15px; color: var(--accent); font-weight: 600; margin-top: 4px; }
.result.lost .margin { color: var(--ink-2); }
.result .tally { display: inline-flex; align-items: center; gap: 5px; margin-top: 10px; padding: 5px 12px; border-radius: 999px; background: #f2f0ec; font-size: 13.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.result .tally b { color: var(--ink); font-weight: 600; }
.result .tally .vs { margin: 0 6px; color: var(--ink-3); }
.result .tally .tb, .result .tally .tw { width: 10px; height: 10px; border-radius: 50%; }
.result .tally .tb { background: #222; }
.result .tally .tw { background: #fff; box-shadow: inset 0 0 0 1px #bbb; }
.result .meta { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.detail { margin: 14px 0 14px; text-align: left; border-top: 1px solid var(--sep); padding-top: 10px; font-size: 13px; color: var(--ink-2); }
.detail summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.detail summary::-webkit-details-marker { display: none; }
.detail summary::after { content: "›"; transition: transform .2s; }
.detail[open] summary::after { transform: rotate(90deg); }
.srow { display: flex; justify-content: space-between; padding: 5px 0; font-size: 12.5px; }
.srow + .srow { border-top: 1px dashed var(--sep); }
.srow b { color: var(--ink); font-weight: 600; }

.d-body { margin: -6px 0 6px; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; text-align: center; }
.d-input {
  width: 100%; margin-top: 8px; font: inherit; font-size: 20px; font-weight: 600; text-align: center;
  padding: 9px; border-radius: 8px; border: 1px solid var(--sep); background: #f7f6f3;
  -webkit-user-select: text; user-select: text;
}
.d-input:focus { outline: none; border-color: var(--accent); }
.d-error { color: var(--red); font-size: 12.5px; min-height: 18px; margin: 6px 0 4px; text-align: center; }
.rest-count { font-size: 40px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; margin: 4px 0 10px; }

/* ---------------- 竖屏 / 窄屏 ---------------- */
@media (orientation: portrait), (max-width: 760px) {
  .main { flex-direction: column; gap: 18px; justify-content: flex-start; padding-top: 18px; }
  .spacer { display: none; }
  .side {
    width: 100%; max-width: 620px;
    display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "b w" "hint hint" "act act"; gap: 0 10px;
  }
  #p-black { grid-area: b; }
  #p-white { grid-area: w; }
  .hint { grid-area: hint; margin: 8px 0 0; }
  .side-actions { grid-area: act; margin: 10px 0 0; }
}
@media (max-width: 640px) {
  .title { display: none; }
  .home-portal-link span { display: none; }
  .home-portal-link { padding: 6px 7px; border-radius: 8px; }
  .toolbar { grid-template-columns: auto auto 1fr; }
  .status { text-align: left; }
  .tool { width: 44px; }
  .tool span { display: none; }
  .replay input[type=range] { width: 120px; }
}
