:root {
  color-scheme: light;
  --paper: #E7E4EC;
  --card: #F9F8FB;
  --field: #FFFFFF;
  --copy-tint: #F1EDF6;
  --ink: #1A171E;
  --ink-2: #544C5C;
  --ink-3: #6B6474;
  --rule: #D6D1DD;
  --rule-strong: #C1BACA;
  --accent: #5A2A6E;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6DCEE;
  --flag: #A32F4E;
  --shadow: 0 1px 2px rgba(26,23,30,.05), 0 10px 26px rgba(26,23,30,.06);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #16131A;
  --card: #1E1A24;
  --field: #131019;
  --copy-tint: #201A29;
  --ink: #E9E4EE;
  --ink-2: #ABA4B4;
  --ink-3: #8E8797;
  --rule: #322C3A;
  --rule-strong: #443C4E;
  --accent: #B98BD9;
  --accent-ink: #1B1122;
  --accent-soft: #2A2033;
  --flag: #E38AA0;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 30px rgba(0,0,0,.3);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 'IBM Plex Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  background: var(--accent); color: var(--accent-ink);
  font: 600 11px/1 'IBM Plex Mono', monospace;
  letter-spacing: .08em;
  padding: 7px 8px 6px;
  border-radius: 4px;
}
.brand-name {
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 18px;
  letter-spacing: .01em;
}

.theme-toggle {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  width: 62px; height: 30px; padding: 0 7px;
  cursor: pointer;
  background: var(--field);
  border: 1px solid var(--rule-strong); border-radius: 999px;
  transition: background .18s, border-color .18s;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent);
  transition: transform .24s cubic-bezier(.4, 0, .2, 1), background .18s;
}
.theme-toggle .icon {
  position: relative;
  width: 14px; height: 14px;
  color: var(--ink-3);
  transition: color .18s;
}
html[data-theme="light"] .icon-sun { color: var(--accent-ink); }
html[data-theme="dark"] .icon-moon { color: var(--accent-ink); }
html[data-theme="dark"] .theme-knob { transform: translateX(32px); }

.shell {
  max-width: 1120px; margin: 0 auto;
  padding: 26px 24px 72px;
  display: grid; grid-template-columns: 190px 1fr; gap: 30px;
  align-items: start;
}

.rail { position: sticky; top: 82px; }
.rail-label {
  margin: 0 0 8px;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-btn {
  appearance: none; text-align: left; cursor: pointer;
  background: none; border: 0; border-radius: 5px;
  padding: 8px 10px;
  color: var(--ink-2);
  transition: background .14s, color .14s;
}
.rail-btn:hover { background: var(--accent-soft); color: var(--ink); }
.rail-btn.is-current {
  background: var(--accent-soft); color: var(--ink);
  font-weight: 500;
  box-shadow: inset 2px 0 0 var(--accent);
}

.tool {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 24px 24px 16px;
  animation: rise .22s ease-out;
}
.tool[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.tool-head { margin-bottom: 20px; }
.tool-head h2 {
  margin: 0 0 4px;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 22px;
  letter-spacing: -.005em;
}
.tool-blurb { margin: 0; max-width: 62ch; font-size: 14px; color: var(--ink-2); }

.split { display: grid; grid-template-columns: 1fr 58px 1fr; }

.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; height: 26px; margin-bottom: 8px;
}
.field-label {
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}
.pane-box {
  width: 100%; min-height: 344px; resize: vertical;
  padding: 14px 15px;
  background: var(--field);
  border: 1px solid var(--rule); border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13.5px; line-height: 1.6;
  transition: border-color .13s;
}
.pane-box::placeholder { color: var(--ink-3); }
.pane-box:focus { border-color: var(--rule-strong); outline-offset: -1px; }
.pane-box.is-out { background: var(--copy-tint); color: var(--ink-2); }

.seam { position: relative; display: flex; align-items: center; justify-content: center; }
.seam::before {
  content: "";
  position: absolute; top: 42px; bottom: 6px; left: 50%;
  border-left: 1px dashed var(--rule-strong);
}
.seam-badge {
  position: relative; margin-top: 34px;
  padding: 5px 7px 4px;
  background: var(--card);
  border: 1px solid var(--rule-strong); border-radius: 4px;
  font: 600 11px/1 'IBM Plex Mono', monospace;
  letter-spacing: .04em; white-space: nowrap;
  color: var(--accent);
}

.meter {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 13px;
  border-top: 1px solid var(--rule);
}
.meter-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--ink-3);
}
.meter-text .flag { color: var(--flag); }
.meter-actions { display: flex; gap: 8px; }

.mini-btn {
  appearance: none; cursor: pointer;
  background: none; color: var(--ink-2);
  border: 1px solid var(--rule-strong); border-radius: 6px;
  padding: 6px 11px;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 13px; letter-spacing: .02em;
  transition: background .14s, color .14s, border-color .14s;
}
.mini-btn:hover { background: var(--accent-soft); color: var(--ink); }
.mini-btn:disabled { opacity: .45; cursor: not-allowed; background: none; }

.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 30px; max-width: 620px;
}
.field { display: flex; flex-direction: column; gap: 8px; }

input[type="text"], select {
  width: 100%; padding: 10px 13px;
  background: var(--field);
  border: 1px solid var(--rule); border-radius: 7px;
  font-family: 'IBM Plex Mono', monospace; font-size: 14px;
  transition: border-color .13s;
}
select { font-family: 'IBM Plex Sans', sans-serif; }
input:focus, select:focus { border-color: var(--rule-strong); }
input::placeholder { color: var(--ink-3); }

.input-suffix { position: relative; }
.input-suffix .suffix {
  position: absolute; right: 13px; top: 50%;
  transform: translateY(-50%);
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-3);
  pointer-events: none;
}
.input-suffix input { padding-right: 30px; }

.chips { display: flex; gap: 6px; }
.chip {
  appearance: none; cursor: pointer;
  background: none; color: var(--ink-2);
  border: 1px solid var(--rule); border-radius: 5px;
  padding: 4px 10px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12.5px;
  transition: background .14s, color .14s, border-color .14s;
}
.chip:hover { background: var(--accent-soft); color: var(--ink); }
.chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.segmented { display: flex; border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; }
.seg {
  appearance: none; cursor: pointer; flex: 1;
  background: none; color: var(--ink-2); border: 0;
  padding: 8px 10px;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 13.5px;
  transition: background .14s, color .14s;
}
.seg + .seg { border-left: 1px solid var(--rule); }
.seg:hover { background: var(--accent-soft); }
.seg.is-on { background: var(--accent); color: var(--accent-ink); }
.seg:focus-visible { outline-offset: -4px; border-radius: 6px; }
.seg.is-on:focus-visible { outline-color: var(--accent-ink); }

.hint { margin: 0; font-size: 12.5px; color: var(--ink-3); }
.hint.is-error { color: var(--flag); }

.readout {
  max-width: 620px; margin-top: 26px;
  background: var(--copy-tint);
  border: 1px solid var(--rule); border-radius: 8px;
  overflow: hidden;
}
.readout-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 20px; padding: 11px 16px;
}
.readout-row + .readout-row { border-top: 1px dashed var(--rule-strong); }
.readout-key {
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}
.readout-val {
  font-family: 'IBM Plex Mono', monospace; font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.readout-row.is-primary { background: var(--accent-soft); }
.readout-row.is-primary .readout-key { color: var(--accent); }
.readout-row.is-primary .readout-val { font-size: 21px; font-weight: 500; color: var(--ink); }

.barcode-stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 150px; margin-top: 26px; padding: 22px;
  background: #FFFFFF;
  border: 1px solid var(--rule); border-radius: 8px;
}
#barcode-svg { max-width: 100%; height: auto; }
#barcode-svg:empty { display: none; }
.barcode-empty {
  margin: 0;
  font-size: 13.5px; text-align: center;
  color: #6B6474;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 40;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  background: var(--ink); color: var(--paper);
  border-radius: 7px;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600; font-size: 13.5px;
  opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border: 3px solid var(--paper); border-radius: 8px;
}

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; gap: 18px; padding: 18px 16px 56px; }
  .rail {
    position: static;
    display: flex; overflow-x: auto;
    margin: 0 -16px; padding: 0 16px 4px;
    scroll-padding-inline: 16px;
    scrollbar-width: none;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-label { display: none; }
  .rail-group { flex-direction: row; gap: 8px; }
  .rail-btn {
    white-space: nowrap; padding: 7px 13px;
    background: var(--card); border: 1px solid var(--rule);
  }
  .rail-btn.is-current { box-shadow: none; border-color: var(--accent); }
  .tool { padding: 20px 18px 14px; }
  .split { grid-template-columns: 1fr; }
  .seam { height: 46px; }
  .seam::before {
    top: 50%; bottom: auto; left: 8px; right: 8px;
    border-left: 0; border-top: 1px dashed var(--rule-strong);
  }
  .seam-badge { margin-top: 0; }
  .pane-box { min-height: 240px; }
  .form-grid { grid-template-columns: 1fr; gap: 20px; }
}

@media (hover: none) and (pointer: coarse) {
  .pane-box, input[type="text"], select { font-size: 16px; }
}

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