:root {
  --paper: #f3efe6; --card: #fbf9f4; --ink: #1e1c19; --mute: #6b655a; --line: #d8d1c2;
  --accent: #a8482a; --accent-ink: #fbf9f4; --accent-soft: #f1ddd2; --track: #e7e1d4;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #191816; --card: #211f1c; --ink: #ece6d8; --mute: #a39b8b; --line: #3a3731;
    --accent: #d0703f; --accent-ink: #191816; --accent-soft: #3a2a22; --track: #2c2925;
  }
}
:root[data-theme="dark"] {
  --paper: #191816; --card: #211f1c; --ink: #ece6d8; --mute: #a39b8b; --line: #3a3731;
  --accent: #d0703f; --accent-ink: #191816; --accent-soft: #3a2a22; --track: #2c2925;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font: 15px/1.5 "IBM Plex Sans", system-ui, sans-serif; }
main { max-width: 1120px; margin: 0 auto; padding: 28px 16px 40px; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--line); }
a:hover { border-bottom-color: var(--accent); }
h1 { font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 40px; letter-spacing: -0.01em; margin: 0 0 4px; }
h1 .tag { font: 500 13px/1 "IBM Plex Mono", monospace; color: var(--mute); vertical-align: middle; margin-left: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.sub { margin: 0 0 4px; color: var(--mute); max-width: 760px; }
.links { margin: 0 0 22px; }
.mono { font-family: "IBM Plex Mono", monospace; font-size: 13px; }
.muted { color: var(--mute); }
.hidden { display: none !important; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--mute); }

.controls { display: flex; flex-wrap: wrap; gap: 14px 28px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--card); }
.seg button { font: inherit; border: 0; background: transparent; color: var(--ink); height: 36px; padding: 0 14px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--track); }
.seg button.on { background: var(--ink); color: var(--paper); }
.seg button small { font-family: "IBM Plex Mono", monospace; font-size: 11px; opacity: 0.7; margin-left: 4px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; font-weight: 500; }
.link-btn { color: var(--accent); cursor: pointer; font-size: 14px; font-weight: 400; }
.drop { border: 1px dashed var(--line); border-radius: 4px; min-height: 280px; display: grid; place-items: center; overflow: hidden; position: relative; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop img { max-width: 100%; max-height: 420px; display: none; }
.drop img.shown { display: block; }
.drop p { color: var(--mute); margin: 0; padding: 20px; text-align: center; }
.examples { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.examples button { padding: 0; border: 1px solid var(--line); border-radius: 3px; background: none; cursor: pointer; aspect-ratio: 4 / 3; overflow: hidden; }
.examples button:hover { border-color: var(--accent); }
.examples img { width: 100%; height: 100%; object-fit: cover; display: block; }
button.primary { font: 500 15px "IBM Plex Sans", sans-serif; height: 40px; border: 0; border-radius: 4px; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.primary:hover:not(:disabled) { filter: brightness(0.92); }
button.primary:disabled { background: var(--track); color: var(--mute); cursor: default; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .pct { font-family: "IBM Plex Mono", monospace; font-size: 13px; color: var(--mute); }
.bar-row .track { grid-column: 1 / -1; height: 8px; background: var(--track); border-radius: 2px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--ink); }
.bar-row:first-child .fill { background: var(--accent); }

#seg-canvas { width: 100%; height: auto; display: block; border-radius: 3px; }
.opacity { display: flex; align-items: center; gap: 10px; }
.opacity input { flex: 1; accent-color: var(--accent); }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; font-size: 14px; }
.lg-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; }
.lg-chip { width: 12px; height: 12px; border-radius: 2px; }
.lg-row .pct { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--mute); }

.status { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 14px; align-items: center; }
.progress { grid-column: 1 / -1; height: 3px; background: var(--track); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
footer { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
footer p { margin: 4px 0; font-size: 14px; }
