:root {
  --bg: #f5efe4;
  --panel: #fffaf2;
  --text: #2b2118;
  --muted: #7a6a58;
  --line: #d9cbb5;
  --accent: #7a4b1e;
  --accent-text: #fff;
  --board: #e7c27d;
  --board-line: #6b4a20;
  --board-label: #4a3414;
  --grain: rgba(120, 70, 20, .07);
  --piece: #f6e3b4;
  --piece-edge: #a77b3c;
  --piece-text: #1d140b;
  --promoted: #c0261a;
  --sel: rgba(46, 125, 50, .45);
  --dest: rgba(46, 125, 50, .55);
  --last: rgba(255, 170, 0, .35);
  --check: rgba(220, 40, 40, .35);
  --good: #2e7d32;
  --bad: #c62828;
  --shadow: 0 2px 10px rgba(60, 40, 10, .15);
  --mincho: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", "Noto Serif CJK JP", "MS PMincho", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a16; --panel: #2a251f; --text: #efe6d8; --muted: #b4a68f; --line: #4a4035;
    --accent: #c98a45; --accent-text: #1d1a16; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #1d1a16; --panel: #2a251f; --text: #efe6d8; --muted: #b4a68f; --line: #4a4035;
  --accent: #c98a45; --accent-text: #1d1a16; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: bold; }
button:disabled { opacity: .45; cursor: default; }
select, input[type=number], textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type=number] { width: 5em; }

.screen { display: none; min-height: 100vh; padding: 0 16px 24px; max-width: 1100px; margin: 0 auto; }
.screen.active { display: block; }

/* ホーム */
.home-head { text-align: center; padding: 40px 0 16px; }
.home-logo {
  width: 84px; height: 96px; margin: 0 auto 10px; background: var(--piece); border: 2px solid var(--piece-edge);
  clip-path: polygon(50% 0, 86% 16%, 100% 100%, 0 100%, 14% 16%);
  display: flex; align-items: center; justify-content: center;
}
.home-logo span { font-family: var(--mincho); font-size: 46px; font-weight: bold; color: var(--piece-text); margin-top: 14px; }
h1 { font-family: var(--mincho); font-size: 30px; margin: 0; letter-spacing: .08em; }
.sub { color: var(--muted); margin: 4px 0 0; }
.menu { display: flex; flex-direction: column; gap: 12px; max-width: 420px; margin: 24px auto 0; }
.big { font-size: 18px; padding: 14px; border-radius: 14px; box-shadow: var(--shadow); }
.small-menu { flex-direction: row; justify-content: center; }
.small-menu button { flex: 1; }
.soon { max-width: 420px; margin: 24px auto 0; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; color: var(--muted); }
.soon-title { margin: 0 0 4px; font-size: 14px; }
.soon ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.soon li { font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.ver { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

/* 上のバー */
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.bar h2 { font-size: 18px; margin: 0; flex: 1; }
.bar .back { min-height: 40px; padding: 6px 12px; }
.engine-tag { font-size: 12px; color: var(--muted); }

/* フォーム */
.form { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.label { font-weight: bold; }
.label small { font-weight: normal; color: var(--muted); }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.err { color: var(--bad); margin: 0; min-height: 1em; white-space: pre-wrap; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: bold; }
.custom-time { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(22px); }
.prose h3 { margin: 8px 0 0; font-size: 16px; }
.prose p, .prose ul { margin: 0; }

/* 対局画面 */
.game-wrap { display: flex; gap: 16px; align-items: flex-start; justify-content: center; }
.board-col { width: min(100%, 520px); flex: none; }
.kifu-col { width: 220px; flex: none; }
@media (max-width: 760px) {
  .game-wrap { flex-direction: column; align-items: stretch; }
  .board-col { width: 100%; max-width: 520px; margin: 0 auto; }
  .kifu-col { width: 100%; max-width: 520px; margin: 0 auto; }
  .kifu { max-height: 30vh; }
}
.player { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; font-size: 14px; }
.player .mark { display: inline-block; width: 14px; height: 16px; margin-right: 4px; vertical-align: -2px;
  clip-path: polygon(50% 0, 86% 16%, 100% 100%, 0 100%, 14% 16%); border: 1px solid var(--text); }
.player .mark.black { background: var(--text); }
.player .mark.white { background: transparent; box-shadow: inset 0 0 0 2px var(--text); }
.player.turn .nm { font-weight: bold; }
.player.turn::after { content: ""; }
.clock { font-variant-numeric: tabular-nums; font-size: 18px; padding: 0 8px; border-radius: 6px; min-width: 5em; text-align: right; }
.player.turn .clock { background: var(--accent); color: var(--accent-text); }
.clock.low { background: var(--bad) !important; color: #fff !important; }

.hand { display: flex; flex-wrap: wrap; gap: 4px; min-height: 44px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin: 2px 0; }
.hand.top { justify-content: flex-end; }
.hand .hp { position: relative; width: 38px; height: 40px; padding: 0; min-height: 0; border: none; background: none; }
.hand .hp .pc { width: 34px; height: 38px; font-size: 22px; }
.hand .hp .cnt { position: absolute; right: -4px; bottom: -2px; font-size: 12px; font-weight: bold; background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 5px; line-height: 16px; }
.hand .hp.sel .pc { outline: 3px solid var(--good); }

.board-frame { background: var(--board); border-radius: 6px; padding: 4px 4px 6px; box-shadow: var(--shadow); }
.files { display: grid; grid-template-columns: repeat(9, 1fr) 18px; font-size: 12px; color: var(--board-label); text-align: center; }
.board-and-ranks { display: flex; }
.ranks { width: 18px; display: grid; grid-template-rows: repeat(9, 1fr); font-size: 12px; color: var(--board-label); align-items: center; justify-items: center; font-family: var(--mincho); }
.board-wrap { flex: 1; position: relative; }
.arrows { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); pointer-events: none; overflow: visible; }
.board { width: 100%; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); border: 2px solid var(--board-line); aspect-ratio: 9 / 9.6; }
.cell { position: relative; border: 1px solid var(--board-line); border-width: 0 1px 1px 0; display: flex; align-items: center; justify-content: center; padding: 0; min-height: 0; border-radius: 0; background: transparent; cursor: pointer; }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
.cell.last { background: var(--last); }
.cell.check { background: var(--check); }
.cell.sel { background: var(--sel); }
.cell.dest::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--dest); pointer-events: none; }
.cell.dest.cap::after { width: 86%; height: 86%; background: transparent; border: 3px solid var(--dest); }
.pc {
  width: 86%; height: 92%; display: flex; align-items: center; justify-content: center;
  background: var(--piece); color: var(--piece-text); font-family: var(--mincho); font-weight: bold;
  font-size: clamp(16px, 6vw, 30px); line-height: 1;
  clip-path: polygon(50% 0, 86% 16%, 100% 100%, 0 100%, 14% 16%);
  padding-top: 12%; pointer-events: none; user-select: none;
  filter: drop-shadow(0 1px 0 var(--piece-edge));
}
.pc.gote { transform: rotate(180deg); padding-top: 0; padding-bottom: 12%; align-items: center; }
.pc.pro { color: var(--promoted); }
.cell.moved .pc { animation: drop .18s ease-out; }
@keyframes drop { from { transform: scale(1.15); } to { transform: none; } }
.cell.moved .pc.gote { animation: dropg .18s ease-out; }
@keyframes dropg { from { transform: rotate(180deg) scale(1.15); } to { transform: rotate(180deg); } }

.status { min-height: 1.6em; text-align: center; font-size: 14px; color: var(--muted); padding: 4px 0; }
.status.thinking::after { content: "…"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.controls button { flex: 1; min-width: 0; padding: 8px 6px; }

/* 評価値 */
.evalbox { margin-bottom: 6px; }
.evalbar { position: relative; height: 14px; border-radius: 999px; overflow: hidden; background: #3b3b3b; border: 1px solid var(--line); }
.evalfill { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; background: #f3f3f3; transition: width .4s; }
.evalmid { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.evaltext { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 2px 0; font-variant-numeric: tabular-nums; }
.evaltext #evalWho { font-weight: bold; }
.evaltext .plus { color: var(--good); }
.evaltext .minus { color: var(--bad); }

/* 棋譜 */
.kifu-head { font-weight: bold; padding: 4px 0; }
.kifu { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.kifu li { padding: 3px 8px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 8px; }
.kifu li .no { color: var(--muted); width: 2.5em; text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.kifu li.cur { background: var(--last); font-weight: bold; }
.kifu li.res { color: var(--bad); }
.view-extra { margin-top: 8px; }

/* 保存した棋譜 */
.libList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.libList li { display: flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.libList li .t { flex: 1; font-size: 14px; }
.libList li .t small { display: block; color: var(--muted); }
.libList li button { min-height: 36px; padding: 4px 10px; }
.libList .empty { color: var(--muted); justify-content: center; }

/* ダイアログ */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.dialog { background: var(--bg); border-radius: 14px; padding: 16px; width: min(100%, 380px); box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.dlg-title { font-weight: bold; font-size: 18px; margin-bottom: 8px; }
.dlg-body { margin-bottom: 12px; white-space: pre-wrap; }
.dlg-btns { display: flex; flex-direction: column; gap: 8px; }
.dlg-btns.two { flex-direction: row; }
.dlg-btns.two button { flex: 1; }
.promo-choices { display: flex; gap: 12px; justify-content: center; }
.promo-choices button { width: 90px; height: 100px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.promo-choices .pc { width: 50px; height: 56px; font-size: 30px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
.toast[hidden] { display: none; }

/* ---- 盤・駒・背景の種類 ---- */
.board-frame { background-color: var(--board); background-image: repeating-linear-gradient(92deg, var(--grain) 0 2px, transparent 2px 11px), repeating-linear-gradient(88deg, transparent 0 23px, var(--grain) 23px 25px); }
:root[data-board="kaya"] { --board: #d39a45; --board-line: #4f3010; --board-label: #3b230a; --grain: rgba(90, 45, 5, .12); }
:root[data-board="green"] { --board: #86a874; --board-line: #2c4523; --board-label: #1d2e17; --grain: rgba(0, 0, 0, 0); }
:root[data-board="mono"] { --board: #fbfbfb; --board-line: #222; --board-label: #222; --grain: rgba(0, 0, 0, 0); --piece: #fff; --piece-edge: #222; --piece-text: #111; --promoted: #c00; }
:root[data-board="mono"] .pc { filter: drop-shadow(0 0 .6px #000) drop-shadow(0 0 .6px #000); }
:root[data-piece="gothic"] .pc { font-family: system-ui, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif; font-weight: 800; }
.pc.two { flex-direction: column; font-size: clamp(9px, 3.3vw, 17px); line-height: 1.02; padding-top: 18%; }
.pc.two.gote { padding-top: 0; padding-bottom: 18%; }
.hand .hp .pc.two { font-size: 12px; }
.promo-choices .pc.two { font-size: 18px; }
:root[data-bg="washi"] body { background-color: #f4ede0; background-image: radial-gradient(rgba(150, 120, 80, .08) 1px, transparent 1.4px), radial-gradient(rgba(150, 120, 80, .05) 1px, transparent 1.6px); background-size: 7px 7px, 13px 11px; }
:root[data-bg="tatami"] body { background-color: #c8cf98; background-image: repeating-linear-gradient(0deg, rgba(70, 80, 20, .10) 0 2px, transparent 2px 5px); }
:root[data-bg="tatami"] .bar { background: #c8cf98; }
:root[data-bg="night"] body { background-image: radial-gradient(ellipse at top, #2b2620, #15120f 70%); background-attachment: fixed; }
:root[data-bg="night"] .bar { background: transparent; }
:root[data-bg="plain"] { --bg: #fafafa; }
.looks { display: flex; flex-wrap: wrap; gap: 6px; }
.looks button { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.looks button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: bold; }
.look-preview { width: 220px; max-width: 100%; margin: 0 auto; }
.board.preview { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); aspect-ratio: 4 / 4.3; }
.board.preview .cell:nth-child(4n) { border-right: none; }
.board.preview .cell { border-width: 0 1px 1px 0; cursor: default; }
.board.preview .pc { font-size: 26px; }
.board.preview .pc.two { font-size: 14px; }

/* ---- 候補手 ---- */
.hint-btn.on { background: #fff3c4; border-color: #e0a800; font-weight: bold; color: #5a4200; }
.hint-list { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.hint-list .cand { display: flex; align-items: center; gap: 8px; color: var(--text); padding: 2px 0; }
.hint-list .cdot { width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: bold; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.hint-list .ctext { flex: 1; font-weight: bold; }
.hint-list .cval { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- 検討 ---- */
.badge { margin-left: auto; font-size: 11px; border-radius: 4px; padding: 0 5px; color: #fff; align-self: center; }
.badge.bad { background: var(--bad); }
.badge.dub { background: #e08a00; }
.review-box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; font-size: 14px; }
.rv-head { font-weight: bold; margin-bottom: 4px; }
.rv-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rv-progress span { flex: 1; font-size: 13px; }
.rv-progress button { min-height: 34px; padding: 4px 12px; }
.rv-bar { width: 100%; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.rv-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.rv-gwrap { margin: 4px 0 8px; }
.rv-graph { width: 100%; height: 90px; display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.rv-area { fill: rgba(30, 111, 217, .18); }
.rv-mid { stroke: var(--muted); stroke-width: .4; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.rv-line { fill: none; stroke: #1e6fd9; stroke-width: 2; }
.rv-cur { stroke: var(--bad); stroke-width: 1.5; }
.rv-glabel { font-size: 11px; color: var(--muted); }
.rv-count div { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 2px 0; }
.rv-count b { width: 100%; font-size: 13px; }
.rv-count .bad { color: var(--bad); }
.rv-count .dub { color: #c07400; }
.rv-count .best { color: var(--muted); font-size: 12px; }
.rv-sec { margin-top: 8px; }
.rv-sec p { margin: 2px 0 4px; }
.rv-jump { display: block; width: 100%; text-align: left; min-height: 34px; padding: 4px 10px; margin: 3px 0; font-size: 13px; }
.review-note { white-space: pre-wrap; margin-top: 8px; padding: 8px; border-radius: 6px; background: var(--bg); border-left: 4px solid #1e6fd9; font-size: 13px; }
.review-note.bad { border-left-color: var(--bad); }
.review-note.dub { border-left-color: #e08a00; }
.review-note:empty { display: none; }

/* ---- 戦法の学習 ---- */
.study-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.study-card { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; }
.study-card .sc-name { font-weight: bold; font-size: 17px; font-family: var(--mincho); }
.study-card .sc-tag { font-size: 12px; color: var(--accent); }
.study-card .sc-sum { font-size: 13px; color: var(--muted); }
.study-box { margin-top: 10px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.study-box .note-head { font-weight: bold; margin-bottom: 2px; }
.study-box p { margin: 2px 0; }
.study-box ul { margin: 4px 0; padding-left: 1.3em; }

/* ---- 目隠し将棋 ---- */
.pc.blank { color: transparent; }
.move-input { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.move-input input { flex: 1; min-width: 0; font-size: 18px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.move-input button { min-width: 72px; }
.move-input .err { width: 100%; font-size: 13px; min-height: 0; }
.move-input .err:empty { display: none; }

/* ---- 戦略指定 ---- */
.senpo-info { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid #8e44ad; border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; font-size: 13px; }
.senpo-info .me { font-weight: bold; color: var(--text); }
.senpo-info .warn { color: var(--bad); margin-top: 2px; }
.sub-label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
/* ---- 暫定の棋力 ---- */
.rank-box { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; max-width: 420px; margin: 16px auto 0; padding: 10px 14px; border: 2px solid var(--accent); border-radius: 14px; }
.rank-box .rank-label { font-size: 13px; color: var(--muted); }
.rank-box .rank-main { font-family: var(--mincho); font-size: 26px; font-weight: bold; color: var(--accent); }
.rank-box .rank-sub { font-size: 12px; color: var(--muted); }
.rank-big { font-family: var(--mincho); font-size: 22px; font-weight: bold; color: var(--accent); text-align: center; }
.rank-list { list-style: none; padding: 0; margin: 8px 0 0; font-size: 14px; }
.rank-list li { padding: 3px 0; border-bottom: 1px solid var(--line); }
.study-group { font-weight: bold; color: var(--accent); margin-top: 6px; }