:root {
  --bg: #0F1115;
  --card: #151922;
  --elev: #1B2230;
  --mut: #9AA4B2;
  --text: #E9EEF5;

  --accent: #1E66D9;
  /* blue */
  --danger: #CF2525;
  /* waste (unused) */
  --success: #24BB45;
  /* cuts */
  --warn: #D4CB24;
  /* warnings */
  --leftover: #D0D5DD;
  /* neutral leftover */
  --ring: rgba(30, 102, 217, .35);
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial;
  color: var(--text);
  background: var(--bg);
  position: relative;
  font-size: 16px;
}

/* ---- FIX background artifact: draw glow on a fixed layer ---- */
body::before {
  content: "";
  position: fixed;
  /* stays put while scrolling */
  inset: -25% -10% -25% -10%;
  z-index: -1;
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(30, 102, 217, .25), transparent 60%),
    radial-gradient(900px 500px at 85% 110%, rgba(36, 187, 69, .18), transparent 60%);
  filter: blur(0.3px);
  pointer-events: none;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px;
}

/* Golden ratio: 1.618 */
.top h1 {
  margin: 0 0 4px;
  font-size: 26px;
}

.mut {
  color: var(--mut);
}

.inputs-card {
  margin-bottom: 0;
}

.card {
  background: linear-gradient(180deg, var(--card), var(--elev));
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, .25);
}

.card.visual {
  margin-top: 16px;
}

.viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.viz-header .card-title {
  margin-bottom: 0;
}

.inputs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.inputs-header .card-title {
  margin-bottom: 0;
  font-size: 26px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 26px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--mut);
  user-select: none;
}

.toggle .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.toggle .slider {
  width: 38px;
  height: 22px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  position: relative;
  transition: 0.3s;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--mut);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked+.slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked+.slider::after {
  background: #fff;
  transform: translateX(16px);
}

.toggle input.sr-only:focus-visible+.slider {
  box-shadow: 0 0 0 3px var(--ring);
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.label {
  font-size: 13px;
  color: var(--mut);
}

input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0d111a;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, .08);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-size: 18px;
}

input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

.cuts-head {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--mut);
  font-size: 15px;
}

.cuts {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.cut-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cut-row input.qty {
  width: 72px;
  font-size: 18px;
}

.cut-row input.len {
  width: 88px;
  font-size: 18px;
}

/* Remove button gets an icon */
.cut-row .remove {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.cut-row .remove::before {
  content: "";
  width: 14px;
  height: 14px;
  display: inline-block;
  background: currentColor;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>') no-repeat center / contain;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>') no-repeat center / contain;
}

/* Hover state ONLY for the remove button: danger red */
.cut-row .remove:hover {
  background: var(--danger);
  /* #CF2525 */
  border-color: var(--danger);
  color: #fff;
}

/* Buttons + icons */
.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .12);
  background: #0f1420;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}

.btn .ico {
  width: 18px;
  height: 18px;
  display: inline-flex;
}

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

.btn:hover {
  background: #121a2a;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring);
}

.btn.ghost {
  background: transparent;
}

.cta {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}

.btn.highlight-pulse {
  animation: pulse-ring 2s infinite;
  border-color: var(--accent);
  color: #fff;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 var(--ring);
  }

  70% {
    box-shadow: 0 0 0 10px transparent;
  }

  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.export-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.export-wrap:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring);
  border-radius: 10px;
}

.export-warning {
  font-size: 13px;
  color: var(--warn);
  white-space: nowrap;
}


/* Bars */
#viz {
  margin-top: 8px;
  display: grid;
  gap: 14px;
}

.plate-title {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 20px;
}

.bar {
  position: relative;
  height: 36px;
  border-radius: 8px;
  overflow: visible;
  background: #0d111a;
  border: 1px solid rgba(255, 255, 255, .08);
  display: flex;
  flex-direction: row;
}

.seg:first-child {
  border-radius: 8px 0 0 8px;
}

.seg:last-child {
  border-radius: 0 8px 8px 0;
  border-right: none;
}

.seg:only-child {
  border-radius: 8px;
  border-right: none;
}

.seg {
  height: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
  line-height: 36px;
  font-size: 16px;
  color: #fff;
  border-right: 2px dashed rgba(0, 0, 0, .5);
}

.seg--vertical {
  writing-mode: vertical-lr;
  line-height: 1;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
}

.seg.cut {
  background: var(--success);
}

/* Default leftover = red */
.seg.leftover {
  background: var(--danger);
  color: #fff;
}

/* Special leftover (largest) = blue */
.seg.leftover-new {
  background: var(--accent);
  font-weight: 700;
}

/* Leftover segments carry an ✕ marker next to the size (matches the print) */
.seg.leftover::after,
.seg.leftover-new::after {
  content: " \2715";
}

/* Narrow leftover: keep only the ✕ in the bar, float the size above it.
   Reserve a fixed slot for the ✕ so it never gets squeezed out, even though
   that nudges the bar proportions slightly off. */
.seg.marker-only {
  overflow: visible;
  position: relative;
  min-width: 18px;
}

.seg.marker-only::after {
  content: "\2715";
}

.seg-above-label {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  writing-mode: vertical-lr;
  font-size: 12px;
  line-height: 1;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}

/* Make room above the bar for the floating size label */
.plate-row.has-above-label .bar {
  margin-top: 22px;
}

.legend {
  margin-top: 6px;
  color: var(--mut);
  font-size: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
}

.legend .box {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 6px;
  border: 1px solid rgba(0, 0, 0, .2);
}

.legend .box.success {
  background: var(--success);
}

.legend .box.leftover {
  background: var(--danger);
}

.legend .box.accent {
  background: var(--accent);
}

.foot {
  margin-top: 18px;
  font-size: 13px;
  text-align: center;
  color: var(--mut);
}

/* ---- Viz error / notice messages ---- */
.viz-error {
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(207, 37, 37, .15);
  border: 1px solid rgba(207, 37, 37, .4);
  color: #f87171;
  font-size: 14px;
}

.viz-notice {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(212, 203, 36, .12);
  border: 1px solid rgba(212, 203, 36, .35);
  color: var(--warn);
  font-size: 13px;
  margin-bottom: 4px;
}

/* ---- Mobile layout ---- */
@media (max-width: 600px) {
  .wrap {
    padding: 14px;
  }

  .row2 {
    grid-template-columns: 1fr;
  }

  .cuts-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .cut-row {
    flex-wrap: wrap;
  }

  .cut-row input.qty {
    width: 70px;
  }

  .cut-row input.len {
    width: 100%;
    flex: 1;
    min-width: 0;
  }

  .cut-row .remove {
    margin-left: 0;
  }

  .viz-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .export-wrap {
    flex-wrap: wrap;
  }
}