/* 圍棋・一局到底 —— 視覺與響應式 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f6f1e6;
  --bg-deep: #efe7d5;
  --ink: #2a2118;
  --dim: #857a67;
  --card: #fffdf7;
  --line: #e6dcc7;
  --accent: #b03a2e;
  --accent-deep: #8f2d23;
  --accent-soft: #f6e3dd;
  --gold: #c9973f;
  --shadow-sm: 0 1px 3px rgba(70, 50, 15, 0.08), 0 1px 2px rgba(70, 50, 15, 0.06);
  --shadow-md: 0 6px 18px rgba(70, 50, 15, 0.12), 0 2px 6px rgba(70, 50, 15, 0.08);
  --shadow-lg: 0 18px 50px rgba(50, 35, 10, 0.22);
  --radius: 14px;
}

html, body { height: 100%; }
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #fbf7ee 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }
.dim { color: var(--dim); font-size: 0.92rem; }

/* ---------- 按鈕 ---------- */
.btn {
  padding: 9px 16px; min-height: 40px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--ink);
  font: inherit; font-size: 0.93rem; font-weight: 500;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  touch-action: manipulation;
}
.btn:hover { background: #f5eedb; box-shadow: var(--shadow-md); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; box-shadow: none; }
.btn.primary {
  background: linear-gradient(180deg, #c04437 0%, var(--accent) 60%, var(--accent-deep) 100%);
  border-color: var(--accent-deep); color: #fff;
}
.btn.primary:hover { background: linear-gradient(180deg, #c94a3c, var(--accent-deep)); }
.btn.warn { border-color: #d8a49b; color: var(--accent); background: #fdf8f4; }
.btn.back { font-size: 0.88rem; padding: 7px 13px; min-height: 36px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 9px; }

/* ---------- 主選單 ---------- */
.menu-wrap {
  max-width: 880px; margin: 0 auto; padding: 8vh 24px 56px; text-align: center;
}
.menu-wrap h1 {
  font-size: clamp(1.75rem, 6vw, 3rem);
  letter-spacing: 0.08em; font-weight: 800;
  display: inline-flex; align-items: center; gap: 0.18em;
  white-space: nowrap;
}
.menu-wrap h1 span { color: var(--accent); }
.menu-wrap h1::before, .menu-wrap h1::after {
  content: ''; width: 0.52em; height: 0.52em; border-radius: 50%;
  margin: 0 0.25em; flex: none;
}
.menu-wrap h1::before {
  background: radial-gradient(circle at 35% 30%, #6b6f76, #0c0c0f 70%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}
.menu-wrap h1::after {
  background: radial-gradient(circle at 35% 30%, #fff, #c9c4b0 75%);
  border: 1px solid #b9b3a0; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.tagline { margin: 16px 0 40px; color: var(--dim); font-size: 1.06rem; }

.menu-cards { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.menu-card {
  flex: 1 1 220px; max-width: 260px; padding: 24px 20px 22px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; font: inherit; color: inherit; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  transition: transform 0.16s, box-shadow 0.16s;
}
.menu-card::after {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  opacity: 0; transition: opacity 0.16s;
}
.menu-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.menu-card:hover::after { opacity: 1; }
.menu-card em {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2em; height: 2em; border-radius: 10px; flex: none;
  font-style: normal; font-size: 1.05rem; font-weight: 800;
  color: #fff; background: linear-gradient(160deg, #c04437, var(--accent-deep));
  box-shadow: var(--shadow-sm);
}
.menu-card .mc-text { min-width: 0; }
.menu-card b { display: block; font-size: 1.22rem; margin: 12px 0 8px; letter-spacing: 0.02em; }
.menu-card span { font-size: 0.87rem; color: var(--dim); display: block; }
.menu-note { margin-top: 36px; font-size: 0.88rem; color: var(--dim); }
#menu-glossary { margin-top: 16px; }

/* ---------- 關卡列表 ---------- */
.list-wrap { max-width: 700px; margin: 0 auto; padding: 36px 22px 60px; }
.list-wrap h2 { margin: 16px 0 6px; font-size: 1.5rem; letter-spacing: 0.03em; }
.level-list { margin-top: 24px; display: flex; flex-direction: column; gap: 13px; }
.level-card {
  padding: 17px 20px; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 12px; cursor: pointer; font: inherit; color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.13s, box-shadow 0.13s, border-color 0.13s;
}
.level-card:hover { transform: translateX(5px); box-shadow: var(--shadow-md); border-left-color: var(--accent); }
.level-card b { display: block; font-size: 1.06rem; }
.level-card span { font-size: 0.88rem; color: var(--dim); }

/* ---------- 對局畫面 ---------- */
.play-wrap {
  display: flex; gap: 28px; align-items: flex-start; justify-content: center;
  padding: 24px 20px 48px; max-width: 1120px; margin: 0 auto;
}
.board-col { flex: 0 1 660px; min-width: 0; }
.play-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
#play-title { font-weight: 700; font-size: 1.06rem; letter-spacing: 0.02em; }
#board { width: 100%; }
#status-line { margin-top: 10px; font-size: 0.9rem; color: var(--dim); text-align: center; }

.side-col {
  flex: 0 0 308px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 24px;
}

/* 階段列 */
#phase-bar {
  margin-left: auto; display: flex; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px; box-shadow: var(--shadow-sm);
}
#phase-bar span {
  padding: 4px 14px; font-size: 0.84rem; color: var(--dim);
  border-radius: 999px; transition: all 0.3s; white-space: nowrap;
}
#phase-bar span.active {
  background: linear-gradient(160deg, #c04437, var(--accent-deep));
  color: #fff; font-weight: 700; box-shadow: var(--shadow-sm);
}

/* 提示卡 */
#tip-card {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 15px 17px; min-height: 92px; box-shadow: var(--shadow-sm);
}
#tip-card.flash { animation: tipflash 0.55s; }
@keyframes tipflash { 0% { background: var(--accent-soft); } 100% { background: var(--card); } }
#tip-title { font-size: 0.96rem; margin-bottom: 6px; color: var(--accent); letter-spacing: 0.02em; }
#tip-body { font-size: 0.93rem; white-space: pre-line; }

/* 數地面板 */
#counting-panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow-md);
}
#counting-panel h3 { margin-bottom: 4px; letter-spacing: 0.05em; }
.score-row { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 0.96rem; }
.score-row.neutral { color: var(--dim); font-size: 0.85rem; }
.score-row b { font-size: 1.1rem; }
.dot { width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; }
.dot.black { background: radial-gradient(circle at 35% 30%, #6b6f76, #0c0c0f 70%); }
.dot.white { background: radial-gradient(circle at 35% 30%, #fff, #c9c4b0 75%); border: 1px solid #b0aa96; }
#counting-panel .btn-row { margin-top: 10px; }

/* ---------- 棋盤 SVG ---------- */
.goban { display: block; width: 100%; height: auto; filter: drop-shadow(0 10px 24px rgba(70, 45, 10, 0.28)); }
.goban-bg { stroke: #b98d47; stroke-width: 1.5; }
.goban-line { stroke: #6b5230; stroke-width: 1; opacity: 0.85; }
.goban-star { fill: #5d4626; }
.goban-coord { fill: #97783f; font-size: 11px; text-anchor: middle; font-weight: 500; }
.stone-black { stroke: #000; stroke-width: 0.5; }
.stone-white { stroke: #a9a390; stroke-width: 0.7; }
.stone.dead { opacity: 0.5; }
.dead-mark { stroke: #c0392b; stroke-width: 2.2; stroke-linecap: round; }
.last-mark { fill: none; stroke-width: 1.9; }
.last-mark.on-black { stroke: #fff; }
.last-mark.on-white { stroke: #333; }
.move-num { font-size: 12px; text-anchor: middle; font-weight: 700; }
.move-num.on-black { fill: #fff; }
.move-num.on-white { fill: #3a2f22; }
.hint-pt { fill: rgba(176, 58, 46, 0.16); stroke: var(--accent); stroke-width: 1.8; }
.hint-pt.pulse { animation: pulse 1.4s infinite; }
.hint-pt.soft { fill: rgba(176, 58, 46, 0.09); stroke-dasharray: 4 3; animation: none; }
@keyframes pulse { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: 0.3; } }
.hint-label { fill: var(--accent-deep); font-size: 13.5px; font-weight: 800; text-anchor: middle; }
.terr-black { fill: rgba(25, 25, 28, 0.55); }
.terr-white { fill: rgba(255, 255, 253, 0.82); stroke: #a9a390; stroke-width: 0.5; }
.terr-none { fill: rgba(140, 120, 90, 0.28); }
.illegal-flash { fill: rgba(200, 40, 30, 0.45); }

/* ---------- 語言切換(浮動,不佔版面) ---------- */
#lang-toggle {
  position: fixed; top: 12px; right: 12px; z-index: 55;
  width: 44px; height: 36px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--accent);
  font: inherit; font-size: 0.88rem; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform 0.12s, box-shadow 0.12s;
}
#lang-toggle:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* ---------- 術語小辭典 ---------- */
.term {
  text-decoration: underline dotted var(--accent) 1.5px;
  text-underline-offset: 3px;
  cursor: help;
}
.term:hover { background: var(--accent-soft); border-radius: 3px; }

#gloss-pop {
  position: fixed; z-index: 70; display: none;
  max-width: min(320px, calc(100vw - 24px)); padding: 13px 15px;
  background: #322718; color: #f6f1e6; border-radius: 13px;
  box-shadow: var(--shadow-lg);
  font-size: 0.89rem; line-height: 1.65;
}
#gloss-pop.open { display: block; }
#gloss-pop b { color: #f0c66a; display: block; margin-bottom: 4px; }

#glossary-list { margin-top: 22px; display: flex; flex-direction: column; gap: 11px; }
.gloss-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 17px; box-shadow: var(--shadow-sm);
}
.gloss-item b { color: var(--accent); margin-right: 6px; }
.gloss-item small { color: var(--dim); }
.gloss-item p { font-size: 0.9rem; margin-top: 4px; }

/* ---------- Toast / Modal ---------- */
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #322718; color: #f6f1e6; padding: 11px 22px; border-radius: 12px;
  font-size: 0.92rem; opacity: 0; pointer-events: none; transition: 0.25s; z-index: 50;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#modal {
  position: fixed; inset: 0; background: rgba(42, 30, 12, 0.5);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 18px;
}
#modal.open { display: flex; }
.modal-box {
  background: var(--card); border-radius: 18px; padding: 28px 30px;
  max-width: 460px; width: 100%; box-shadow: var(--shadow-lg);
  animation: modalin 0.22s ease-out;
}
@keyframes modalin { from { transform: translateY(14px) scale(0.97); opacity: 0; } }
.modal-box h2 { margin-bottom: 12px; font-size: 1.35rem; }
#modal-body p { margin-bottom: 10px; font-size: 0.95rem; }
#modal-buttons { margin-top: 18px; justify-content: flex-end; }

/* ---------- 響應式:平板 ---------- */
@media (max-width: 920px) {
  .play-wrap { flex-direction: column; align-items: center; gap: 16px; padding: 18px 16px 40px; }
  .board-col { flex: none; width: 100%; max-width: 620px; }
  .side-col { position: static; flex: none; width: 100%; max-width: 620px; }
  .menu-wrap { padding-top: 6vh; }
}

/* ---------- 響應式:手機 ---------- */
@media (max-width: 640px) {
  body { line-height: 1.6; }
  .menu-wrap { padding: 40px 18px 44px; }
  .tagline { margin: 12px 0 28px; font-size: 0.98rem; }
  .menu-cards { flex-direction: column; align-items: stretch; gap: 14px; }
  .menu-card { max-width: none; flex: none; display: flex; align-items: center; gap: 15px; padding: 16px 18px; }
  .menu-card b { margin: 0 0 4px; font-size: 1.1rem; }
  .menu-note { margin-top: 26px; }

  .list-wrap { padding: 22px 16px 44px; }
  .list-wrap h2 { font-size: 1.3rem; }

  .play-wrap { padding: 12px 10px 34px; }
  .play-head { gap: 9px; margin-bottom: 10px; }
  #play-title { font-size: 0.98rem; }
  #phase-bar { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }
  #phase-bar span { flex: 1; text-align: center; padding: 5px 0; }
  #status-line { font-size: 0.85rem; margin-top: 8px; }
  #tip-card { min-height: 0; padding: 13px 14px; }
  #tip-body { font-size: 0.92rem; }

  .btn { min-height: 44px; font-size: 0.95rem; flex: 1 1 auto; }
  .btn.back { flex: 0 0 auto; }
  #counting-panel .btn-row .btn { flex: 1 1 46%; }

  .modal-box { padding: 22px 20px; border-radius: 16px; }
  #modal-buttons .btn { flex: 1 1 46%; }
  .goban-coord { font-size: 13px; }
}
