* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, Arial, sans-serif;
  background: #020617;
  color: #e5e7eb;
}

.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.header {
  text-align: center;
  margin-bottom: 18px;
}

.header h1 {
  margin: 0;
  color: #38bdf8;
}

.header p {
  color: #94a3b8;
  margin: 6px 0 0;
}

.panel {
  background: #111827;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 90px 160px 130px auto auto;
  gap: 10px;
  align-items: center;
}

.controls select,
.controls input,
.controls button,
#craftableCount {
  width: 100%;
}

select,
input,
button,
#craftableCount {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #334155;
  padding: 10px;
  font-size: 15px;
}

select,
input {
  background: #020617;
  color: #e5e7eb;
}

select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

select:focus,
input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 8px rgba(56,189,248,0.4);
}

button {
  background: #38bdf8;
  color: #020617;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

button:hover {
  opacity: 0.9;
}

button:active {
  transform: scale(0.98);
}

#craftableCount {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020617;
  color: #22c55e;
  font-weight: 800;
  white-space: nowrap;
}

.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.view-toggle button {
  background: #0f172a;
  color: #e5e7eb;
}

.view-toggle button.active {
  background: #38bdf8;
  color: #020617;
}

.xp-toggle,
.xp-boost-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
  color: #e5e7eb;
  font-weight: 700;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #334155;
  border-radius: 999px;
  transition: 0.25s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #e5e7eb;
  border-radius: 50%;
  transition: 0.25s;
}

.switch input:checked + .slider {
  background: #38bdf8;
  box-shadow: 0 0 12px rgba(56,189,248,0.5);
}

.switch input:checked + .slider::before {
  transform: translateX(24px);
}

.boost-options {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px;
}

.boost-options input {
  display: none;
}

.boost-options label {
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 999px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #cbd5e1;
  transition: 0.2s ease;
}

.boost-options input:checked + label {
  background: #38bdf8;
  color: #020617;
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56,189,248,0.45);
}

.output-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.queue-list {
  display: grid;
  gap: 8px;
}

.queue-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px;
}

.queue-name {
  font-weight: 700;
  color: #f8fafc;
}

.queue-row button,
.danger-btn {
  background: #ef4444;
  color: white;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid #1f2937;
}

.result-row:last-child {
  border-bottom: none;
}

.result-row strong {
  color: #facc15;
}

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

.materials-header h2 {
  margin: 0;
}

.mini-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #cbd5e1;
}

.material-owned-row {
  grid-template-columns: 1fr 90px 70px !important;
}

.material-owned-row .owned-input {
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  min-height: 34px;
  padding: 6px 8px;
}

.material-owned-row .needed-after-owned {
  text-align: right;
  color: #22c55e;
  font-weight: 800;
}

.summary-box {
  background: #020617;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.section-divider {
  height: 1px;
  margin: 12px 0 10px;
  background: linear-gradient(to right, transparent, #334155, transparent);
}

#stopLevel {
  color: #f472b6;
}

#xpTotal {
  color: #22c55e;
}

#recyclableTotal {
  color: #38bdf8;
}

#costTotal {
  color: #facc15;
}

.muted {
  color: #94a3b8;
  font-size: 14px;
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.82);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 18px;
}

.modal h3 {
  margin: 0 0 14px;
  color: #38bdf8;
}

.modal h4 {
  margin: 16px 0 8px;
}

.modal label {
  display: block;
  margin: 10px 0 6px;
  color: #cbd5e1;
  font-size: 14px;
}

.modal input,
.modal select,
.modal button {
  width: 100%;
  margin-bottom: 8px;
}

.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr 100px 46px;
  gap: 8px;
  margin-bottom: 8px;
}

.editor-row button {
  background: #ef4444;
  color: white;
  padding: 0;
}

.secondary-btn {
  background: #0f172a;
  color: #e5e7eb;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.modal-divider {
  border: none;
  border-top: 1px solid #334155;
  margin: 18px 0;
}

@media (max-width: 760px) {
  .app {
    padding: 12px;
  }

  .controls,
  .output-grid,
  .view-toggle {
    grid-template-columns: 1fr;
  }

  .controls select,
  .controls input,
  .controls button,
  #craftableCount {
    width: 100%;
  }

  .xp-toggle,
  .xp-boost-toggle {
    align-items: stretch;
    flex-direction: column;
  }

  .boost-options {
    grid-template-columns: repeat(4, 1fr);
  }

  .boost-options label {
    text-align: center;
  }

  .queue-row {
    grid-template-columns: 1fr auto;
  }

  .queue-row button {
    grid-column: 1 / -1;
  }

  .material-owned-row {
    grid-template-columns: 1fr 90px 70px !important;
  }

  .editor-row {
    grid-template-columns: 1fr;
  }

  .editor-row button {
    min-height: 38px;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}
