/* Same tokens and type as the rest of the site, so every tool reads as one family.
   Layout: numbered step cards on the left, live preview and export on the right.
   On phones the preview pins to the top so you always see the frame you are editing. */
:root{
  --bg:#e9edf1; --surface:#ffffff; --sunken:#f3f5f8; --ink:#16202b; --muted:#586574; --line:#cfd6de;
  --accent:#1d5fc4; --good:#1b8048; --warn:#a86a00; --bad:#c62f2f;
  --warn-bg:#fbf0d9; --bad-bg:#fbe6e6; --tint:#e6eefb;
  --font-display:"Barlow Condensed","Arial Narrow",Arial,sans-serif;
  --font-body:"IBM Plex Sans",system-ui,-apple-system,"Segoe UI",sans-serif;
  --font-num:"IBM Plex Mono",ui-monospace,Menlo,Consolas,monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){color-scheme:dark;
    --bg:#10151a; --surface:#1a2129; --sunken:#141a21; --ink:#e7ecf1; --muted:#9aa7b4; --line:#2f3945;
    --accent:#6ea8ff; --good:#4ec785; --warn:#e6b045; --bad:#ff7070; --warn-bg:#33290f; --bad-bg:#3a1a1a; --tint:#1c2a40;}
}
:root[data-theme="dark"]{color-scheme:dark;
  --bg:#10151a; --surface:#1a2129; --sunken:#141a21; --ink:#e7ecf1; --muted:#9aa7b4; --line:#2f3945;
  --accent:#6ea8ff; --good:#4ec785; --warn:#e6b045; --bad:#ff7070; --warn-bg:#33290f; --bad-bg:#3a1a1a; --tint:#1c2a40;}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--font-body);font-size:16px;line-height:1.45}
button,input,select{font:inherit;color:inherit}
button{cursor:pointer}
button:disabled{cursor:not-allowed;opacity:.45}
button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible{outline:3px solid var(--accent);outline-offset:2px}
[hidden]{display:none!important}

.wrap{max-width:1120px;margin:0 auto;padding:20px 16px 32px;display:flex;flex-direction:column;gap:18px}
.page-head{display:flex;flex-direction:column;gap:14px}
.page-head h1{font-family:var(--font-display);font-weight:700;font-size:2.2rem;line-height:1;margin:0;text-transform:uppercase;letter-spacing:.01em;text-wrap:balance}
.page-head p{margin:8px 0 0;color:var(--muted);max-width:60ch}
.head-side{display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap}
.head-side .field{flex:1 1 200px;max-width:280px}
.head-buttons{display:flex;gap:8px}

.workspace{display:flex;flex-direction:column;gap:14px}
.controls{display:flex;flex-direction:column;gap:14px;min-width:0}
.output{display:contents}
.card{background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:16px;display:flex;flex-direction:column;gap:14px;min-width:0}
.step{display:flex;align-items:baseline;gap:10px;margin:0;font-family:var(--font-display);font-weight:600;font-size:1.35rem;text-transform:uppercase;letter-spacing:.02em}
.step b{font-family:var(--font-num);font-size:.8rem;font-weight:600;color:var(--surface);background:var(--ink);border-radius:4px;padding:2px 7px;letter-spacing:0}
.seg-note{margin-left:auto;font-family:var(--font-body);font-size:.8rem;font-weight:500;color:var(--muted);text-transform:none;letter-spacing:0}

.field{display:flex;flex-direction:column;gap:5px;min-width:0}
.field label,.lbl{font-weight:600;font-size:.92rem}
.field-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.wide{grid-column:1/-1}
.hint{color:var(--muted);font-size:.84rem;margin:0}
.hint.big{font-size:.93rem;max-width:60ch}
input:not([type=checkbox]):not([type=color]):not([type=file]),select{width:100%;min-width:0;font-size:16px;background:var(--sunken);border:1px solid var(--line);border-radius:7px;padding:10px;min-height:44px}
input:not([type=checkbox]):not([type=color]){font-family:var(--font-num)}
.unit-input{display:flex}
.unit-input input{border-radius:7px 0 0 7px!important;flex:1}
.unit-input select{width:auto;flex:none;border-left:0;border-radius:0 7px 7px 0;background:var(--surface)}
.check-row{display:flex;gap:10px;align-items:center;font-size:.95rem;cursor:pointer;min-height:32px}
.check-row input{flex:none;width:20px;height:20px;margin:0;accent-color:var(--accent)}
.nested{margin:6px 0 10px 30px}

.type-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.type-button{border:1px solid var(--line);border-radius:8px;background:var(--sunken);color:var(--muted);display:flex;align-items:center;justify-content:center;flex-direction:column;gap:2px;min-height:76px;padding:6px 2px;font-family:var(--font-display);font-weight:500;font-size:.95rem;line-height:1.05;text-align:center;overflow-wrap:anywhere}
.type-button svg{width:32px;height:32px;color:var(--ink)}
.type-button:hover{border-color:var(--accent)}
.type-button.active{border:2px solid var(--accent);background:var(--tint);color:var(--ink);font-weight:600}

.composite{display:flex;flex-direction:column;gap:10px}
.explainer{background:var(--tint);border-radius:8px;padding:10px 12px;font-size:.88rem}
.segment-tabs{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.segment-tab{padding:10px;text-align:left;background:var(--sunken);border:1px solid var(--line);border-radius:8px;color:var(--muted)}
.segment-tab span{display:block;font-weight:600;font-size:.92rem;color:var(--ink)}
.segment-tab small{font-size:.78rem;display:block;margin-top:2px}
.segment-tab.active{border:2px solid var(--accent);background:var(--tint)}
.segment-actions{display:flex;justify-content:space-between;gap:12px}
.text-button{border:0;background:transparent;color:var(--accent);padding:8px 0;font-size:.9rem;font-weight:600;min-height:36px}
.text-button:hover{text-decoration:underline}
.text-button.danger{color:var(--bad)}

.more{border-top:1px dashed var(--line);padding-top:10px}
.more summary{list-style:none;cursor:pointer;font-weight:600;font-size:.92rem;color:var(--accent);display:flex;justify-content:space-between;align-items:center;min-height:32px}
.more summary::-webkit-details-marker{display:none}
.more summary span{font-size:1.3rem;line-height:1;transition:transform .15s}
.more[open] summary span{transform:rotate(45deg)}
.more-inner{padding-top:6px}

.datum-row{display:grid;grid-template-columns:30px 1fr 118px 40px;gap:6px;align-items:center;margin-bottom:8px}
.datum-rank{font-family:var(--font-num);font-size:.78rem;color:var(--muted)}
.datum-row input{font-weight:600}
.datum-row select{padding-left:8px;padding-right:4px}
.remove-datum{border:1px solid var(--line);background:var(--surface);color:var(--muted);font-size:1.2rem;line-height:1;border-radius:7px;min-height:44px;padding:0}
.remove-datum:hover{color:var(--bad);border-color:var(--bad)}
.add-button{border:1.5px dashed var(--line);border-radius:8px;background:transparent;color:var(--accent);font-weight:600;font-size:.9rem;width:100%;padding:10px;min-height:44px}
.add-button:hover{border-color:var(--accent)}
#datumControls{display:flex;flex-direction:column;gap:6px}
.empty-note{font-size:.9rem;color:var(--muted);background:var(--sunken);padding:12px;border-radius:8px;margin:0}

.color-row{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
#swatches{display:flex;gap:10px}
.swatch{width:34px;height:34px;border:3px solid var(--surface);border-radius:50%;box-shadow:0 0 0 1px var(--line);padding:0}
.swatch.active{box-shadow:0 0 0 3px var(--accent)}
.custom-color{display:flex;gap:8px;align-items:center;font-size:.88rem;color:var(--muted);cursor:pointer}
.custom-color input{width:34px;height:34px;padding:0;border:0;background:transparent;cursor:pointer}

/* preview */
.preview-card{padding:0;gap:0;overflow:hidden;order:-1;position:sticky;top:0;z-index:5;box-shadow:0 6px 16px rgba(0,0,0,.14)}
.preview-head{display:flex;align-items:center;gap:10px;padding:10px 12px}
.preview-head h2{margin:0;font-family:var(--font-display);font-size:1.15rem;text-transform:uppercase;letter-spacing:.02em;font-weight:600}
.tag{font-family:var(--font-num);font-size:.68rem;letter-spacing:.06em;border:1px solid var(--line);color:var(--muted);border-radius:4px;padding:3px 7px;white-space:nowrap}
.preview-head .primary{margin-left:auto;white-space:nowrap}
.preview-head h2{white-space:nowrap}
@media (max-width:559px){.tag{display:none}.type-button{font-size:.86rem}}
/* The drawing surface is always light paper so a black frame stays readable in dark mode. */
.paper{background-color:#fbfcfd;background-image:radial-gradient(#d5dce3 .9px,transparent .9px);background-size:16px 16px;display:flex;align-items:center;justify-content:center;border-top:1px solid var(--line);border-bottom:1px solid var(--line);padding:14px 12px;min-height:96px;overflow:auto}
.frame-wrap{max-width:100%;width:100%;text-align:center}
.frame-wrap svg{width:auto;max-width:100%;height:auto;max-height:120px;display:inline-block;vertical-align:middle}
.preview-foot{display:none;justify-content:space-between;gap:12px;padding:10px 14px;font-size:.8rem;color:var(--muted);font-variant-numeric:tabular-nums;flex-wrap:wrap}

.primary{background:var(--accent);color:var(--surface);border:1px solid var(--accent);border-radius:8px;padding:12px 16px;font-weight:600;display:flex;align-items:center;gap:10px;min-height:46px}
.primary:hover:not(:disabled){filter:brightness(1.1)}
.primary.small{min-height:36px;padding:6px 12px;font-size:.88rem}
.full{width:100%}
.button-tail{font-family:var(--font-num);font-size:.72rem;font-weight:500;margin-left:auto;opacity:.8;letter-spacing:.08em}
.ghost{font-size:.88rem;font-weight:600;color:var(--accent);background:transparent;border:1.5px solid var(--accent);border-radius:999px;padding:7px 16px;min-height:44px}
.ghost:hover{background:var(--accent);color:var(--surface)}
.export-options{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
.resolution{font-size:.88rem;display:flex;align-items:center;gap:8px;color:var(--muted)}
.resolution select{width:auto;min-height:38px;padding:6px 8px}
.download-row{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.download{text-align:left;border:1px solid var(--line);background:var(--sunken);border-radius:8px;padding:10px 12px;min-height:54px}
.download:hover:not(:disabled){border-color:var(--accent)}
.download>span{font-weight:600;display:block}
.download small{display:block;color:var(--muted);font-size:.76rem;margin-top:2px}
.setup-bar{display:flex;align-items:center;justify-content:space-between;font-size:.9rem;color:var(--muted);gap:12px;flex-wrap:wrap;padding:0 4px}
.setup-bar>div{display:flex;gap:18px;align-items:center}
.practice-note{color:var(--muted);font-size:.84rem;padding:0 4px;display:flex;flex-direction:column;gap:4px;align-items:flex-start}
.practice-note p{margin:0;max-width:68ch}
.practice-note strong{color:var(--ink)}

#validation:empty{display:none}
#validation{display:flex;flex-direction:column;gap:10px}
.validation-box{background:var(--warn-bg);border:1px solid var(--warn);border-left-width:6px;border-radius:8px;padding:10px 14px;font-size:.88rem;color:var(--ink)}
.validation-box.error{background:var(--bad-bg);border-color:var(--bad)}
.validation-box summary{cursor:pointer;font-weight:600;display:flex;justify-content:space-between;list-style:none;min-height:24px}
.validation-box summary::-webkit-details-marker{display:none}
.validation-box ul{padding-left:18px;margin:6px 0 0}
.validation-box li+li{margin-top:4px}

.toast{position:fixed;bottom:22px;left:50%;transform:translate(-50%,15px);background:var(--ink);color:var(--surface);padding:12px 18px;border-radius:8px;box-shadow:0 8px 30px rgba(0,0,0,.25);opacity:0;transition:.2s;pointer-events:none;z-index:1000;font-size:.92rem;max-width:90vw;min-width:220px;text-align:center}
.toast.visible{opacity:1;transform:translate(-50%,0)}
dialog{border:1px solid var(--line);padding:0;border-radius:12px;max-width:730px;width:92%;max-height:85vh;color:var(--ink);background:var(--surface);box-shadow:0 18px 90px rgba(0,0,0,.35)}
dialog::backdrop{background:rgba(10,18,26,.55)}
.dialog-header{position:sticky;top:0;display:flex;align-items:center;justify-content:space-between;padding:16px 20px;background:var(--surface);border-bottom:1px solid var(--line)}
.dialog-header h2{margin:0;font-family:var(--font-display);font-size:1.6rem;text-transform:uppercase;letter-spacing:.02em}
.dialog-header button{border:1px solid var(--line);background:var(--sunken);border-radius:50%;width:40px;height:40px;font-size:1.4rem;line-height:1;color:var(--muted)}
.guide-body{padding:6px 20px 22px;font-size:.93rem;line-height:1.6}
.guide-body h3{font-size:1.02rem;margin:20px 0 8px}
.guide-body p{margin:0 0 10px}
.guide-grid{display:grid;grid-template-columns:1fr;gap:10px}
.guide-grid>div{border:1px solid var(--line);border-radius:8px;padding:12px}
.guide-grid p{margin:4px 0 0;font-size:.88rem;color:var(--muted)}
.guide-body a{color:var(--accent)}
.guide-body ul{padding-left:20px;margin:0}
.guide-body li{margin:6px 0}

@media (min-width:560px){
  .guide-grid{grid-template-columns:repeat(3,1fr)}
  .frame-wrap svg{max-height:150px}
}
@media (min-width:940px){
  .page-head{flex-direction:row;justify-content:space-between;align-items:flex-end}
  .page-head h1{font-size:2.9rem}
  .workspace{display:grid;grid-template-columns:minmax(330px,410px) 1fr;gap:18px;align-items:start}
  .output{display:flex;flex-direction:column;gap:14px;position:sticky;top:14px;min-width:0}
  .preview-card{position:static;order:0;box-shadow:none}
  .preview-head{padding:14px 16px}
  .preview-head .primary{display:none}
  .paper{min-height:260px;padding:36px 24px}
  .frame-wrap svg{max-height:300px;width:90%;max-width:680px}
  .preview-foot{display:flex}
}
@media (prefers-reduced-motion:reduce){.toast,.more summary span{transition:none}}
