/* 一手詰将棋 早押しバトル ── 漆の黒・榧の盤・朱と藍 */
:root {
  --cell: 36px;
  --sumi: #14100c;
  --sumi2: #1f1812;
  --sumi3: #2a2119;
  --washi: #f2e8d2;
  --washi-dim: #bfb29a;
  --gold: #c9a25a;
  --gold-2: #e5c88a;
  --shu: #c8452c;
  --shu-soft: rgba(200, 69, 44, .34);
  --ai: #4b7fb3;
  --ai-soft: rgba(75, 127, 179, .36);
  --ink: #1b120a;
  --line: rgba(52, 30, 10, .78);
  --mincho: 'Shippori Mincho B1', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --gothic: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 80% at 50% 0%, #2a1e14 0%, transparent 60%),
    radial-gradient(90% 60% at 50% 100%, #1d140d 0%, transparent 70%),
    var(--sumi);
  color: var(--washi);
  font-family: var(--gothic);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
body.menu-open { overflow: auto; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* ================= メニュー ================= */
.menu { min-height: 100dvh; display: flex; justify-content: center; padding: max(24px, env(safe-area-inset-top)) 16px 32px; }
.menu-inner { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 26px; }
.title { display: flex; align-items: center; gap: 18px; padding-top: 4vh; }
.title-koma {
  flex: none; width: 74px; height: 84px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .5));
}
.title-koma span {
  display: flex; align-items: flex-end; justify-content: center; width: 100%; height: 100%;
  clip-path: polygon(50% 0, 82% 13%, 96% 100%, 4% 100%, 18% 13%);
  background: linear-gradient(170deg, #f7e4b3, #e2bc77 60%, #cf9f55);
  font-family: var(--mincho); font-weight: 800; font-size: 44px; color: #a8190f; padding-bottom: 8px;
}
.title h1 { margin: 0; display: flex; flex-direction: column; font-family: var(--mincho); font-weight: 800; line-height: 1.05; }
.t-small { font-size: 18px; letter-spacing: .5em; color: var(--gold); font-weight: 600; }
.t-big { font-size: clamp(36px, 10vw, 52px); letter-spacing: .04em; }

.rules { list-style: none; margin: 0; padding: 0; counter-reset: r; border-top: 1px solid rgba(201, 162, 90, .35); }
.rules li {
  counter-increment: r; position: relative; padding: 13px 0 13px 46px; font-size: 14px; line-height: 1.6;
  color: var(--washi-dim); border-bottom: 1px solid rgba(201, 162, 90, .18);
}
.rules li::before {
  content: counter(r, cjk-ideographic); position: absolute; left: 4px; top: 11px;
  font-family: var(--mincho); font-weight: 800; font-size: 22px; color: var(--gold);
}
.rules b { display: block; color: var(--washi); font-size: 16px; font-weight: 700; }

.choose { display: flex; flex-direction: column; gap: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 14px 16px; border-radius: 10px; border: 1px solid rgba(242, 232, 210, .16); background: var(--sumi2);
  transition: border-color .15s, background .15s;
}
.seg-btn b { font-size: 17px; }
.seg-btn small { font-size: 12px; color: var(--washi-dim); }
.seg-btn.on { border-color: var(--gold); background: linear-gradient(180deg, #33261a, #241a12); box-shadow: inset 0 0 0 1px var(--gold); }
.points { display: flex; align-items: center; gap: 8px; transition: opacity .2s; }
.points.dim { opacity: .3; pointer-events: none; }
.points-label { font-size: 14px; color: var(--washi-dim); margin-right: 4px; }
.pt { flex: 1; height: 48px; border-radius: 10px; border: 1px solid rgba(242, 232, 210, .16); background: var(--sumi2); font-size: 17px; font-weight: 700; }
.pt.on { background: var(--washi); color: var(--ink); border-color: var(--washi); }
.start {
  height: 60px; border: 0; border-radius: 12px; font-size: 20px; font-weight: 900; letter-spacing: .2em;
  background: linear-gradient(180deg, #d4553a, #b13a22); color: #fff4e6;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 8px 20px rgba(160, 40, 20, .35);
  transition: transform .08s;
}
.start:active { transform: translateY(1px) scale(.99); }
.mute-link { align-self: center; background: none; border: 0; color: var(--washi-dim); font-size: 13px; padding: 6px 10px; text-decoration: underline; text-underline-offset: 3px; }
.foot { margin: 0; text-align: center; font-size: 12px; color: rgba(191, 178, 154, .6); }

/* ================= 対局画面 ================= */
.game {
  position: fixed; inset: 0; display: grid;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.game.duo { grid-template-columns: 1fr auto 1fr; grid-template-areas: "p0 strip p1"; }
body.portrait .game.duo { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; grid-template-areas: "p1" "strip" "p0"; }
body.portrait .game.duo .panel[data-p="1"] { transform: rotate(180deg); }
.game.solo { grid-template-rows: auto 1fr; grid-template-areas: "strip" "p0"; }

/* 中央の帯 */
.strip {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 12px; min-width: 120px;
  border-left: 1px solid rgba(201, 162, 90, .2); border-right: 1px solid rgba(201, 162, 90, .2);
}
body.portrait .strip, .game.solo .strip {
  flex-direction: row; min-width: 0; height: 44px; padding: 0 10px; gap: 10px;
  border: 0; border-top: 1px solid rgba(201, 162, 90, .22); border-bottom: 1px solid rgba(201, 162, 90, .22);
  background: rgba(0, 0, 0, .25);
}
.game.solo .strip { border-top: 0; }
.st-q { font-family: var(--mincho); font-weight: 600; font-size: 14px; color: var(--gold); white-space: nowrap; }
.st-q b { font-size: 22px; margin: 0 2px; color: var(--washi); }
.st-timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 22px; letter-spacing: .02em; min-width: 3.6em; text-align: center; }
body.portrait .st-timer, .game.solo .st-timer { font-size: 18px; flex: 1; }
.st-btn { height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(242, 232, 210, .2); background: transparent; font-size: 13px; white-space: nowrap; }
.st-btn.off { color: var(--washi-dim); border-style: dashed; }

/* プレイヤー */
.panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px; min-width: 0; min-height: 0; --me: var(--shu); --me-soft: var(--shu-soft); }
.panel.ai { --me: var(--ai); --me-soft: var(--ai-soft); }
.panel.solo-panel { --me: var(--gold); --me-soft: rgba(201, 162, 90, .4); }
.phead { width: calc(var(--cell) * 9.55 + 10px); display: flex; align-items: center; gap: 10px; min-height: 36px; }
body.portrait .duo .phead { width: calc(var(--cell) * 10.9 + 10px); }
.pname { display: flex; align-items: center; gap: 7px; font-family: var(--mincho); font-weight: 800; font-size: 20px; white-space: nowrap; }
.pdot { width: 12px; height: 12px; border-radius: 50%; background: var(--me); box-shadow: 0 0 0 3px rgba(0, 0, 0, .35); }
.pips { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.pips i { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--me); }
.pips i.on { background: var(--me); }
.pscore { font-size: 26px; font-variant-numeric: tabular-nums; color: var(--washi); min-width: 1.2em; text-align: right; }
.stats { flex: 1; display: flex; gap: 14px; font-size: 12px; color: var(--washi-dim); }
.stats b { display: inline-block; margin-left: 4px; font-size: 18px; color: var(--washi); font-variant-numeric: tabular-nums; }
.giveup { height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid rgba(242, 232, 210, .22); background: rgba(0, 0, 0, .2); font-size: 14px; font-weight: 700; white-space: nowrap; }
.giveup.on { background: var(--me); border-color: var(--me); color: #fff; }
.giveup-note { margin: 0; font-size: 11px; color: rgba(191, 178, 154, .55); }
body.portrait .giveup-note { display: none; }

.pbody { display: flex; flex-direction: column; align-items: center; gap: 6px; }
body.portrait .duo .pbody { flex-direction: row; align-items: flex-end; }

/* 盤 */
.stage { position: relative; display: flex; flex-direction: column; align-items: center; border-radius: 6px; }
.goteinfo { align-self: flex-start; font-size: 11px; color: rgba(191, 178, 154, .7); padding: 0 0 3px 4px; height: 17px; }
.frame {
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto;
  padding: 3px 3px 5px 6px; border-radius: 5px;
  background:
    repeating-linear-gradient(90deg, rgba(90, 50, 15, .08) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, #c08640, #a86f30);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5), 0 1px 0 rgba(255, 230, 180, .35) inset;
}
.files { grid-column: 1; grid-row: 1; display: grid; grid-template-columns: repeat(9, var(--cell)); padding: 0 2px; }
.ranks { grid-column: 2; grid-row: 2; display: grid; grid-template-rows: repeat(9, var(--cell)); padding: 2px 0; width: calc(var(--cell) * .5); }
.files span, .ranks span { display: flex; align-items: center; justify-content: center; font-family: var(--mincho); font-weight: 600; color: rgba(40, 20, 4, .8); font-size: calc(var(--cell) * .3); }
.files span { height: calc(var(--cell) * .42); }
.board {
  grid-column: 1; grid-row: 2; position: relative;
  display: grid; grid-template-columns: repeat(9, var(--cell)); grid-template-rows: repeat(9, var(--cell));
  border: 2px solid #2c1a0b;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.32' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.26 0 0 0 0 0.07 0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(160deg, #eccb86 0%, #e2b56b 45%, #d9a85b 100%);
  background-size: 300px 300px, 100% 100%;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.sq:nth-child(9n) { border-right: 0; }
.sq:nth-child(n+73) { border-bottom: 0; }
.star { position: absolute; width: calc(var(--cell) * .14); height: calc(var(--cell) * .14); border-radius: 50%; background: #2c1a0b; transform: translate(-50%, -50%); pointer-events: none; z-index: 1; }
.s1 { left: calc(var(--cell) * 3); top: calc(var(--cell) * 3); }
.s2 { left: calc(var(--cell) * 6); top: calc(var(--cell) * 3); }
.s3 { left: calc(var(--cell) * 3); top: calc(var(--cell) * 6); }
.s4 { left: calc(var(--cell) * 6); top: calc(var(--cell) * 6); }

.sq.sel { background: var(--me-soft); }
.sq.last { background: rgba(255, 206, 84, .62); }
.sq.last-from { background: rgba(255, 206, 84, .25); }
.sq.miss { background: rgba(170, 24, 12, .5); }
.sq.target { background: var(--me-soft); }
.sq.dot::after { content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(48, 22, 4, .55); z-index: 2; }
.sq.cap::after { content: ''; position: absolute; inset: 7%; border-radius: 50%; border: 3px solid var(--me); z-index: 2; }

/* 駒（五角形） */
.pcw { width: 86%; height: 93%; display: flex; filter: drop-shadow(0 1.5px 1.2px rgba(40, 18, 0, .55)); }
.pcw.king { width: 92%; height: 99%; }
.pcw.g { transform: rotate(180deg); }
.pc {
  width: 100%; height: 100%; display: flex; align-items: flex-end; justify-content: center;
  clip-path: polygon(50% 0, 82% 13%, 96% 100%, 4% 100%, 18% 13%);
  background: linear-gradient(172deg, #f8e6b6 0%, #ecd090 45%, #dcb26a 100%);
}
.pc span { font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * .58); line-height: 1; margin-bottom: 9%; color: var(--ink); }
.king .pc span { font-size: calc(var(--cell) * .62); }
.pc.pr span { color: #a8190f; }

/* 持駒 */
.hand {
  display: flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 8px;
  width: calc(var(--cell) * 9.55 + 10px); min-height: calc(var(--cell) * 1.25 + 8px);
  background: rgba(0, 0, 0, .22); border: 1px solid rgba(201, 162, 90, .16);
}
.hand-label { font-size: 11px; color: var(--washi-dim); writing-mode: vertical-rl; letter-spacing: .2em; margin-right: 4px; }
.hand-pieces { display: flex; gap: 6px; flex-wrap: wrap; }
.hp { position: relative; width: calc(var(--cell) * 1.12); height: calc(var(--cell) * 1.18); display: flex; align-items: center; justify-content: center; border-radius: 6px; }
.hp .pcw { width: 84%; height: 92%; }
.hp.sel { background: var(--me-soft); box-shadow: 0 0 0 2px var(--me) inset; }
.hp .cnt { position: absolute; right: -2px; bottom: -2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--washi); color: var(--ink); font-style: normal; font-size: 12px; font-weight: 900; display: flex; align-items: center; justify-content: center; }
body.portrait .duo .hand { flex-direction: column; width: calc(var(--cell) * 1.35); min-height: calc(var(--cell) * 9.5); padding: 8px 2px; justify-content: flex-start; }
body.portrait .duo .hand-pieces { flex-direction: column; flex-wrap: nowrap; }
body.portrait .duo .hand-label { writing-mode: horizontal-tb; margin: 0 0 4px; letter-spacing: .1em; }

/* 幕（カウントダウン）：盤と持駒は空。数字・第N問・スコアだけ */
.cover {
  position: absolute; inset: -4px; z-index: 10; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 45%, rgba(201, 162, 90, .14), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .02) 0 2px, transparent 2px 10px),
    var(--sumi2);
  border: 1px solid rgba(201, 162, 90, .35);
}
.panel.covered .cover { display: flex; }
.cd-q { font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * .62); letter-spacing: .2em; color: var(--gold); }
.cd-num { font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * 3.6); line-height: 1.05; color: var(--washi); min-height: 1.05em; font-variant-numeric: tabular-nums; }
.cd-num.pop { animation: pop .8s cubic-bezier(.2, .9, .3, 1); }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 85% { opacity: 1; } 100% { opacity: .2; transform: scale(.94); } }
.cd-score { display: flex; gap: 12px; align-items: center; font-weight: 900; font-size: calc(var(--cell) * .52); font-variant-numeric: tabular-nums; }
.cd-score i { font-style: normal; color: var(--washi-dim); }
.shu-t { color: #e36a50; }
.ai-t { color: #7fa9d6; }

.gofx { position: absolute; left: 50%; top: 50%; z-index: 9; pointer-events: none; opacity: 0; font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * 2.6); color: #fff7e8; text-shadow: 0 4px 18px rgba(160, 40, 20, .8), 0 0 2px #000; transform: translate(-50%, -50%); }
.gofx.play { animation: gofx .45s ease-out forwards; }
@keyframes gofx { 0% { opacity: .85; transform: translate(-50%, -50%) scale(.7); } 50% { opacity: .5; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.35); } }

/* お手つき */
.lock { position: absolute; inset: 0; z-index: 8; display: none; align-items: center; justify-content: center; background: rgba(25, 10, 4, .42); border-radius: 6px; overflow: hidden; }
.panel.locked .lock { display: flex; }
.panel.locked .frame { animation: shake .32s; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.stamp {
  font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * .95); color: #f04a2c; letter-spacing: .12em;
  border: 4px solid #f04a2c; border-radius: 10px; padding: .1em .45em; transform: rotate(-8deg);
  background: rgba(255, 246, 230, .92); box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.lock .bar { position: absolute; left: 0; bottom: 0; height: 7px; width: 100%; background: #f04a2c; transform-origin: left; }
.panel.locked .lock .bar { animation: drain 1.5s linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* 結果 */
.banner {
  position: absolute; left: 50%; top: 50%; z-index: 7; display: none; flex-direction: column; align-items: center; gap: 2px;
  transform: translate(-50%, -50%); min-width: 68%; padding: 12px 18px 14px; pointer-events: none;
  background: rgba(242, 232, 210, .96); color: var(--ink); border-radius: 10px; text-align: center;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55); border-top: 5px solid var(--gold);
}
.banner.show { display: flex; animation: bannerIn .3s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes bannerIn { from { transform: translate(-50%, -40%) scale(.9); opacity: 0; } }
.banner.win { border-top-color: var(--me); }
.banner.lose { background: rgba(40, 32, 25, .95); color: var(--washi); border-top-color: #6a5c4c; }
.banner.pass { border-top-color: #7c6f60; }
.banner b { font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * .66); }
.banner.win b { color: var(--me); }
.banner .mv { font-family: var(--mincho); font-weight: 800; font-size: calc(var(--cell) * .52); }
.banner .tm { font-weight: 900; font-size: calc(var(--cell) * .9); font-variant-numeric: tabular-nums; line-height: 1.1; }
.banner .tm small { font-size: .45em; margin-left: 2px; }
.banner .note { font-size: 12px; opacity: .7; }
.banner em { font-style: normal; font-size: 12px; font-weight: 900; color: #fff; background: var(--shu); padding: 2px 8px; border-radius: 99px; margin-top: 3px; }

/* 成る／成らない */
.promo { position: absolute; left: 6%; right: 6%; top: 18%; z-index: 9; display: none; gap: 10px; }
.promo.low { top: auto; bottom: 14%; }
.promo.show { display: flex; }
.promo button {
  flex: 1; height: max(52px, calc(var(--cell) * 1.4)); border-radius: 10px; border: 2px solid var(--ink);
  background: var(--washi); color: var(--ink); font-family: var(--mincho); font-weight: 800; font-size: max(18px, calc(var(--cell) * .58));
  box-shadow: 0 8px 20px rgba(0, 0, 0, .45);
}
.promo .pb-naru { background: #a8190f; color: #fff4e6; border-color: #6e0f08; }

/* ================= 優勝 ================= */
.victory { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(12, 8, 5, .88); backdrop-filter: blur(4px); padding: 20px; animation: fade .4s; }
@keyframes fade { from { opacity: 0; } }
.vic-main, .vic-mirror { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.vic-mirror { display: none; }
body.portrait.duo .victory { justify-content: space-around; }
body.portrait.duo .vic-mirror { display: flex; transform: rotate(180deg); }
.vic-kicker { margin: 0; font-size: 13px; letter-spacing: .4em; color: var(--gold); }
.vic-title { margin: 0; font-family: var(--mincho); font-weight: 800; font-size: clamp(40px, 11vw, 72px); line-height: 1.1; }
.vic-score { margin: 0; font-size: 28px; font-weight: 900; font-variant-numeric: tabular-nums; }
.vic-sub { margin: 0 0 14px; font-size: 13px; color: var(--washi-dim); }
.vic-btns { display: flex; flex-direction: column; gap: 10px; width: min(320px, 80vw); }
.ghost-btn { height: 50px; border-radius: 12px; border: 1px solid rgba(242, 232, 210, .3); background: transparent; font-size: 16px; font-weight: 700; }

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