/* ==========================================================================
   Satisfactory Optimizer — fonts + theme tokens
   Cozy vendored UI font (Nunito, latin subset) — self-contained, no runtime
   CDN. Palette leans warm/industrial (Satisfactory pioneer-orange accent on
   warm-dark / warm-paper surfaces); ink stays high-contrast vs its surface.
   ========================================================================== */

@font-face { font-family: "Nunito"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/nunito-400.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 600; font-display: swap; src: url("../assets/fonts/nunito-600.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 700; font-display: swap; src: url("../assets/fonts/nunito-700.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 800; font-display: swap; src: url("../assets/fonts/nunito-800.woff2") format("woff2"); }

:root[data-theme="dark"] {
  --surface: #17181b;
  --surface-2: #202227;
  --border: #35383f;
  --ink: #f3f4f6;
  --ink-2: #bbc0c9;
  --ink-muted: #858c96;
  --accent: #ff9d42;
  --accent-ink: #17130b;
  --good: #5cc98a;
  --warning: #e6b23c;
  --critical: #e0655b;
}

:root[data-theme="light"] {
  --surface: #faf9f6;
  --surface-2: #efece6;
  --border: #e2ded6;
  --ink: #1d1a16;
  --ink-2: #514b42;
  --ink-muted: #897f73;
  --accent: #cf6f11;
  --accent-ink: #ffffff;
  --good: #2f8f57;
  --warning: #9a6b00;
  --critical: #c0392b;
}

/* ==========================================================================
   Base reset
   ========================================================================== */

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl {
  margin: 0 0 0.5rem 0;
}

ul,
ol {
  padding-left: 1.25rem;
}

button {
  font: inherit;
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

table {
  border-collapse: collapse;
}

/* ==========================================================================
   Header / footer
   ========================================================================== */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.site-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.theme-toggle {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--ink);
}

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

.site-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.site-footer p {
  margin: 0;
}

/* ==========================================================================
   App layout — sidebar + results grid
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

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

.sidebar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
}

.results {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  min-height: 200px;
}

/* ==========================================================================
   Stat tiles (.tiles / .tile)
   ========================================================================== */

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tile {
  flex: 1 1 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
}

.tile__label {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tile__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
}

/* ==========================================================================
   Meter (.meter / .meter__fill / .meter--binding)
   ========================================================================== */

.meter {
  position: relative;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.meter__fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Binding = resource fully consumed; always pair with a text/icon label
   in the markup, since color alone isn't CVD-distinct. */
.meter--binding .meter__fill {
  background: var(--warning);
}

/* ==========================================================================
   Build table (.build-table)
   ========================================================================== */

.build-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.build-table th,
.build-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.build-table th {
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.build-table tbody tr:hover {
  background: var(--surface-2);
}

/* ==========================================================================
   Belt list (.belt-list)
   ========================================================================== */

.belt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.belt-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

/* ==========================================================================
   Chip (.chip / .chip--saturated)
   ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--ink-2);
  white-space: nowrap;
}

/* Saturated = belt/pipe line at capacity; markup must include a text
   label or icon alongside this, color alone isn't CVD-distinct. */
.chip--saturated {
  border-color: var(--critical);
  color: var(--critical);
}

/* ==========================================================================
   Icons (.icon / .icon-fallback)
   ========================================================================== */

.icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 0.25rem;
  background: var(--surface);
  flex-shrink: 0;
}

.icon-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

/* ==========================================================================
   Status text (.good / .warning / .critical)
   Always pair with an icon or text label in markup — never rely on color
   alone to convey status.
   ========================================================================== */

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

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

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

/* ==========================================================================
   Hint text (.hint)
   Small static note, e.g. the "fluids not yet supported" note in Resources.
   ========================================================================== */

.hint {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ==========================================================================
   Form controls — modern, comfortable dark UI
   Controls are created as bare <input>/<select>/<button> (no classes), so
   they're themed by element selector scoped to .app / .sidebar. The combobox
   option buttons carry their own inline list-item styling and stay unaffected.
   ========================================================================== */

.sidebar { padding: 1.25rem; }

/* Text / number / search inputs and selects share one field look. */
.app input[type="text"],
.app input[type="number"],
.app input[type="search"],
.app select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.65rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.app input::placeholder { color: var(--ink-muted); }

.app input[type="text"]:hover,
.app input[type="number"]:hover,
.app input[type="search"]:hover,
.app select:hover { border-color: var(--ink-muted); }

.app input[type="text"]:focus-visible,
.app input[type="number"]:focus-visible,
.app input[type="search"]:focus-visible,
.app select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

/* Selects: custom chevron (the native one is gone via appearance:none). */
.app select {
  cursor: pointer;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%239aa3ad' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M1 1.5 6 6.5 11 1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
}

/* Checkboxes adopt the accent. */
.app input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* Buttons: base = a clear secondary. Combobox option buttons keep their inline
   transparent/borderless look, so they aren't turned into bordered buttons. */
.sidebar button:not(.search-option),
.results button {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.04s ease;
}

.sidebar button:not(.search-option):hover,
.results button:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.sidebar button:not(.search-option):active,
.results button:active { transform: translateY(1px); }

.sidebar button:not(.search-option):focus-visible,
.results button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

/* Primary action — Optimize. */
#optimize-btn {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}

#optimize-btn:hover {
  background: color-mix(in srgb, var(--accent) 88%, #fff);
  border-color: transparent;
}

/* Sidebar section headings become labelled dividers with breathing room. */
.sidebar h3 {
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.sidebar h3:first-child { margin-top: 0.25rem; }

/* Field label text (the caption above each control). */
.sidebar label > span:first-child { color: var(--ink-2); font-weight: 500; }

/* Alt-recipes <details>/<summary> disclosure. */
.sidebar summary {
  cursor: pointer;
  padding: 0.5rem 0;
  color: var(--ink-2);
  font-weight: 500;
  user-select: none;
}

.sidebar summary:hover { color: var(--ink); }

/* Searchable combobox popup + options. */
.search-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  max-height: 15rem;
  overflow-y: auto;
  padding: 0.25rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.search-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  background: transparent;
  border: none;
  border-radius: 0.4rem;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}

.search-option:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.search-empty {
  padding: 0.5rem 0.6rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* Resource card — a roomier two-row layout. */
.res-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  margin-bottom: 0.6rem;
  background: var(--surface);
}

.res-card__row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.res-card__nodes {
  display: flex;
  gap: 0.5rem;
}

.res-card__nodes > label {
  flex: 1 1 0;
  margin-bottom: 0 !important;
}

.res-card__rate {
  align-self: center;
  color: var(--ink-2);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Overclock control inside a resource card: header (label + editable %) then
   a full-width magnetic slider. */
.res-card__oc {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.res-card__oc-label {
  color: var(--ink-2);
  white-space: nowrap;
}

.res-card__oc-input {
  width: 4rem;
  margin-left: auto;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.res-card__oc-pct {
  color: var(--ink-2);
}

.res-card__oc-slider {
  display: block;
  width: 100%;
  margin: 0.2rem 0 0.1rem;
}

/* Themed range slider (used by the overclock control). */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

input[type="range"]:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 3px;
}

/* Maximize-mode target rows (item picker + weight + remove). */
.target-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

/* Alternate-recipe rows (checkbox + name): one per line, hover to pick. */
.alt-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border-radius: 0.35rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.alt-row:hover {
  background: var(--surface-2);
}

/* Notice that alternates are off by default. */
.alt-warning {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--warning);
}

/* Selected-item icon overlaid inside a searchable picker's input. */
.search-prefix {
  position: absolute;
  left: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.15rem;
  height: 1.15rem;
  object-fit: contain;
  pointer-events: none;
  border-radius: 3px;
}

/* Per-part rate chips (multi-target Maximize). */
.perpart {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1.25rem;
}

.perpart__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--ink-2);
}

/* Tiered SVG flow diagram. */
.diagram-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.5rem;
}

.diagram {
  display: block;
}

.diagram-box {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1;
}

.diagram-node--raw .diagram-box {
  stroke: var(--accent);
  stroke-width: 1.5;
}

/* Output/storage sink node — dashed green = "leaves the system". */
.diagram-node--output .diagram-box {
  stroke: var(--good);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
}

/* Surplus/byproduct sink — dashed amber = "leftover, not yet refined/used". */
.diagram-node--surplus .diagram-box {
  stroke: var(--warning);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
}

/* Input source node in a refinement mini-diagram. */
.diagram-node--input .diagram-box {
  stroke: var(--ink-muted);
}

/* Refinement options — a mini-diagram per leftover byproduct. */
.refine-group {
  margin: 0.25rem 0 1.5rem;
}

.refine-group__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.6rem;
}

.refine-option {
  margin-bottom: 0.9rem;
}

.refine-option__title {
  font-weight: 600;
  color: var(--ink-2);
  font-size: 0.9rem;
  margin: 0 0 0.35rem 0.15rem;
}


.diagram-title {
  fill: var(--ink);
  font: 700 12px "Nunito", system-ui, sans-serif;
}

.diagram-sub {
  fill: var(--ink-muted);
  font: 600 11px "Nunito", system-ui, sans-serif;
}

.diagram-edge {
  fill: none;
  stroke: var(--ink-muted);
  stroke-width: 1.5;
  opacity: 0.55;
}

.diagram-arrow {
  fill: var(--ink-muted);
}

/* Red Reset button (top-left of the sidebar). */
.sidebar button.reset-btn {
  background: var(--critical);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}

.sidebar button.reset-btn:hover {
  background: color-mix(in srgb, var(--critical) 85%, #000);
}
