:root {
  --ink: #17110d;
  --night: #1b120d;
  --navy: #2b1d15;
  --gold: #d7b66a;
  --gold-dark: #84612e;
  --red: #a4372d;
  --cream: #f4ead6;
  --wood: #dfb570;
  --wood-dark: #c69a52;
  --wood-line: #4a2c12;
  --koma-face: #f6dda6;
  --sumi: #17110d;
  --sumi-soft: #251a13;
  --lacquer: #4a1713;
  --lacquer-hi: #76261f;
  --bengara: #a4372d;
  --washi: #eadcc1;
  --washi-muted: #bcae94;
  --wood-edge: #6a4525;
  --cell: clamp(30px, min(8.6vw, 7.9vh), 56px);
  --cell: round(down, clamp(30px, min(8.6vw, 7.9vh), 56px), 1px);
  --pixel: "DotGothic16", "Yu Gothic", monospace;
  --serif: "Noto Serif JP", "Yu Mincho", serif;
}

* { box-sizing: border-box; }
html, body {
  width: 100%; min-height: 100%; margin: 0; background: var(--sumi); color: var(--cream); overflow: hidden;
  text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
button { font: inherit; }
button:focus-visible { outline: 3px solid #f0c85d; outline-offset: 3px; }
.hidden { display: none !important; }

body {
  font-family: var(--pixel);
  background:
    radial-gradient(circle at 50% 32%, #3a291d 0, #1c130e 48%, #0e0a07 100%);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: 1000; pointer-events: none; opacity: .07;
  background:
    repeating-linear-gradient(0deg, transparent 0 4px, rgba(31, 18, 8, .42) 4px 5px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 7px);
  mix-blend-mode: multiply;
}

#app, .screen { width: 100%; height: 100dvh; }
.screen { display: none; position: relative; overflow: hidden; }
.screen.active { display: block; animation: screen-in .38s steps(8); }
@keyframes screen-in { from { opacity: 0; filter: brightness(2); } to { opacity: 1; filter: none; } }

/* ---------- タイトル ---------- */
#title-screen {
  background:
    linear-gradient(90deg, rgba(255,255,255,.025) 50%, transparent 50%) 0 0/8px 8px,
    radial-gradient(ellipse at 50% 21%, rgba(44,137,144,.52), transparent 36%),
    linear-gradient(#061b26 0 45%, #071116 72%);
}
.title-sky { position: absolute; inset: 0; overflow: hidden; }
.title-sky::before {
  content: ""; position: absolute; left: 50%; top: 8%; width: min(52vw, 520px); aspect-ratio: 1; transform: translateX(-50%);
  border: 3px solid rgba(241,196,95,.13); border-radius: 50%;
  box-shadow: 0 0 0 22px rgba(241,196,95,.025), 0 0 80px rgba(73,212,187,.13);
}
.title-sky::after {
  content: ""; position: absolute; left: -5%; right: -5%; bottom: 0; height: 31%;
  background:
    linear-gradient(135deg, transparent 0 46%, #0b2930 47% 54%, transparent 55%) 0 0/160px 110px,
    linear-gradient(45deg, transparent 0 46%, #0a242a 47% 54%, transparent 55%) 40px 0/180px 115px,
    linear-gradient(#0b252c, #02090c);
  border-top: 3px solid #1b4f50;
}
.title-sky i { position: absolute; width: 5px; height: 5px; background: #d6e6c3; box-shadow: 0 0 7px #fff; animation: star 2.4s steps(2) infinite; }
.title-sky i:nth-child(1) { top: 15%; left: 15%; }
.title-sky i:nth-child(2) { top: 26%; right: 19%; animation-delay: .6s; }
.title-sky i:nth-child(3) { top: 48%; left: 11%; animation-delay: 1.2s; }
.title-sky i:nth-child(4) { top: 10%; right: 10%; animation-delay: 1.8s; }
@keyframes star { 50% { opacity: .2; transform: scale(.6); } }

.title-frame {
  position: relative; z-index: 2; width: min(700px, calc(100% - 28px)); min-height: 100%; margin: 0 auto;
  padding: clamp(12px, 2vh, 24px) 0 44px; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.series-label { margin: 0 0 3px; color: #7eaaa8; font-size: 11px; letter-spacing: .4em; }
.title-emblem {
  position: absolute; top: max(22px, 5vh); left: 8%; width: 58px; height: 58px; padding: 5px; transform: rotate(-8deg);
  border: 2px solid #d69b50; color: #d69b50; opacity: .76;
}
.title-emblem::before { content: ""; position: absolute; inset: 4px; border: 1px solid #d69b50; }
.title-emblem span { position: relative; display: grid; height: 100%; place-items: center; font: 900 31px var(--serif); }
h1 { position: relative; margin: 0 0 1px; height: clamp(92px, 17vh, 145px); width: 100%; text-align: center; line-height: .88; }
h1 small { display: block; margin-bottom: 2px; color: #bcd5cf; font: 11px var(--pixel); letter-spacing: .8em; text-indent: .8em; }
h1 span {
  display: inline-block; color: #e5f1df; font: 900 clamp(44px, 8vh, 73px) var(--serif); letter-spacing: -.08em;
  text-shadow: 3px 3px 0 #133f43, 6px 6px 0 #02090c, 0 0 20px rgba(255,255,255,.15);
}
h1 strong {
  display: inline-block; margin-left: .12em; color: var(--gold); font: 900 clamp(42px, 7.5vh, 69px) var(--serif); letter-spacing: -.08em;
  text-shadow: 2px 2px 0 #9c4c2c, 5px 5px 0 #4a1e19, 7px 7px 0 #02090c;
}
.title-copy { margin: 0 0 clamp(9px, 2vh, 18px); color: #9fc5bd; font: 700 clamp(11px, 1.6vh, 14px) var(--serif); letter-spacing: .24em; }

.mode-grid { width: min(590px, 96%); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-card {
  position: relative; min-height: clamp(58px, 8.7vh, 76px); padding: 7px 34px 7px 8px; display: flex; align-items: center; gap: 10px; cursor: pointer;
  color: #e9f4e8; background: linear-gradient(180deg, #194a50, #0b2d35); border: 2px solid #3c7774; border-radius: 3px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.08), inset -3px -3px 0 rgba(0,0,0,.28), 4px 4px 0 #02090c;
  transition: transform .08s, filter .08s;
}
.mode-card:hover, .mode-card.selected { filter: brightness(1.28); transform: translate(-1px,-1px); border-color: #80c2b6; }
.mode-card:active { transform: translate(3px,3px); box-shadow: inset 2px 2px 0 rgba(0,0,0,.3); }
.mode-card.primary { background: linear-gradient(180deg, #995032, #63291f); border-color: #d69b50; }
.mode-card.gold { background: linear-gradient(180deg, #66501f, #34280f); border-color: #d5ae4f; }
.mode-card > i {
  position: absolute; right: 4px; top: 4px; bottom: 4px; width: 24px; display: grid; place-items: center;
  color: #e9ce7f; border-left: 1px solid rgba(255,255,255,.17); font-style: normal; font-size: 10px; writing-mode: vertical-rl; letter-spacing: .15em;
}
.mode-icon {
  flex: 0 0 40px; width: 40px; height: 40px; display: grid; place-items: center; color: #e8c578; background: #071a20;
  border: 1px solid #ad8650; box-shadow: inset 0 0 0 3px #102e31; font: 900 23px var(--serif);
}
.mode-body { min-width: 0; display: flex; flex-direction: column; text-align: left; }
.mode-body b { font: 700 clamp(14px, 2vh, 18px) var(--serif); letter-spacing: .08em; }
.mode-body small { color: #9fc3be; font-size: 10px; white-space: nowrap; }
.title-actions { display: flex; gap: 10px; margin-top: clamp(8px, 1.5vh, 14px); }
.subtle-btn, .hud-actions button, .back-btn {
  padding: 6px 15px; color: #a9c9c4; background: #07161c; border: 1px solid #426968; box-shadow: 2px 2px 0 #000; cursor: pointer;
}
.subtle-btn:hover, .back-btn:hover { color: #fff; border-color: var(--gold); }
.title-controls { margin: 8px 0 0; color: #607e7c; font-size: 10px; }
.title-disclaimer {
  width: min(640px, 96%); margin: clamp(6px, 1vh, 10px) 0 0; padding: 6px 10px;
  color: #698b87; background: rgba(3, 15, 19, .74); border: 1px solid #294b4b;
  box-shadow: inset 0 0 0 1px rgba(166, 141, 88, .08); font-size: clamp(7px, 1.15vh, 9px); line-height: 1.42; text-align: center;
}
.title-disclaimer b { display: block; margin-bottom: 2px; color: #a68d58; font-weight: 400; letter-spacing: .14em; }
.title-disclaimer span { display: block; }
.title-footer { position: absolute; z-index: 3; bottom: 9px; left: 16px; right: 16px; display: flex; justify-content: space-between; color: #416564; font-size: 9px; }

/* ---------- サブ画面共通ヘッダ ---------- */
.sub-header {
  position: relative; z-index: 5; height: 54px; display: grid; grid-template-columns: 130px 1fr 130px; align-items: center; gap: 8px;
  padding: 0 12px; background: linear-gradient(#17313a, #08161c); border-bottom: 3px solid #8c5b28; box-shadow: 0 3px 0 #020507;
}
.sub-header .back-btn { justify-self: start; font-size: 11px; padding: 6px 10px; }
.sub-title { text-align: center; }
.sub-title small { display: block; color: #8eaaa8; font-size: 9px; letter-spacing: .3em; }
.sub-title h2 { margin: 0; color: var(--gold); font: 900 19px var(--serif); letter-spacing: .2em; text-shadow: 2px 2px #000; }
.sub-header .sound-control, .sub-header .dojo-rank { justify-self: end; }
.dojo-rank { color: #9fc3be; font-size: 11px; }
.dojo-rank b { color: var(--gold); font-size: 15px; }

/* ---------- 相手選択 ---------- */
#select-screen, #tsume-screen, #pieces-screen { background: #04121a; }
.select-main { height: calc(100dvh - 54px); overflow: auto; padding: 14px 12px calc(20px + env(safe-area-inset-bottom)); }
.char-list { width: min(680px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.char-card {
  position: relative; display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 9px 10px; cursor: pointer;
  color: #e9f4e8; text-align: left; background: linear-gradient(180deg, #12333c, #0a2129); border: 2px solid #2e5a5c; border-radius: 3px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.06), 4px 4px 0 #02090c; transition: filter .08s, transform .08s;
}
.char-card:hover { filter: brightness(1.22); }
.char-card.selected { border-color: var(--gold); background: linear-gradient(180deg, #274b46, #0f2c2c); transform: translate(-1px,-1px); }
.char-card.selected::after { content: "挑戦"; position: absolute; right: -6px; top: -8px; padding: 2px 7px; color: #251607; background: var(--gold); border: 1px solid #fff0a1; box-shadow: 2px 2px 0 #000; font-size: 10px; }
.char-face {
  width: 56px; height: 62px; background: transparent; border: 0;
  filter: drop-shadow(2px 3px 0 rgba(0, 0, 0, .55));
}
.char-info { min-width: 0; }
.char-info .nm { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.char-info .nm b { color: #ffe9b0; font: 700 17px var(--serif); letter-spacing: .1em; }
.char-info .nm small { color: #86aaa5; font-size: 10px; }
.net-tag {
  padding: 1px 6px; color: #0d2430; background: linear-gradient(180deg, #8fd8c8, #58a795); border: 1px solid #c8f0e2;
  font-style: normal; font-size: 9px; letter-spacing: .12em; box-shadow: 1px 1px 0 #000;
}
.char-info .stars { color: var(--gold); font-size: 11px; letter-spacing: .18em; text-shadow: 1px 1px 0 #000; }
.char-info .stars i { color: #33514f; font-style: normal; }
.char-info p { margin: 3px 0 0; color: #a7c6bf; font-size: 10px; line-height: 1.5; }
.char-info .quote { color: #d8b06a; font-size: 10px; }
.char-record { align-self: start; text-align: right; color: #7fa5a0; font-size: 10px; line-height: 1.6; white-space: nowrap; }
.char-record b { color: #e9c476; }
.select-options {
  width: min(680px, 100%); margin: 12px auto 0; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.side-choice { display: flex; border: 1px solid #426968; box-shadow: 2px 2px 0 #000; }
.side-choice button { padding: 8px 13px; color: #a9c9c4; background: #07161c; border: 0; border-right: 1px solid #2b4a4a; cursor: pointer; font-size: 11px; }
.side-choice button:last-child { border-right: 0; }
.side-choice button.active { color: #251607; background: var(--gold); }
.start-btn {
  padding: 11px 30px; color: #2b1200; font: 700 15px var(--serif); letter-spacing: .2em; cursor: pointer;
  background: linear-gradient(180deg, #ffd985, #d99a3e); border: 2px solid #fff0b3; box-shadow: 3px 3px 0 #4a1e19, inset -2px -2px 0 rgba(0,0,0,.2);
}
.start-btn:hover { filter: brightness(1.1); }
.start-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 #4a1e19; }

/* ---------- 詰将棋一覧 ---------- */
.tsume-main { height: calc(100dvh - 54px); overflow: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
.tsume-note { width: min(680px, 100%); margin: 0 auto 10px; color: #7fa5a0; font-size: 10px; text-align: center; }
.tsume-grid { width: min(680px, 100%); margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.tsume-card {
  position: relative; padding: 10px 10px 9px; cursor: pointer; text-align: left; color: #e9f4e8;
  background: linear-gradient(180deg, #12333c, #0a2129); border: 2px solid #2e5a5c; border-radius: 3px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.06), 4px 4px 0 #02090c; transition: filter .08s;
}
.tsume-card:hover { filter: brightness(1.25); border-color: #80c2b6; }
.tsume-card .tno { display: flex; align-items: center; justify-content: space-between; }
.tsume-card .tno b { color: #ffe9b0; font: 700 14px var(--serif); }
.tsume-card .tmoves { padding: 1px 7px; color: #251607; background: #d5ae4f; border: 1px solid #ffe9ad; font-size: 10px; box-shadow: 1px 1px 0 #000; }
.tsume-card h3 { margin: 5px 0 2px; color: #d9ead9; font: 700 13px var(--serif); letter-spacing: .06em; }
.tsume-card .tstate { color: #6f938f; font-size: 10px; }
.tsume-card.cleared { border-color: #ad8650; background: linear-gradient(180deg, #3d3517, #201a0a); }
.tsume-card.cleared .tstate { color: var(--gold); }

/* ---------- 駒の動き ---------- */
.pieces-main { height: calc(100dvh - 54px); overflow: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
.pieces-note { width: min(760px, 100%); margin: 0 auto 10px; color: #7fa5a0; font-size: 10px; text-align: center; }
.piece-grid { width: min(760px, 100%); margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; }
.piece-card {
  padding: 9px; color: #e9f4e8; background: linear-gradient(180deg, #12333c, #0a2129); border: 2px solid #2e5a5c; border-radius: 3px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.06), 4px 4px 0 #02090c; text-align: center;
}
.piece-card h3 { margin: 0 0 2px; color: #ffe9b0; font: 700 13px var(--serif); }
.piece-card h3 small { color: #86aaa5; font-size: 9px; margin-left: 5px; }
.piece-card .diag { display: grid; grid-template-columns: repeat(5, 22px); gap: 1px; justify-content: center; margin: 6px 0; }
.diag-cell { width: 22px; height: 22px; display: grid; place-items: center; background: #c9a05b; border: 1px solid #7a5222; }
.diag-cell.me { background: #c9a05b; padding: 1px; }
.diag-cell.dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #7a3018; box-shadow: 0 0 0 1px #43180a; }
.diag-cell.ray { color: #7a3018; font-weight: 700; font-size: 13px; }
.piece-card p { margin: 2px 0 0; color: #a7c6bf; font-size: 9px; line-height: 1.5; text-align: left; }

/* ---------- 対局画面 ---------- */
#game-screen { background: #03090d; }
.game-hud {
  position: relative; z-index: 20; height: 48px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: 0 10px; background: linear-gradient(#17313a, #08161c); border-bottom: 3px solid #8c5b28; box-shadow: 0 3px 0 #020507;
}
.round-plate { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.round-plate span { color: var(--gold); font: 900 19px var(--serif); text-shadow: 2px 2px #000; }
.round-plate small { color: #8eaaa8; font-size: 10px; }
.hud-center { display: flex; align-items: center; justify-content: center; gap: 12px; min-width: 0; }
.hud-center b { color: #e9c476; font-size: 12px; white-space: nowrap; }
.hud-center span { color: #b6cfca; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-actions { display: flex; justify-content: flex-end; align-items: center; gap: 5px; }
.hud-actions span { display: flex; gap: 5px; }
.hud-actions button { padding: 5px 8px; font-size: 10px; white-space: nowrap; }
.hud-actions button.active { color: #251607; background: var(--gold); border-color: #fff0a1; box-shadow: 2px 2px 0 #5d2f1d; }
.hud-actions button:disabled { opacity: .4; cursor: default; }

.shogi-main {
  position: relative; height: calc(100dvh - 48px); display: flex; align-items: stretch; justify-content: center; gap: 12px;
  width: min(100%, 1280px); margin: 0 auto; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.board-zone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 0; }

/* 対局者バー */
.seat-bar {
  width: calc(var(--cell) * 9 + 26px); display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  background: rgba(3,18,18,.86); border: 1px solid #6c8d78; box-shadow: 2px 2px #00201c;
}
.seat-bar .face {
  flex: 0 0 30px; width: 30px; height: 33px; background: transparent; border: 0;
  filter: drop-shadow(1px 1.5px 1px rgba(0, 0, 0, .5));
}
.seat-bar .who { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.seat-bar .who b { color: #ffe9b0; font: 700 13px var(--serif); letter-spacing: .06em; }
.seat-bar .who small { color: #86aaa5; font-size: 9px; }
.seat-bar.turn-active { border-color: var(--gold); box-shadow: 0 0 10px rgba(242,196,95,.25), 2px 2px #00201c; }
.think { color: #ffe081; font-size: 10px; }
.think i { font-style: normal; animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

.hand-row { flex: 1; display: flex; flex-wrap: wrap; gap: 3px; justify-content: flex-end; min-height: 30px; align-items: center; }
.hand-piece {
  position: relative; width: 27px; height: 30px; cursor: pointer; border: 0; padding: 0; background: transparent;
  filter: drop-shadow(1px 2px 1px rgba(0, 0, 0, .5));
}
.hand-piece[data-count]::after {
  content: attr(data-count); position: absolute; right: 0; bottom: -1px; padding: 0 2px; color: #ffe9b0; background: #3a2408;
  font: 9px var(--pixel); border: 1px solid #8a5a26;
}
.hand-piece.selected { filter: drop-shadow(0 0 5px #ffd76a) drop-shadow(0 0 2px #ffe9a8); transform: translateY(-2px); }

/* 長押しドラッグ */
.board, .hand-row { touch-action: none; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 55; width: calc(var(--cell) * 1.14); height: calc(var(--cell) * 1.2);
  pointer-events: none; filter: drop-shadow(0 10px 9px rgba(0, 0, 0, .5)) drop-shadow(0 0 8px rgba(255, 215, 106, .4));
}
.drag-ghost svg { width: 100%; height: 100%; display: block; }
.cell.drop-hover { background: rgba(255, 240, 150, .5); box-shadow: inset 0 0 0 3px rgba(255, 214, 110, .95); }
.koma.drag-src, .hand-piece.drag-src { opacity: .28; }
.hand-piece.disabled { cursor: default; opacity: .8; }

/* 盤 */
.board-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.board-wrap::before {
  content: ""; position: absolute; inset: -8% -14%; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 46%, rgba(240, 190, 100, .16), transparent 62%);
}
.coords-files { display: grid; grid-template-columns: repeat(9, var(--cell)); margin-right: 16px; padding-left: clamp(6px, 1vw, 12px); box-sizing: content-box; }
.coords-files span { text-align: center; color: #86a89a; font-size: 10px; padding-bottom: 2px; }
.board-frame { position: relative; display: flex; }
.coords-ranks { display: grid; grid-template-rows: repeat(9, var(--cell)); width: 16px; }
.coords-ranks span { display: grid; place-items: center; color: #86a89a; font-size: 10px; }
.board {
  position: relative; display: grid; grid-template-columns: repeat(9, var(--cell)); grid-template-rows: repeat(9, var(--cell));
  background: #dfb46f;
  border: clamp(6px, 1vw, 12px) solid transparent;
  border-image: linear-gradient(155deg, #46280f, #2a1608 45%, #1a0d05) 1;
  box-shadow:
    inset 0 0 0 2px rgba(238, 194, 110, .55),
    inset 0 0 0 4px #190d04,
    6px 8px 0 rgba(0, 0, 0, .48),
    0 6px 40px rgba(0, 0, 0, .5),
    0 0 46px rgba(226, 176, 90, .15);
}
.board-bg { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.cell { position: relative; z-index: 1; cursor: pointer; border-right: 1px solid rgba(48, 29, 9, .8); border-bottom: 1px solid rgba(48, 29, 9, .8); }
/* 外周はSVGの枠線に任せて二重線を防ぐ (#board先頭の背景SVGを数えないよう nth-of-type) */
.cell:nth-of-type(9n) { border-right: 0; }
.cell:nth-of-type(n+73) { border-bottom: 0; }
.cell.last { background: rgba(242,196,95,.32); box-shadow: inset 0 0 0 1px rgba(255,214,199,.25); }
.cell.sel { background: rgba(255,240,150,.4); }
.cell.target::after {
  content: ""; position: absolute; z-index: 3; left: 50%; top: 50%; width: 26%; height: 26%; transform: translate(-50%,-50%);
  border-radius: 50%; background: rgba(32,84,60,.68); box-shadow: 0 0 5px rgba(20,60,40,.6);
}
.cell.target.cap-target::after {
  width: 74%; height: 74%; background: transparent; border: 3px solid rgba(182,51,50,.8); box-shadow: 0 0 6px rgba(182,51,50,.5);
}
.cell.hint-to { box-shadow: inset 0 0 0 3px rgba(255,214,110,.9); animation: hintPulse 1s steps(2) infinite; }
.cell.hint-from { box-shadow: inset 0 0 0 3px rgba(255,214,110,.5); }
@keyframes hintPulse { 50% { box-shadow: inset 0 0 0 3px rgba(255,214,110,.35); } }
.cell.check-cell { animation: checkPulse .5s steps(2) infinite; }
@keyframes checkPulse { 0%,100% { background: rgba(182,51,50,.42); } 50% { background: rgba(182,51,50,.16); } }

/* 駒 */
.koma {
  position: absolute; z-index: 2; left: 4%; top: 2.5%; width: 92%; height: 95%;
  filter: drop-shadow(1px 2.5px 1.5px rgba(30, 13, 2, .52));
  transition: transform .07s;
}
.koma svg, .hand-piece svg, .promo-koma svg, .char-face svg, .seat-bar .face svg, .diag-cell.me svg { width: 100%; height: 100%; display: block; }
.koma-svg text { font-family: var(--serif); font-weight: 900; text-anchor: middle; user-select: none; pointer-events: none; }
.koma.gote { transform: rotate(180deg); }
.koma.danger::before {
  content: "!"; position: absolute; z-index: 4; right: 6%; top: 2%; color: #ffdada; background: var(--red); border: 1px solid #ffb0a0;
  width: 32%; height: 32%; display: grid; place-items: center; font: 900 calc(var(--cell)*.24) var(--pixel); border-radius: 50%;
}
.koma.gote.danger::before { transform: rotate(180deg); }
.cell.sel .koma { filter: drop-shadow(0 0 7px #ffd76a); }
@keyframes komaDrop { from { transform: translateY(-14%) scale(1.12); } to { transform: none; } }
@keyframes komaDropG { from { transform: rotate(180deg) translateY(-14%) scale(1.12); } to { transform: rotate(180deg); } }
.koma.placed { animation: komaDrop .14s steps(3); }
.koma.gote.placed { animation: komaDropG .14s steps(3); }

/* 盤上フラッシュ演出 */
.board-flash {
  position: absolute; z-index: 30; left: 50%; top: 42%; transform: translate(-50%,-50%); pointer-events: none;
  color: #ffe9b0; font: 900 clamp(30px, 6.4vh, 52px) var(--serif); letter-spacing: .14em; white-space: nowrap;
  text-shadow: 0 0 14px rgba(255,120,60,.7), 3px 3px 0 #4a1e19, 5px 5px 0 #02090c;
  animation: flashPop .9s steps(6) forwards;
}
.board-flash.red { color: #ff9d8a; }
@keyframes flashPop { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.5); } 18% { opacity: 1; transform: translate(-50%,-50%) scale(1.12); } 30% { transform: translate(-50%,-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* サイドパネル */
.side-zone { width: 236px; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.guide-panel, .tsume-panel {
  padding: 9px 10px; color: #d9ead9; background: rgba(4,26,24,.92); border: 1px solid #3f7a68; box-shadow: 3px 3px 0 #001410;
}
.guide-panel b, .tsume-panel b, .kifu-panel b { display: block; margin-bottom: 4px; color: var(--gold); font: 700 12px var(--serif); letter-spacing: .18em; }
.guide-panel p, .tsume-panel p { margin: 0; font-size: 10px; line-height: 1.65; }
.guide-panel .gm-move { color: #ffe081; }
.kifu-panel {
  flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 9px 10px 6px;
  color: #cfe2da; background: rgba(3,16,20,.9); border: 1px solid #35555c; box-shadow: 3px 3px 0 #010a0d;
}
.kifu-panel ol { flex: 1; margin: 0; padding: 0 0 0 2px; list-style: none; overflow-y: auto; font-size: 10px; line-height: 1.75; }
.kifu-panel li { display: flex; gap: 6px; }
.kifu-panel li i { flex: 0 0 26px; color: #6f938f; font-style: normal; text-align: right; }
.kifu-panel li.now { color: #ffe081; }

/* 結果オーバーレイ */
.overlay {
  position: absolute; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(2, 8, 10, .78); animation: fadeIn .25s steps(5);
}
@keyframes fadeIn { from { opacity: 0; } }
.result-card {
  width: min(430px, 92%); padding: 22px 20px 18px; text-align: center;
  background: linear-gradient(180deg, #14343d, #081920); border: 2px solid #8c5b28;
  box-shadow: inset 0 0 0 3px #051013, 6px 6px 0 #02090c;
}
.result-card h2 { margin: 0 0 2px; font: 900 clamp(34px, 7vh, 52px) var(--serif); letter-spacing: .18em; color: var(--gold); text-shadow: 2px 2px 0 #7c3c1c, 4px 4px 0 #2c1208; }
.result-card h2.lose { color: #9db4c8; text-shadow: 2px 2px 0 #23405c, 4px 4px 0 #0a1622; }
.result-card h2.draw { color: #a9c9b4; text-shadow: 2px 2px 0 #2c5544, 4px 4px 0 #0c221a; }
.result-card .reason { margin: 0 0 8px; color: #b6cfca; font-size: 12px; letter-spacing: .1em; }
.result-card .oppline { margin: 0 auto 12px; padding: 7px 9px; width: fit-content; max-width: 100%; color: #ffe9b0; background: rgba(0,0,0,.35); border: 1px solid #4a6c62; font-size: 11px; }
.result-card .lesson { margin: -4px auto 12px; color: #9fc3be; font-size: 10px; line-height: 1.6; }
.result-card .btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.result-card .btns button {
  padding: 9px 16px; cursor: pointer; color: #e9f4e8; background: linear-gradient(180deg, #194a50, #0b2d35);
  border: 2px solid #3c7774; box-shadow: 3px 3px 0 #02090c; font-size: 12px;
}
.result-card .btns button.primary { color: #2b1200; background: linear-gradient(180deg, #ffd985, #d99a3e); border-color: #fff0b3; font-weight: 700; }
.result-card .btns button:hover { filter: brightness(1.18); }

/* ---------- モーダル ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(1, 6, 8, .8); }
.modal-card {
  position: relative; width: min(560px, calc(100% - 30px)); max-height: 84dvh; overflow: auto; padding: 20px 22px;
  background: linear-gradient(180deg, #10303a, #081820); border: 2px solid #8c5b28; box-shadow: inset 0 0 0 3px #051013, 6px 6px 0 #02090c;
}
.modal-close {
  position: sticky; top: 0; float: right; margin: -8px -8px 0 8px; width: 30px; height: 30px; cursor: pointer;
  color: #ffd9a0; background: #34180f; border: 1px solid #8c5b28; font-size: 15px;
}
.modal-card h2 { margin: 0 0 10px; color: var(--gold); font: 900 19px var(--serif); letter-spacing: .12em; }
.modal-card h3 { margin: 14px 0 4px; color: #ffe9b0; font: 700 13px var(--serif); }
.modal-card p, .modal-card li { color: #c9ddd5; font-size: 11px; line-height: 1.75; }
.modal-card p { margin: 4px 0; }
.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 8px 0; }
.rules-grid div { padding: 7px 9px; background: rgba(0,0,0,.28); border: 1px solid #2e5a5c; }
.rules-grid b { color: #ffe9b0; font-size: 11px; }
.rules-grid p { margin: 3px 0 0; font-size: 10px; }
.kifu-modal-list { columns: 2; column-gap: 18px; margin: 6px 0 0; padding: 0; list-style: none; font-size: 11px; line-height: 1.8; }
.kifu-modal-list li i { color: #6f938f; font-style: normal; margin-right: 6px; }

/* 成り選択 */
.promo-choice { display: flex; gap: 14px; justify-content: center; margin-top: 12px; }
.promo-choice button {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 18px 10px; cursor: pointer;
  color: #cfe2da; background: rgba(0,0,0,.3); border: 2px solid #3c7774; box-shadow: 3px 3px 0 #02090c; font-size: 12px;
}
.promo-choice button:hover { border-color: var(--gold); filter: brightness(1.2); }
.promo-koma { width: 54px; height: 60px; filter: drop-shadow(1px 2px 1px rgba(0, 0, 0, .5)); }

/* ---------- 和の将棋意匠 ---------- */
#title-screen {
  background:
    linear-gradient(90deg, rgba(255,255,255,.018) 50%, transparent 50%) 0 0/6px 6px,
    radial-gradient(ellipse at 50% 18%, rgba(191, 137, 66, .18), transparent 38%),
    linear-gradient(180deg, #24170f 0 48%, #130d09 76%, #0c0806 100%);
}
.title-sky::before {
  top: 3%; width: min(56vw, 560px);
  background:
    radial-gradient(circle at 43% 37%, rgba(255,255,255,.38) 0 1px, transparent 2px),
    repeating-linear-gradient(7deg, rgba(99,66,37,.06) 0 1px, transparent 1px 7px),
    radial-gradient(circle, #ead7ad 0 57%, #c7a061 70%, rgba(158,108,49,.12) 71%);
  border: 1px solid rgba(231, 199, 125, .36);
  box-shadow: 0 0 0 18px rgba(194, 145, 76, .035), 0 0 78px rgba(177, 110, 43, .18);
  opacity: .24;
}
.title-sky::after {
  left: 0; right: 0; bottom: 0; height: 34%;
  background:
    linear-gradient(90deg, transparent 47%, rgba(196,151,89,.12) 48% 52%, transparent 53%) 0 0/112px 100%,
    linear-gradient(0deg, transparent 47%, rgba(196,151,89,.1) 48% 52%, transparent 53%) 0 0/100% 62px,
    linear-gradient(180deg, rgba(58,35,22,.48), #0d0907 76%);
  border-top: 1px solid rgba(199, 160, 91, .42);
  box-shadow: inset 0 3px 0 rgba(74, 23, 19, .5);
}
.title-sky i {
  width: 7px; height: 7px; background: #b44735; border: 1px solid #d89d5b; border-radius: 0;
  box-shadow: 0 0 0 2px rgba(92,35,24,.4); transform: rotate(45deg); animation: star 3.2s steps(2) infinite;
}
.title-sky i:nth-child(even) { background: #c9a455; border-color: #efd48b; }
@keyframes star { 50% { opacity: .28; transform: rotate(45deg) scale(.7); } }

.series-label {
  color: #bca676; font-family: var(--serif); font-size: 10px; letter-spacing: .62em; text-indent: .62em;
}
.title-emblem { border-color: #a93b2f; color: #b54738; opacity: .88; }
.title-emblem::before { border-color: #a93b2f; }
h1 small { color: #a99572; }
h1 span {
  color: #f0e5cf;
  text-shadow: 2px 2px 0 #5b3c24, 5px 5px 0 #17100b, 0 0 24px rgba(242,222,181,.16);
}
h1 strong {
  color: #d4ae5c;
  text-shadow: 2px 2px 0 #a43a2e, 5px 5px 0 #4b1713, 7px 7px 0 #100b08;
}
.title-copy { color: #c8b797; }

.mode-card {
  color: #2a1b12;
  background:
    repeating-linear-gradient(6deg, rgba(85,54,29,.045) 0 1px, transparent 1px 7px),
    linear-gradient(145deg, #f0e3c9, #d4bd98);
  border-color: #755033; border-radius: 1px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.35), inset -3px -3px 0 rgba(76,42,20,.14), 4px 4px 0 #0d0806;
}
.mode-card:hover, .mode-card.selected { filter: brightness(1.1); border-color: #b13c2f; }
.mode-card.primary {
  color: #f3e7d0; background: linear-gradient(145deg, #7c2922, #4d1714); border-color: #bf8b51;
}
.mode-card.gold {
  color: #f5e8ca; background: linear-gradient(145deg, #6f5227, #3e2b17); border-color: #c7a35b;
}
.mode-card > i { color: #7e2b24; border-left-color: rgba(80,45,25,.2); font-family: var(--serif); }
.mode-card.primary > i, .mode-card.gold > i { color: #e0c27d; border-left-color: rgba(255,255,255,.14); }
.mode-icon {
  flex-basis: 40px; color: #2b170b; background: linear-gradient(155deg, #f0d89f, #c99d5d);
  border: 0; clip-path: polygon(50% 0, 88% 13%, 100% 100%, 0 100%, 12% 13%);
  box-shadow: inset 0 0 0 3px rgba(102,62,27,.32); padding-top: 3px;
}
.mode-body small { color: #64503c; }
.mode-card.primary .mode-body small, .mode-card.gold .mode-body small { color: #cbbd9f; }
.subtle-btn, .hud-actions button, .back-btn {
  color: #cfbea0; background: linear-gradient(180deg, #2d2018, #1a120d); border-color: #705136; box-shadow: 2px 2px 0 #0b0705;
}
.subtle-btn:hover, .back-btn:hover { color: #f7ecd9; border-color: #c6a35c; background: #3b271a; }
.title-controls { color: #8f806a; }
.title-disclaimer {
  color: #958772; background: rgba(21, 14, 10, .78); border-color: #4c3828;
  box-shadow: inset 0 0 0 1px rgba(211, 174, 100, .06);
}
.title-disclaimer b { color: #b79a62; }
.title-footer { color: #786650; }

.sub-header, .game-hud {
  background:
    linear-gradient(90deg, rgba(255,255,255,.025), transparent 28%, rgba(255,255,255,.018) 72%, transparent),
    linear-gradient(#3b2519, #1b120d);
  border-bottom-color: #9b6e35; box-shadow: 0 3px 0 #0d0805, inset 0 -1px 0 #4f1915;
}
.sub-title small, .round-plate small { color: #a39277; }
.sub-title h2, .round-plate span { color: #d8b96f; text-shadow: 2px 2px #160d08; }
.dojo-rank { color: #bba98b; }

#select-screen, #tsume-screen, #pieces-screen, #game-screen {
  background:
    linear-gradient(90deg, rgba(206,171,105,.035) 1px, transparent 1px) 0 0/72px 100%,
    linear-gradient(0deg, rgba(206,171,105,.03) 1px, transparent 1px) 0 0/100% 54px,
    radial-gradient(circle at 50% 32%, #302116, #130d09 72%);
}
.char-card, .tsume-card, .piece-card {
  color: #eee1ca;
  background:
    repeating-linear-gradient(7deg, rgba(213,182,119,.025) 0 1px, transparent 1px 8px),
    linear-gradient(145deg, #38271d, #211710);
  border-color: #684b34; border-radius: 1px;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.035), 4px 4px 0 #0d0806;
}
.char-card:hover, .tsume-card:hover { filter: brightness(1.14); border-color: #a67a43; }
.char-card.selected {
  border-color: #d0aa5b; background: linear-gradient(145deg, #5b241d, #321512);
}
.char-card.selected::after {
  color: #f4e8d2; background: #9e342a; border-color: #d3a55d; box-shadow: 2px 2px 0 #130b08;
}
.char-info .nm b, .piece-card h3, .tsume-card .tno b { color: #efd8ab; }
.char-info .nm small, .piece-card h3 small { color: #9d8c73; }
.char-info .stars { color: #d3af62; }
.char-info .stars i { color: #594737; }
.char-info p, .piece-card p { color: #c5b69e; }
.char-info .quote { color: #d6a968; }
.char-record, .tsume-note, .pieces-note { color: #9f917c; }
.char-record b { color: #ddbd76; }
.side-choice { border-color: #755437; box-shadow: 2px 2px 0 #0d0806; }
.side-choice button { color: #bfaf94; background: #211711; border-right-color: #553b27; }
.side-choice button.active { color: #28180d; background: #d1ad62; }
.start-btn {
  color: #f7ead3; background: linear-gradient(180deg, #a94437, #72251f); border-color: #d4a55b;
  box-shadow: 3px 3px 0 #32110e, inset -2px -2px 0 rgba(0,0,0,.2);
}
.start-btn:active { box-shadow: 1px 1px 0 #32110e; }
.tsume-card h3 { color: #d7c8ad; }
.tsume-card .tmoves { color: #2d1b0d; background: #caa65d; border-color: #e6c982; }
.tsume-card .tstate { color: #8f816e; }
.tsume-card.cleared { border-color: #a67b41; background: linear-gradient(145deg, #4d3b20, #2b2112); }
.diag-cell { background: #d2aa69; border-color: #74491f; }
.diag-cell.me { background: #d2aa69; }
.diag-cell.dot::after { background: #8f2f26; box-shadow: 0 0 0 1px #4d1712; }
.diag-cell.ray { color: #8f2f26; }

.hud-center b { color: #ddbd77; }
.hud-center span { color: #c7b79c; }
.hud-actions button.active { color: #28170c; background: #d3ae62; border-color: #ead08f; box-shadow: 2px 2px 0 #3e160f; }
.seat-bar {
  background: rgba(29, 19, 13, .92); border-color: #765838; box-shadow: 2px 2px #0b0705;
}
.seat-bar .who b { color: #efd9ad; }
.seat-bar .who small { color: #99886f; }
.seat-bar.turn-active { border-color: #d2ad63; box-shadow: 0 0 10px rgba(210,173,99,.22), 2px 2px #0b0705; }
.think { color: #e0bd70; }
.coords-files span, .coords-ranks span { color: #aa936d; }
.cell.last { background: rgba(168,55,45,.22); box-shadow: inset 0 0 0 1px rgba(255,224,175,.22); }
.cell.sel { background: rgba(255,228,139,.38); }
.cell.target::after { background: rgba(99,58,31,.72); box-shadow: 0 0 5px rgba(59,31,15,.65); }
.cell.target.cap-target::after { border-color: rgba(164,55,45,.85); box-shadow: 0 0 6px rgba(164,55,45,.52); }
.hand-piece[data-count]::after { color: #f0d9ac; background: #3c2511; border-color: #94642d; }

.guide-panel, .tsume-panel, .kifu-panel {
  color: #d7c9b0; background: rgba(31, 21, 15, .94); border-color: #715139; box-shadow: 3px 3px 0 #0b0705;
}
.guide-panel b, .tsume-panel b, .kifu-panel b { color: #d3af62; }
.guide-panel .gm-move, .kifu-panel li.now { color: #e2bd6b; }
.kifu-panel li i { color: #8f806b; }

.overlay { background: rgba(13, 8, 6, .84); }
.result-card, .modal-card {
  background:
    repeating-linear-gradient(7deg, rgba(224,193,130,.025) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, #39261a, #1b120d);
  border-color: #a5763a; box-shadow: inset 0 0 0 3px #130c08, 6px 6px 0 #0a0604;
}
.result-card h2 { color: #d8b663; text-shadow: 2px 2px 0 #8e3027, 4px 4px 0 #37110e; }
.result-card h2.lose { color: #b5aa98; text-shadow: 2px 2px 0 #59493b, 4px 4px 0 #1a120d; }
.result-card h2.draw { color: #c8b68d; text-shadow: 2px 2px 0 #69532f, 4px 4px 0 #20160d; }
.result-card .reason { color: #c4b49a; }
.result-card .oppline { color: #eed8ad; border-color: #684b33; }
.result-card .lesson { color: #ab9c84; }
.result-card .btns button {
  color: #e7dac4; background: linear-gradient(180deg, #402b1e, #241811); border-color: #745136; box-shadow: 3px 3px 0 #0c0705;
}
.result-card .btns button.primary { color: #f7ead3; background: linear-gradient(180deg, #a94437, #72251f); border-color: #d4a55b; }
.modal { background: rgba(12, 8, 6, .84); }
.modal-close { color: #f0d9ab; background: #4b1713; border-color: #a6753a; }
.modal-card h2 { color: #d8b663; }
.modal-card h3, .rules-grid b { color: #efd8ac; }
.modal-card p, .modal-card li { color: #cfc0a8; }
.rules-grid div { background: rgba(8,5,3,.26); border-color: #684a32; }
.kifu-modal-list li i { color: #8f806b; }
.promo-choice button { color: #d7c8ae; background: rgba(10,6,4,.28); border-color: #765236; box-shadow: 3px 3px 0 #0b0705; }

@media (prefers-reduced-motion: reduce) {
  .screen.active, .title-sky i, .think i, .cell.hint-to, .cell.check-cell, .koma.placed, .koma.gote.placed, .board-flash { animation: none; }
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 940px) {
  .side-zone { display: none; }
  .shogi-main { gap: 0; }
  :root { --cell: clamp(28px, min(10.2vw, 7.4vh), 52px); --cell: round(down, clamp(28px, min(10.2vw, 7.4vh), 52px), 1px); }
  .hud-center span { display: none; }
}
@media (max-width: 560px) {
  .game-hud { height: 58px; grid-template-columns: auto 1fr; }
  .round-plate small { display: none; }
  .hud-center { justify-content: flex-end; }
  .hud-center b { display: none; }
  .hud-actions { grid-column: 1 / -1; position: absolute; right: 6px; top: 30px; }
  .hud-actions button { padding: 4px 6px; font-size: 9px; }
  .game-hud { display: block; padding-top: 5px; }
  .round-plate { position: absolute; left: 10px; top: 7px; }
  :root { --cell: clamp(26px, min(10.4vw, 6.9vh), 46px); --cell: round(down, clamp(26px, min(10.4vw, 6.9vh), 46px), 1px); }
  .seat-bar { width: calc(var(--cell) * 9 + 18px); }
  .mode-grid { grid-template-columns: 1fr; }
  .title-emblem { display: none; }
  .sub-header { grid-template-columns: auto 1fr auto; }
  .rules-grid, .kifu-modal-list { columns: auto; grid-template-columns: 1fr; }
}
