  :root { --bg:#1b1e24; --panel:#23272f; --panel2:#2b303a; --ink:#e8eaf0; --dim:#9aa3b2;
          --line:#3a4150; --accent:#4da3ff; --good:#3fce7c; --bad:#ff5d5d; }
  * { box-sizing:border-box; }
  html,body { margin:0; height:100%; background:var(--bg); color:var(--ink);
    font:14px/1.45 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }
  #app { display:flex; height:100vh; }
  #side { width:308px; min-width:308px; background:var(--panel); border-right:1px solid var(--line);
    overflow-y:auto; padding:14px 14px 30px; }
  #side h1 { font-size:17px; margin:0 0 2px; }
  /* the title row: the "?" sits at the right edge of the sidebar */
  .sideHead { display:flex; align-items:center; gap:8px; }
  .sideHead h1 { flex:1; }
  #side .sub { color:var(--dim); font-size:12px; margin:0 0 12px; }
  #side details.acc { border-top:1px solid var(--line); margin:12px 0 0; padding:0 0 4px; }
  #side details.acc:first-of-type { border-top:none; margin-top:6px; }
  #side details.acc > summary { list-style:none; cursor:pointer; font-size:12px; text-transform:uppercase;
    letter-spacing:.08em; color:var(--dim); padding:10px 2px 4px; display:flex; align-items:center; gap:6px; }
  #side details.acc > summary::-webkit-details-marker { display:none; }
  #side details.acc > summary::after { content:'▸'; margin-left:auto; }
  #side details.acc[open] > summary::after { content:'▾'; }
  .subgroup { border:1px solid var(--line); border-radius:8px; padding:8px 10px; margin:8px 0; }
  .subhead { font-size:12px; text-transform:uppercase; letter-spacing:.08em; color:var(--dim); margin-bottom:2px; }
  #view { flex:1; position:relative; min-width:0; }
  #c { width:100%; height:100%; display:block; touch-action:none; }
  #hud { position:absolute; left:12px; top:12px; background:rgba(20,23,29,.82); border:1px solid var(--line);
    border-radius:8px; padding:8px 11px; font-size:12.5px; pointer-events:none; max-width:340px; }
  #hud b { color:#fff; }
  #hud .ok { color:var(--good); font-weight:600; }
  #hud .warn { color:var(--bad); font-weight:600; }
  #toast { position:absolute; left:50%; bottom:18px; transform:translateX(-50%);
    background:#11141a; border:1px solid var(--line); border-radius:8px; padding:8px 14px;
    font-size:13px; opacity:0; transition:opacity .25s; pointer-events:none; white-space:nowrap; }
  .row { display:flex; gap:6px; flex-wrap:wrap; align-items:center; margin:6px 0; }
  button { background:var(--panel2); color:var(--ink); border:1px solid var(--line); border-radius:6px;
    padding:6px 9px; font-size:13px; cursor:pointer; }
  button:hover { border-color:var(--accent); }
  button.primary { background:#14518f; border-color:#2f6fb3; color:#fff; }
  button.danger { border-color:#7a2e2e; }
  button:disabled { opacity:.45; cursor:default; }
  button.active { outline:2px solid var(--accent); }
  select, input[type=text] { background:#14171c; color:var(--ink); border:1px solid var(--line);
    border-radius:6px; padding:6px 8px; font-size:13px; }
  label { font-size:12.5px; color:var(--dim); }
  .plist { display:flex; flex-direction:column; gap:4px; }
  .pitem { display:flex; align-items:center; gap:8px; padding:6px 8px; border:1px solid var(--line);
    border-radius:6px; cursor:pointer; background:var(--panel2); }
  .pitem.sel { outline:2px solid var(--accent); }
  .pitem .sw { width:16px; height:16px; border-radius:4px; flex:none; border:1px solid rgba(0,0,0,.4); }
  .pitem .nm { flex:1; }
  .pitem .ct { color:var(--dim); font-size:12px; }
  .pitem .eye { background:none; border:none; padding:2px 4px; font-size:14px; }
  .pad { display:grid; grid-template-columns:repeat(3,1fr); gap:5px; width:172px; }
  .pad button { padding:7px 0; }
  .kv { font-size:12.5px; color:var(--dim); }
  .kv b { color:var(--ink); }
  .hint { font-size:12px; color:var(--dim); margin:6px 0; }
  /* "?" help button and popup: the instructions live here, not in the
     sidebar, so they take up no room until asked for. */
  .helpBtn { width:22px; height:22px; min-width:22px; padding:0; border-radius:50%;
    font-size:13px; font-weight:700; line-height:1; background:var(--panel2);
    color:var(--accent); border:1px solid var(--accent); vertical-align:middle; }
  #helpOverlay { position:fixed; inset:0; background:rgba(10,12,16,.72); z-index:60;
    display:flex; align-items:center; justify-content:center; padding:20px; }
  .helpPanel { background:var(--panel); border:1px solid var(--line); border-radius:10px;
    padding:14px 18px; max-width:560px; width:100%; max-height:82vh; overflow-y:auto; }
  .helpHead { margin:0 0 6px; }
  .helpBody h2 { font-size:12px; text-transform:uppercase; letter-spacing:.08em;
    color:var(--dim); margin:14px 0 4px; }
  .helpBody h2:first-child { margin-top:0; }
  .helpBody p { font-size:13px; margin:4px 0; }
  .kbd { background:#14171c; border:1px solid var(--line); border-radius:4px; padding:0 5px;
    font:12px ui-monospace,Menlo,monospace; }
  /* 3D piece editor — it replaces the right panel while editing:
     the sidebar stays visible but dimmed and blocked (nothing else
     can be done while editing), and the editor fills the rest of
     the screen, canvas flexing to use all of it. On a narrow screen
     it takes the full width instead. */
  #ed3dOverlay { position:fixed; inset:0; background:rgba(10,12,16,.72); z-index:50;
    display:flex; align-items:stretch; }
  .ed3dPanel { background:var(--panel); border:none; border-left:1px solid var(--line);
    padding:14px; margin-left:308px; flex:1; min-width:0;
    display:flex; flex-direction:column; }
  @media (max-width: 700px) {
    .ed3dPanel { margin-left:0; }
  }
  .ed3dHead { margin:0 0 8px; }
  #ed3dCanvas { width:100%; flex:1; min-height:0; display:block; background:#14171c;
    border:1px solid var(--line); border-radius:8px; touch-action:none; }
  .ed3dError { color:#ff9a9a; background:#3d1a1a; border:1px solid #7a2a2a;
    border-radius:6px; padding:8px 10px; margin:8px 0; font-size:13px; }
