/* ===================================================================
   ガイドブック共通のスタイル。
   盤面は本番の対局画面（game.html）と同じ色・駒・重ね方。そこに解説用の印・矢印・吹き出しを足す。
   =================================================================== */

:root {
  --guide-text: #1f2937;
  --guide-muted: #6b7280;
  --guide-line: #e5e7eb;
  --guide-accent: #2563eb;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --teacher-bubble: #eff6ff;
  --teacher-border: #bfdbfe;
  --student-bubble: #fff7ed;
  --student-border: #fed7aa;
  --ulb-size: 300px;
}

body {
  font-family: 'Inter', 'Helvetica Neue', 'Arial', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
}

/* ---------- 本文 ---------- */
.guide-article {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 28px 22px 36px;
  color: var(--guide-text);
  line-height: 1.9;
  font-size: 16px;
}
@media (min-width: 640px) {
  .guide-article { padding: 40px 48px 48px; }
}
.guide-article h1 { font-size: 1.6rem; font-weight: 800; line-height: 1.4; margin: 0 0 0.6rem; }
.guide-article h2 {
  font-size: 1.25rem; font-weight: 800; line-height: 1.5;
  margin: 2.6rem 0 1rem; padding: 0.3rem 0 0.3rem 0.8rem;
  border-left: 5px solid var(--guide-accent);
}
.guide-article h3 { font-size: 1.05rem; font-weight: 700; margin: 2rem 0 0.6rem; }
.guide-article p { margin: 0.9rem 0; }
.guide-article ul, .guide-article ol { margin: 0.8rem 0 0.8rem 1.4rem; }
.guide-article ul { list-style: disc; }
.guide-article ol { list-style: decimal; }
.guide-article li { margin: 0.25rem 0; }
.guide-article strong { font-weight: 700; background: linear-gradient(transparent 62%, #fde68a 62%); }

.guide-chapter-label { font-size: 0.8rem; font-weight: 700; color: var(--guide-accent); letter-spacing: 0.05em; }
.guide-lead { color: var(--guide-muted); margin-top: 0.4rem; }

/* 棋譜（文中） */
.kifu {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #f3f4f6;
  border: 1px solid var(--guide-line);
  border-radius: 6px;
  padding: 0.05em 0.4em;
  white-space: nowrap;
}

/* ---------- 盤面図 ---------- */
figure.ulb { margin: 1.4rem auto; width: var(--ulb-size); max-width: 100%; }
figure.ulb figcaption { font-size: 0.85rem; color: var(--guide-muted); line-height: 1.6; margin-top: 0.5rem; text-align: center; }
.ulb-info {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.8rem; color: var(--guide-muted); margin: 0 0 0.35rem 16px;
}
.ulb-turn { font-weight: 700; color: var(--guide-text); display: inline-flex; align-items: center; gap: 0.3em; }
.ulb-hands { display: inline-flex; align-items: center; gap: 0.25em; }
.ulb-dot {
  display: inline-block; width: 0.85em; height: 0.85em; border-radius: 50%; vertical-align: -0.1em;
}
.ulb-dot.white { background: radial-gradient(circle at 50% 30%, #ffffff, #cccccc); border: 1px solid #888; }
.ulb-dot.black { background: radial-gradient(circle at 50% 30%, #555555, #111111); border: 1px solid #000; }
.ulb-hands .ulb-dot { margin-left: 0.4em; }

.ulb-frame { display: grid; grid-template-columns: 16px 1fr; grid-template-rows: 1fr 16px; }
.ulb-ranks { display: grid; grid-template-rows: repeat(4, 1fr); }
.ulb-files { display: grid; grid-template-columns: repeat(4, 1fr); }
.ulb-ranks span, .ulb-files span {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--guide-muted); line-height: 1;
}

.ulb-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
/* 高いスタックは上のマスにはみ出して描く（本番と同じ）ので、盤は切り抜かず角のマスだけ丸める */
.ulb-board .cell:nth-child(1) { border-top-left-radius: 6px; }
.ulb-board .cell:nth-child(4) { border-top-right-radius: 6px; }
.ulb-board .cell:nth-child(13) { border-bottom-left-radius: 6px; }
.ulb-board .cell:nth-child(16) { border-bottom-right-radius: 6px; }
.ulb-board .cell { position: relative; display: flex; justify-content: center; align-items: center; }
.ulb-board .cell.light { background-color: var(--board-light); }
.ulb-board .cell.dark { background-color: var(--board-dark); }
/* 本番の駒（game.html の .piece と同じ色・影）。重なりは駒の高さの約2割ずつ上にずらし、下の駒の色も読めるようにする。
   高いスタックは本番だと上のマスにはみ出すが、ガイドでは駒を少し小さくしてマスの中に収める（--n = そのマスの枚数） */
.ulb-board .piece {
  --size: min(75%, calc(92% / (1 + 0.18 * (var(--n, 1) - 1))));
  position: absolute; width: var(--size); height: var(--size); border-radius: 50%; box-sizing: border-box;
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.5);
  transform: translateY(calc(var(--i, 0) * -18% + (var(--n, 1) - 1) * 9%));
}
.ulb-board .piece.white { background: radial-gradient(circle at 50% 30%, #ffffff, #cccccc); border: 2px solid #888; }
.ulb-board .piece.black { background: radial-gradient(circle at 50% 30%, #555555, #111111); border: 2px solid #000; }
/* 直前の手で増えた（緑）・減った（赤）マス。本番と同じ色 */
.ulb-board .cell.increased::before, .ulb-board .cell.decreased::before {
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none; border-radius: inherit;
}
.ulb-board .cell.increased::before { background-color: rgba(22, 163, 74, 0.4); }
.ulb-board .cell.decreased::before { background-color: rgba(220, 38, 38, 0.4); }

/* 印 */
.ulb-mark { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; }
.ulb-mark.focus { box-shadow: inset 0 0 0 4px rgba(250, 204, 21, 0.95); z-index: 15; }
.ulb-mark.good { box-shadow: inset 0 0 0 4px rgba(22, 163, 74, 0.9); z-index: 15; }
.ulb-mark.bad { box-shadow: inset 0 0 0 4px rgba(220, 38, 38, 0.9); z-index: 15; }
.ulb-mark.reach { background: rgba(220, 38, 38, 0.28); z-index: 0; }
.ulb-mark.area { background: rgba(59, 130, 246, 0.3); z-index: 0; }
.ulb-label {
  position: absolute; top: 3px; right: 3px; z-index: 25;
  min-width: 1.35em; height: 1.35em; padding: 0 0.25em; border-radius: 999px;
  background: #1f2937; color: #fff; font-size: 11px; font-weight: 700; line-height: 1.35em; text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

/* 矢印 */
.ulb-arrows { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 30; pointer-events: none; }
.ulb-arrow { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: 0.88; }
.ulb-arrow.move { stroke: #2563eb; }
.ulb-arrow.good { stroke: #16a34a; }
.ulb-arrow.bad { stroke: #dc2626; }
.ulb-arrow.alt { stroke: #4b5563; stroke-dasharray: 14 12; opacity: 0.75; }
.ulb-arrowhead.move { fill: #2563eb; }
.ulb-arrowhead.good { fill: #16a34a; }
.ulb-arrowhead.bad { fill: #dc2626; }
.ulb-arrowhead.alt { fill: #4b5563; }

/* 指す前 → 指した後 */
.ulb-pair { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.4rem 1rem; margin: 1.4rem 0; }
.ulb-pair figure.ulb { margin: 0; --ulb-size: 240px; }
.ulb-pair.compare { gap: 0.6rem 1.6rem; align-items: flex-start; }
.ulb-pair-arrow { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; color: var(--guide-muted); font-size: 1.3rem; }
.ulb-pair-arrow .kifu { font-size: 0.8rem; }
@media (max-width: 560px) {
  .ulb-pair { flex-direction: column; }
  .ulb-pair-arrow i { transform: rotate(90deg); }
}

/* ◀ ▶ でめくる盤面 */
.ulb-seq-nav { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 0.5rem; }
.ulb-seq-nav button {
  width: 2.2rem; height: 2.2rem; border-radius: 999px; border: 1px solid var(--guide-line); background: #fff;
  color: var(--guide-text); cursor: pointer;
}
.ulb-seq-nav button:hover:not(:disabled) { background: #f3f4f6; }
.ulb-seq-nav button:disabled { opacity: 0.35; cursor: default; }
.ulb-seq-count { font-size: 0.85rem; color: var(--guide-muted); min-width: 3.5em; text-align: center; }
.ulb-seq-view figcaption { min-height: 3.2em; }

/* 文中の小さなスタック（横から見た絵。上が一番上の駒） */
.stk { display: inline-flex; align-items: center; vertical-align: middle; margin: 0 0.15em; }
.stk-pile { display: inline-flex; flex-direction: column; gap: 1px; }
.stk-disc { display: block; width: 1.4em; height: 0.42em; border-radius: 0.21em; box-sizing: border-box; }
.stk-disc.white { background: linear-gradient(#ffffff, #d6d3d1); border: 1px solid #78716c; }
.stk-disc.black { background: linear-gradient(#57534e, #1c1917); border: 1px solid #000; }

/* ---------- 吹き出し ---------- */
.talk { display: flex; align-items: flex-start; gap: 0.7rem; margin: 1.1rem 0; }
.talk-right { flex-direction: row-reverse; }
.talk-person { flex: 0 0 auto; width: 60px; display: flex; flex-direction: column; align-items: center; }
.talk-avatar-svg { width: 56px; height: 56px; display: block; }
.talk-name { font-size: 0.7rem; color: var(--guide-muted); margin-top: 0.15rem; white-space: nowrap; }
.talk-bubble {
  position: relative; max-width: calc(100% - 80px);
  padding: 0.7rem 1rem; border-radius: 14px; border: 1.5px solid; line-height: 1.8;
}
.talk-bubble > :first-child { margin-top: 0; }
.talk-bubble > :last-child { margin-bottom: 0; }
.talk-teacher .talk-bubble { background: var(--teacher-bubble); border-color: var(--teacher-border); }
.talk-student .talk-bubble { background: var(--student-bubble); border-color: var(--student-border); }
.talk-bubble::before, .talk-bubble::after {
  content: ''; position: absolute; top: 18px; border: 8px solid transparent;
}
.talk-left .talk-bubble::before { left: -17px; border-right-color: inherit; border-right-width: 9px; }
.talk-left .talk-bubble::after { left: -14px; border-right-color: var(--teacher-bubble); }
.talk-right .talk-bubble::before { right: -17px; border-left-color: inherit; border-left-width: 9px; }
.talk-right .talk-bubble::after { right: -14px; border-left-color: var(--student-bubble); }
@media (max-width: 480px) {
  .talk-person { width: 46px; }
  .talk-avatar-svg { width: 42px; height: 42px; }
  .talk-bubble { max-width: calc(100% - 60px); padding: 0.6rem 0.8rem; }
}

/* ---------- 囲み ---------- */
.box { border-radius: 10px; padding: 0.9rem 1.1rem; margin: 1.4rem 0; border: 1.5px solid; }
.box > :first-child { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.box-title { display: flex; align-items: center; gap: 0.45rem; font-weight: 800; margin-bottom: 0.35rem; }
.box.rule { background: #f5f3ff; border-color: #c4b5fd; }
.box.rule .box-title { color: #6d28d9; }
.box.point { background: #eff6ff; border-color: #93c5fd; }
.box.point .box-title { color: #1d4ed8; }
.box.caution { background: #fef2f2; border-color: #fca5a5; }
.box.caution .box-title { color: #b91c1c; }
.box.column { background: #f9fafb; border-color: #d1d5db; }
.box.column .box-title { color: #374151; }
.box.term { background: #f0fdf4; border-color: #86efac; }
.box.term .box-title { color: #15803d; }

/* 表 */
.guide-table { width: 100%; border-collapse: collapse; margin: 1.2rem 0; font-size: 0.92rem; line-height: 1.6; }
.guide-table th, .guide-table td { border: 1px solid var(--guide-line); padding: 0.5rem 0.65rem; text-align: left; vertical-align: top; }
.guide-table th { background: #f3f4f6; font-weight: 700; white-space: nowrap; }
.guide-table td:first-child { white-space: nowrap; }
.guide-table a { color: var(--guide-accent); }

/* 問題 */
.quiz { border: 2px solid #fbbf24; background: #fffbeb; border-radius: 12px; padding: 1rem 1.1rem; margin: 1.6rem 0; }
.quiz-title { font-weight: 800; color: #b45309; display: flex; align-items: center; gap: 0.45rem; }
.quiz details { margin-top: 0.6rem; }
.quiz summary {
  display: inline-block; cursor: pointer; list-style: none;
  background: #f59e0b; color: #fff; font-weight: 700; font-size: 0.9rem;
  border-radius: 999px; padding: 0.3rem 1rem;
}
.quiz summary::-webkit-details-marker { display: none; }
.quiz details[open] summary { background: #d97706; }
.quiz-answer { margin-top: 0.6rem; }

/* ---------- 章の移動・目次 ---------- */
.guide-pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--guide-line); }
.guide-pager a { color: var(--guide-accent); font-weight: 700; text-decoration: none; }
.guide-pager a:hover { text-decoration: underline; }
.guide-pager .pager-soon { color: var(--guide-muted); }
.guide-page-toc { background: #f9fafb; border-radius: 10px; padding: 0.8rem 1.1rem; margin: 1.4rem 0 0.5rem; }
.guide-page-toc p { margin: 0 0 0.3rem; font-weight: 700; font-size: 0.85rem; color: var(--guide-muted); }
.guide-page-toc ol { margin: 0 0 0 1.4rem !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0 1rem; }
.guide-page-toc a { color: var(--guide-accent); text-decoration: none; }
.guide-page-toc a:hover { text-decoration: underline; }
.guide-article h2[id] { scroll-margin-top: 1rem; }
.guide-toc-part { margin-top: 1.8rem; }
.guide-toc-part h2 { margin-top: 0; }
.guide-toc { list-style: none !important; margin-left: 0 !important; padding: 0; counter-reset: toc; }
.guide-toc li { margin: 0; border-bottom: 1px solid var(--guide-line); }
.guide-toc a, .guide-toc .toc-soon { display: flex; align-items: baseline; gap: 0.8rem; padding: 0.7rem 0.2rem; text-decoration: none; color: var(--guide-text); }
.guide-toc a:hover { background: #f9fafb; }
.guide-toc .toc-no { color: var(--guide-accent); font-weight: 800; min-width: 2.2em; }
.guide-toc .toc-sub { color: var(--guide-muted); font-size: 0.85rem; }
.guide-toc .toc-soon { color: var(--guide-muted); }
.toc-badge { margin-left: auto; font-size: 0.7rem; background: #f3f4f6; color: var(--guide-muted); border-radius: 999px; padding: 0.1rem 0.6rem; white-space: nowrap; }

.guide-error { border: 2px solid #dc2626; background: #fef2f2; color: #b91c1c; padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.85rem; }
