@font-face {font-family:'Zen Maru Gothic';font-style:normal;font-weight:500;font-display:swap;src:url('fonts/zen-maru-gothic-japanese-500-normal.woff2') format('woff2')}
@font-face {font-family:'Zen Maru Gothic';font-style:normal;font-weight:700;font-display:swap;src:url('fonts/zen-maru-gothic-japanese-700-normal.woff2') format('woff2')}
@font-face {font-family:'Zen Maru Gothic';font-style:normal;font-weight:900;font-display:swap;src:url('fonts/zen-maru-gothic-japanese-900-normal.woff2') format('woff2')}
:root {
  --bg:#ecdcc0; --bar:#e2cca8; --board:#e3b874; --cell:#d6a65e;
  --black:#2a2a2e; --black-edge:#141416; --white:#fbf6ea; --white-edge:#cdbf9f;
  --ink:#2b3550; --accent:#2b3550; --panel:#fbf6ea; --muted:#6b5a43;
  --font:'Zen Maru Gothic',sans-serif; --gap:12px; --radius:20px;
  --max-width:960px; --button-size:44px; --motion:160ms;
  --home-top:64px; --home-bottom:72px; --home-rank-width:29%; --home-history-width:41%;
  --note:#111111; --link-text:#ffffff;
}
* {box-sizing:border-box}
[hidden] {display:none !important}
body {margin:0;background:var(--bg);color:var(--ink);font:500 16px/1.6 var(--font)}
main {max-width:var(--max-width);margin:auto}
main > section:not(.home) {max-width:480px;margin:auto;padding:20px 16px}
h1 {font-size:22px} h2 {font-size:19px}
h1,h2,h3,p {margin:0 0 var(--gap)}
button,input,textarea,select {font:inherit;max-width:100%;min-width:0}
select,textarea {background:var(--panel);color:var(--ink);border:1px solid var(--muted);border-radius:10px;padding:6px 8px}
button,select,summary {min-height:var(--button-size);touch-action:manipulation}
button {border:1px solid var(--ink);border-radius:var(--radius);padding:8px 16px;background:transparent;color:var(--ink);cursor:pointer}
button.primary {background:var(--accent);color:var(--white);border-color:var(--accent);font-weight:900;box-shadow:0 5px 0 #1c2335}
button.primary:active {transform:translateY(3px);box-shadow:0 2px 0 #1c2335}
button:disabled {color:var(--muted);background:var(--panel);border-color:var(--muted);opacity:1;cursor:default}
:focus-visible {outline:3px solid var(--accent);outline-offset:3px}
.row {display:flex;gap:var(--gap);flex-wrap:wrap;align-items:center}
.between {justify-content:space-between}
body:has(.home:not([hidden])) {padding:0;overflow:hidden}
main:has(.home:not([hidden])) {max-width:none}
.home {height:calc(100dvh - var(--home-top));display:grid;grid-template-rows:minmax(0,1fr) var(--home-bottom)}
.home-body {position:relative;min-height:0}
.home-top {height:var(--home-top);display:flex;align-items:center;justify-content:space-between;gap:12px;padding:0 clamp(16px,3vw,36px);background:var(--bar)}
.home-top nav {display:flex;gap:10px}
.home-top button {width:40px;height:40px;min-height:40px;padding:0;border:0;border-radius:50%;font-size:17px;font-weight:700;flex-shrink:0}
.home-top button:hover {background:#2b355012}
.home-top button {display:grid;place-items:center}
.nav-icon {width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.nav-icon .stone-b {fill:var(--ink)}.nav-icon .stone-w {fill:var(--white)}.nav-icon .eye-b {fill:var(--white);stroke:none}.nav-icon .dot {fill:currentColor}
.logo {display:flex;align-items:center;gap:10px;color:var(--ink);font-size:18px;font-weight:900;text-decoration:none;white-space:nowrap}
.logo img {display:block;width:auto;height:42px;margin:-4px 0}
.hero,.history-panel {min-width:0;position:absolute;padding:0}
.hero {left:12%;width:var(--home-rank-width);height:72%;top:14%;text-align:center;display:flex;flex-direction:column}
.rank-summary {flex:1;display:flex;flex-direction:column;justify-content:center;min-height:0}
.hero #rank-start {width:100%;margin:0;flex-shrink:0;border-radius:18px;padding:18px;font-size:22px;letter-spacing:.2em}
/* Side-by-side layout: the rank column narrows with the window, so the start button scales down with it (tablet ≈ 46px tall, wide PC unchanged). */
@media (min-width:641px) {.hero #rank-start {width:78%;align-self:center;margin-bottom:6%;padding:clamp(10px,1.4vw,18px) 16px;font-size:clamp(16px,1.7vw,22px);border-radius:clamp(12px,1.4vw,18px)}}
.history-panel {left:54%;width:var(--home-history-width);height:86%;top:7%;display:flex;flex-direction:column}
.history-panel h2 {font-size:15px;color:var(--muted);flex-shrink:0;font-weight:700;margin-bottom:18px}
.home-footer {display:flex;align-items:center;justify-content:space-between;gap:20px;padding:0 3%;background:var(--bar);color:var(--ink);min-width:0;font-size:14px}
.home-footer p {margin:0;text-align:left}
.home-footer .links {flex-wrap:nowrap;flex-shrink:0}
.home-footer button {width:clamp(88px,12vw,140px);border-radius:999px;padding:8px;background:transparent}
.home-footer button:disabled {color:var(--ink);border-color:var(--ink)}
.home-footer button[data-link] {color:var(--link-text);border-color:transparent;font-weight:700}
.home-footer button[data-link=note] {background:var(--note)}
#history-list {min-height:0;overflow-y:auto;overscroll-behavior:contain;overflow-wrap:anywhere;padding:4px;flex:1}
#history-list button {display:grid;grid-template-columns:56px minmax(0,1fr) auto;align-items:center;gap:16px;width:100%;text-align:left;margin:0;border:0;border-bottom:1px solid #6b5a4326;border-radius:0;background:transparent;padding:12px 4px;font-size:15px}
#history-list .history-board {width:56px;height:56px}
.history-result {font-size:14px;font-weight:700}
.history-detail {display:block;font-size:12px;color:var(--muted)}
#history-list button:hover {background:var(--panel)}
#history-list time {display:block;font-size:12px;color:var(--muted)}
body:has(.home:not([hidden])) #notice {position:fixed;left:8px;right:8px;bottom:14%;z-index:3;max-height:20dvh;overflow:auto;border:1px solid var(--muted)}
body:has(.home:not([hidden])) #update-app {position:fixed;left:8px;top:4%;z-index:3;font-size:12px;min-height:32px;padding:2px 8px}
@media (max-width:640px) {
  :root {--home-top:56px;--home-bottom:104px}
  .home-top {padding:0 16px;gap:8px}
  .home-top nav {gap:4px}
  .home-top button {width:36px;height:36px;min-height:36px}
  .home-body {display:flex;flex-direction:column;gap:28px;padding:22px 20px 12px}
  .hero,.history-panel {position:static;width:100%;padding:0}
  .hero {height:auto;flex-shrink:0;padding:8px 0 4px}
  /* Phone: keep the start button clear of the marks above and the history below, and narrower than the page. */
  .hero #rank-start {width:72%;max-width:260px;align-self:center;margin:22px 0 6px;padding:13px 16px;font-size:19px;border-radius:14px}
  .history-panel {height:auto;flex:1;min-height:0}
  .home-footer {display:grid;grid-template-columns:1fr;gap:4px;padding:8px 12px}
  .home-footer p {font-size:13px;line-height:1.5}
  .home-footer .links {justify-content:flex-end}
  .home-footer button {width:100px;padding:2px 8px}
}
.rank {font-size:clamp(56px,7vw,88px);font-weight:900;line-height:1.2;margin-bottom:24px}
#marks {display:flex;justify-content:center;gap:28px;margin-bottom:18px;color:var(--muted);font-size:15px}
.mark-group {display:grid;gap:8px;justify-items:center}
.mark-dots {display:flex;gap:6px;justify-content:center}
.mark-dots i {width:14px;height:14px;border:2px solid var(--ink);border-radius:50%}
.mark-dots .filled {background:var(--ink)}
.hero button {font-size:1.4rem;margin-top:var(--gap)}
.links {display:flex;flex-wrap:wrap;justify-content:center;gap:8px}
.hint {font-size:.875rem;color:var(--muted)}
.notice {background:var(--panel);border-radius:var(--radius);padding:var(--gap);margin:var(--gap) 0;overflow-wrap:anywhere}
.board-wrap {position:relative}
svg {width:100%;height:auto;display:block;touch-action:manipulation;user-select:none}
svg:focus:not(:focus-visible) {outline:none}
svg:focus-visible {outline:3px solid var(--accent);outline-offset:3px}
/* Fit the whole screen in one view: board shrinks to the height left after header and controls. */
#board {max-height:calc(100dvh - var(--game-chrome,245px))}
#puzzle-board {max-height:calc(100dvh - var(--puzzle-chrome,265px))}
.learn-guide {display:flex;flex-direction:column;gap:8px}
.learn-talk {display:flex;align-items:center;gap:10px;min-height:88px}
#learn-character {width:auto;height:88px;flex:none;filter:drop-shadow(0 3px 2px rgb(43 53 80 / .12))}
#learn-character.talking {animation:tutorial-bounce 420ms ease-out}
#learn-bubble {position:relative;flex:1;margin:0 0 0 10px;padding:10px 14px;background:var(--panel);border:2px solid var(--accent);border-radius:16px;line-height:1.5;filter:drop-shadow(0 3px 0 rgb(43 53 80 / .12))}
/* Tail: an ink triangle with a paper triangle inset by the border width, centred on the bubble. */
#learn-bubble::before,#learn-bubble::after {content:"";position:absolute;top:50%;width:0;height:0;border-style:solid;border-color:transparent}
#learn-bubble::before {left:-13px;margin-top:-9px;border-width:9px 13px 9px 0;border-right-color:var(--accent)}
#learn-bubble::after {left:-9.5px;margin-top:-6.5px;border-width:6.5px 10px 6.5px 0;border-right-color:var(--panel)}
#learn-board {display:flex;justify-content:center}
/* The tutorial fills the screen under the header; the board takes whatever height the bubble and buttons leave. */
main>section[data-screen='#/learn']:not([hidden]) {display:flex;flex-direction:column;height:calc(100dvh - var(--home-top));min-height:480px}
[data-screen='#/learn'] .learn-guide {flex:1;min-height:0}
#learn-board {flex:1;min-height:200px}
#learn-board svg {height:100%;max-height:none}
#learn-bubble.talking {animation:bubble-pop 260ms ease-out;transform-origin:0 50%}
@keyframes bubble-pop {from {opacity:0;transform:scale(.92)} to {opacity:1;transform:none}}
@keyframes tutorial-bounce {0%{transform:translateY(0)}40%{transform:translateY(-5px)}100%{transform:translateY(0)}}
.columns {display:grid;grid-template-columns:repeat(8,minmax(0,1fr));gap:2px}
.columns button {padding:0;border-radius:8px}
.columns button[aria-pressed=true] {background:var(--ink);color:var(--white)}
.sr-only {position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}
main>section[data-screen='#/game'] {padding:16px 0}
@media (min-width:641px) {main>section[data-screen='#/game'] {padding:24px 0 0}}
.game-hud {display:flex;align-items:center;justify-content:center;gap:28px;text-align:center}
.game-hud h1 {font-size:18px;margin:0}
.scores {display:flex;justify-content:center;gap:12px;font-weight:900;font-size:38px;line-height:1.3}
.scores [data-score] {display:flex;align-items:center;gap:5px;border-bottom:3px solid transparent;padding:3px 5px;border-radius:10px}
.scores small {font-size:13px;color:var(--muted)}
.scores svg {width:22px;height:24px}
.scores .near-win {border-color:var(--ink);background:var(--panel)}
.score-flight {position:fixed;pointer-events:none;z-index:5;font:900 32px var(--font);color:var(--white);background:var(--ink);padding:3px 12px;border-radius:18px;white-space:nowrap;box-shadow:0 3px 8px #0004}
.reach.waiting {animation:reach-pulse 1600ms ease-in-out infinite}
.chain-label {font-size:23px;font-weight:900;fill:var(--ink);stroke:var(--panel);stroke-width:5px;paint-order:stroke}
@keyframes reach-pulse {50% {opacity:.35}}
@keyframes result-in {from {opacity:0;transform:translateY(10px) scale(.94)} to {opacity:1;transform:none}}
.overlay:not([hidden]) {animation:result-in 300ms ease-out}
.overlay[data-outcome=win] {box-shadow:0 0 0 6px #e3b874,0 6px 22px #2b355044}
.overlay[data-outcome=win] h2::before {content:'✦ ';color:var(--ink)}
[data-screen='#/game'] #turn {text-align:center;font-size:15px;font-weight:700;color:var(--ink);margin:6px 0 0}
[data-screen='#/game'] #selected {text-align:center;font-size:11px;margin:0}
.game-actions {display:flex;justify-content:center;align-items:flex-start;gap:28px}
.game-actions>button,.game-actions summary {border:0;padding:8px 4px;background:transparent;text-decoration:underline;text-underline-offset:4px;font-size:14px;font-weight:500}
.game-actions details {border:0;padding:0;max-width:260px}
.game-actions summary {list-style:none;text-align:center}
.game-actions summary::-webkit-details-marker {display:none}
.overlay {position:absolute;inset:25% 10% auto;background:var(--panel);border:3px solid var(--ink);border-radius:var(--radius);padding:20px;text-align:center}
dialog {background:var(--panel);color:var(--ink);border:2px solid var(--ink);border-radius:var(--radius);width:min(440px,calc(100% - 24px));max-height:calc(100dvh - 32px);padding:20px;overflow:auto}
dialog::backdrop {background:#0008}
label {display:block;margin:var(--gap) 0}
input[type=checkbox] {width:22px;height:22px;vertical-align:middle}
textarea {width:100%;min-height:100px;resize:vertical;overflow-wrap:anywhere}
pre {white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.5 var(--font)}
details {border-top:1px solid var(--muted);padding:8px 0}
summary {cursor:pointer;font-weight:bold}
/* Licenses sit inside クレジット: indented under a rule, smaller and lighter than the top-level sections. */
#licenses {margin:8px 0 0 6px;padding-left:12px;border-left:2px solid var(--muted)}
#licenses details {border-top:0;padding:0}
#licenses summary {font-size:14px;line-height:var(--button-size);font-weight:500;color:var(--muted)}
.puzzle-head {margin-bottom:20px}
.puzzle-head h1 {margin:0}
#puzzle-list {display:grid;gap:14px}
/* One card per length; the fill behind the label is the share solved. */
.puzzle-set {display:flex;align-items:center;justify-content:space-between;min-height:72px;padding:0 22px;border-width:2px;font-size:22px;font-weight:900;
  background:linear-gradient(90deg,var(--panel) calc(var(--done)*100%),transparent 0)}
.puzzle-set .count {font-size:18px;font-weight:700;font-variant-numeric:tabular-nums}
#puzzle-title {margin:0 0 8px;display:flex;align-items:center;gap:10px}
.puzzle-check {display:inline-grid;place-items:center;width:28px;height:28px;border-radius:50%;background:var(--ink);color:var(--panel);font-size:16px}
.puzzle-check[hidden] {display:none}
#puzzle-status {text-align:center;font-weight:700;margin:10px 0 14px}
.puzzle-actions {display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.puzzle-actions button {padding:8px 4px}
#learn-next,#learn-restart {margin:4px 4px 4px 0}
#replay-error {padding:16px;background:var(--panel);border-radius:var(--radius)}
/* Replay: result first, then the board, then one control strip. Phone stacks; wide screens put the board left. */
main>section.replay {max-width:1040px;padding:4px 16px 12px}
.replay-top {display:flex;align-items:center;gap:8px}
.replay-top h1 {font-size:14px;color:var(--muted);margin:0;font-weight:700}
.replay-home {border:0;padding:4px 6px;min-height:36px;font-size:14px;font-weight:700}
.replay-body {display:flex;flex-direction:column;align-items:center;gap:8px}
.replay-body[data-error=true] .replay-board-wrap,.replay-body[data-error=true] .replay-side>:not(#replay-play) {display:none}
.replay-side {display:contents}
.replay-head {order:-2;text-align:center}
#replay-scores {order:-1;font-size:30px}
.replay-outcome {display:flex;align-items:center;justify-content:center;gap:10px;margin:0;font-size:32px;font-weight:900;line-height:1.2}
.replay-outcome span {font-size:13px;font-weight:700;color:var(--ink);background:var(--panel);border:1.5px solid var(--ink);border-radius:999px;padding:2px 10px}
.replay-outcome[data-outcome=loss] {color:var(--muted)}
.replay-meta {margin:2px 0 0;font-size:13px;color:var(--muted)}
.replay-board-wrap {width:100%;display:flex;justify-content:center}
/* Short windows scroll instead of shrinking the board to nothing. */
#replay-board {max-height:max(260px,calc(100dvh - var(--replay-chrome,500px)));width:auto;max-width:100%}
.replay-ply {width:100%;max-width:420px;display:grid;grid-template-columns:auto 1fr;align-items:center;gap:14px}
#replay-position {margin:0;white-space:nowrap;color:var(--muted);font-size:14px}
#replay-position strong {font-size:30px;font-weight:900;color:var(--ink);font-variant-numeric:tabular-nums;display:inline-block;min-width:2ch;text-align:right}
#replay-seek {width:100%;accent-color:var(--ink);height:28px;margin:0}
.replay-transport {display:flex;align-items:center;justify-content:center;gap:10px}
.replay-transport button {display:grid;place-items:center;padding:0;border-radius:50%}
.replay-transport svg {fill:currentColor}
.replay-transport .step {width:44px;height:44px;border:0;background:transparent}
.replay-transport .step svg {width:22px;height:22px}
.replay-transport .step:not(:disabled):hover {background:#2b355014}
.replay-transport .step:disabled {background:transparent;opacity:.3}
.replay-transport .play {width:56px;height:56px;background:var(--ink);color:var(--white);border:0;margin:0 6px}
.replay-transport .play:active {transform:scale(.94)}
.replay-transport .play svg {width:26px;height:26px}
.replay-transport .play [data-icon=pause],.replay-transport .play[data-playing=true] [data-icon=play] {display:none}
.replay-transport .play[data-playing=true] [data-icon=pause] {display:inline}
.replay-action {width:100%;max-width:340px;font-weight:700;padding:10px 16px;margin:0}
.replay-action:not(.primary) {border:0;text-decoration:underline;text-underline-offset:4px;padding:6px;min-height:36px}
@media (min-width:900px) {
  main>section.replay {padding-top:12px}
  .replay-body {flex-direction:row;align-items:center;justify-content:center;gap:56px}
  /* Board width follows the height left on screen (viewBox is 268x302). */
  .replay-board-wrap {width:min(calc((100dvh - 140px) * 268 / 302),56vw);flex:0 0 auto}
  #replay-board {width:100%;max-height:none}
  .replay-side {display:flex;flex-direction:column;gap:22px;width:340px;flex-shrink:0}
  .replay-head {order:0;text-align:left}.replay-outcome {justify-content:flex-start;font-size:48px}.replay-meta {font-size:14px}
  #replay-scores {order:0;justify-content:flex-start;font-size:42px}
  .replay-transport {justify-content:flex-start;margin-left:-10px}
  .replay-action {max-width:none}.replay-links {margin-top:0}
}
@media (max-width:360px) {.game-hud {gap:10px}.scores {gap:6px}.home-top {padding:0 10px}.home-top nav {gap:0}#history-list button {gap:8px}}
@media (prefers-reduced-motion:reduce) {:root {--motion:0ms}}
/* Promotion: full-screen indigo moment, new rank as the hero. */
.promotion {position:fixed;inset:0;z-index:10;background:var(--ink);color:var(--white);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:clamp(8px,2vh,20px);overflow:hidden;cursor:pointer;opacity:0}
.promotion-rain {position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
.promotion-title,.promotion-stage,.promotion .promotion-go {z-index:1}
.promotion-rain [data-stone=B] {filter:drop-shadow(0 0 1.5px #fbf6eaaa)}
.promotion-title {position:relative;margin:0;font-size:clamp(22px,4vw,30px);font-weight:900;letter-spacing:.4em;padding-left:.4em;color:var(--board)}
.promotion-stage {position:relative;display:grid;place-items:center;min-height:1.3em;font-size:clamp(84px,22vw,168px);line-height:1.1}
.promotion-old,.promotion-new {grid-area:1/1;font-weight:900}
.promotion-old {color:#fbf6ea80;font-size:.62em}
.promotion-new {color:var(--white);transform-origin:50% 100%}
.promotion .promotion-go {position:relative;margin-top:clamp(12px,3vh,32px);min-width:180px;background:var(--board);color:var(--ink);border-color:var(--board);box-shadow:0 5px 0 #b98c48}
/* Study: the record's own controls (auto play, seek) step aside; the step buttons walk the tried moves. */
.replay-body[data-study=true] #replay-seek,.replay-body[data-study=true] #replay-auto {display:none}
.replay-links {display:flex;justify-content:center;gap:20px;flex-wrap:wrap;margin-top:16px}
.replay-links .replay-action {width:auto}
.replay-links:has(>:not([hidden])) {min-height:36px}
.hint-column {animation:hint-glow 1.4s ease-in-out infinite}
@keyframes hint-glow {0%,100% {opacity:.12} 50% {opacity:.5}}
.learn-actions {display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:12px}
.learn-actions button {margin:0;padding:8px 14px;font-size:15px}
[data-screen='#/learn']>header {flex-wrap:nowrap;gap:8px}
[data-screen='#/learn']>header h1 {white-space:nowrap}
#learn-skip {font-size:13px;padding:6px 12px;white-space:nowrap;flex-shrink:0}
@media (max-width:360px) {[data-screen='#/learn']>header h1 {font-size:20px} #learn-skip {font-size:12px;padding:5px 10px}}
@media (max-width:360px) {.home-top {gap:4px;padding:0 8px} .home-top nav {gap:0} .home-top button {width:34px;height:34px;min-height:34px} .logo {gap:4px;font-size:16px} .logo img {height:36px}}
#learn-scores {font-size:30px;line-height:1.2;flex:none}
