  :root {
    --bg: #080a14;
    --bg-2: #0c0f1d;
    --panel: #111527;
    --panel-2: #171b31;
    --line: #262c4c;
    --line-soft: #1d2240;
    --text: #e8ebf7;
    --muted: #8e96bd;
    --accent: #6d7cff;          /* indigo  */
    --accent-2: #b06cff;        /* violet  */
    --accent-soft: rgba(124,110,255,.16);
    --ok: #3ecf8e;
    --err: #ff6b81;
    --r: 14px;
    --shadow: 0 12px 32px rgba(0,0,0,.38);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    color: var(--text);
    background:
      radial-gradient(900px 460px at 15% -180px, rgba(109,124,255,.20), transparent 70%),
      radial-gradient(900px 460px at 85% -160px, rgba(176,108,255,.18), transparent 70%),
      var(--bg);
    font: 14.5px/1.55 ui-sans-serif, system-ui, "Segoe UI", Roboto, Inter, sans-serif;
    -webkit-font-smoothing: antialiased;
  }
  a { color: var(--accent-2); text-decoration: none; }
  h2, h3 { margin: 0; }
  form { margin: 0; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: #2b3159; border-radius: 20px; }

  /* ---------------------------------------------------------- top bar */
  .topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 12px 22px;
    background: rgba(8,10,20,.82);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line-soft);
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; }
  .brand .mark {
    width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
    background: linear-gradient(145deg, var(--accent-2), var(--accent));
    color: #fff; box-shadow: 0 6px 18px rgba(124,110,255,.42);
  }
  .brand small { display: block; font-weight: 450; color: var(--muted); font-size: 11px; }
  .chip {
    font-size: 11.5px; color: var(--muted); border: 1px solid var(--line);
    padding: 4px 10px; border-radius: 999px; background: var(--panel);
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  }
  .chip.warn { color: #ffc98a; border-color: #4a3a20; background: #1e1709; }
  .chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
  .chip.warn .dot { background: #ffc98a; }
  .grow { flex: 1; }

  /* ---------------------------------------------------------- controls */
  input[type=text], input[type=password], textarea, select {
    background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
    border-radius: 10px; padding: 9px 12px; width: 100%; font: inherit; outline: none;
    transition: border-color .15s, box-shadow .15s;
  }
  input:focus, textarea:focus {
    border-color: #5a63a8; box-shadow: 0 0 0 3px var(--accent-soft);
  }
  textarea { resize: vertical; min-height: 66px; line-height: 1.5; }
  ::placeholder { color: #626a99; }
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
    border-radius: 10px; padding: 9px 15px; font: inherit; cursor: pointer;
    transition: transform .1s, border-color .15s, background .15s;
  }
  .btn:hover { border-color: #3b4478; background: #1b2039; }
  .btn:active { transform: translateY(1px); }
  .btn:disabled { opacity: .4; cursor: not-allowed; }
  .btn.primary {
    background: linear-gradient(145deg, var(--accent-2), var(--accent));
    border-color: transparent; color: #fff; font-weight: 620;
    box-shadow: 0 6px 20px rgba(109,124,255,.34);
  }
  .btn.primary:hover { filter: brightness(1.06); }
  .btn.ghost { background: transparent; }
  .btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 9px; }
  .btn.danger:hover { border-color: #5a2338; color: #ff9bb0; }
  .icon { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.9;
    stroke-linecap: round; stroke-linejoin: round; flex: none; }

  /* ---------------------------------------------------------- layout */
  main { max-width: 1380px; margin: 0 auto; padding: 26px 22px 90px; }
  .section { margin-bottom: 34px; }
  .section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
  .step {
    width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
    background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
    font-size: 12.5px; font-weight: 650; flex: none;
  }
  .step.done { background: rgba(62,207,142,.13); border-color: #1f5a44; color: var(--ok); }
  .section-head h2 { font-size: 16.5px; letter-spacing: -.01em; }
  .section-head p { margin: 0; color: var(--muted); font-size: 12.5px; }
  .card-surface {
    background: linear-gradient(180deg, var(--panel), var(--bg-2));
    border: 1px solid var(--line-soft); border-radius: var(--r);
  }

  /* ---------------------------------------------------------- angle tiles */
  .angles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
  @media (max-width: 1000px) { .angles { grid-template-columns: repeat(2, 1fr); } }
  @media (max-width: 620px) { .angles { grid-template-columns: 1fr; } }
  .tile {
    position: relative; aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden;
    background: var(--bg-2); border: 1px solid var(--line-soft); transition: border-color .15s;
  }
  .tile.empty { border: 1.5px dashed #2f3663; }
  .tile.empty:hover, .tile.drag { border-color: var(--accent); background: #151934; }
  .tile .pick {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 7px; cursor: pointer; text-align: center;
    padding: 16px;
  }
  .tile .pick .big { color: var(--muted); }
  .tile .pick b { font-size: 14.5px; }
  .tile .pick span { font-size: 12px; color: var(--muted); }
  .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .tile .scrim {
    position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 10px;
    background: linear-gradient(transparent, rgba(6,8,16,.93));
    display: flex; align-items: center; gap: 8px;
  }
  .tile .scrim b { font-size: 13.5px; }
  .tile .tools {
    position: absolute; top: 8px; right: 8px; display: flex; gap: 6px;
    opacity: 0; transition: opacity .15s;
  }
  .tile:hover .tools { opacity: 1; }
  .tools .btn { background: rgba(8,10,20,.82); backdrop-filter: blur(6px); }
  .tag {
    font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase;
    padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted);
    background: rgba(8,10,20,.72);
  }
  .tag.on { color: var(--ok); border-color: #1f5a44; background: rgba(62,207,142,.10); }
  .tag.run { color: var(--accent-2); border-color: #4a2f6b; background: rgba(176,108,255,.10); }
  .tag i.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor;
    display: inline-block; }
  .tag:has(i.dot) { display: inline-flex; align-items: center; gap: 6px; }
  .quiet { color: var(--muted); font-size: 12px; }

  /* ---------------------------------------------------------- parts */
  .parts-stack { display: flex; flex-direction: column; gap: 16px; }
  .part-form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
  .filepick {
    border: 1.5px dashed #2f3663; border-radius: 12px; padding: 16px; text-align: center;
    cursor: pointer; color: var(--muted); font-size: 12.5px; display: block;
  }
  .filepick:hover { border-color: var(--accent); color: var(--text); }
  .filepick img { max-height: 110px; border-radius: 8px; display: block; margin: 0 auto 8px; }
  /* staged parts: a card each, laid out as a grid rather than a long stack */
  .staged-parts {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px;
  }
  .staged-parts:empty { display: none; }
  .staged-part {
    position: relative; display: flex; flex-direction: column; gap: 8px; padding: 10px;
    border: 1px solid var(--line-soft); border-radius: 13px; min-width: 0;
    background: linear-gradient(180deg, rgba(109,124,255,.07), rgba(176,108,255,.04)), var(--bg-2);
  }
  .staged-part img {
    width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 9px;
    border: 1px solid var(--line); background: #06080f;
  }
  .staged-part .fields { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
  .staged-part textarea { min-height: 62px; font-size: 12.5px; padding: 8px 10px; }
  .staged-part input[type=text] { font-size: 12.5px; padding: 7px 10px; }
  .staged-n {
    position: absolute; top: 17px; left: 17px; z-index: 2;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 7px;
    display: grid; place-items: center; font-size: 11px; font-weight: 650; color: #fff;
    background: linear-gradient(145deg, var(--accent), var(--accent-2));
    box-shadow: 0 3px 10px rgba(8,10,20,.6);
  }
  .staged-part .rm-staged {
    position: absolute; top: 17px; right: 17px; z-index: 2;
    background: rgba(8,10,20,.76); backdrop-filter: blur(6px);
  }
  .parts-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px; align-content: start; }
  .part {
    position: relative; border-radius: 13px; overflow: hidden;
    background: linear-gradient(180deg, rgba(109,124,255,.07), rgba(176,108,255,.04)), var(--panel);
    border: 1px solid var(--line-soft); transition: border-color .15s, transform .12s;
  }
  .part:hover { border-color: #39407a; transform: translateY(-1px); }
  .part img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #06080f;
    display: block; }
  .part .meta { padding: 9px 11px; }
  .part .meta b { font-size: 13px; display: block; }
  .part .meta p { margin: 3px 0 0; font-size: 11.5px; color: var(--muted);
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .part .rm { position: absolute; top: 7px; right: 7px; opacity: 0; transition: opacity .15s; }
  .part:hover .rm { opacity: 1; }
  .empty-note {
    color: var(--muted); font-size: 13px; border: 1.5px dashed #2b3159; border-radius: 12px;
    padding: 26px; text-align: center;
  }

  /* ---------------------------------------------------------- run bar */
  .runbar {
    display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
    padding: 16px 18px; border-radius: var(--r);
    background: linear-gradient(140deg, rgba(109,124,255,.10), rgba(176,108,255,.08)), var(--panel);
    border: 1px solid var(--line);
  }
  .runbar .meter { flex: 1; min-width: 180px; }
  .bar { height: 6px; border-radius: 99px; background: #1c2140; overflow: hidden; margin-top: 8px; }
  .bar i { display: block; height: 100%; border-radius: 99px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }

  /* ---------------------------------------------------------- results */
  .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 18px; }
  @media (max-width: 520px) { .cards { grid-template-columns: 1fr; } }
  .card {
    border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow);
    background: linear-gradient(180deg, var(--panel), var(--bg-2));
    border: 1px solid var(--line-soft); display: flex; flex-direction: column;
  }
  .card-head { display: flex; align-items: center; gap: 9px; padding: 12px 15px;
    border-bottom: 1px solid var(--line-soft); }
  .card-head b { font-size: 14.5px; }
  .card-title { letter-spacing: .16em; text-transform: uppercase; font-size: 12.5px !important;
    color: #c9cff0; }
  .stage-wrap { position: relative; padding: 12px; }
  .stage { position: relative; aspect-ratio: 4 / 3; background: #06080f;
    border-radius: 10px; overflow: hidden; max-height: 62vh; }
  .stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
  .veil {
    position: absolute; inset: 12px; border-radius: 10px;
    display: flex; flex-direction: column; gap: 12px;
    align-items: center; justify-content: center; background: rgba(6,8,16,.76);
    color: var(--muted); font-size: 12.5px; backdrop-filter: blur(2px); z-index: 5;
  }
  .spinner { width: 30px; height: 30px; border-radius: 50%;
    border: 3px solid #2a3059; border-top-color: var(--accent); animation: spin 1s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ------- tap-to-mark, shown while an angle has no render yet ------- */
  .stage.markable { cursor: crosshair; }
  .stage.markable::after {
    content: ''; position: absolute; inset: 0; border-radius: 10px;
    border: 1.5px solid transparent; transition: border-color .15s;
  }
  .stage.markable:hover::after { border-color: rgba(124,110,255,.6); }
  .mark-hint {
    position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
    background: rgba(8,10,20,.84); border: 1px solid var(--line); color: #c9cff0;
    padding: 6px 12px; border-radius: 999px; font-size: 12px; pointer-events: none;
    backdrop-filter: blur(6px);
  }
  .mark-hint .icon { width: 13px; height: 13px; }
  .cmp .mark-hint { z-index: 3; opacity: 0; transition: opacity .18s; }
  .cmp:hover .mark-hint { opacity: 1; }

  /* ------- before / after wipe ------- */
  .cmp {
    position: relative; aspect-ratio: 4 / 3; max-height: 62vh; background: #06080f; overflow: hidden;
    border-radius: 10px; touch-action: none; user-select: none; cursor: crosshair;
  }
  .cmp img { position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: contain; display: block; pointer-events: none; }
  .cmp-before-layer { position: absolute; inset: 0;
    clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0); }
  .cmp-tag {
    position: absolute; top: 10px; padding: 4px 11px; border-radius: 8px; z-index: 3;
    background: rgba(8,10,20,.8); border: 1px solid rgba(255,255,255,.1);
    font-size: 11px; font-weight: 600; letter-spacing: .05em; color: #e9eff6;
    backdrop-filter: blur(6px); pointer-events: none;
  }
  .cmp-tag.left { left: 10px; }
  .cmp-tag.right { right: 10px; }
  .cmp-divider {
    position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 14px; z-index: 4;
    cursor: ew-resize; display: flex; justify-content: center;
    transform: translateX(-7px);
  }
  .cmp-divider::before {
    content: ''; width: 2px; height: 100%; background: rgba(255,255,255,.92);
    box-shadow: 0 0 12px rgba(0,0,0,.55);
  }
  .cmp-handle {
    position: absolute; top: 50%; left: 7px; transform: translate(-50%, -50%);
    width: 38px; height: 38px; border-radius: 50%; border: none; padding: 0;
    background: #fff; color: #0b0d10; display: grid; place-items: center;
    cursor: ew-resize; box-shadow: 0 4px 16px rgba(0,0,0,.55);
  }
  .cmp-handle .icon { width: 17px; height: 17px; stroke-width: 2.4; }
  .cmp-handle:hover { background: #f4f2ff; }
  .cmp-handle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
  .vrow { display: flex; gap: 6px; padding: 9px 13px; overflow-x: auto;
    border-bottom: 1px solid var(--line-soft); }
  .vchip { flex: none; border: 1px solid var(--line); background: var(--panel-2);
    color: var(--muted); border-radius: 8px; padding: 4px 10px; font-size: 11.5px; cursor: pointer; }
  .vchip:hover { color: var(--text); }
  .vchip.active { border-color: var(--accent); color: var(--accent-2); background: #1b1a3a; }
  .vchip.err { border-color: #5a2338; color: #ff9bb0; }
  .vchip:disabled { cursor: default; }
  .card-body { padding: 13px 15px 15px; display: flex; flex-direction: column; gap: 11px; }
  .errbox { background: #24101a; border: 1px solid #5a2338; color: #ffb4c4; border-radius: 10px;
    padding: 9px 11px; font-size: 12px; white-space: pre-wrap; max-height: 130px; overflow: auto; }
  .notebox { background: var(--bg-2); border: 1px solid var(--line-soft); color: var(--muted);
    border-radius: 10px; padding: 9px 11px; font-size: 12px; max-height: 92px; overflow: auto; }
  .refine { display: flex; flex-direction: column; gap: 10px; }
  .refine .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--muted); display: flex; align-items: center; gap: 6px; }
  .refine .lbl em { font-style: normal; color: #5d6b7d; text-transform: none; letter-spacing: 0; }
  .slot { border: 1px solid var(--line-soft); border-radius: 12px; padding: 11px;
    background: rgba(255,255,255,.012); display: flex; flex-direction: column; gap: 8px; }
  .slot .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .preview { display: none; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); }
  .preview img { width: 46px; height: 34px; object-fit: cover; border-radius: 6px;
    border: 1px solid var(--line); }
  .preview.on { display: flex; }
  input[type=file].hidden-file { position: absolute; width: 1px; height: 1px; opacity: 0;
    pointer-events: none; }

  /* ---------------------------------------------------------- modal + toast */
  .modal { position: fixed; inset: 0; z-index: 60; background: rgba(5,6,14,.88);
    display: flex; align-items: center; justify-content: center; padding: 18px; }
  .modal[hidden] { display: none; }
  .modal .sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    padding: 16px; width: min(1020px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
  .modal .sheet header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
  #boxCanvas { display: block; max-width: 100%; margin: 0 auto; border-radius: 10px;
    background: #06080f; cursor: crosshair; touch-action: none; }
  .boxnotes { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
  .boxnotes .row { display: flex; align-items: center; gap: 9px; }
  .boxnotes .n { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
    background: #ff2d2d; color: #fff; font-size: 12px; font-weight: 700; flex: none; }
  .toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px;
    padding: 11px 17px; font-size: 13px; z-index: 70; box-shadow: var(--shadow); }
  .toast[hidden] { display: none; }
  .toast.bad { border-color: #5a2338; color: #ffb4c4; background: #1c0f18; }
  .pop { position: relative; }
  .pop > summary { list-style: none; cursor: pointer; }
  .pop > summary::-webkit-details-marker { display: none; }
  .pop .panel-pop {
    position: absolute; right: 0; top: calc(100% + 9px); width: 300px; z-index: 50;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
    display: flex; flex-direction: column; gap: 9px; box-shadow: var(--shadow);
  }
