:root {
  --bg: #14100c;
  --panel: #313031;
  --panel-dark: #242324;
  --slot: #1a1917;
  --bevel-light: #6d6b66;
  --bevel-dark: #0c0b0a;
  --orange: #ffae42;
  --orange-dim: #e58a2a;
  --text: #e9e6dc;
  --text-dim: #b3ad9c;
  --green: #5b912e;
  --green-light: #79b53d;
  --danger: #b5462f;
  --font-ui: "Titillium Web", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(12, 9, 6, 0.78), rgba(12, 9, 6, 0.88)),
    url("./assets/bg-factorio.jpg") center center / cover fixed no-repeat,
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
}

.topbar {
  text-align: center;
  padding: 22px 16px 8px;
}
.topbar h1 {
  margin: 0;
  color: var(--orange);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 0 #000;
}
.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  max-width: 1080px;
  margin: 18px auto;
  padding: 0 16px;
  align-items: start;
}
@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.fz-panel {
  background: var(--panel);
  border-radius: 3px;
  padding: 16px;
  box-shadow:
    inset 2px 2px 0 var(--bevel-light),
    inset -2px -2px 0 var(--bevel-dark),
    0 3px 6px rgba(0, 0, 0, 0.5);
  margin-bottom: 16px;
}
.output-col .fz-panel:last-child {
  margin-bottom: 0;
}

.panel-title {
  color: var(--orange);
  font-weight: 600;
  margin-bottom: 10px;
}

.field {
  margin-bottom: 14px;
}
.field > label,
.field-head label {
  display: block;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.field small {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
}
.field code {
  background: var(--slot);
  padding: 0 4px;
  border-radius: 2px;
  color: var(--orange);
}
.row {
  display: flex;
  gap: 12px;
}
.row .field {
  flex: 1;
}
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

input[type="number"],
input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  background: var(--slot);
  color: var(--text);
  border: none;
  border-radius: 2px;
  padding: 8px 9px;
  font-family: inherit;
  font-size: 14px;
  box-shadow:
    inset 2px 2px 0 var(--bevel-dark),
    inset -1px -1px 0 #3a3937;
}
textarea {
  resize: vertical;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  word-break: break-all;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--orange-dim);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%23b3ad9c' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

input[type="color"] {
  width: 42px;
  height: 32px;
  padding: 2px;
  background: var(--slot);
  border: none;
  border-radius: 2px;
  box-shadow: inset 2px 2px 0 var(--bevel-dark);
}
input[type="range"] {
  accent-color: var(--orange);
  padding: 0;
  box-shadow: none;
  background: transparent;
}

.fz-btn {
  background: linear-gradient(180deg, var(--green-light), var(--green));
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 15px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.04s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.45);
}
.fz-btn:hover {
  filter: brightness(1.1);
}
.fz-btn:active {
  transform: translateY(1px);
  filter: brightness(0.95);
}
.fz-btn.small {
  padding: 5px 11px;
  font-size: 13px;
  border-radius: 3px;
}
/* Ghost destructive button: quiet by default, red on hover, so it doesn't dominate rows. */
.fz-btn.danger {
  background: var(--slot);
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  padding: 5px 10px;
  box-shadow: inset 0 0 0 1px var(--bevel-dark);
}
.fz-btn.danger:hover {
  background: var(--danger);
  color: #fff;
  filter: none;
}

.signal-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--slot);
  color: var(--text);
  border: none;
  border-radius: 2px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  box-shadow:
    inset 2px 2px 0 var(--bevel-dark),
    inset -1px -1px 0 #3a3937;
}
.signal-btn:hover {
  outline: 1px solid var(--orange-dim);
}
.signal-btn.small {
  flex: 1;
  padding: 5px 8px;
}

.dynamic-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.list-row {
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 2px;
}
.list-row.drag-over {
  outline: 2px dashed var(--orange-dim);
  outline-offset: 1px;
}
.drag-handle {
  flex: 0 0 auto;
  cursor: grab;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  user-select: none;
}
.drag-handle:active {
  cursor: grabbing;
}
input.pct-input {
  width: 64px;
  flex: 0 0 auto;
}
.unit {
  color: var(--text-dim);
  font-size: 13px;
  flex: 0 0 auto;
}

/* Signal icon chips */
.sig-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 2px;
  vertical-align: middle;
}
.sig-swatch {
  border: 1px solid rgba(0, 0, 0, 0.5);
}
.sig-glyph {
  background: #3b3a38;
  color: var(--text);
  font-weight: 700;
  font-family: "Consolas", monospace;
  border-radius: 2px;
}
.sig-sprite {
  background-repeat: no-repeat;
  image-rendering: auto;
}
.sig-emoji {
  background: #3b3a38;
  border-radius: 2px;
}
.sig-chip {
  background: #3b3a38;
  color: var(--orange);
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 2px;
}

/* Preview */
.preview-screen {
  background: #0d0c0b;
  border-radius: 3px;
  padding: 16px 14px;
  min-height: 60px;
  display: flex;
  align-items: center;
  box-shadow: inset 2px 2px 6px rgba(0, 0, 0, 0.7);
  margin-bottom: 12px;
  overflow-x: auto;
}
.gauge-line {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.gauge-bar {
  font-family: "DejaVu Sans Mono", "Consolas", monospace;
  font-size: 17px;
  letter-spacing: -0.5px;
}
.gauge-label {
  font-weight: 700;
  font-size: 16px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.copied {
  color: var(--green-light);
  font-weight: 600;
}

details summary {
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 600;
}

/* Picker modal */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.picker-panel {
  position: relative;
  width: min(560px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.picker-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}
.picker-close:hover {
  color: var(--orange);
}
.picker-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-right: 24px;
}
.picker-tab {
  background: var(--panel-dark);
  color: var(--text-dim);
  border: none;
  border-radius: 2px;
  padding: 6px 11px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
.picker-tab.active {
  background: var(--orange-dim);
  color: #1a1410;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 42px);
  gap: 5px;
  overflow-y: auto;
  padding: 4px;
  background: var(--slot);
  border-radius: 2px;
  box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.6);
  flex: 1;
  min-height: 120px;
}
.pick-cell {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2c2b29;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 1px 1px 0 #444, inset -1px -1px 0 #111;
}
.pick-cell:hover {
  outline: 2px solid var(--orange);
}
.picker-manual {
  display: flex;
  gap: 8px;
}
.picker-manual input {
  flex: 1;
}

.foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 16px;
}
.foot p {
  margin: 3px 0;
}
.foot a {
  color: var(--orange-dim);
}

/* Nav */
.topnav {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}
.topnav a {
  padding: 6px 14px;
  border-radius: 3px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  background: var(--panel);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
}
.topnav a.active {
  color: #1a1410;
  background: var(--orange);
}
.topnav a:hover:not(.active) {
  color: var(--orange);
}

/* Quality: setup controls */
.slot-count {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.slot-count.over {
  color: var(--danger);
}
.machine-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.machine-row select {
  flex: 1;
}
.row-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.row-inline input {
  width: 90px;
}
.module-row select {
  width: auto;
  flex: 1;
  min-width: 0;
  padding: 6px 26px 6px 8px;
  background-position: right 8px center;
}
.module-row .module-quality {
  flex: 0 0 auto;
  width: 108px;
}
input.count-input {
  width: 52px;
  flex: 0 0 auto;
}

/* Tier controls */
.tier-segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tier-btn {
  flex: 1;
  min-width: 70px;
  padding: 6px 4px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--slot);
  border-bottom: 3px solid var(--tier);
}
.tier-btn.active {
  color: #fff;
  background: var(--tier);
}
.tier-keep {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.keep-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 2px;
  background: var(--slot);
  border-left: 4px solid var(--tier);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

/* Quality: output */
.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.big-yield {
  display: flex;
  flex-direction: column;
}
.big-yield span {
  font-size: 34px;
  font-weight: 700;
  color: var(--orange);
  line-height: 1;
}
.big-yield small {
  color: var(--text-dim);
}
.chances {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}
.chances b {
  color: var(--text);
}
.yield-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.yield-table th {
  text-align: right;
  color: var(--text-dim);
  font-weight: 600;
  border-bottom: 1px solid var(--bevel-dark);
  padding: 4px 6px;
}
.yield-table th:first-child {
  text-align: left;
}
.yield-table td {
  padding: 5px 6px;
  border-bottom: 1px solid #2a2927;
}
/* Recycled tiers keep nothing — de-emphasize so kept tiers stand out. */
.yield-table tr.recycled-row td {
  color: var(--text-dim);
  opacity: 0.55;
}
.tier-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: -1px;
}
.yield-val {
  font-family: "Consolas", monospace;
  text-align: right;
}
.yield-tag {
  text-align: right;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
}
.yield-tag.keep {
  color: var(--green-light);
}
.yield-tag.recycle {
  color: var(--text-dim);
}

/* Tradeoff graph */
.graph-host {
  background: #0d0c0b;
  border-radius: 3px;
  padding: 6px;
  box-shadow: inset 2px 2px 6px rgba(0, 0, 0, 0.7);
}
.tradeoff-svg {
  width: 100%;
  height: auto;
  display: block;
}
.tradeoff-svg .axis {
  stroke: #55534e;
  stroke-width: 1;
}
.tradeoff-svg .grid {
  stroke: #24221f;
  stroke-width: 1;
}
.tradeoff-svg .tick {
  fill: var(--text-dim);
  font-size: 9px;
  font-family: var(--font-ui);
}
.tradeoff-svg .axis-label {
  fill: var(--text-dim);
  font-size: 9px;
  font-family: var(--font-ui);
}
.tradeoff-svg .line {
  stroke-width: 2;
}
.tradeoff-svg .best {
  fill: #fff;
  stroke: #000;
  stroke-width: 1;
}
.tradeoff-svg .current {
  fill: none;
  stroke: #fff;
  stroke-width: 1.5;
}

.rate-input {
  margin-bottom: 10px;
}
.rate-input label {
  color: var(--text-dim);
  font-weight: 600;
}
.rate-input input {
  width: 80px;
}

/* Carrier recommender */
.carrier-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.carrier-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--slot);
  color: var(--text);
  border: none;
  border-radius: 3px;
  padding: 5px 9px 5px 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  box-shadow: inset 1px 1px 0 #3a3937, inset -1px -1px 0 var(--bevel-dark);
}
.carrier-chip:hover {
  outline: 1px solid var(--orange-dim);
}
.carrier-chip small {
  color: var(--text-dim);
  font-size: 11px;
}

.recycle-out {
  margin-top: 12px;
}
.recycle-title {
  color: var(--orange);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}
.recycle-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  padding: 2px 0;
}

.machines-needed {
  margin-top: 12px;
}
.tier-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tier-inline select,
#machine-tier {
  width: auto;
  padding: 6px 26px 6px 8px;
  background-position: right 8px center;
}
.machine-row #machine-tier {
  flex: 0 0 auto;
  width: 120px;
}

/* Goal section: item vs raw-material mode */
.goal-modes {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.goal-mode {
  flex: 1;
  padding: 7px 10px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--slot);
  box-shadow: inset 1px 1px 0 var(--bevel-dark);
}
.goal-mode.active {
  color: #1a1410;
  background: var(--orange);
  box-shadow: none;
}
.goal-body {
  margin-bottom: 4px;
}
.upcycling-now {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 10px;
  background: var(--slot);
  border-radius: 3px;
  border-left: 3px solid var(--green-light);
  font-size: 13px;
  color: var(--text-dim);
}
#resolved-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-weight: 600;
}

.slot-warn {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 3px;
  background: rgba(181, 70, 47, 0.15);
  border-left: 3px solid var(--danger);
  color: #e8977f;
  font-size: 13px;
  font-weight: 600;
}

.feed-hint {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin: 2px 0 10px;
}

.machine-suggest {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 3px;
  background: rgba(255, 174, 66, 0.12);
  border-left: 3px solid var(--orange);
  font-size: 13px;
  color: var(--text);
}
.machine-suggest[hidden] {
  display: none;
}
.machine-suggest span:not(.sig-icon) {
  flex: 1;
}
