:root {
  font-family: Inter, "PingFang SC", system-ui, sans-serif;
  color: #172019;
  background: #f5f2e9;
  color-scheme: light;
  --paper: #f5f2e9;
  --card: rgba(255, 255, 255, .72);
  --card-solid: #fbfaf6;
  --green: #1a593f;
  --green-soft: #e6eee9;
  --muted: #68716b;
  --line: rgba(25, 52, 39, .13);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
main { max-width: 1440px; margin: auto; padding: 12px 24px; }
header { display: flex; align-items: center; gap: 14px; min-height: 66px; }
header h1 { font-size: 24px; margin: 0; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .08em; }
.logo { display: block; width: 54px; height: 54px; border-radius: 14px; object-fit: cover; box-shadow: 0 4px 13px #0002; }
.status { margin-left: auto; max-width: 42%; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: var(--green); white-space: nowrap; }
.layout { display: grid; grid-template-columns: minmax(480px, 760px) minmax(330px, 1fr); gap: 22px; }
.play { min-width: 0; }
.mode { display: grid; grid-template-columns: repeat(3, 1fr); background: #dfded7; border-radius: 12px; padding: 3px; }
.mode button { border: 0; background: transparent; border-radius: 10px; padding: 9px; }
.mode .active { background: white; box-shadow: 0 1px 4px #0002; color: var(--green); font-weight: 700; }
.toolbar { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 6px; min-height: 49px; padding: 6px 2px; }
.toolbar .history-tools, .toolbar .view-tools { display: flex; gap: 4px; align-items: center; }
.toolbar strong { text-align: center; }
.toolbar button { border: 0; background: transparent; padding: 7px; border-radius: 9px; }
.toolbar .history-tools button, .toolbar .view-tools button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 20px; }
.toolbar button:hover { background: var(--green-soft); }
.toolbar .round { width: 36px; height: 36px; padding: 0; border-radius: 50%; color: var(--green); background: var(--green-soft); font-family: serif; font-weight: 800; }
.toolbar .round.active { color: white; background: var(--green); }
.board-shell { position: relative; width: 100%; aspect-ratio: 1; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 10px; overflow: hidden; box-shadow: 0 10px 28px #0002; }
.square { position: relative; border: 0; padding: 0; display: grid; place-items: center; min-width: 0; aspect-ratio: 1; }
.light { background: #eadcb5; }
.dark { background: #568064; }
.selected { box-shadow: inset 0 0 0 clamp(3px, .7vw, 6px) #f0c830; z-index: 1; }
.last { box-shadow: inset 0 0 0 clamp(2px, .5vw, 4px) #ef941c; }
.selected.last { box-shadow: inset 0 0 0 clamp(3px, .7vw, 6px) #f0c830, inset 0 0 0 clamp(7px, 1.2vw, 10px) #ef941c99; }
.target::after { content: ""; position: absolute; width: 24%; height: 24%; background: #3588ddaa; border-radius: 50%; z-index: 2; }
.piece { font-family: "Apple Symbols", "Noto Sans Symbols 2", serif; font-size: clamp(34px, 7vw, 76px); line-height: 1; filter: drop-shadow(0 2px 1px #0004); z-index: 1; }
.piece.w { color: #fff; text-shadow: 0 0 2px #111; }
.piece.b { color: #151515; }
.square small { position: absolute; z-index: 4; font-weight: 800; font-size: clamp(10px, 1.25vw, 14px); line-height: 1; text-transform: lowercase; pointer-events: none; }
.rank-label { left: 4px; top: 4px; }
.file-label { right: 4px; bottom: 4px; }
.square.light small { color: #568064; }
.square.dark small { color: #eadcb5; }
.candidate-arrows { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 1px 1px #0006); }
.arrow-number { fill: white; font-size: 3.2px; font-family: system-ui, sans-serif; font-weight: 800; text-anchor: middle; dominant-baseline: central; }
.setup-tools { margin: 0 0 8px; padding: 8px; border-radius: 11px; background: var(--card); border: 1px solid var(--line); }
.setup-tools > div { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.setup-tools button, .setup-tools select { border: 1px solid var(--line); border-radius: 8px; background: var(--card-solid); padding: 6px 9px; }
.setup-tools button.active { color: white; background: var(--green); }
.setup-tools label { margin-left: auto; font-size: 12px; color: var(--muted); }
.setup-tools .finish { color: white; background: var(--green); }
.setup-pieces { margin-top: 6px; }
.setup-pieces small { width: 30px; color: var(--muted); }
.setup-pieces .piece-tool { width: 35px; height: 35px; padding: 0; font-family: "Apple Symbols", serif; font-size: 25px; line-height: 1; }
aside { display: flex; flex-direction: column; gap: 11px; max-height: calc(100vh - 91px); overflow: auto; padding-right: 4px; }
.module { background: var(--card); border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.module summary { cursor: pointer; font-weight: 700; padding: 13px 14px; list-style: none; display: flex; justify-content: space-between; }
.module summary::after { content: "\25bc"; color: var(--green); }
.module[open] summary::after { content: "\25b2"; }
.module-body { padding: 0 14px 14px; }
.review { display: flex; flex-direction: column; gap: 3px; padding: 10px; margin-bottom: 9px; border-radius: 10px; background: var(--green-soft); }
.review span { color: var(--muted); font-size: 12px; }
.candidate-heading { display: flex; align-items: center; justify-content: space-between; margin: 5px 0; color: var(--muted); font-size: 12px; }
.candidate-heading button { border: 0; color: var(--green); background: transparent; }
.candidate { display: grid; grid-template-columns: 24px minmax(88px, 1fr) auto auto 33px; gap: 7px; align-items: center; width: 100%; padding: 9px; border: 0; text-align: left; color: inherit; background: #edf0eb; border-radius: 9px; margin-top: 7px; }
.candidate:hover { background: #e1e9e4; }
.candidate > span { min-width: 0; display: flex; flex-direction: column; }
.candidate code { font-size: 16px; font-weight: 700; }
.candidate span small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace; }
.candidate em { color: var(--muted); font-size: 11px; font-style: normal; font-weight: 700; }
.candidate:first-child em, .candidate strong { color: var(--green); }
.candidate.previewing { background: var(--green-soft); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--green) 65%, transparent); }
.candidate > small { color: var(--muted); }
.variation-trail { position: absolute; inset: 0; z-index: 5; width: 100%; height: 100%; pointer-events: none; }
.variation-trail line { stroke: #2ba66d; stroke-width: 1.1; stroke-linecap: round; stroke-dasharray: 2.2 1.8; animation: variation-draw .68s ease-out both; }
.variation-target-ring { fill: none; stroke: #2ba66d; stroke-width: .75; transform-box: fill-box; transform-origin: center; filter: drop-shadow(0 1px 2px #0005); animation: variation-ring .68s ease-out both; }
.variation-piece { --from-x: 0%; --from-y: 0%; --to-x: 0%; --to-y: 0%; position: absolute; z-index: 7; display: grid; place-items: center; width: 12.5%; height: 12.5%; left: calc(var(--from-x) - 6.25%); top: calc(var(--from-y) - 6.25%); font-family: "Apple Symbols", "Noto Sans Symbols 2", serif; font-size: clamp(34px, 7vw, 76px); line-height: 1; pointer-events: none; filter: drop-shadow(0 5px 4px #0006); animation: variation-move .68s cubic-bezier(.2,.78,.24,1) both; }
.variation-piece.w { color: white; text-shadow: 0 0 2px #111; }
.variation-piece.b { color: #151515; }
.variation-banner { position: absolute; z-index: 8; top: 10px; left: 50%; display: flex; align-items: center; gap: 7px; max-width: calc(100% - 20px); padding: 7px 10px; border: 1px solid #2ba66d66; border-radius: 999px; background: color-mix(in srgb, var(--card-solid) 86%, transparent); box-shadow: 0 5px 18px #0003; transform: translateX(-50%); white-space: nowrap; }
.variation-banner b { padding: 3px 7px; border-radius: 999px; color: white; background: var(--green); font: 700 11px ui-monospace, monospace; }
.variation-banner strong { color: var(--green); }
.variation-banner button { border: 0; color: var(--green); background: transparent; }
@keyframes variation-move { from { left: calc(var(--from-x) - 6.25%); top: calc(var(--from-y) - 6.25%); transform: scale(1); } 50% { transform: scale(1.09); } to { left: calc(var(--to-x) - 6.25%); top: calc(var(--to-y) - 6.25%); transform: scale(1); } }
@keyframes variation-draw { from { stroke-dashoffset: 20; opacity: .25; } to { stroke-dashoffset: 0; opacity: .9; } }
@keyframes variation-ring { from { opacity: .25; transform: scale(.72); } to { opacity: 1; transform: scale(1); } }
.module label { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.module input[type="range"] { flex: 1; }
.module input[type="number"], .module select { max-width: 100px; padding: 5px; }
.module-body > button, .primary { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--card-solid); }
.primary { color: white; border-color: var(--green); background: var(--green); }
.module p { font-size: 13px; line-height: 1.55; color: var(--muted); }
.chart-wrap { position: relative; height: 150px; overflow: hidden; border-radius: 10px; background: var(--card-solid); }
.chart { width: 100%; height: 100%; }
.chart-zero { stroke: #7b837e66; stroke-width: 1; }
.chart-grid { stroke: #7b837e24; stroke-width: 1; }
.chart-axis { fill: var(--muted); font: 10px ui-monospace, monospace; }
.chart-line { fill: none; stroke: var(--green); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: var(--green); }
.chart-white, .chart-black { position: absolute; left: 7px; color: var(--muted); font-size: 10px; }
.chart-white { top: 5px; }
.chart-black { bottom: 5px; }
.record-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.record-head > span { display: flex; flex: 1 1 100px; flex-direction: column; }
.record-head small { color: var(--muted); }
.record-head button, .moves button { border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; color: inherit; background: var(--card-solid); }
.record-head .primary { color: white; background: var(--green); }
.moves { max-height: 220px; overflow: auto; margin-top: 8px; }
.moves p { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 5px; align-items: center; margin: 5px 0; font-family: ui-monospace, monospace; }
.moves p button { overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
footer { text-align: center; font-size: 11px; color: #858a86; padding: 14px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: #0007; }
.record-modal { width: min(620px, 100%); max-height: min(760px, 88vh); overflow: auto; padding: 18px; border-radius: 16px; background: var(--card-solid); box-shadow: 0 22px 80px #0006; }
.result-modal { width: min(420px, 100%); padding: 26px; border-radius: 18px; text-align: center; background: var(--card-solid); box-shadow: 0 22px 80px #0006; }
.result-modal h2 { margin: 10px 0 6px; }
.result-modal p { margin: 0 0 20px; color: var(--muted); line-height: 1.6; }
.result-modal > div:last-child { display: flex; justify-content: center; gap: 10px; }
.result-modal button { padding: 9px 14px; border: 1px solid var(--line); border-radius: 9px; color: inherit; background: var(--paper); font-weight: 700; }
.result-modal button.primary { color: white; background: var(--green); }
.result-mark { display: grid; place-items: center; width: 48px; height: 48px; margin: auto; border-radius: 50%; color: white; background: var(--green); font-size: 26px; font-weight: 900; }
.record-modal header { min-height: 0; align-items: flex-start; }
.record-modal h2, .record-modal h3 { margin: 0; }
.record-modal header p { margin: 3px 0 14px; color: var(--muted); font-size: 12px; }
.record-modal header button { margin-left: auto; border: 0; color: var(--green); background: transparent; }
.record-modal label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.record-modal textarea { min-height: 100px; resize: vertical; padding: 9px; border: 1px solid var(--line); border-radius: 9px; color: inherit; background: var(--paper); font-family: ui-monospace, monospace; }
.record-modal .wide { width: 100%; margin: 9px 0 18px; }
.saved-games { display: flex; flex-direction: column; gap: 7px; margin-top: 9px; }
.saved-games button { display: flex; flex-direction: column; gap: 3px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; text-align: left; color: inherit; background: var(--paper); }
.saved-games span { color: var(--muted); font-size: 11px; }
.notice { position: fixed; left: 50%; bottom: 22px; z-index: 30; display: flex; align-items: center; gap: 14px; width: min(520px, calc(100% - 28px)); padding: 12px 14px; border-radius: 12px; color: white; background: #193d2d; box-shadow: 0 8px 30px #0005; transform: translateX(-50%); }
.notice span { flex: 1; }
.notice button { border: 0; color: white; background: transparent; font-weight: 800; }

@media (max-width: 850px) {
  main { padding: 8px 12px; }
  header { min-height: 56px; }
  .logo { width: 46px; height: 46px; }
  header h1 { font-size: 19px; }
  .brand p { font-size: 12px; }
  .status { display: none; }
  .layout { display: block; }
  .toolbar { font-size: 13px; }
  .toolbar button { padding: 6px 5px; }
  .board-shell { width: min(100%, calc(100vh - 146px)); margin: auto; }
  .setup-tools + .board-shell { width: min(100%, calc(100vh - 270px)); min-width: 280px; }
  aside { max-height: none; margin-top: 13px; }
  .piece { font-size: min(10vw, 10vh); }
  .candidate { grid-template-columns: 22px minmax(76px, 1fr) auto auto 30px; padding: 8px 6px; }
}

@media (max-width: 430px) {
  .toolbar strong { font-size: 12px; }
  .toolbar button:not(.round) { font-size: 12px; }
  .setup-tools label { margin-left: 0; }
  .record-head button { font-size: 12px; }
}

@media (prefers-color-scheme: dark) {
  :root { color: #ecefe9; background: #151a17; color-scheme: dark; --paper: #151a17; --card: rgba(37, 44, 40, .92); --card-solid: #2c342f; --green: #6dd7a7; --green-soft: #263c32; --muted: #b4bcb7; --line: rgba(225, 238, 230, .13); }
  .mode { background: #2b322e; }
  .mode .active { color: #c8f4df; background: #3b453f; }
  .candidate { background: #343c37; }
  .candidate:hover { background: #3c4941; }
  .light { background: #d7c69e; }
  .dark { background: #466b55; }
  .square.light small { color: #466b55; }
  .square.dark small { color: #d7c69e; }
  footer, .brand p { color: #a8afa9; }
}
html{min-height:100%;background:var(--paper)}body{min-height:100dvh}@media(display-mode:standalone){body{padding-top:env(safe-area-inset-top);padding-right:env(safe-area-inset-right);padding-bottom:env(safe-area-inset-bottom);padding-left:env(safe-area-inset-left);overscroll-behavior-y:none}main{min-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom))}}
