:root {
  --bg: #0f1115;
  --bg-elev-1: #171a21;
  --bg-elev-2: #1c212b;
  --bg-elev-3: #222936;
  --text: #e8edf6;
  --muted: #9aa6bb;
  --primary: #86b7ff;
  --primary-2: #a98cff;
  --good: #7ddc9d;
  --warn: #ffd27a;
  --bad: #ff8f95;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 12px 30px rgba(0,0,0,0.28);
  --radius: 18px;
  --field: #131821;
  --field-2: #101521;
  --track: #182033;
  --tooltip-show-delay: 0.8s;
}

* { box-sizing: border-box; }
html {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}
html, body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
  margin: 0;
  padding: 20px 12px;
  min-height: 100dvh;
}

.app-footer {
  position: fixed;
  left: 16px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  opacity: 0.55;
  z-index: 1;
}

.app-footer-sep {
  opacity: 0.7;
}

.app-footer-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.app-footer-link:hover,
.app-footer-link:focus-visible {
  color: var(--text);
  opacity: 1;
}

.app {
  width: min(1500px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

.hero, .panel, .result-card {
  background: linear-gradient(180deg, var(--bg-elev-2), var(--bg-elev-1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 24px 24px 18px;
  display: grid;
  gap: 10px;
  background:
    radial-gradient(circle at top right, rgba(169,140,255,0.18), transparent 32%),
    radial-gradient(circle at top left, rgba(134,183,255,0.16), transparent 28%),
    linear-gradient(180deg, #1a1d26, #12161e);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 700; letter-spacing: 0.2px; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.subtle { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  align-items: start;
}

.grid > aside.panel {
  position: sticky;
  top: 20px;
  align-self: start;
}

.panel { padding: 18px; display: grid; gap: 18px; }
.section { display: grid; gap: 10px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-stack {
  display: grid;
  gap: 6px;
  align-content: start;
}

.field label,
.label-row {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.label-value {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.field input[type="number"],
.field textarea {
  width: 100%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 13px;
  outline: none;
  transition: 140ms ease;
  font: inherit;
}

.number-input {
  position: relative;
  display: grid;
}

.number-input input[type="number"] {
  padding-right: 40px;
  -moz-appearance: textfield;
}

.number-input input[type="number"]::-webkit-outer-spin-button,
.number-input input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-spin {
  position: absolute;
  right: 7px;
  top: 7px;
  bottom: 7px;
  display: flex;
  flex-direction: column;
  width: 22px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}

.number-spin-btn {
  flex: 1;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: 140ms ease;
}

.number-spin-btn + .number-spin-btn {
  border-top: 1px solid var(--border);
}

.number-spin-btn:hover {
  color: var(--text);
  background: rgba(134,183,255,0.10);
}

.number-spin-btn:active {
  background: rgba(134,183,255,0.16);
}

.number-spin-btn::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.number-spin-btn[data-dir="up"]::before {
  border-bottom: 5px solid currentColor;
}

.number-spin-btn[data-dir="down"]::before {
  border-top: 5px solid currentColor;
}

.number-warning {
  position: absolute;
  right: 36px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--muted);
  cursor: help;
  pointer-events: auto;
  transition: color 140ms ease;
}

.number-warning:hover,
.number-warning:focus-visible {
  color: var(--text);
}

.number-input.has-warning .number-warning {
  display: flex;
}

.number-input.has-warning input[type="number"] {
  padding-right: 62px;
}

.number-warning svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.field input[type="number"]:focus,
.field textarea:focus {
  border-color: rgba(134,183,255,0.55);
  box-shadow: 0 0 0 4px rgba(134,183,255,0.10);
}

.distribution-grid {
  display: grid;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--field-2);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.segmented button {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  box-shadow: none;
}

.segmented button.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(134,183,255,0.18), rgba(169,140,255,0.14));
  border-color: rgba(134,183,255,0.24);
}

.bias-wrap {
  display: grid;
  gap: 3px;
}

.bias-wrap + .bias-wrap {
  margin-top: 10px;
}

.slider-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.slider-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: -4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  box-shadow: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: linear-gradient(90deg, rgba(134,183,255,0.35), rgba(169,140,255,0.35));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #dce9ff, #9dc0ff);
  border: 2px solid #0c1220;
  box-shadow: 0 0 0 5px rgba(134,183,255,0.12), 0 2px 10px rgba(0,0,0,0.35);
}

input[type="range"]::-moz-range-track {
  height: 8px;
  background: linear-gradient(90deg, rgba(134,183,255,0.35), rgba(169,140,255,0.35));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #dce9ff, #9dc0ff);
  border: 2px solid #0c1220;
  box-shadow: 0 0 0 5px rgba(134,183,255,0.12), 0 2px 10px rgba(0,0,0,0.35);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--field);
  border: 1px solid var(--border);
}

.checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: #0f1523;
  position: relative;
  display: inline-block;
  cursor: pointer;
  transition: 140ms ease;
  flex: 0 0 auto;
  vertical-align: middle;
}

.checkbox::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  transform: translate(-50%, -50%) scale(0);
  transition: 140ms ease;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 10px rgba(134,183,255,0.3);
}

.checkbox:checked {
  border-color: rgba(134,183,255,0.45);
  background: rgba(134,183,255,0.10);
}

.checkbox:checked::after { transform: translate(-50%, -50%) scale(1); }

.match-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
  min-height: 18px;
  user-select: none;
  margin-top: 2px;
}

.match-toggle .checkbox {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.match-toggle .checkbox::after {
  width: 7px;
  height: 7px;
  border-radius: 2px;
}

.actions {
  display: grid;
  gap: 10px;
}

button {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: 140ms ease;
}

button:disabled {
  cursor: default;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #0b1020;
  box-shadow: 0 10px 25px rgba(134,183,255,0.22);
}

.btn-primary:hover { transform: translateY(-1px); }

.btn-secondary {
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-inline {
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  font-weight: 650;
  line-height: 1;
}

.btn-inline:hover {
  color: var(--text);
  transform: none;
}

.results {
  display: grid;
  gap: 18px;
  align-content: start;
}

.result-list {
  display: grid;
  gap: 18px;
}

.result-card {
  padding: 18px;
  display: grid;
  gap: 16px;
  margin: 0;
}

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  align-items: start;
}

.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
}

.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }

table {
  width: 100%;
  border-collapse: collapse;
  overflow: visible;
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.25px;
  text-transform: uppercase;
  background: rgba(255,255,255,0.02);
}

tr:last-child td { border-bottom: none; }

.gm-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.gearbox-matrix {
  display: grid;
  grid-template-columns: max-content repeat(var(--gm-cols), 82px) max-content;
  justify-content: start;
  align-items: center;
  gap: 6px;
  min-width: max-content;
}

.gm-rowlabel {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
  padding-right: 6px;
  white-space: nowrap;
}

.gm-io {
  align-self: center;
}

.gm-output {
  text-align: left;
  padding-right: 0;
  padding-left: 6px;
}

.gm-pad {
  width: 0;
}

.gm-ratio {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.gm-box {
  display: grid;
  place-items: center;
  padding: 2px 0;
}

.gm-box-img {
  width: 100%;
  max-width: 96px;
  height: auto;
  display: block;
}

.gm-box-img.gm-flip {
  transform: scaleX(-1);
}

.gm-state-cell {
  display: grid;
  place-items: center;
  background: #fff;
  padding: 3px;
  margin: 3px;
  width: 100%;
  max-width: 76px;
}

.gm-state {
  width: 100%;
  aspect-ratio: 3 / 1;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.gm-gear-ratio {
  text-align: left;
  padding-left: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.gm-state.on {
  background: #ff1f1f;
}

.gm-state.off {
  background: #3a1414;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }

.target-header {
  display: grid;
  gap: 4px;
}

.target-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.target-edit-hint {
  margin-right: 60px;
  text-align: right;
}

.target-bar {
  gap: 10px;
  padding: 18px;
}

main.results > .target-bar {
  -webkit-user-select: none;
  user-select: none;
}

main.results > .target-bar #targetMeta,
main.results > .target-bar .target-edit-hint,
main.results > .target-bar [data-target-value] {
  -webkit-user-select: text;
  user-select: text;
}

.result-card .target-bar {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
}

.bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 96px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}

.fit-preview-header,
.fit-bar-row {
  display: grid;
  grid-template-columns: 56px minmax(120px, 1fr) repeat(3, minmax(58px, max-content));
  gap: 10px;
  align-items: center;
}

.fit-preview-header {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.25px;
  text-transform: uppercase;
}

.fit-preview-header > div:nth-child(n + 3),
.fit-bar-row > div:nth-child(n + 3) {
  text-align: left;
}

.bar-track {
  position: relative;
  height: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
}

.bar-target,
.bar-actual {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.bar-target {
  background: linear-gradient(90deg, rgba(169,140,255,0.55), rgba(134,183,255,0.9));
  opacity: 0.75;
}

#targetBars .bar-track {
  cursor: pointer;
  overflow: visible;
}

#targetBars .bar-target {
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

#targetBars .bar-track:hover .bar-target,
#targetBars .bar-target:focus-visible {
  background: linear-gradient(90deg, #dce9ff, #9dc0ff);
  box-shadow: 0 0 0 5px rgba(134,183,255,0.12), 0 2px 10px rgba(0,0,0,0.35);
  opacity: 1;
  outline: none;
}

.bar-actual {
  background: rgba(125,220,157,0.90);
  box-shadow: 0 0 14px rgba(125,220,157,0.28);
  height: 6px;
  top: 3px;
  bottom: 3px;
}

.empty {
  padding: 0;
  text-align: center;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 12px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.empty button {
  min-width: 260px;
}

@media (max-width: 1120px) {
  .grid { grid-template-columns: 1fr; }

  .grid > aside.panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .field-grid, .actions { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 60px 1fr 88px; }
  .target-edit-hint { margin-right: 52px; }
  .fit-preview-header,
  .fit-bar-row {
    grid-template-columns: 44px minmax(90px, 1fr) repeat(3, minmax(42px, max-content));
    gap: 8px;
  }
  .hero { padding: 20px; }
  .panel, .result-card { padding: 16px; }
  h1 { font-size: 25px; }
}

.app-toast {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 1000;
  width: min(360px, calc(100vw - 40px));
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  background: linear-gradient(180deg, var(--bg-elev-3), var(--bg-elev-2));
  border: 1px solid rgba(125, 220, 157, 0.28);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  overflow: hidden;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.app-toast-search {
  border-color: rgba(134, 183, 255, 0.32);
}

.app-toast-visible {
  opacity: 1;
  pointer-events: auto;
}

.app-toast-hide {
  opacity: 0;
  pointer-events: none;
}

.app-toast-title {
  font-weight: 650;
  color: var(--good);
}

.app-toast-search .app-toast-title {
  color: var(--primary);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-toast-spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(134, 183, 255, 0.25);
  border-top-color: var(--primary);
  animation: app-toast-spin 0.7s linear infinite;
}

@keyframes app-toast-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .app-toast-spinner {
    animation-duration: 1.6s;
  }
}

.app-toast-body {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.app-toast-dismiss {
  justify-self: start;
  margin-top: 2px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.app-toast-dismiss:hover {
  background: rgba(255, 255, 255, 0.08);
}

.app-toast-timeout {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(125, 220, 157, 0.18);
}

.app-toast-search .app-toast-timeout {
  background: rgba(134, 183, 255, 0.18);
}

.app-toast-timeout-bar {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--good);
  transform-origin: right center;
  animation: app-toast-timeout var(--app-toast-duration, 3s) linear forwards;
}

.app-toast-search .app-toast-timeout-bar {
  background: var(--primary);
}

.app-toast-reset {
  border-color: rgba(255, 210, 122, 0.28);
}

.app-toast-reset .app-toast-title {
  color: var(--warn);
}

.app-toast-reset .app-toast-timeout {
  background: rgba(255, 210, 122, 0.18);
}

.app-toast-reset .app-toast-timeout-bar {
  background: var(--warn);
}

@keyframes app-toast-timeout {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.has-tooltip {
  cursor: help;
}

#app-tooltip {
  position: fixed;
  z-index: 10000;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  white-space: normal;
  text-align: left;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

#app-tooltip.app-tooltip-visible {
  opacity: 1;
  visibility: visible;
}
