:root {
  --bg: #15140f;
  --panel: rgba(58, 56, 52, 0.55);
  --panel-solid: #2b2a26;
  --line: rgba(255, 255, 255, 0.22);
  --text: #f2f0eb;
  --muted: #a9a59c;
  --accent: #4c1d95;
  --accent-hover: #5b23b3;
  --accent-ring: #8b5cf6;
  --ok: #7ccf6a;
  --warn: #e0a84a;
  --error: #f08a7e;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: Inter, "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  /* The game scene (bg.webp) dimmed under the UI, as on the mockup; the
     gradients underneath stand in while it loads or if it's missing. */
  background-image:
    linear-gradient(rgba(10, 9, 7, 0.72), rgba(10, 9, 7, 0.78)),
    url("/bg.webp"),
    radial-gradient(ellipse 60% 50% at 50% 55%, rgba(70, 64, 48, 0.55), transparent 70%),
    radial-gradient(ellipse 50% 60% at 15% 20%, rgba(38, 52, 40, 0.6), transparent 70%),
    radial-gradient(ellipse 45% 55% at 85% 30%, rgba(60, 48, 34, 0.55), transparent 70%),
    linear-gradient(180deg, #1b1a15 0%, #121110 100%);
  background-size: cover, cover, auto, auto, auto, auto;
  background-position: center;
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

[hidden] { display: none !important; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 40px;
}
.logo img { display: block; width: 40px; height: 40px; }
.nav { display: flex; flex-wrap: wrap; gap: 8px 32px; justify-content: flex-end; }
.nav a {
  font-size: 13px;
  text-decoration: none;
  color: var(--text);
  opacity: 0.85;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
}
.nav a:hover { opacity: 1; }
.nav a.active { opacity: 1; border-bottom-color: var(--accent-ring); }

main { flex: 1; display: flex; }

/* Calculator */
.calc {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(220px, 260px) minmax(300px, 405px);
  justify-content: center;
  align-items: start;
  gap: 48px;
  padding: 72px 40px 48px;
}

.dropzone {
  position: relative;
  height: 265px;
  border: 2px dashed var(--accent-ring);
  border-radius: 4px;
  background: rgba(20, 19, 16, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:focus-visible, .dropzone.drag { background: rgba(76, 29, 149, 0.18); border-color: #b197fc; }
.dz-empty { padding: 20px; }
.dz-icon { width: 40px; height: 40px; color: #fff; }
.dz-empty h2 { font-size: 15px; font-weight: 600; margin: 10px 0 8px; }
.dz-empty p { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin: 0 0 22px; }
.dz-empty .dz-hint { font-size: 11px; margin: 14px 0 0; opacity: 0.75; }
.dz-busy p { color: var(--muted); font-size: 13px; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-ring);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dz-preview { position: absolute; inset: 6px; display: flex; align-items: center; justify-content: center; }
.preview-frame { position: relative; max-width: 100%; max-height: 100%; line-height: 0; }
.preview-frame img { max-width: 100%; max-height: 249px; display: block; }
#overlay { position: absolute; inset: 0; }
.slot-box { position: absolute; border: 2px solid var(--ok); border-radius: 2px; }
.slot-box.unknown { border-color: rgba(224, 168, 74, 0.7); border-style: dashed; }
.slot-box.other { border-color: rgba(255, 255, 255, 0.35); }

.btn {
  font: inherit;
  font-size: 14px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 12px 36px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-wide { width: 100%; padding: 15px 20px; }

.link {
  font: inherit; font-size: 12px; color: #c4b5fd;
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline;
}

.recognized {
  margin-top: 16px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px;
  backdrop-filter: blur(6px);
}
.recognized-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
#items { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
#items li { display: grid; grid-template-columns: 32px 1fr 72px 24px; align-items: center; gap: 8px; font-size: 13px; }
#items img { width: 32px; height: 32px; object-fit: contain; }
#items input {
  font: inherit; font-size: 13px; color: var(--text); width: 100%;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
#items input:focus { outline: none; border-color: var(--accent-ring); }
#items .remove { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0; }
#items .remove:hover { color: var(--text); }
#items .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.error { font-size: 13px; color: var(--error); margin: 12px 0 0; }

.col-controls { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 72px; }
.recyclers {
  display: flex; gap: 4px; padding: 4px;
  background: rgba(30, 29, 26, 0.75);
  border-radius: 8px;
}
.recycler {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.recycler svg { width: 22px; height: 22px; }
.recycler[aria-checked="true"] { background: var(--accent); }
.recycler:hover:not([aria-checked="true"]) { background: rgba(255, 255, 255, 0.08); }
.recycler:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 1px; }
.efficiency, .timer { display: flex; align-items: center; gap: 14px; font-size: 17px; }
.efficiency svg, .timer svg { width: 30px; height: 30px; color: #fff; }

.results {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px 34px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  backdrop-filter: blur(6px);
}
.res {
  display: flex; align-items: center; gap: 16px;
  min-height: 115px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
}
.res:nth-child(odd) { border-right: 1px solid var(--line); }
.res:nth-last-child(-n+2):nth-child(odd), .res:last-child { border-bottom: 0; }
.res img { width: 48px; height: 48px; object-fit: contain; }
.res .amount { font-size: 19px; font-variant-numeric: tabular-nums; }
.res .label { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.res .amount.zero { opacity: 0.9; }
.col-results .timer { justify-content: center; margin-top: 30px; }

/* Text pages */
.doc { flex: 1; max-width: 960px; margin: 0 auto; padding: 48px 40px; }
.doc h1 { font-size: 26px; margin: 0 0 16px; }
.doc p { line-height: 1.6; color: #d9d5cc; }
.doc .lead { color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
th { font-weight: 600; color: var(--muted); white-space: nowrap; }
td.item { white-space: nowrap; }
td.item img { width: 28px; height: 28px; vertical-align: middle; margin-right: 8px; object-fit: contain; }
.yield { display: inline-flex; align-items: center; gap: 3px; margin: 2px 8px 2px 0; white-space: nowrap; }
.yield img { width: 20px; height: 20px; object-fit: contain; }
.yield .chance { color: var(--muted); }
.rec-head { display: inline-flex; align-items: center; gap: 6px; }
.rec-head svg { width: 18px; height: 18px; }

@media (max-width: 1100px) {
  .calc { grid-template-columns: minmax(0, 420px); gap: 28px; padding: 32px 16px; }
  .col-controls { padding-top: 0; }
  .topbar { padding: 14px 16px; flex-direction: column; align-items: flex-start; }
  .nav { justify-content: flex-start; gap: 6px 20px; }
  .doc { padding: 32px 16px; }
}
@media (max-width: 420px) {
  .results { padding: 12px 16px; }
  .res { min-height: 90px; gap: 10px; padding: 0 8px; }
  .res img { width: 38px; height: 38px; }
}

#items li.add { grid-template-columns: 1fr; }
.add-select {
  font: inherit; font-size: 12.5px; color: var(--muted);
  background: rgba(0, 0, 0, 0.3); border: 1px dashed var(--line); border-radius: 6px; padding: 6px 8px;
}
.add-select:focus { outline: none; border-color: var(--accent-ring); color: var(--text); }

/* Toggle switch */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; max-width: 260px; font-size: 13px; line-height: 1.35; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: none; position: relative; width: 38px; height: 22px; margin-top: 1px;
  background: rgba(255, 255, 255, 0.18); border-radius: 11px; transition: background 0.15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent-ring); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.switch small { display: block; margin-top: 3px; font-size: 11.5px; color: var(--muted); }

/* Slots whose count label couldn't be read */
.slot-box.unreadable { border-color: var(--error); border-width: 3px; }
#items .warn { color: var(--error); }
#items input.warn { border-color: var(--error); }
