:root {
    --paper: #EDF1F4;
    --surface: #FFFFFF;
    --surface-2: #F5F8FA;
    --ink: #101B23;
    --ink-2: #4F6373;
    --ink-3: #7A8C99;
    --line: #D5DEE5;
    --line-2: #E7EDF1;
    --accent: #0A6C7E;
    --accent-ink: #FFFFFF;
    --accent-soft: #DDEFF3;
    --mark: #C4453C;
    --ok: #14795C;
    --warn: #8F5D06;
    --stage: #7E878E;
    --shadow: 0 1px 2px rgba(16, 28, 38, .07), 0 10px 30px -18px rgba(16, 28, 38, .45);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper: #0D141A;
      --surface: #161F26;
      --surface-2: #1C262E;
      --ink: #E6EDF2;
      --ink-2: #9FB0BC;
      --ink-3: #778996;
      --line: #2A3742;
      --line-2: #222D36;
      --accent: #37A9BE;
      --accent-ink: #042129;
      --accent-soft: #0E2F38;
      --mark: #EE7C71;
      --ok: #4EC099;
      --warn: #D8A048;
      --stage: #3D454B;
      --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -18px rgba(0, 0, 0, .8);
    }
  }

  :root[data-theme="dark"] {
    --paper: #0D141A;
    --surface: #161F26;
    --surface-2: #1C262E;
    --ink: #E6EDF2;
    --ink-2: #9FB0BC;
    --ink-3: #778996;
    --line: #2A3742;
    --line-2: #222D36;
    --accent: #37A9BE;
    --accent-ink: #042129;
    --accent-soft: #0E2F38;
    --mark: #EE7C71;
    --ok: #4EC099;
    --warn: #D8A048;
    --stage: #3D454B;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -18px rgba(0, 0, 0, .8);
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
  }

  h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.02em; text-wrap: balance; }

  button, input, select { font: inherit; color: inherit; }

  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

  .num { font-family: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace; font-variant-numeric: tabular-nums; }

  .micro {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--ink-3);
  }

  /* ---------- top bar ---------- */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

  /* Il logo è nero su fondo trasparente: al buio sta su una targa chiara, così
     restano i suoi colori invece di invertirli in qualcosa di sporco. */
  .logo-plate { display: inline-flex; flex: none; border-radius: 9px; }
  :root:not([data-theme="light"]) .logo-plate,
  :root[data-theme="dark"] .logo-plate { padding: 6px 11px; background: #F4F7F9; }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .logo-plate { padding: 0; background: none; }
  }
  .brand-logo { display: block; height: 40px; width: auto; }

  .brand h1 { font-size: 16px; line-height: 1.2; }
  .brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--ink-2); }

  .topbar-actions { display: flex; align-items: center; gap: 8px; }

  .lock {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11.5px;
    font-weight: 600;
  }

  /* ---------- buttons ---------- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
  }
  .btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
  .btn:active { transform: translateY(1px); }
  .btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
  .btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .btn-accent:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }
  .btn-wide { width: 100%; padding: 12px 14px; font-size: 14px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; font-weight: 500; }

  /* ---------- layout ---------- */
  .workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 352px;
    gap: 16px;
    align-items: start;
    max-width: 1460px;
    margin: 0 auto;
    padding: 16px 18px 28px;
  }
  @media (max-width: 1060px) { .workbench { grid-template-columns: minmax(0, 1fr); padding: 14px; } }

  .col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

  .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
  }

  .panel-head {
    display: flex; align-items: baseline; gap: 9px;
    padding: 12px 14px 0;
  }
  .step {
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 0 4px;
    line-height: 16px;
    flex: none;
  }
  .panel-head h2 { font-size: 13.5px; }
  .panel-head .hint { margin-left: auto; font-size: 11.5px; color: var(--ink-3); }
  .panel-body { padding: 12px 14px 14px; }

  /* ---------- stage ---------- */
  .stage-shell { position: relative; background: var(--stage); border-radius: 12px 12px 0 0; overflow: hidden; }
  .stage-shell canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
  .stage-shell.dragging canvas { cursor: grabbing; }
  #stageBox { height: min(58vh, 520px); min-height: 320px; }
  @media (max-width: 1060px) { #stageBox { height: min(52vh, 430px); } }

  .marker {
    position: absolute;
    width: 26px; height: 26px;
    margin: -13px 0 0 -13px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: rgba(196, 69, 60, .92);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
    cursor: grab;
    touch-action: none;
    padding: 0;
    display: grid; place-items: center;
  }
  .marker::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
  .marker:active { cursor: grabbing; }
  .marker span {
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(20, 28, 34, .82);
    color: #fff;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
  }
  .marker.flip span { left: auto; right: 32px; }
  .markers[hidden] { display: none; }

  .dropzone {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    padding: 24px;
    background: var(--surface-2);
    text-align: center;
  }
  .dropzone.over { background: var(--accent-soft); }
  .dz-inner { max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
  .dz-inner h3 { font-size: 17px; }
  .dz-inner p { margin: 0; font-size: 13px; color: var(--ink-2); }
  .dz-note { font-size: 11.5px; color: var(--ink-3); }
  .dz-icon { color: var(--accent); }

  /* ---------- stage toolbar ---------- */
  .toolbar {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 10px 14px;
    border-top: 1px solid var(--line-2);
  }
  .tool { display: flex; align-items: center; gap: 8px; }
  .tool label { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }
  .tool input[type="range"] { width: 108px; }
  .tool .val { font-size: 11.5px; color: var(--ink-2); min-width: 34px; text-align: right; }
  .toolbar .spacer { flex: 1 1 auto; }

  .toggle {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 12.5px; color: var(--ink-2); cursor: pointer; user-select: none;
  }
  .toggle input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

  /* ---------- sliders ---------- */
  input[type="range"] {
    -webkit-appearance: none; appearance: none;
    background: transparent;
    height: 20px;
    margin: 0;
    cursor: pointer;
  }
  input[type="range"]::-webkit-slider-runnable-track {
    height: 4px; border-radius: 2px; background: var(--line);
  }
  input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 15px; height: 15px; margin-top: -5.5px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  }
  input[type="range"]::-moz-range-thumb {
    width: 13px; height: 13px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--accent);
  }

  .console { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; }
  .slider-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
  .slider-row .name { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-2); }
  .slider-row .value { font-size: 11.5px; color: var(--ink-3); }
  .slider-row input { grid-column: 1 / -1; width: 100%; }

  .console-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
  .console-actions .note { font-size: 11.5px; color: var(--ink-3); margin-left: auto; }

  /* ---------- format chips ---------- */
  .formats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
  .fmt {
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
  }
  .fmt:hover { border-color: var(--ink-3); }
  .fmt strong { display: block; font-size: 12.5px; font-weight: 600; }
  .fmt span { display: block; font-size: 11px; color: var(--ink-3); font-family: "IBM Plex Mono", monospace; }
  .fmt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
  .fmt[aria-pressed="true"] span { color: var(--accent); }

  .fmt-note { margin: 9px 0 0; font-size: 11.5px; color: var(--ink-2); }

  .custom-size { display: none; gap: 8px; margin-top: 10px; align-items: end; }
  .custom-size.on { display: flex; }
  .field { display: flex; flex-direction: column; gap: 3px; }
  .field label { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
  .field input, .field select {
    padding: 7px 9px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    font-size: 13px;
    width: 100%;
  }
  .field input[type="number"] { width: 76px; font-family: "IBM Plex Mono", monospace; }

  /* ---------- checks ---------- */
  .checks { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
  .check {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 9px;
    border-radius: 7px;
    background: var(--surface-2);
    font-size: 12.5px;
  }
  .check .label { color: var(--ink-2); }
  .check .value { margin-left: auto; font-family: "IBM Plex Mono", monospace; font-size: 12px; font-weight: 500; }
  .check .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
  .check.ok .dot { background: var(--ok); }
  .check.ok .value { color: var(--ok); }
  .check.warn .dot { background: var(--warn); }
  .check.warn .value { color: var(--warn); }

  .help { margin: 0 0 10px; font-size: 12.5px; color: var(--ink-2); }
  .warn { margin: 6px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--warn); }
  .icao { margin: 10px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--ink-3); }
  .icao b { color: var(--ink-2); font-weight: 600; }
  .help b { font-weight: 600; color: var(--ink); }

  /* ---------- sheet ---------- */
  .sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
  #labelField { margin-top: 10px; }
  #labelField input { font-size: 12.5px; }

  .sheet-preview {
    margin-top: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: 9px;
    padding: 10px;
    display: flex; align-items: center; gap: 12px;
  }
  .sheet-preview canvas { display: block; max-width: 132px; max-height: 132px; width: auto; height: auto; box-shadow: 0 1px 6px rgba(0, 0, 0, .22); background: #fff; }
  .sheet-facts { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .sheet-facts .big { font-size: 22px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
  .sheet-facts .lbl { font-size: 11.5px; color: var(--ink-2); }

  .stepper { display: flex; align-items: center; gap: 6px; }
  .stepper button {
    width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line);
    background: var(--surface); cursor: pointer; font-size: 15px; line-height: 1; font-weight: 600;
  }
  .stepper button:hover { background: var(--surface-2); }
  .stepper .count { font-family: "IBM Plex Mono", monospace; font-size: 15px; font-weight: 500; min-width: 28px; text-align: center; }

  .exports { display: flex; flex-direction: column; gap: 8px; }
  .export-note { font-size: 11.5px; color: var(--ink-3); margin: 2px 0 0; }

  .printer-tip {
    margin-top: 11px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--line-2);
  }
  .printer-tip ul { margin: 6px 0 0; padding-left: 16px; }
  .printer-tip li { font-size: 12px; color: var(--ink-2); margin-bottom: 2px; }
  .printer-tip b { color: var(--ink); font-weight: 600; }

  .result { margin-top: 12px; display: none; }
  .result.on { display: block; }
  .result img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
  .result p { margin: 7px 0 0; font-size: 11.5px; color: var(--ink-2); }

  .foot {
    max-width: 1460px;
    margin: 0 auto;
    padding: 10px 18px 34px;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    text-align: center;
    border-top: 1px solid var(--line);
  }
  .foot-logo img { display: block; height: 52px; width: auto; }
  .foot-copy { margin: 0; font-size: 11.5px; color: var(--ink-2); max-width: 70ch; }
  .foot-note { margin: 0; font-size: 11.5px; color: var(--ink-3); max-width: 70ch; }
  .foot-ver { font-family: "IBM Plex Mono", monospace; opacity: .7; }

  .toast {
    position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(10px);
    background: var(--ink); color: var(--paper);
    padding: 10px 16px; border-radius: 9px; font-size: 13px; font-weight: 500;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .6);
    opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
    z-index: 40; max-width: 88vw; text-align: center;
  }
  .toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }

  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
