:root{
  --bg:#DDE1E6; --panel:#F0F2F4; --panel2:#E4E8EC; --line:#C2C9D1;
  --frame:#4E5966; --frame2:#3E4854; --frame-text:#B9C2CC; --felt:#EDF0F2;
  --pt-a:#C0C8D1; --pt-b:#8C98A5;
  --you:#F5F1E7; --you-edge:#AFA48C; --you-text:#3A342A;
  --cpu:#1C222A; --cpu-edge:#4E5863; --cpu-text:#DDE2E7;
  --accent:#B87614; --accent-2:#E4A233; --accent-soft:rgba(184,118,20,.16);
  --best:#12786A; --best-soft:rgba(18,120,106,.14);
  --hit:#A84228; --trail:#59697C;
  --text:#161A20; --muted:#5A646E; --strong:#0C1015;
  --shadow:0 1px 2px rgba(16,22,30,.14), 0 6px 18px rgba(16,22,30,.10);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#0E1217; --panel:#171C22; --panel2:#1E242B; --line:#2C343D;
    --frame:#222A32; --frame2:#161B21; --frame-text:#6E7883; --felt:#151A20;
    --pt-a:#2D353F; --pt-b:#414C58;
    --you:#EAE4D6; --you-edge:#8B8271; --you-text:#2A251D;
    --cpu:#090C10; --cpu-edge:#5A6570; --cpu-text:#C7CED5;
    --accent:#E0A93F; --accent-2:#F3C267; --accent-soft:rgba(224,169,63,.18);
    --best:#3EB6A1; --best-soft:rgba(62,182,161,.16);
    --hit:#D2694B; --trail:#8496A9;
    --text:#DFE4E9; --muted:#8B959F; --strong:#F2F5F8;
    --shadow:0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"]{
  --bg:#0E1217; --panel:#171C22; --panel2:#1E242B; --line:#2C343D;
  --frame:#222A32; --frame2:#161B21; --frame-text:#6E7883; --felt:#151A20;
  --pt-a:#2D353F; --pt-b:#414C58;
  --you:#EAE4D6; --you-edge:#8B8271; --you-text:#2A251D;
  --cpu:#090C10; --cpu-edge:#5A6570; --cpu-text:#C7CED5;
  --accent:#E0A93F; --accent-2:#F3C267; --accent-soft:rgba(224,169,63,.18);
  --best:#3EB6A1; --best-soft:rgba(62,182,161,.16);
  --hit:#D2694B; --trail:#8496A9;
  --text:#DFE4E9; --muted:#8B959F; --strong:#F2F5F8;
  --shadow:0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
}

*{box-sizing:border-box}
body{
  background:var(--bg); color:var(--text);
  font-family:"Zen Kaku Gothic New","Hiragino Kaku Gothic ProN","Yu Gothic",system-ui,sans-serif;
  font-size:15px; line-height:1.7; margin:0;
  -webkit-font-smoothing:antialiased;
}
.wrap{max-width:1220px; margin:0 auto; padding:22px 24px 56px; display:flex; flex-direction:column; gap:18px}

/* ---------- header ---------- */
header{display:flex; align-items:flex-end; justify-content:space-between; gap:24px; flex-wrap:wrap}
h1{
  font-family:"Zen Old Mincho",serif; font-weight:700; font-size:27px;
  letter-spacing:.06em; margin:0; color:var(--strong); line-height:1.2;
}
.sub{color:var(--muted); font-size:12.5px; letter-spacing:.10em; margin-top:3px}
.hdr-right{display:flex; align-items:center; gap:14px; flex-wrap:wrap}

.field{display:flex; align-items:center; gap:8px}
.field > label{font-size:12px; letter-spacing:.08em; color:var(--muted)}
select, button{
  font-family:inherit; font-size:14px; color:var(--text);
  background:var(--panel); border:1px solid var(--line); border-radius:3px;
  padding:7px 12px; cursor:pointer;
}
select:focus-visible, button:focus-visible, .sw:focus-visible{outline:2px solid var(--accent); outline-offset:2px}
button.primary{
  background:var(--accent); border-color:var(--accent); color:#fff; font-weight:700;
  letter-spacing:.06em;
}
:root[data-theme="dark"] button.primary,
:root:not([data-theme="light"]) button.primary{color:#12161B}
@media (prefers-color-scheme: light){:root:not([data-theme="dark"]) button.primary{color:#fff}}
button:disabled{opacity:.4; cursor:default}
button:not(:disabled):hover{border-color:var(--accent)}

.sw{display:inline-flex; align-items:center; gap:7px; cursor:pointer; font-size:13px; color:var(--muted)}
.sw input{accent-color:var(--accent); width:15px; height:15px; cursor:pointer}

/* ---------- main split ---------- */
.main{display:grid; grid-template-columns:minmax(0,1fr) 296px; gap:22px; align-items:start}

/* ---------- board ---------- */
.board-wrap{container-type:inline-size; width:100%}
.board{
  position:relative; width:100%; aspect-ratio:100/72.4;
  background:var(--frame); border-radius:4px; box-shadow:var(--shadow);
  user-select:none;
}
.felt{position:absolute; background:var(--felt)}
.barcol{position:absolute; background:var(--frame2); border-radius:1px}
.tri{position:absolute; }
.tri.up{clip-path:polygon(0 0,100% 0,50% 100%)}
.tri.dn{clip-path:polygon(0 100%,100% 100%,50% 0)}
.zone{position:absolute; cursor:default; z-index:5}
.zone.on{cursor:pointer}
.lbl{
  position:absolute; text-align:center; font-family:"IBM Plex Mono",monospace;
  font-size:2.0cqw; line-height:1; color:var(--frame-text); opacity:.8; pointer-events:none;
}
.trayline{position:absolute; background:var(--frame); opacity:.9; pointer-events:none}
.ck{
  position:absolute; width:6.2%; aspect-ratio:1; border-radius:50%;
  z-index:3; pointer-events:none;
  display:flex; align-items:center; justify-content:center;
  font-family:"IBM Plex Mono",monospace; font-size:2.5cqw; font-weight:600;
}
.ck.y{background:var(--you); border:.35cqw solid var(--you-edge); color:var(--you-text)}
.ck.c{background:var(--cpu); border:.35cqw solid var(--cpu-edge); color:var(--cpu-text)}
.ck.src{box-shadow:0 0 0 .5cqw var(--accent), 0 0 2.4cqw var(--accent-soft); z-index:4}
.ck.sel{box-shadow:0 0 0 .7cqw var(--accent-2), 0 0 3cqw var(--accent); z-index:4}
.ck.best{box-shadow:0 0 0 .5cqw var(--best), 0 0 2.4cqw var(--best-soft); z-index:4}
.ck.moved{outline:.32cqw dashed var(--trail); outline-offset:.16cqw}
.trailfrom{
  position:absolute; width:6.2%; aspect-ratio:1; border-radius:50%;
  border:.28cqw dashed var(--trail); opacity:.45; z-index:2;
}
.ghost{
  position:absolute; width:6.2%; aspect-ratio:1; border-radius:50%;
  border:.45cqw dashed var(--accent); background:var(--accent-soft); z-index:3;
  animation:pulse 1.5s ease-in-out infinite;
}
.ghost.best{border-color:var(--best); background:var(--best-soft)}
@keyframes pulse{0%,100%{opacity:.55} 50%{opacity:1}}
@media (prefers-reduced-motion: reduce){.ghost{animation:none; opacity:.9}}
.offbar{position:absolute; border-radius:.4cqw; z-index:3}
.offbar.y{background:var(--you); border:.2cqw solid var(--you-edge)}
.offbar.c{background:var(--cpu); border:.2cqw solid var(--cpu-edge)}
.caption{
  margin:11px 2px 0; font-size:12.5px; color:var(--muted); letter-spacing:.02em;
}
.caption b{color:var(--text); font-weight:500}
.caption.legend{margin-top:5px; display:flex; align-items:center; gap:6px 24px; flex-wrap:wrap}
.caption.legend .item{display:inline-flex; align-items:center; gap:7px; white-space:nowrap}
.caption.legend .key{
  display:inline-block; width:13px; height:13px; border-radius:50%; flex:none;
  background:var(--panel); box-shadow:0 0 0 2px var(--accent);
}
.caption.legend .key.bst{box-shadow:0 0 0 2px var(--best)}
.caption.legend .key.trl{box-shadow:none; border:2px dashed var(--trail)}

/* ---------- side panel ---------- */
.side{display:flex; flex-direction:column; gap:14px}
.card{background:var(--panel); border:1px solid var(--line); border-radius:4px; padding:14px 15px}
.card h2{
  font-size:11px; letter-spacing:.16em; color:var(--muted); margin:0 0 10px;
  font-weight:500; text-transform:uppercase;
}
.navi{
  background:var(--panel); border:1px solid var(--line);
  border-left:3px solid var(--accent); border-radius:3px;
  padding:13px 15px; min-height:74px; display:flex; flex-direction:column; gap:5px; justify-content:center;
}
.navi .big{font-size:15.5px; font-weight:500; color:var(--strong); line-height:1.55}
.navi .small{font-size:12.5px; color:var(--muted)}

.dicerow{display:flex; gap:9px; align-items:center; min-height:50px}
.die{
  width:44px; height:44px; border-radius:5px; background:var(--panel2);
  border:1px solid var(--line); position:relative; flex:none;
}
.die.spent{opacity:.28}
.die.mine{border-color:var(--you-edge)}
.die.theirs{border-color:var(--cpu-edge)}
.pip{position:absolute; width:7px; height:7px; border-radius:50%; background:var(--strong)}
.dice-empty{color:var(--muted); font-size:13px}

table.sc{width:100%; border-collapse:collapse; font-size:13.5px}
table.sc th{
  text-align:left; font-weight:500; color:var(--muted); font-size:11.5px;
  letter-spacing:.1em; padding:0 0 6px;
}
table.sc td{padding:4px 0; border-top:1px solid var(--line)}
table.sc td.n{
  text-align:right; font-family:"IBM Plex Mono",monospace; font-variant-numeric:tabular-nums;
  color:var(--strong);
}
.dot{display:inline-block; width:11px; height:11px; border-radius:50%; margin-right:7px; vertical-align:-1px}
.dot.y{background:var(--you); border:1px solid var(--you-edge)}
.dot.c{background:var(--cpu); border:1px solid var(--cpu-edge)}

.btns{display:flex; flex-direction:column; gap:8px}
.btns button{width:100%; padding:10px}
.thinking{font-size:12.5px; color:var(--accent); letter-spacing:.08em}

details.help{background:var(--panel); border:1px solid var(--line); border-radius:4px; padding:0}
details.help summary{
  cursor:pointer; padding:11px 15px; font-size:12.5px; letter-spacing:.1em; color:var(--muted);
  list-style:none;
}
details.help summary::-webkit-details-marker{display:none}
details.help summary::before{content:"＋　"; color:var(--accent)}
details.help[open] summary::before{content:"−　"}
details.help .body{padding:0 15px 14px; font-size:13px; color:var(--muted); line-height:1.85}
details.help .body b{color:var(--text); font-weight:500}
details.help .body ol{margin:0; padding-left:1.25em}

/* ---------- result overlay ---------- */
.overlay{
  position:absolute; inset:0; z-index:20; display:flex; align-items:center; justify-content:center;
  background:color-mix(in srgb, var(--bg) 78%, transparent); border-radius:4px;
}
.result{
  background:var(--panel); border:1px solid var(--line); border-radius:5px;
  padding:26px 34px; text-align:center; box-shadow:var(--shadow);
}
.result .t{font-family:"Zen Old Mincho",serif; font-size:30px; color:var(--strong); letter-spacing:.08em}
.result .d{color:var(--muted); font-size:13.5px; margin:6px 0 18px}

footer{color:var(--muted); font-size:12px; letter-spacing:.04em; border-top:1px solid var(--line); padding-top:14px}

@media (max-width: 900px){
  .main{grid-template-columns:minmax(0,1fr)}
}
