/* SPDX-License-Identifier: AGPL-3.0-only */
*{box-sizing:border-box}
html,body{margin:0;height:100%;font-family:system-ui,Segoe UI,Arial,sans-serif;background:#0f1724;color:#e8edf5}
body{display:flex;flex-direction:column}
#top{display:flex;gap:16px;align-items:center;padding:6px 14px;background:#16233a;border-bottom:1px solid #2a3b5a;flex-wrap:wrap}
#top h1{font-size:18px;margin:0}
#top label{font-size:13px}
select,button{font:inherit;font-size:13px;padding:5px 9px;border-radius:7px;border:1px solid #3a4f77;background:#22344f;color:#e8edf5;cursor:pointer}
button:hover{background:#2c4466}
button.primary{background:#1f9d62;border-color:#27c07a;font-weight:600}
button.primary:hover{background:#25b472}
button:disabled{opacity:.45;cursor:not-allowed}
main{display:grid;grid-template-columns:190px 1fr 290px;flex:1;min-height:0}
aside{overflow:auto;padding:8px;background:#121c2e}
#palette h2,#side h2{font-size:14px;margin:8px 0 6px;color:#9db4d8}
.cat{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#7f95ba;margin:10px 0 4px}
.pcs{display:block;width:100%;text-align:left;margin:0 0 4px;padding:6px 8px}
.pcs.on{background:#e6a817;color:#1a1200;border-color:#ffd25e}
#stage{position:relative;min-width:0}
#c{width:100%;height:100%;display:block;touch-action:none}
#toolbar{position:absolute;left:8px;right:8px;bottom:8px;display:flex;gap:6px;flex-wrap:wrap;align-items:center;background:#0d1626cc;padding:6px;border-radius:10px}
.sep{width:1px;height:22px;background:#3a4f77}
#banner{position:absolute;top:14px;left:50%;transform:translateX(-50%);background:#1f9d62;padding:10px 20px;border-radius:12px;font-size:18px;font-weight:700;box-shadow:0 6px 24px #0008;text-align:center}
#count{position:absolute;top:8px;left:10px;font-size:12px;color:#9db4d8}
#side section{margin-bottom:14px}
#chList{padding-left:20px;margin:0;font-size:13px}
#chList li{margin-bottom:6px}
#chList li.ok{color:#5be39b}
#chList li.ok::marker{content:"✔ "}
#insBody{font-size:13px;line-height:1.4}
#insBody b{color:#ffd25e}
#help ul{padding-left:18px;font-size:12px;color:#b8c7e0;margin:0}
#dialog{position:fixed;inset:0;background:#000a;display:flex;align-items:center;justify-content:center;z-index:10}
#dialog[hidden]{display:none}
#dialog .box{background:#16233a;border:1px solid #3a4f77;border-radius:12px;padding:18px;width:min(520px,92vw)}
#dialog textarea{width:100%;background:#0d1626;color:#e8edf5;border:1px solid #3a4f77;border-radius:8px;padding:6px;font-size:12px}
#dialog .row{display:flex;gap:8px;margin-top:10px;justify-content:flex-end}

.cursorBtn{background:#2a4a3a;border-color:#4fbf86;font-weight:600;margin-bottom:6px}
.cursorBtn.on,#btnCursor.on{background:#1f9d62;border-color:#27c07a;color:#fff}
#hint{position:absolute;top:8px;left:50%;transform:translateX(-50%);font-size:12px;color:#ffd25e;background:#0d1626cc;padding:3px 10px;border-radius:8px;pointer-events:none}
#hint:empty{display:none}
#help ul{font-size:12.5px;line-height:1.35}
#help li{margin-bottom:4px}
#toolbar button{padding:4px 8px;font-size:12px}

#modes{display:flex;gap:8px;margin-left:auto;flex-wrap:wrap}
button.mode{font-weight:700;font-size:13px;padding:7px 12px;border-width:2px}
button.analyze{background:#6c3fc9;border-color:#a98bff}
button.analyze:hover{background:#7d51dd}
button.analyze.active{background:#ffd25e;border-color:#fff;color:#2b1d00}
button.load{background:#0d6fb8;border-color:#6fc3ff}
button.load:hover{background:#1583d1}
button.light{background:#a85a00;border-color:#ffb457}
button.light:hover{background:#c26b08}
button.light.active{background:#ffb457;border-color:#fff;color:#2b1700}
#help{background:#1b2c49;border:2px solid #4a6fa5;border-radius:10px;margin-bottom:12px}
#help summary{cursor:pointer;font-size:15px;font-weight:700;color:#ffd25e;padding:9px 10px;list-style:none}
#help summary::-webkit-details-marker{display:none}
#help summary::before{content:'▶ ';font-size:12px}
#help[open] summary::before{content:'▼ '}
#help summary small{font-weight:400;color:#9db4d8;font-size:11px}
#help ul{padding:0 10px 8px 26px;margin:0}
#toast{position:absolute;top:44px;left:50%;transform:translateX(-50%);background:#e6a817;color:#1a1200;font-weight:600;font-size:13px;padding:8px 14px;border-radius:10px;box-shadow:0 6px 20px #0008;max-width:80%;text-align:center;z-index:5}
#toast[hidden]{display:none}
#legend{position:absolute;top:8px;right:10px;display:flex;gap:10px;font-size:12px;background:#0d1626cc;padding:4px 10px;border-radius:8px}
#legend[hidden]{display:none}
#legend i{display:inline-block;width:18px;height:18px;border-radius:50%;text-align:center;line-height:18px;font-style:normal;font-weight:700;color:#fff;margin-right:4px}
#anaBody{font-size:12.5px;line-height:1.4}
#anaBody .mq{margin-bottom:8px;padding:6px 8px;background:#1b2c49;border-radius:8px}
#anaBody .mq span{color:#b8c7e0}
#anaBody .law{color:#ffd25e}
#count{top:auto;bottom:70px}

#help{margin:12px 0 0}
#chList li{line-height:1.35}
/* ---------- Responsive ---------- */
@media(max-width:1100px){main{grid-template-columns:150px 1fr 240px}#top h1{font-size:16px}}
@media(max-width:820px){
  html,body{height:auto;min-height:100%}
  body{display:block}
  #top{gap:6px 10px;padding:6px 10px}
  #top h1{font-size:15px;width:100%}
  #top label{font-size:12px}
  #top select{max-width:46vw}
  #modes{margin-left:0;width:100%}
  button.mode{flex:1 1 auto;font-size:12px;padding:7px 8px}
  main{display:flex;flex-direction:column;min-height:0}
  #palette{order:1;padding:6px;overflow:visible}
  #palette h2{display:none}
  #pieceList{display:flex;flex-wrap:nowrap;gap:6px;overflow-x:auto;padding-bottom:6px;-webkit-overflow-scrolling:touch}
  #pieceList .cat{flex:none;margin:0;align-self:center;white-space:nowrap}
  #pieceList .pcs{flex:none;width:auto;margin:0;white-space:nowrap;padding:9px 12px}
  .cursorBtn{display:block;margin-bottom:6px;width:100%}
  #stage{order:2;display:flex;flex-direction:column}
  #c{height:52vh;min-height:280px;flex:none}
  #toolbar{position:static;margin:6px;left:auto;right:auto;bottom:auto}
  #toolbar button{padding:9px 10px;font-size:13px}
  #count{bottom:auto;top:6px}
  #legend{top:6px;right:4px;font-size:11px;flex-wrap:wrap;max-width:60%}
  #hint{display:none}
  #side{order:3;overflow:visible}
}
@media(pointer:coarse){button,select{min-height:36px}.sep{display:none}}
#anaBody .mq.good{border-left:4px solid #1f9d62}
#anaBody .mq.bad{border-left:4px solid #6b7a99}

#foot{flex:none;text-align:center;font-size:12px;color:#9db4d8;background:#0d1626;border-top:1px solid #2a3b5a;padding:4px 8px}
#foot a{color:#ffd25e}
