
  :root {
    --bg: #0c0e12;
    --surface: #14171d;
    --surface-2: #1c2027;
    --surface-3: #232834;
    --edge: #262c37;
    --edge-soft: #1d222b;
    --ink: #e9ecf1;
    --ink-mid: #a6aeba;
    --ink-dim: #6e7886;
    --accent: #e9a23b;
    --accent-bright: #f5b65c;
    --accent-soft: rgba(233, 162, 59, .13);
    --accent-edge: rgba(233, 162, 59, .45);
    --accent-ink: #221604;
    --track: #2a303c;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    display: flex; flex-direction: column;
    background: var(--bg); color: var(--ink);
    font: 13px/1.45 var(--f-ui);
    user-select: none; overflow: hidden;
  }
  svg { display: block; }

  /* ---------- buttons & chips ---------- */
  .btn {
    background: var(--surface-2); color: var(--ink);
    border: 1px solid var(--edge); border-radius:0;
    padding: 5px 12px; font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap;
    transition: background .12s, border-color .12s;
  }
  .btn:hover:not(:disabled) { background: var(--surface-3); border-color: #343c4a; }
  .btn:active:not(:disabled) { transform: translateY(1px); }
  .btn:disabled { opacity: .35; cursor: default; }
  .btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
  .btn.primary:hover:not(:disabled) { background: var(--accent-bright); border-color: transparent; }
  .btn.icon { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; }
  .btn.small { padding: 3px 9px; border-radius:0; font-size: 12px; }
  .sel {
    background: var(--surface-2); color: var(--ink-mid);
    border: 1px solid var(--edge); border-radius:0;
    padding: 4px 6px; font: inherit; font-size: 12px; cursor: pointer; outline: none;
  }
  .sel:hover { background: var(--surface-3); color: var(--ink); }
  kbd {
    font: 10.5px/1.5 Consolas, monospace; color: var(--ink-mid);
    background: var(--surface-3); border: 1px solid #333b49; border-bottom-width: 2px;
    border-radius:0; padding: 0 5px;
  }

  /* ---------- top bar ---------- */
  #topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; background: var(--surface);
    border-bottom: 1px solid var(--edge-soft);
    min-width: 0;
  }
  .prep-name {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 650; letter-spacing: .3px; margin-right: 10px;
  }
  .tb-sep { width: 1px; height: 20px; background: var(--edge); margin: 0 4px; }
  .spacer { flex: 1; }
  #zoomVal { min-width: 46px; text-align: center; color: var(--ink-mid); font-variant-numeric: tabular-nums; font-size: 12px; }
  .bg-switch {
    display: flex; align-items: center; gap: 3px;
    padding: 2px; background: var(--surface-2);
    border: 1px solid var(--edge); border-radius:0;
  }
  .bg-option {
    width: 25px; height: 24px; padding: 0; border: 1px solid transparent; border-radius:0;
    background: transparent; display: grid; place-items: center; cursor: pointer;
  }
  .bg-option:hover { background: var(--surface-3); }
  .bg-option.active { border-color: var(--accent-edge); background: var(--accent-soft); }
  .bg-swatch {
    width: 15px; height: 15px; border-radius:0; border: 1px solid rgba(0, 0, 0, .55);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
  }
  .bg-swatch.checker {
    background:
      linear-gradient(45deg, #9a9a9a 25%, transparent 25%),
      linear-gradient(-45deg, #9a9a9a 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #9a9a9a 75%),
      linear-gradient(-45deg, transparent 75%, #9a9a9a 75%),
      #c8c8c8;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
    background-size: 8px 8px;
  }
  .bg-swatch.white { background: #fff; }
  .bg-swatch.black { background: #050505; }
  .bg-swatch.gray { background: #777; }

  .export-icon { width: 15px; height: 15px; margin-right: 6px; display: inline-block; vertical-align: -3px; }

  /* ---------- context bar (tool options) ---------- */
  #contextbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
    padding: 6px 14px; min-height: 40px;
    background: var(--surface); border-bottom: 1px solid var(--edge);
  }
  #ctxToolName { font-weight: 600; color: var(--accent); min-width: 84px; font-size: 12.5px; }
  .slider { display: flex; align-items: center; gap: 8px; color: var(--ink-dim); font-size: 12px; white-space: nowrap; }
  .slider input[type=range] {
    -webkit-appearance: none; appearance: none;
    width: 110px; height: 4px; border-radius:0; background: var(--track); outline: none; cursor: pointer;
  }
  .slider input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 15px; height: 15px; border-radius:0;
    background: var(--accent); border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
  }
  .slider .val { color: var(--ink); min-width: 26px; text-align: right; font-variant-numeric: tabular-nums; }
  .chk { display: flex; align-items: center; gap: 7px; color: var(--ink-dim); cursor: pointer; white-space: nowrap; font-size: 12px; }
  .chk input {
    appearance: none; -webkit-appearance: none; width: 30px; height: 17px; margin: 0;
    border-radius:0; background: var(--track); border: 1px solid var(--edge);
    position: relative; cursor: pointer; transition: background .15s, border-color .15s;
  }
  .chk input::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px;
    border-radius:0; background: var(--ink-dim); transition: left .15s, background .15s;
  }
  .chk input:checked { background: var(--accent-soft); border-color: var(--accent-edge); }
  .chk input:checked::after { left: 15px; background: var(--accent); }
  .keylab { display: flex; align-items: center; gap: 7px; color: var(--ink-dim); font-size: 12px; cursor: pointer; }
  .keylab input[type=color] { width: 26px; height: 22px; padding: 0; border: 1px solid var(--edge); border-radius:0; background: none; cursor: pointer; }
  .mask-cluster { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .cluster-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink-dim); margin-right: 2px; }

  /* ---------- workspace: tool rail + canvas ---------- */
  #workspace { display: flex; flex: 1; min-height: 0; }
  #rail {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 10px 7px; background: var(--surface);
    border-right: 1px solid var(--edge-soft); z-index: 20;
  }
  #rail .sep { width: 26px; height: 1px; background: var(--edge); margin: 5px 0; }
  #rail .tool {
    position: relative; width: 38px; height: 38px; border-radius:0;
    border: 1px solid transparent; background: transparent; color: var(--ink-mid);
    display: grid; place-items: center; cursor: pointer; padding: 0;
    transition: background .12s, color .12s;
  }
  #rail .tool:hover { background: var(--surface-2); color: var(--ink); }
  #rail .tool.active { background: var(--accent-soft); border-color: var(--accent-edge); color: var(--accent); }
  #rail .tool .kchip {
    position: absolute; right: 4px; bottom: 2px;
    font: 600 8.5px/1.4 Consolas, monospace; color: var(--ink-dim);
  }
  #rail .tool.active .kchip { color: var(--accent); }
  #rail .tool::after {
    content: attr(data-tip);
    position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    background: #0b0d11; border: 1px solid var(--edge); border-radius:0;
    padding: 6px 10px; white-space: nowrap; font-size: 12px; color: var(--ink);
    box-shadow: var(--shadow); opacity: 0; pointer-events: none;
    transition: opacity .12s ease .2s; z-index: 40;
  }
  #rail .tool:hover::after { opacity: 1; }

  main { position: relative; flex: 1; overflow: hidden; min-width: 0; }
  #view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

  #dropHint { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
  .drop-card {
    text-align: center; padding: 44px 60px; border: 1.5px dashed #313947; border-radius:0;
    background: rgba(20, 23, 29, .55); color: var(--ink-dim);
  }
  .drop-card svg { margin: 0 auto; }
  .drop-card .big { font-size: 19px; font-weight: 600; color: var(--ink); margin: 14px 0 6px; }
  .drop-card .dim { margin-top: 10px; font-size: 12px; }

  /* ---------- status bar ---------- */
  footer {
    display: flex; align-items: center; gap: 16px;
    padding: 5px 14px; background: var(--surface);
    border-top: 1px solid var(--edge-soft); color: var(--ink-dim);
    font-size: 11.5px; font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden;
  }
  footer .sw {
    display: inline-block; width: 10px; height: 10px; border-radius:0;
    border: 1px solid rgba(0, 0, 0, .6); vertical-align: -1px; margin-right: 5px;
  }
  footer #statHint { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }
  footer kbd { font-size: 9.5px; padding: 0 4px; }

  /* ---------- help overlay ---------- */
  #helpModal {
    position: fixed; inset: 0; z-index: 100; display: none;
    background: rgba(4, 5, 8, .62); backdrop-filter: blur(3px);
    place-items: center;
  }
  #helpModal.open { display: grid; }
  .help-card {
    width: min(880px, 92vw); max-height: 86vh; overflow: auto;
    background: var(--surface); border: 1px solid var(--edge);
    border-radius:0; box-shadow: var(--shadow); padding: 24px 28px;
  }
  .help-card h2 { margin: 0; font-size: 17px; }
  .help-sub { margin: 6px 0 0; color: var(--ink-dim); font-size: 12.5px; }
  .help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px 32px; margin-top: 18px; }
  .help-grid h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin: 0 0 8px; }
  .help-grid .row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 3.5px 0; color: var(--ink-mid); font-size: 12.5px; }
  .help-grid .row .keys { white-space: nowrap; flex-shrink: 0; }
  .help-close { margin-top: 18px; }

  /* ---------- export studio ---------- */
  #exportModal {
    position: fixed; inset: 0; z-index: 110; display: none;
    background: rgba(4, 5, 8, .72); backdrop-filter: blur(4px);
    place-items: center; padding: 24px;
  }
  #exportModal.open { display: grid; }
  .export-shell {
    width: min(920px, 96vw); max-height: 92vh; overflow: auto;
    background: var(--surface); border: 1px solid var(--edge);
    border-radius:0; box-shadow: var(--shadow);
  }
  .export-head {
    display: flex; align-items: flex-start; gap: 18px; padding: 22px 24px 18px;
    border-bottom: 1px solid var(--edge);
  }
  .export-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
  .export-head p { margin: 4px 0 0; color: var(--ink-dim); font-size: 12.5px; }
  .export-head .icon-close { margin-left: auto; flex: 0 0 auto; }
  .export-tabs {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
    padding: 12px 24px; border-bottom: 1px solid var(--edge-soft);
  }
  .export-tab {
    border: 1px solid transparent; border-radius:0; padding: 9px 8px;
    background: transparent; color: var(--ink-mid); font: inherit; cursor: pointer;
  }
  .export-tab:hover { background: var(--surface-2); color: var(--ink); }
  .export-tab.active { background: var(--accent-soft); border-color: var(--accent-edge); color: var(--accent-bright); }
  .export-body { display: grid; grid-template-columns: minmax(280px, .9fr) minmax(320px, 1.1fr); min-height: 360px; }
  .export-preview {
    padding: 22px 24px; border-right: 1px solid var(--edge); min-width: 0;
    background: #101319;
  }
  .preview-stage {
    height: 238px; display: grid; place-items: center; overflow: hidden;
    border: 1px solid #2a303a; border-radius:0;
    background-color: #b9bdc3;
    background-image: linear-gradient(45deg, #969ba2 25%, transparent 25%), linear-gradient(-45deg, #969ba2 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #969ba2 75%), linear-gradient(-45deg, transparent 75%, #969ba2 75%);
    background-position: 0 0, 0 10px, 10px -10px, -10px 0; background-size: 20px 20px;
  }
  #exportPreview { display: block; max-width: 100%; max-height: 100%; }
  .plate-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; min-height: 31px; }
  .plate-chip {
    display: flex; align-items: center; gap: 7px; min-width: 0;
    padding: 5px 8px; border: 1px solid var(--edge); border-radius:0;
    color: var(--ink-mid); font-size: 11.5px; background: var(--surface);
  }
  .plate-chip i { width: 14px; height: 14px; border-radius:0; border: 1px solid rgba(255,255,255,.25); flex: 0 0 auto; }
  .plate-chip input[type=color] {
    width: 18px; height: 18px; padding: 0; border: 1px solid rgba(255,255,255,.25);
    border-radius:0; background: transparent; cursor: pointer; flex: 0 0 auto;
  }
  .palette-reset { align-self: center; }
  .preview-note { margin: 12px 0 0; color: var(--ink-dim); font-size: 11.5px; line-height: 1.45; }
  .export-settings { padding: 22px 24px; }
  .export-settings h3 { margin: 0 0 6px; font-size: 14px; }
  .export-settings .mode-copy { margin: 0 0 20px; min-height: 38px; color: var(--ink-mid); font-size: 12.5px; line-height: 1.5; }
  .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .field { display: grid; gap: 6px; color: var(--ink-dim); font-size: 11.5px; }
  .field .sel { width: 100%; padding: 7px 8px; color: var(--ink); }
  .export-options { display: grid; gap: 11px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--edge); }
  .export-options .chk { color: var(--ink-mid); }
  #registrationOption { display: grid; gap: 11px; }
  #registrationOption[hidden] { display: none; }
  .option-help { margin: -5px 0 0 37px; color: var(--ink-dim); font-size: 11px; line-height: 1.4; }
  .export-summary {
    margin-top: 20px; padding: 11px 12px; border-left: 3px solid var(--accent);
    background: var(--accent-soft); color: var(--ink-mid); font-size: 12px; line-height: 1.5;
  }
  .export-foot {
    display: flex; align-items: center; gap: 10px; padding: 14px 24px;
    border-top: 1px solid var(--edge); background: var(--surface-2);
  }
  #exportProgress { color: var(--ink-dim); font-size: 11.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .export-foot .spacer { min-width: 12px; }
  .btn.busy { pointer-events: none; opacity: .7; }
  .btn:focus-visible, .sel:focus-visible, .tool:focus-visible, .bg-option:focus-visible, .export-tab:focus-visible {
    outline: 2px solid var(--accent-bright); outline-offset: 2px;
  }

  @media (max-width: 760px) {
    .prep-name { margin-right: 2px; }
    #topbar { padding-inline: 8px; flex-wrap: wrap; }
    #topbar .tb-sep { display: none; }
    #zoomVal { display: none; }
    #exportModal { padding: 12px; }
    .export-shell { width: 100%; max-width: 100%; }
    .export-tabs { grid-template-columns: repeat(2, 1fr); }
    .export-body { grid-template-columns: 1fr; }
    .export-preview { border-right: 0; border-bottom: 1px solid var(--edge); }
    .preview-stage { height: 190px; }
    #contextbar { gap: 9px; padding-inline: 10px; }
    .mask-cluster { width: 100%; }
  }

  @media (max-width: 520px) {
    #topbar .spacer { display: none; }
    #topbar .prep-name { width: 20px; flex: 0 0 20px; overflow: hidden; white-space: nowrap; gap: 8px; }
    #topbar #zoomOutBtn, #topbar #zoomInBtn { display: none; }
    .export-head, .export-settings, .export-preview { padding-left: 16px; padding-right: 16px; }
    .export-tabs { padding-left: 16px; padding-right: 16px; }
    .export-foot { padding-left: 16px; padding-right: 16px; flex-wrap: wrap; }
    #exportProgress { width: 100%; }
    .export-foot .spacer { display: none; }
    .export-foot #exportCancel { margin-left: auto; }
    footer #printInfo, footer #statPos, footer #statColor, footer #statHint { display: none; }
    footer #statName { overflow: hidden; text-overflow: ellipsis; }
    #rail .tool::after { display: none; }
  }

  @media (max-width: 380px) {
    .field-grid { grid-template-columns: 1fr; }
    .preview-stage { height: 170px; }
  }
