/* PV Attri Generator — calm, dark, one accent. No external fonts or stylesheets. */
:root {
  --bg: #0a0b0d;
  --surface: #121418;
  --surface-2: #171a1f;
  --raised: #25292f;
  --stage: #0e1013;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.11);
  --line-3: rgba(255, 255, 255, 0.2);
  --text: #eceef2;
  --text-2: #a3a9b3;
  --text-3: #6b727d;
  --accent: #0578ff;
  --accent-hi: #2189ff;
  --accent-text: #5aa5ff;
  --accent-soft: rgba(5, 120, 255, 0.22);
  --warn: #f0c35a;
  --ok: #52c98e;
  --err: #ff6b6b;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --side: 360px;
  --bar: 56px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { height: 100vh; height: 100dvh; display: grid; grid-template-rows: var(--bar) minmax(0, 1fr); overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(5, 120, 255, 0.4); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-3); }

body[data-app='single'] .only-bulk,
body[data-app='bulk'] .only-single,
body[data-kind='prime'] .only-unit,
body:not([data-kind='rent']) .only-rent,
body:not([data-kind='channel']) .only-channel { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 0 20px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 4px; height: 20px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 14px rgba(5, 120, 255, 0.55); }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 13px; color: var(--text-3); padding-left: 10px; border-left: 1px solid var(--line-2); white-space: nowrap; }

.switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
}
.switch button {
  position: relative; z-index: 1; height: 30px; min-width: 84px; padding: 0 16px;
  border: 0; background: none; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text-2); transition: color 0.2s var(--ease);
}
.switch button:hover { color: var(--text); }
.switch button[aria-pressed='true'] { color: var(--text); }
.switch-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 8px;
  background: var(--raised); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.28s var(--ease);
}
body[data-app='bulk'] .switch-thumb { transform: translateX(100%); }

.rules {
  justify-self: end; display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-2); text-decoration: none; font-size: 13px; white-space: nowrap; transition: color 0.15s;
}
.rules:hover { color: var(--text); }
.rules .ic { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 0; }
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.side-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 18px 24px 20px;
  display: flex; flex-direction: column; gap: 18px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}
.sec { flex: none; }
.sec-bulk { flex: 1 0 auto; display: flex; flex-direction: column; }
.sec-bulk textarea { flex: 1 1 auto; }
.lbl { display: block; margin-bottom: 8px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.lbl-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.lbl-row .lbl { margin: 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbl-row .link { flex: none; white-space: nowrap; }
.lbl-hint { margin-left: 6px; font-weight: 400; font-size: 12px; color: var(--text-3); }
.count { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--text-3); }
kbd {
  font: inherit; font-size: 11px; font-weight: 600; padding: 0 5px; border-radius: 5px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text-2);
}
.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-size: 12.5px; font-weight: 500; color: var(--accent-text); transition: color 0.15s;
}
.link:hover { color: #86bcff; }
.link:disabled { color: var(--text-3); cursor: default; opacity: 0.6; }

/* inputs */
.title-input, textarea, .split-row {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s; outline: none;
}
.title-input:hover, textarea:hover, .split-row:hover { border-color: var(--line-3); }
.title-input:focus, textarea:focus, .split-row:focus-within {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface-2);
}
.title-input { height: 46px; padding: 0 14px; font-size: 16px; font-weight: 500; letter-spacing: -0.005em; }
::placeholder { color: var(--text-3); opacity: 1; }
textarea {
  display: block; min-height: 244px; resize: vertical; padding: 10px 14px;
  font-size: 14px; line-height: 1.6; scrollbar-width: thin;
}
.split { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.split-row { display: flex; align-items: center; height: 36px; padding-left: 12px; border-radius: 10px; cursor: text; }
.split-row span { width: 12px; font-size: 11.5px; font-weight: 600; color: var(--text-3); font-variant-numeric: tabular-nums; }
.split-row input { flex: 1; min-width: 0; height: 100%; padding: 0 12px 0 8px; background: none; border: 0; outline: none; font-size: 14px; }
.split .link { align-self: flex-start; margin-top: 2px; }

/* segmented controls */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
}
.seg button {
  height: 30px; border: 0; border-radius: 8px; background: none; cursor: pointer; white-space: nowrap;
  font-size: 13px; font-weight: 500; color: var(--text-2); transition: background 0.18s var(--ease), color 0.18s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05); }

.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; flex: none;
  font-size: 10px; font-weight: 600; letter-spacing: 0.07em; white-space: nowrap;
  background: rgba(255, 255, 255, 0.06); color: var(--text-2);
}
.chip:empty { display: none; }
.sep { color: var(--text-3); margin: 0 6px; }

.note { margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.note:empty { display: none; }
.note-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.note-lines { min-width: 0; color: var(--text); }
.note-why { font-size: 12px; color: var(--text-3); }

.warn {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.45;
  color: #f3d596; background: rgba(240, 195, 90, 0.06); border: 1px solid rgba(240, 195, 90, 0.2);
  animation: rise 0.25s var(--ease) both;
}
.warn p, .card-warn p { display: flex; gap: 8px; margin: 0; }
.warn p + p { margin-top: 6px; }
.warn .ic, .card-warn .ic { width: 14px; height: 14px; margin-top: 1.5px; color: var(--warn); }
/* missing glyphs / a template that won't load: an error, not a style note */
.warn.has-error, .warn.is-error { color: #ffc9c9; background: rgba(255, 107, 107, 0.07); border-color: rgba(255, 107, 107, 0.28); }
.warn p.is-error, .card-warn p.is-error { color: #ffc9c9; }
.warn p.is-error .ic, .card-warn p.is-error .ic, .warn.is-error .ic { color: var(--err); }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }

/* formats */
.formats { display: flex; flex-direction: column; gap: 1px; margin: 0 -8px; }
.fmt { display: flex; align-items: center; border-radius: 9px; transition: background 0.15s; }
.fmt:hover { background: rgba(255, 255, 255, 0.03); }
.fmt.active { background: rgba(5, 120, 255, 0.1); }
.fmt-name {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; height: 34px; padding: 0 10px; line-height: 34px;
  border: 0; background: none; cursor: pointer; text-align: left; font-size: 13.5px; color: var(--text-2);
  border-radius: 9px;
}
.fmt-name:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.fmt-name:hover, .fmt.active .fmt-name { color: var(--text); }
.ratio { display: grid; place-items: center; width: 16px; height: 16px; flex: none; align-self: center; }
.ratio b { display: block; border: 1.5px solid currentColor; border-radius: 2.5px; opacity: 0.45; transition: opacity 0.15s, color 0.15s; }
.fmt.active .ratio b { color: var(--accent-text); opacity: 1; }
.fmt-label { white-space: nowrap; font-weight: 500; }
.fmt-plat { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fmt-tick { width: 16px; height: 16px; flex: none; align-self: center; color: var(--accent-text); opacity: 0; transition: opacity 0.15s; }
.fmt.active .fmt-tick { opacity: 1; }

/* rent / channel details */
.sec-unit { display: flex; flex-direction: column; gap: 16px; }
.field .lbl { margin-bottom: 8px; }
.text-input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input:hover { border-color: var(--line-3); }
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.text-input::placeholder { color: var(--text-3); }
.seg button:disabled { opacity: 0.35; cursor: not-allowed; }
.seg button:disabled:hover { color: var(--text-2); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 7px; border-radius: 3px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.sw-white { background: #fff; }
.sw-black { background: #000; }
.toggle { position: relative; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.toggle-ui {
  position: relative; flex: none; width: 34px; height: 20px; border-radius: 10px; background: var(--line-3);
  transition: background 0.18s var(--ease);
}
.toggle-ui::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); transition: transform 0.18s var(--ease);
}
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-ui { box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle input:disabled + .toggle-ui, .toggle input:disabled ~ .toggle-text { opacity: 0.4; }
.toggle-text { display: flex; flex-direction: column; font-size: 13.5px; font-weight: 500; color: var(--text); }
.toggle-sub { font-size: 12px; font-weight: 400; color: var(--text-3); }
.field .hint { margin-top: 6px; }
.field .hint.is-warn { color: var(--warn); }

/* customise */
.custom { border: 1px solid var(--line); border-radius: var(--r); transition: border-color 0.2s, background 0.2s; }
.custom.open { border-color: var(--line-2); background: rgba(255, 255, 255, 0.015); }
.custom-head {
  width: 100%; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px;
  border: 0; background: none; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--text); border-radius: var(--r);
}
.custom-head > .ic:first-child { color: var(--text-2); }
.custom-head .chev { margin-left: auto; color: var(--text-3); transition: transform 0.25s var(--ease); }
.custom.open .chev { transform: rotate(180deg); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(5, 120, 255, 0.2); animation: pop 0.3s var(--ease) both; }
.custom-body { padding: 6px 14px 14px; display: flex; flex-direction: column; gap: 18px; animation: rise 0.25s var(--ease) both; }
.slider-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.slider-top label { font-size: 12.5px; color: var(--text-2); }
.slider-top output { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; transition: color 0.15s; }
.slider-top output.changed { color: var(--text); }
.ends { display: flex; justify-content: space-between; margin-top: 2px; font-size: 11px; color: var(--text-3); }
.custom-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.custom-foot .hint { margin: 0; }

input[type='range'] {
  --a: 0%; --b: 0%; --track: rgba(255, 255, 255, 0.1);
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 22px; margin: 0;
  background: none; cursor: pointer;
}
input[type='range']:focus-visible { outline: none; }
input[type='range']::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--track) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--track) var(--b));
}
input[type='range']::-moz-range-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--track) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--track) var(--b));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 0 0 0 var(--accent-soft);
  transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
input[type='range']::-moz-range-thumb {
  width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}
input[type='range']:hover::-webkit-slider-thumb { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 0 0 5px rgba(5, 120, 255, 0.16); }
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 0 0 5px rgba(5, 120, 255, 0.35); }
input[type='range']:active::-webkit-slider-thumb { transform: scale(1.1); }

/* actions */
.side-actions {
  position: relative; padding: 16px 24px 20px; border-top: 1px solid var(--line); background: var(--bg);
  transition: box-shadow 0.2s;
}
.side.more-below .side-actions { box-shadow: 0 -14px 22px -14px rgba(0, 0, 0, 0.9); border-top-color: var(--line-2); }
.custom-note { display: flex; align-items: center; gap: 10px; margin: -2px 0 12px; font-size: 12px; color: var(--text-2); }
.custom-note .dot { flex: none; margin-left: 2px; }
.custom-note span:nth-child(2) { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; } /* wraps rather than hiding a value */
.custom-note .link { font-size: 12px; }
.export-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.export-row .lbl { margin: 0; }
.seg-sm { padding: 2px; border-radius: 9px; }
.seg-sm button { height: 26px; padding: 0 12px; border-radius: 7px; font-size: 12.5px; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; white-space: nowrap; font-size: 13.5px; font-weight: 500; color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.2s, opacity 0.2s;
}
.btn > * { position: relative; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-3); }
.btn:active:not(:disabled) { transform: translateY(0.5px) scale(0.995); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.busy:disabled { opacity: 1; cursor: progress; }
.btn.primary {
  height: 46px; border-color: transparent; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 10px 26px -12px rgba(5, 120, 255, 0.75);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hi); border-color: transparent; }
.btn.primary:disabled:not(.busy) { background: #1b2230; color: rgba(255, 255, 255, 0.55); box-shadow: none; opacity: 1; }
.btn-sub { font-weight: 500; opacity: 0.72; }
.btn-sub::before { content: '·'; margin: 0 6px 0 0; }
.btn-sub:empty { display: none; }
.btn-fill {
  position: absolute !important; inset: 0; background: rgba(255, 255, 255, 0.2);
  transform: scaleX(0); transform-origin: left; transition: transform 0.25s var(--ease); pointer-events: none;
}
.summary { margin: 2px 0 0; text-align: center; font-size: 12px; color: var(--text-3); }
.summary:empty { display: none; }
.busy .btn-sub { display: none; }

/* ---------------------------------------------------------------- viewer */
.viewer { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 18px 24px 24px; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 36px; margin-bottom: 16px; }
.viewer-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1 1 auto; }
.stat { display: inline-flex; align-items: center; align-self: center; gap: 6px; font-size: 12.5px; color: var(--warn); white-space: nowrap; }
.stat .ic { width: 14px; height: 14px; align-self: center; }
.viewer-title strong { font-size: 15px; font-weight: 600; white-space: nowrap; letter-spacing: -0.005em; }
.viewer-title > span { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-size::before { content: '·'; margin: 0 6px; }
.viewer-title > .stat { color: var(--warn); overflow: visible; }

.bgpick { display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; flex: none; }
.bgpick button {
  display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; font-size: 12.5px; font-weight: 500; color: var(--text-2); transition: background 0.18s, color 0.18s;
}
.bgpick button:hover { color: var(--text); }
.bgpick button[aria-pressed='true'] { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05); }
.bgpick .ic { width: 14px; height: 14px; }
.sw { width: 12px; height: 12px; border-radius: 3.5px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22); flex: none; }
.sw-checker { background: repeating-conic-gradient(#dcdfe3 0 25%, #9ea3aa 0 50%) 0 0 / 6px 6px; }
.sw-dark { background: #15181c; }
.sw-light { background: #e9edf2; }

.stagewrap { flex: 1; min-height: 0; display: grid; gap: 16px; }
.stagewrap[data-shape='tall'] { grid-template-columns: auto minmax(0, 1fr); }
.stagewrap[data-shape='wide'] { grid-template-rows: minmax(0, 1fr) auto; }
.stage {
  position: relative; min-width: 0; min-height: 0; border-radius: var(--r-lg); overflow: hidden;
  border: 1px solid var(--line); background-color: var(--stage);
  background-image: radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1.2px); background-size: 18px 18px;
}
.stage canvas {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 60px -24px rgba(0, 0, 0, 0.9);
  transition: opacity 0.25s;
}
.stage.is-empty canvas { opacity: 0.45; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.empty.is-error .empty-msg { color: #ffc9c9; border-color: rgba(255, 107, 107, 0.35); border-radius: 14px; }
.empty-msg {
  display: inline-flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); pointer-events: auto;
  padding: 9px 16px; border-radius: 999px; font-size: 13px; color: var(--text-2);
  background: rgba(10, 11, 13, 0.78); border: 1px solid var(--line-2); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

.loupe {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  padding: 16px 18px 18px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--stage);
}
.loupe-head { margin-bottom: auto; }
.loupe .specs { margin-top: 28px; margin-bottom: auto; }
.loupe.is-empty .loupe-box { margin-bottom: auto; }
.loupe-head { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.loupe-head .muted { font-weight: 400; }
.loupe-box {
  position: relative; display: flex; align-items: safe center; justify-content: safe center; min-width: 0; min-height: 0; padding-top: 16px;
  overflow: auto; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}
/* whole-number scale only (drawZoom picks ×2 or ×1): never resampled by CSS, the box scrolls instead */
.loupe-box canvas {
  display: block; flex: none; image-rendering: pixelated; border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.loupe-empty { display: grid; grid-template-columns: 5px 150px; grid-template-rows: 12px 12px; gap: 8px 12px; padding: 14px 16px; border-radius: 8px; background: rgba(255, 255, 255, 0.025); }
.loupe-empty i { grid-row: 1 / 3; border-radius: 2px; background: rgba(5, 120, 255, 0.45); }
.loupe-empty b { border-radius: 3px; background: rgba(255, 255, 255, 0.07); }
.loupe-empty b + b { width: 80%; }
.stagewrap[data-shape='wide'] .loupe {
  display: grid; grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: auto auto;
  grid-template-areas: 'head head' 'box specs'; gap: 14px 28px;
}
.stagewrap[data-shape='wide'] .loupe-head { grid-area: head; margin: 0; }
.stagewrap[data-shape='wide'] .loupe-box { grid-area: box; min-height: 150px; padding: 0; }
.stagewrap[data-shape='wide'] .specs { grid-area: specs; align-self: center; margin: 0; }

.specs { margin: 0; display: grid; gap: 0; font-size: 12.5px; }
.specs:empty { display: none; }
.specs div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.specs dt { color: var(--text-3); flex: none; }
.specs dd { margin: 0; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.drop {
  position: absolute; inset: 12px; z-index: 5; display: grid; place-items: center; pointer-events: none;
  border: 1.5px dashed var(--accent); border-radius: 20px; background: rgba(5, 120, 255, 0.09);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); font-size: 14px; font-weight: 600;
  animation: fade 0.15s ease both;
}

/* ---------------------------------------------------------------- bulk */
.bulkview {
  flex: 1; min-height: 0; overflow-y: auto; margin: -6px; padding: 6px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; align-content: start; align-items: start; }
.card {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden; cursor: zoom-in; outline: none;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  transition: border-color 0.18s, transform 0.18s var(--ease), box-shadow 0.18s;
  animation: rise 0.3s var(--ease) both;
}
.card:hover { border-color: var(--line-3); transform: translateY(-1px); box-shadow: 0 14px 30px -18px rgba(0, 0, 0, 0.9); }
.card:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.has-warn { border-color: rgba(240, 195, 90, 0.28); }
.card.has-error { border-color: rgba(255, 107, 107, 0.4); }
.card[data-state='error'] .card-media canvas { opacity: 0.15; }
.bulk-error { margin: 0 0 14px; }
.bulk-error p { align-items: baseline; }
.bulk-error span { flex: 1; min-width: 0; }
.bulk-error .ic { align-self: flex-start; }
.card-media { position: relative; aspect-ratio: 3 / 1; background: var(--stage); overflow: hidden; }
.card-media canvas { display: block; width: 100%; height: 100%; transition: opacity 0.2s; }
.card[data-state='pending'] .card-media canvas { opacity: 0.3; }
.card[data-state='pending'] .card-media::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.06) 50%, transparent 70%) 0 0 / 250% 100%;
  animation: shimmer 1.3s linear infinite;
}
.card-meta { display: flex; align-items: center; gap: 10px; padding: 11px 12px 12px; min-width: 0; border-top: 1px solid var(--line); }
.card-n { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.card-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-warn { padding: 0 12px 12px; font-size: 12px; line-height: 1.4; color: #f3d596; }
.card-warn:empty { display: none; }
.card-warn p + p { margin-top: 4px; }

.bulk-empty {
  flex: 1; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 40px 24px; border-radius: var(--r-lg); border: 1px dashed var(--line-2);
}
.bulk-empty strong { font-size: 15px; font-weight: 600; margin-top: 14px; }
.bulk-empty span { max-width: 320px; font-size: 13px; color: var(--text-3); }
.bulk-empty-art { display: grid; gap: 6px; width: 132px; }
.bulk-empty-art i { display: block; height: 22px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface); position: relative; }
.bulk-empty-art i::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: var(--accent); opacity: 0.8; }
.bulk-empty-art i::after { content: ''; position: absolute; left: 17px; top: 9px; height: 4px; width: 60%; border-radius: 2px; background: rgba(255, 255, 255, 0.14); }
.bulk-empty-art i:nth-child(2)::after { width: 44%; }
.bulk-empty-art i:nth-child(3)::after { width: 52%; }

/* ---------------------------------------------------------------- dialog */
.sheet {
  width: min(1180px, calc(100vw - 48px)); height: min(860px, calc(100dvh - 48px)); max-width: none; max-height: none;
  padding: 0; border: 1px solid var(--line-2); border-radius: 18px; background: #0d0f12; color: var(--text);
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, 0.9);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet 0.22s var(--ease) both; }
.sheet::backdrop { background: rgba(4, 5, 7, 0.66); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line); min-width: 0; }
.sheet-n { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.sheet-head strong { font-size: 15px; font-weight: 600; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-nav { display: flex; gap: 6px; margin-left: auto; flex: none; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: none; color: var(--text-2); transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface); color: var(--text); border-color: var(--line-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
#dlgWarn { margin: 14px 20px 0; }
.sheet .stagewrap { padding: 18px 20px 20px; }

.fatal {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; width: min(640px, calc(100vw - 32px));
  padding: 14px 16px; border-radius: 14px; font-size: 13.5px; line-height: 1.55;
  background: #2a1214; border: 1px solid rgba(255, 107, 107, 0.45); color: #ffd9d9; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.8);
  animation: rise 0.3s var(--ease) both;
}
.fatal code { background: rgba(0, 0, 0, 0.35); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.4); } }
@keyframes sheet { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes shimmer { from { background-position: 125% 0; } to { background-position: -125% 0; } }

/* ---------------------------------------------------------------- narrow screens: one column, sticky actions */
@media (max-width: 1180px) {
  :root { --side: 330px; }
  .bgpick button span { display: none; }
  .bgpick button { padding: 0 9px; }
}
@media (max-width: 900px) {
  body { display: block; height: auto; overflow: visible; }
  .bar {
    position: sticky; top: 0; z-index: 20; grid-template-columns: 1fr auto; padding: 0 16px; height: var(--bar);
    background: rgba(10, 11, 13, 0.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  }
  .rules { display: none; }
  .switch button { min-width: 72px; padding: 0 12px; }
  .shell { display: flex; flex-direction: column; gap: 26px; padding: 20px 16px 0; }
  .side, .side-body, .side-actions { display: contents; }
  .sec-kind { order: 0; }
  .sec-title, .sec-bulk { order: 1; }
  .sec-lines, .sec-unit { order: 2; }
  .viewer { order: 3; padding: 0; }
  .sec-formats { order: 4; }
  .export-row { order: 5; margin: 0; }
  .custom-note { order: 7; margin: 0; }
  .sec-custom { order: 6; }
  .actions {
    order: 8; position: sticky; bottom: 0; z-index: 10; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(10, 11, 13, 0.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  }
  .actions.only-single { flex-direction: row; }
  .actions.only-single .primary { flex: 1; min-width: 0; }
  .actions.only-single .actions-row { display: flex; }
  /* fixed widths: a busy label ("3/7") must not squeeze the primary button */
  .actions.only-single .actions-row .btn { flex: none; width: 72px; padding: 0 8px; font-variant-numeric: tabular-nums; }
  .actions.only-single .actions-row #dlZip { width: 118px; padding: 0 10px; }
  .actions .btn-sub { display: none; }
  .actions .btn { height: 46px; }
  .viewer-head { margin-bottom: 12px; align-items: flex-start; }
  .viewer-title { flex-direction: column; gap: 2px; }
  .pv-size { display: none; } /* the frame size is in the specs; one tidy line on phones */
  .stagewrap, .stagewrap[data-shape] { display: flex; flex-direction: column; gap: 12px; }
  .stagewrap > * { flex: none; }
  .loupe, .stagewrap[data-shape='wide'] .loupe { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
  .loupe-head, .loupe .specs, .stagewrap[data-shape='wide'] .specs { margin: 0; }
  .loupe-box, .stagewrap[data-shape='wide'] .loupe-box { height: auto; padding: 0; }
  .bulkview { overflow: visible; margin: 0; padding: 0; }
  .cards { grid-template-columns: 1fr; gap: 12px; }
  .bulk-empty { padding: 32px 20px; }
  textarea { min-height: 200px; }
  .sheet { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .sheet .stagewrap { padding: 14px 16px 20px; overflow-y: auto; }
  .sheet-head { flex-wrap: wrap; row-gap: 6px; padding: 10px 12px 12px 16px; }
  .sheet-head strong { order: 5; flex-basis: 100%; white-space: normal; }
}
@media (max-width: 420px) {
  .brand-sub { display: none; }
}

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