/* =========================================================
   圍棋 · 樣式
   風格：墨色背景 + 榧木棋盤 + 朱紅印章點綴
   版面：手機直式一欄（棋盤在上、操作在下）；寬螢幕改成左右兩欄
   ========================================================= */
:root {
  color-scheme: dark;
  --bg: #15181b;
  --bg-2: #1d2125;
  --panel: #20252a;
  --line: rgba(236, 226, 205, .12);
  --ink: #ece4d4;
  --ink-soft: #b9b0a0;
  --ink-faint: #7f786c;
  --seal: #c8452d;
  --seal-soft: rgba(200, 69, 45, .16);
  --gold: #d9a95b;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", "MingLiU", serif;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(ellipse at 50% -10%, rgba(217, 169, 91, .10), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(200, 69, 45, .06), transparent 50%),
    var(--bg);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;   /* 禁止雙擊放大 */
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .38; cursor: default; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 10px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 10px);
  gap: 8px;
}

/* ---------- 頂部 ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.back {
  display: grid; place-items: center; width: 34px; height: 34px;
  color: var(--ink-soft); text-decoration: none; font-size: 26px; line-height: 1;
  border-radius: 50%;
}
.back:active { background: var(--bg-2); }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.seal {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  background: var(--seal); color: #fbeee4; border-radius: 6px;
  font: 700 19px var(--serif);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .15);
}
.brand strong { display: block; font: 700 17px var(--serif); letter-spacing: .12em; }
.brand small { display: block; color: var(--ink-faint); font-size: 11px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
.chip {
  padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-2);
  font-size: 13px; font-weight: 600;
}
.chip.primary { background: var(--seal); border-color: var(--seal); color: #fff6ee; }

/* ---------- 主版面 ---------- */
.layout { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.board-area { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board-box { position: relative; line-height: 0; }
#board {
  display: block;
  border-radius: 4px;
  touch-action: none;   /* 棋盤上的手勢交給程式處理 */
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45), 0 2px 0 rgba(255, 255, 255, .06) inset;
}

/* 放大鏡 */
.loupe {
  position: absolute; z-index: 5; pointer-events: none;
  border-radius: 50%;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .55), 0 0 0 3px rgba(255, 255, 255, .85), 0 0 0 5px rgba(0, 0, 0, .35);
}

/* ---------- 面板 ---------- */
.panel { display: flex; flex-direction: column; gap: 8px; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  transition: border-color .2s, box-shadow .2s;
}
.player.active { border-color: rgba(217, 169, 91, .7); box-shadow: 0 0 0 1px rgba(217, 169, 91, .35), 0 0 18px rgba(217, 169, 91, .12); }
.stone { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.stone.black { background: radial-gradient(circle at 35% 30%, #6a6a6a, #1b1b1b 45%, #000 100%); }
.stone.white { background: radial-gradient(circle at 35% 30%, #fff, #e9e5db 60%, #bdb7a8 100%); }
.pinfo { min-width: 0; }
.pinfo strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinfo small { color: var(--ink-faint); font-size: 11px; }
.pinfo b { color: var(--ink); font-weight: 700; }
.thinking { margin-left: auto; display: flex; gap: 3px; }
.thinking[hidden] { display: none; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--gold); animation: blink 1s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

.status-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 0 2px; min-height: 20px; }
#status { font-size: 13.5px; color: var(--ink); }
.eval { font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }

.btn {
  min-height: 44px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); font-size: 14px; font-weight: 600;
}
.btn:not(:disabled):active { transform: translateY(1px); background: #262b30; }
.btn.primary { background: var(--seal); border-color: var(--seal); color: #fff6ee; }
.btn.primary:not(:disabled):active { background: #b23c27; }
.btn.danger { color: #f0a493; }
.btn.ghost { background: transparent; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions[hidden] { display: none; }

.confirm-bar { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.confirm-bar[hidden] { display: none; }
.nudge { display: grid; grid-template-columns: repeat(4, 34px); gap: 4px; }
.nudge button {
  height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2);
  font-size: 15px;
}
.nudge button:active { background: #2a3035; }
#confirmCoord { font-weight: 400; opacity: .8; font-size: 12px; }

.score-bar { padding: 10px; border-radius: 10px; background: var(--panel); border: 1px solid rgba(217, 169, 91, .4); }
.score-bar[hidden] { display: none; }
.score-hint { margin: 0 0 6px; color: var(--ink-soft); font-size: 12px; }
.score-line { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.score-line b { font-size: 18px; color: var(--gold); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.dot.black { background: #000; box-shadow: 0 0 0 1px #555; }
.dot.white { background: #f1eee6; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.review { display: flex; align-items: center; gap: 4px; }
.review button {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft); font-size: 12px; flex: none;
}
.review input[type=range] { flex: 1; min-width: 0; accent-color: var(--gold); height: 34px; }
.rev-label { min-width: 58px; text-align: right; color: var(--ink-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------- 提示訊息 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px);
  transform: translate(-50%, 20px);
  max-width: min(92vw, 440px);
  padding: 10px 16px; border-radius: 12px;
  background: rgba(12, 14, 16, .94); border: 1px solid rgba(217, 169, 91, .35);
  color: var(--ink); font-size: 13.5px; line-height: 1.5; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 對話框 ---------- */
dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(5, 6, 8, .65); backdrop-filter: blur(3px); }
.dlg { padding: 18px 18px 16px; overflow: auto; max-height: calc(100dvh - 26px); }
.kicker { margin: 0 0 2px; color: var(--seal); font-size: 11px; font-weight: 700; letter-spacing: .25em; }
.dlg h2 { margin: 0 0 12px; font: 700 22px var(--serif); letter-spacing: .1em; }
fieldset { border: 0; margin: 0 0 12px; padding: 0; }
legend { padding: 0; margin-bottom: 6px; color: var(--ink-soft); font-size: 12.5px; }
.seg { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 46px; padding: 6px 4px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2);
  font-size: 14px; font-weight: 600; text-align: center; cursor: pointer;
}
.seg small { font-size: 10.5px; font-weight: 400; color: var(--ink-faint); margin-top: 2px; }
.seg input:checked + span { border-color: var(--seal); background: var(--seal-soft); color: #ffe6dc; }
.seg input:checked + span small { color: #e9b5a7; }
.seg input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--seal); }
.note { margin: 0 0 14px; color: var(--ink-faint); font-size: 11.5px; }
.result { text-align: center; }
.result h2 { font-size: 28px; margin: 6px 0 8px; color: var(--gold); }
.detail { margin: 0 0 16px; color: var(--ink-soft); font-size: 13.5px; line-height: 1.7; }

/* ---------- 寬螢幕：左右兩欄 ---------- */
@media (min-width: 860px) and (min-aspect-ratio: 1/1) {
  .app { padding: 14px 24px 18px; }
  .layout { flex-direction: row; gap: 22px; }
  .board-area { flex: 1; }
  .panel { width: 340px; flex: none; justify-content: center; }
  .players { grid-template-columns: 1fr; }
  .toast { bottom: 40px; }
}

/* 很矮的手機（橫拿或小螢幕）：縮小間距 */
@media (max-height: 640px) {
  .app { gap: 5px; }
  .topbar { min-height: 38px; }
  .btn, .nudge button { min-height: 40px; height: 40px; }
  .player { padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
