:root {
  --bg: #0c0e12;
  --bg-2: #12151c;
  --surface: #181c25;
  --surface-2: #1e2430;
  --surface-3: #262d3b;
  --line: rgba(232, 228, 218, 0.08);
  --line-2: rgba(232, 228, 218, 0.14);
  --text: #ece7dc;
  --text-dim: #b4aea3;
  --muted: #7d7880;
  --gold: #e4b15a;
  --gold-2: #f0c57a;
  --gold-dim: rgba(228, 177, 90, 0.14);
  --teal: #4ad4c4;
  --teal-dim: rgba(74, 212, 196, 0.16);
  --indigo: #9aa8ff;
  --indigo-dim: rgba(154, 168, 255, 0.16);
  --danger: #ef7a6c;
  --danger-dim: rgba(239, 122, 108, 0.16);
  --ok: #7ed9a0;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.28);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: Inter, "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --sidebar: 280px;
  --top: 58px;
  --radius: 12px;
  --radius-sm: 9px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 0.32s;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { color-scheme: dark; }
body {
  margin: 0;
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(228, 177, 90, 0.06), transparent 50%),
    radial-gradient(700px 400px at 100% 0%, rgba(74, 212, 196, 0.04), transparent 46%),
    var(--bg);
  color: var(--text);
  font: 14.5px/1.45 var(--sans);
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: page-enter var(--dur) var(--ease);
}

/* ---------- top bar ---------- */
.topbar {
  min-height: var(--top);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 21, 28, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
  z-index: 20;
}
.btn.menu-btn { display: none; }
.btn.icon {
  width: 40px;
  padding: 0;
  justify-content: center;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 0; }
.mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(145deg, var(--gold-2) 0%, #c4892e 100%);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 8px 18px rgba(228,177,90,0.28);
  position: relative;
}
.mark::after {
  content: "";
  position: absolute; inset: 7px 8px 7px 8px;
  background: #141922;
  clip-path: polygon(0 0, 38% 0, 50% 46%, 62% 0, 100% 0, 100% 100%, 72% 100%, 72% 38%, 50% 86%, 28% 38%, 28% 100%, 0 100%);
}
.brand-name { font-weight: 650; letter-spacing: -0.02em; font-size: 15px; }
.brand-sub {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ver {
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.searchwrap {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 14, 18, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), color 0.2s;
}
.searchwrap:focus-within {
  border-color: rgba(228, 177, 90, 0.45);
  color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
.searchwrap input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  height: 36px;
  color: var(--text);
  min-width: 0;
}
.searchwrap input::placeholder { color: var(--muted); }
.slash {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--muted);
}

.top-actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 13px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.01em;
  font-weight: 500;
  transition: background 0.18s var(--ease), border-color 0.18s, transform 0.18s var(--ease), box-shadow 0.18s;
}
.btn:hover { border-color: rgba(232,228,218,0.22); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-2) 0%, var(--gold) 100%);
  border-color: #c4892e;
  color: #1a1208;
  font-weight: 650;
  box-shadow: 0 6px 16px rgba(228, 177, 90, 0.22);
}
.btn.primary:hover { background: var(--gold-2); filter: brightness(1.04); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger-dim); border-color: rgba(239,122,108,0.35); color: #ffc4bc; }
.btn.danger:hover { background: #5a2420; }
.btn.tiny { height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- shell / sidebar ---------- */
.shell { display: flex; flex: 1; min-height: 0; position: relative; }
.sidebar-backdrop {
  display: none;
}
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: rgba(18, 21, 28, 0.92);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.hide-samples {
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0;
  text-transform: none;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}
.hide-samples input { accent-color: var(--gold); width: 16px; height: 16px; }

.stat-list { overflow: auto; flex: 1; padding: 8px 0 12px; }
.cat-label {
  padding: 14px 16px 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}
.stat-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 9px 12px 10px;
  margin: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  width: calc(100% - 16px);
  transition: background 0.2s var(--ease), border-color 0.2s, transform 0.2s var(--ease);
}
.stat-item:hover { background: var(--surface); }
.stat-item.active {
  background: var(--gold-dim);
  border-color: rgba(228, 177, 90, 0.32);
  box-shadow: inset 0 0 0 1px rgba(228,177,90,0.06);
}
.stat-item .name { font-weight: 600; color: var(--text); letter-spacing: -0.015em; }
.stat-item .key {
  grid-column: 1;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
}
.stat-item.active .key { color: #c9b08a; }
.pill {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 99px;
  font-size: 10px;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.pill.sample { background: var(--indigo-dim); color: var(--indigo); }
.side-empty { padding: 22px 16px; color: var(--muted); line-height: 1.5; }
.side-foot {
  padding: 10px 16px 14px;
  color: var(--muted);
  font-size: 11.5px;
  font-family: var(--mono);
  border-top: 1px solid var(--line);
  letter-spacing: 0.04em;
}

.main {
  flex: 1;
  min-width: 0;
  overflow: auto;
  background:
    radial-gradient(1100px 520px at 80% -16%, rgba(228,177,90,0.05), transparent 52%),
    transparent;
}

.hidden { display: none !important; }

/* ---------- empty ---------- */
.empty-board {
  max-width: 560px;
  margin: 10vh auto 0;
  padding: 0 28px 64px;
  animation: panel-enter 0.5s var(--ease);
}
.empty-visual {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 52px;
  margin-bottom: 22px;
  width: 168px;
}
.empty-visual span {
  flex: 1;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, var(--gold-2), var(--teal));
  opacity: 0.85;
  transform-origin: bottom;
  animation: bar-grow 0.7s var(--ease) both;
}
.empty-visual span:nth-child(1) { height: 18%; animation-delay: 0.02s; }
.empty-visual span:nth-child(2) { height: 28%; animation-delay: 0.06s; }
.empty-visual span:nth-child(3) { height: 40%; animation-delay: 0.10s; }
.empty-visual span:nth-child(4) { height: 48%; animation-delay: 0.14s; }
.empty-visual span:nth-child(5) { height: 60%; animation-delay: 0.18s; }
.empty-visual span:nth-child(6) { height: 72%; animation-delay: 0.22s; }
.empty-visual span:nth-child(7) { height: 84%; animation-delay: 0.26s; }
.empty-visual span:nth-child(8) { height: 100%; animation-delay: 0.30s; }
.empty-kicker {
  color: var(--gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
}
.empty-board h1 {
  font-size: clamp(26px, 4vw, 34px);
  margin: 10px 0 14px;
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.empty-board p { color: var(--text-dim); font-size: 15px; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 14px; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- detail / compare ---------- */
.detail, .compare-view {
  padding: 22px 26px 64px;
  max-width: 1120px;
  animation: panel-enter 0.42s var(--ease);
}
.detail-head, .compare-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.title-edit {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.03em;
  padding: 2px 10px 2px 0;
  width: min(560px, 100%);
  transition: border-color 0.2s, background 0.2s, padding 0.2s;
}
.title-edit:hover, .title-edit:focus {
  border-color: var(--line-2);
  background: var(--surface);
  outline: none;
  padding-left: 10px;
}
.keyline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; color: var(--muted); }
.keyline code {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.cat-edit, .desc-edit {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text-dim);
  min-width: 90px;
  transition: border-color 0.2s, background 0.2s;
}
.cat-edit:hover, .desc-edit:hover, .cat-edit:focus, .desc-edit:focus {
  border-color: var(--line-2); background: var(--surface); outline: none; color: var(--text);
}
.desc-edit { width: 100%; max-width: 760px; margin: 6px 0 16px; color: var(--text-dim); }
.detail-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.save-dot { color: var(--muted); font-size: 12px; min-width: 72px; text-align: right; }
.save-dot.ok { color: var(--ok); }
.save-dot.err { color: var(--danger); }

.curve-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  margin-bottom: 16px;
}
.curve-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 10px; gap: 12px; flex-wrap: wrap; }
.curve-row { display: grid; grid-template-columns: repeat(18, 1fr); gap: 4px; height: 58px; align-items: stretch; }
.curve-col {
  position: relative;
  background: #0e131a;
  border-radius: 4px;
  overflow: hidden;
}
.curve-col .seg {
  position: absolute;
  left: 0; right: 0;
  background: linear-gradient(180deg, var(--gold-2), var(--teal));
  opacity: 0.95;
  border-radius: 3px;
  transition: top 0.45s var(--ease), height 0.45s var(--ease);
}
.curve-col .tn {
  position: absolute; bottom: 2px; left: 0; right: 0;
  text-align: center; font-size: 9px; color: var(--muted); font-family: var(--mono);
}

/* fill / scale tools */
.tools-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(240px, 0.7fr);
  gap: 0;
  background:
    linear-gradient(180deg, rgba(228,177,90,0.09) 0%, rgba(24,28,37,0.94) 44%),
    var(--surface);
  border: 1px solid rgba(228,177,90,0.28);
  border-radius: var(--radius);
  margin: 4px 0 18px;
  box-shadow: 0 0 0 1px var(--gold-dim), var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.4s var(--ease), border-color 0.4s;
}
.tools-panel.just-applied {
  animation: confirm-flash 0.75s var(--ease);
  border-color: rgba(126, 217, 160, 0.5);
}
.tools-fill, .tools-scale { padding: 16px 18px 18px; }
.tools-scale {
  border-left: 1px solid rgba(228,177,90,0.18);
  background: rgba(0,0,0,0.12);
}
.tools-kicker {
  color: var(--gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 4px;
}
.tools-lead {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 13px;
  max-width: 52ch;
}
.apply-confirm {
  display: inline-block;
  margin-left: 8px;
  color: var(--ok);
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s, transform 0.25s var(--ease);
}
.apply-confirm.show {
  opacity: 1;
  transform: none;
}
.tools-grid .apply-confirm {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  min-height: 1.2em;
}
.tools-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr)) minmax(148px, 1.1fr) auto;
  gap: 10px 12px;
  align-items: end;
}
.scale-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 12px;
  align-items: end;
  max-width: 280px;
}
.tool-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tool-field > span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}
.tool-in {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
select.tool-in {
  font-family: var(--sans);
  font-size: 13.5px;
  appearance: auto;
  cursor: pointer;
}
.tool-in:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
.tool-apply .btn { height: 38px; white-space: nowrap; }

/* ---------- table ---------- */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
}
.tiers {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  min-width: 640px;
}
.tiers th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
  font-weight: 600;
}
.tiers td { padding: 7px 10px; border-bottom: 1px solid rgba(232,228,218,0.04); vertical-align: middle; }
.tiers tbody tr {
  transition: background 0.2s var(--ease);
}
.tiers tbody tr:hover td { background: rgba(255,255,255,0.018); }
.tiers tbody tr:focus-within td,
.tiers tbody tr.row-on td {
  background: rgba(228, 177, 90, 0.06);
}
.tiers .tnum {
  font-family: var(--mono);
  color: var(--muted);
  width: 48px;
  font-weight: 600;
}
.cell-in {
  width: 112px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.cell-in:focus { outline: 0; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
.cell-in.bad { border-color: var(--danger); background: var(--danger-dim); }
.span-val { font-family: var(--mono); color: var(--text-dim); width: 88px; }

.bar-track {
  position: relative;
  height: 18px;
  background: #0e131a;
  border: 1px solid var(--line);
  border-radius: 99px;
  min-width: 220px;
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  top: 2px; bottom: 2px;
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(74,212,196,0.65), rgba(228,177,90,0.95));
  min-width: 2px;
  transition: left 0.45s var(--ease), width 0.45s var(--ease);
}
.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--mono);
  color: #f4f7fb;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.banner {
  background: var(--indigo-dim);
  border: 1px solid rgba(154,168,255,0.22);
  color: #c9d2fb;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 13.5px;
  animation: panel-enter 0.4s var(--ease);
}

.compare-grid { display: grid; gap: 8px; }
.cmp-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: center;
}
.cmp-bars { position: relative; height: 30px; background: #0e131a; border: 1px solid var(--line); border-radius: 8px; }
.cmp-fill {
  position: absolute;
  top: 4px;
  height: 8px;
  border-radius: 99px;
  opacity: 0.92;
  transition: left 0.45s var(--ease), width 0.45s var(--ease);
}
.cmp-fill.a { background: var(--teal); top: 5px; }
.cmp-fill.b { background: var(--gold); top: 16px; }
.legend { display: flex; gap: 16px; color: var(--text-dim); margin: 8px 0 14px; font-size: 13.5px; flex-wrap: wrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.swatch.a { background: var(--teal); }
.swatch.b { background: var(--gold); }

/* ---------- modals ---------- */
.modal {
  border: 1px solid var(--line-2);
  background: #161c26;
  color: var(--text);
  border-radius: 16px;
  padding: 0;
  width: min(500px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}
.modal.wide { width: min(740px, calc(100vw - 28px)); }
.modal::backdrop { background: rgba(6, 7, 10, 0.72); backdrop-filter: blur(6px); }
.modal[open] { animation: modal-in 0.28s var(--ease); }
.modal[open]::backdrop { animation: fade-in 0.22s ease; }
.modal form { display: flex; flex-direction: column; gap: 14px; padding: 22px 22px 18px; }
.modal header h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.02em; }
.modal header p { margin: 0; color: var(--text-dim); }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.field em { font-style: normal; color: var(--gold); font-size: 11px; margin-left: 6px; }
.field input, .field select, .modal textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus, .modal textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
.modal textarea {
  min-height: 180px;
  font-family: var(--mono);
  font-size: 12.5px;
  resize: vertical;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fmt { color: var(--text-dim); font-size: 13.5px; }
.fmt ul { margin: 8px 0 0; padding-left: 18px; }
.warn { color: #ffb4ac !important; }
.preview {
  background: #0c1016;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  max-height: 160px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
}
#add-key-hint { color: var(--muted); }
#add-key-hint.bad { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
  animation: toast-in 0.32s var(--ease);
  max-width: min(360px, calc(100vw - 32px));
}
.toast.err { border-color: rgba(239,122,108,0.45); }

/* ---------- motion ---------- */
@keyframes page-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes panel-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes bar-grow {
  from { transform: scaleY(0.2); opacity: 0; }
  to { transform: none; opacity: 0.85; }
}
@keyframes confirm-flash {
  0% { box-shadow: 0 0 0 1px rgba(126,217,160,0.45), 0 0 28px rgba(126,217,160,0.22); }
  100% { box-shadow: 0 0 0 1px var(--gold-dim), var(--shadow-sm); }
}
@keyframes drawer-in {
  from { transform: translateX(-105%); }
  to { transform: translateX(0); }
}

/* ========== Breakpoints ==========
   Candybar / phone:        max-width 599px
   Fold / compact tablet:   600px–1199px  (Z Fold 2 inner, portrait + landscape)
   Desktop:                 min-width 1200px
   Dual-segment (optional): if horizontal-viewport-segments: 2, keep width layout
*/
.main { container-type: inline-size; container-name: board; }
.tools-fill { container-type: inline-size; }

/* Fill-curve fields wrap when the fill column (not the viewport) is tight */
@container (max-width: 480px) {
  .tools-grid {
    grid-template-columns: repeat(2, minmax(64px, 1fr));
    gap: 8px 10px;
  }
  .tool-apply { grid-column: 1 / -1; }
  .tools-grid .apply-confirm { grid-column: 1 / -1; }
}

/* Sticky first column on real tables (fold + desktop). Candybar uses cards. */
@media (min-width: 600px) {
  .tiers th:first-child,
  .tiers td.tnum {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg);
    box-shadow: 6px 0 8px -6px rgba(0, 0, 0, 0.55);
  }
  .tiers th:first-child { z-index: 3; }
  .tiers tbody tr:hover td.tnum { background: #141820; }
  .tiers tbody tr:focus-within td.tnum,
  .tiers tbody tr.row-on td.tnum { background: #1c1912; }
}

/* ---------- Fold / compact tablet: 600–1199 (Z Fold 2 inner) ---------- */
@media (min-width: 600px) and (max-width: 1199px) {
  :root { --sidebar: 220px; }
  body { font-size: 13.5px; }
  .slash { display: none; }
  .topbar {
    gap: 8px 10px;
    padding: 6px 12px;
    flex-wrap: wrap;
  }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .brand-name { font-size: 14.5px; }
  .searchwrap {
    max-width: 260px;
    flex: 1 1 140px;
  }
  .searchwrap input { height: 34px; }
  .btn { height: 34px; padding: 0 11px; }
  .btn.tiny { height: 32px; padding: 0 9px; font-size: 12.5px; }
  .btn.icon { width: 36px; }
  .btn.menu-btn { display: none; }

  .sidebar {
    width: var(--sidebar);
    position: relative;
    transform: none;
    box-shadow: none;
  }
  .side-head {
    padding: 10px 10px;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 10.5px;
  }
  .hide-samples { font-size: 12px; gap: 6px; }
  .stat-item {
    padding: 7px 8px 8px;
    margin: 1px 6px;
    width: calc(100% - 12px);
    gap: 2px 6px;
  }
  .stat-item .name { font-size: 13px; }
  .stat-item .key { font-size: 10.5px; }
  .cat-label { padding: 12px 12px 4px; font-size: 10px; }
  .side-foot { padding: 8px 12px 12px; font-size: 11px; }

  .detail, .compare-view {
    padding: 14px 14px 48px;
    max-width: none;
  }
  .title-edit { font-size: 22px; width: min(420px, 100%); }
  .desc-edit { max-width: none; margin: 4px 0 12px; }

  .tools-panel {
    grid-template-columns: minmax(0, 1.4fr) minmax(168px, 0.62fr);
    margin: 2px 0 14px;
  }
  .tools-fill, .tools-scale { padding: 12px 12px 14px; }
  .tools-lead { font-size: 12.5px; margin-bottom: 10px; }
  .tools-kicker { font-size: 11px; }
  .scale-row { max-width: none; }
  .tool-in { padding: 6px 8px; font-size: 12.5px; }
  .tool-apply .btn { height: 34px; }

  .curve-strip { padding: 10px 12px 8px; margin-bottom: 12px; }
  .curve-row { height: 48px; gap: 3px; }
  .curve-col .tn { font-size: 8px; }

  .tiers { min-width: 560px; }
  .tiers th { padding: 8px 8px; font-size: 10.5px; }
  .tiers td { padding: 5px 8px; }
  .cell-in { width: 92px; padding: 6px 8px; font-size: 12.5px; }
  .bar-track { min-width: 148px; height: 16px; }
  .span-val { width: 64px; font-size: 12.5px; }

  .compare-grid { gap: 6px; }
  .cmp-row { grid-template-columns: 32px 1fr; gap: 8px; }
  .cmp-bars { height: 26px; }
}

/* Wider slim rail in the upper fold band (portrait). Landscape overrides below. */
@media (min-width: 900px) and (max-width: 1199px) and (orientation: portrait) {
  :root { --sidebar: 232px; }
  .searchwrap { max-width: 300px; }
  .tools-panel {
    grid-template-columns: minmax(0, 1.55fr) minmax(180px, 0.55fr);
  }
}

/* Landscape Fold inner: same chrome, more table / compare width */
@media (min-width: 600px) and (max-width: 1199px) and (orientation: landscape) {
  :root { --sidebar: 208px; }
  .searchwrap { max-width: 340px; }
  .banner { padding: 7px 12px; margin-bottom: 8px; font-size: 12.5px; }
  .detail, .compare-view { padding: 10px 12px 28px; }
  .title-edit { font-size: 20px; }
  .desc-edit { margin: 2px 0 8px; }
  .tools-panel { margin: 0 0 8px; }
  .tools-fill, .tools-scale { padding: 8px 10px 10px; }
  .tools-lead { font-size: 12px; margin-bottom: 6px; }
  .curve-strip { padding: 8px 10px 6px; margin-bottom: 8px; }
  .curve-row { height: 36px; }
  .compare-grid {
    display: grid;
    grid-template-rows: repeat(9, auto);
    grid-auto-flow: column;
    gap: 6px 18px;
  }
}

/* ---------- Candybar / phone: ≤599 ---------- */
@media (max-width: 599px) {
  :root { --top: auto; --sidebar: 280px; }
  .btn.menu-btn { display: inline-flex; width: 44px; height: 44px; }
  .slash { display: none; }
  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 8px 10px;
  }
  .brand { min-width: 0; }
  .brand-name { font-size: 14.5px; }
  .searchwrap {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    border-radius: 12px;
  }
  .searchwrap input { height: 44px; }
  .top-actions {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .btn { height: 44px; padding: 0 14px; min-width: 44px; }
  .btn.tiny { height: 44px; padding: 0 12px; }
  .hide-samples { min-height: 44px; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(6, 7, 10, 0.58);
    z-index: 24;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease);
  }
  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.32s var(--ease);
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  .stat-item {
    min-height: 44px;
    padding: 11px 14px;
    align-items: center;
  }
  body.drawer-open { overflow: hidden; }

  .detail, .compare-view { padding: 16px 14px 80px; }
  .detail-head, .compare-head { flex-direction: column; align-items: stretch; }
  .detail-actions { width: 100%; }
  .title-edit { font-size: 22px; width: 100%; }
  .empty-board { margin-top: 6vh; padding: 0 20px 48px; }
  .row2 { grid-template-columns: 1fr; }
  .bar-track { min-width: 140px; }
  .modal footer .btn { min-height: 44px; }
  .field input, .field select { min-height: 44px; }
  .tool-in { min-height: 44px; }
  .tool-apply .btn { height: 44px; width: 100%; }
  .curve-row { height: 48px; gap: 3px; }

  /* stacked tools (not a 2-col row) */
  .tools-panel { grid-template-columns: 1fr; margin: 8px 0 20px; }
  .tools-scale { border-left: 0; border-top: 1px solid rgba(228,177,90,0.18); }
  .tools-grid { grid-template-columns: repeat(2, 1fr); }
  .tool-apply { grid-column: 1 / -1; }
  .scale-row { max-width: none; }
  .tools-fill, .tools-scale { padding: 16px 14px 18px; }

  /* 18-tier table as min/max cards */
  .table-scroll { overflow: visible; }
  .tiers { min-width: 0; }
  .tiers thead { display: none; }
  .tiers, .tiers tbody { display: block; width: 100%; }
  .tiers tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    align-items: end;
  }
  .tiers td {
    padding: 0;
    border: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .tiers td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 600;
  }
  .tiers .tnum {
    grid-column: 1 / -1;
    width: auto;
    font-size: 14px;
    color: var(--text);
    flex-direction: row;
    align-items: center;
    gap: 8px;
    position: static;
    box-shadow: none;
    background: transparent;
  }
  .tiers .tnum::before { content: none; }
  .tiers td.window-cell,
  .tiers td.span-cell { grid-column: 1 / -1; }
  .cell-in { width: 100%; min-height: 44px; font-size: 16px; }
  .bar-track { min-width: 0; width: 100%; height: 22px; }
  .span-val { width: auto; font-size: 14px; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
}

/* Dual-segment viewports (Surface Duo, etc.): do not hinge-span.
   Z Fold 2 inner is one flexible display — width + orientation already cover it. */
@media (horizontal-viewport-segments: 2) {
  .shell { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .empty-visual span { opacity: 0.85; transform: none; }
}
