:root {
  --bg: #0f1417;
  --bg2: #171f24;
  --panel: #1c262c;
  --panel2: #222e35;
  --line: #2a363d;
  --txt: #d9e2e6;
  --muted: #8a9aa3;
  --accent: #c8a04a;
  --accent2: #6b8f3d;
  --danger: #b5453a;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
}

/* ---------- header / search bar ---------- */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--bg2);
  border-bottom: 2px solid var(--accent);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { font-size: 17px; font-weight: 700; color: var(--accent); white-space: nowrap; cursor: pointer; user-select: none; }
.brand span { color: var(--muted); font-weight: 400; }
.search-bar { display: flex; gap: 8px; flex: 1; min-width: 280px; }
.search-bar #q { flex: 1; }

/* ---------- controls ---------- */
button {
  background: var(--panel);
  color: var(--txt);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
button.danger { border-color: var(--danger); color: #e89089; }
button.mini { padding: 3px 8px; font-size: 11px; }
button:disabled { opacity: 0.5; cursor: default; }
input, select {
  background: var(--bg);
  color: var(--txt);
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ---------- views ---------- */
.view { display: none; }
.view.active { display: block; }
main#browse.view.active { display: grid; }

main#browse {
  grid-template-columns: 1fr 340px;
  gap: 18px;
  padding: 18px 20px;
  align-items: start;
}
.results-col { min-width: 0; }
.meta { color: var(--muted); margin-bottom: 12px; min-height: 18px; }

/* ---------- mod grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.12s;
}
.card:hover { border-color: var(--accent); }
.card.in-cart { border-color: var(--accent2); }
.card img { width: 100%; height: 118px; object-fit: cover; background: #000; }
.card .body { padding: 10px 12px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.card h3 { margin: 0; font-size: 14px; line-height: 1.25; }
.card .sub { font-size: 12px; }
.card .stats { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: auto; }
.card .stats b { color: var(--accent); font-weight: 600; }
.card .row { display: flex; gap: 6px; padding: 0 12px 12px; }
.card .row button { flex: 1; }
.tag { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 11px; color: var(--muted); }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 18px 0; }
.pager span { color: var(--muted); }

/* ---------- "My Mods" cart sidebar ---------- */
.cart {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
}
.cart-head { display: flex; align-items: center; justify-content: space-between; }
.cart-head h2 { margin: 0; font-size: 15px; color: var(--accent); }
.badge { background: var(--accent2); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.cart-actions { display: flex; gap: 6px; margin: 10px 0; }
.cart-actions button { flex: 1; padding: 6px 8px; font-size: 12px; }
.hint { color: var(--muted); margin: 0 0 12px; }
.hint.sm { font-size: 12px; }
.cart-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cart-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px;
}
.cart-item input[type=checkbox] { flex: none; }
.cart-item .grow { flex: 1; min-width: 0; }
.cart-item .grow strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .grow small { color: var(--muted); font-size: 10px; }
.cart-item .x { background: transparent; border: none; color: var(--danger); font-size: 16px; padding: 0 4px; }
.cart-empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
.cart-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 10px 2px 4px; }
.cart-section-label:first-child { margin-top: 0; }
.cart-item.dep { border-style: dashed; background: var(--bg); }
.cart-item.dep .chain { color: var(--accent2); font-size: 13px; flex: none; }

/* ---------- build view ---------- */
#build { padding: 18px 20px; max-width: 1150px; margin: 0 auto; }
.back { margin-bottom: 14px; }
.preset-bar { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.preset-bar #presetSelect { flex: 1; min-width: 200px; }
.build-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.build-grid h2 { font-size: 15px; color: var(--accent); margin: 18px 0 6px; }
.build-grid h2:first-child { margin-top: 0; }
.build-right label { display: block; margin: 8px 0; }
.build-right label input, .build-right label select { width: 100%; margin-top: 3px; }
.build-right label.check { display: flex; align-items: center; gap: 8px; }
.build-right label.check input { width: auto; margin: 0; }
.build-right > select, .build-right > #scenarioManual, .build-right > button { width: 100%; margin-bottom: 8px; }
#copyModsTop { width: 100%; margin: 8px 0; }

.resolved { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }
.res-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.res-item .pill { font-size: 10px; padding: 1px 6px; border-radius: 8px; }
.pill.sel { background: var(--accent2); color: #fff; }
.pill.dep { background: #3a4750; color: var(--txt); }
.res-item code { color: var(--muted); font-size: 11px; }
.res-item .grow { flex: 1; min-width: 0; }

.gen-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.config-out {
  background: #0a0e10; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-top: 18px; max-height: 480px; overflow: auto;
  font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; white-space: pre; color: #cfe3c4;
}
.warn { color: #f0c674; background: rgba(181,69,58,0.12); border: 1px solid var(--danger); border-radius: 6px; padding: 8px 10px; font-size: 12px; margin: 6px 0; }
.warn.hidden { display: none; }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); width: min(680px, 92vw); max-height: 88vh; overflow-y: auto; position: relative; }
.modal-close { position: absolute; top: 8px; right: 8px; font-size: 22px; line-height: 1; padding: 2px 10px; }
#modalBody { padding: 20px; }
#modalBody img { max-width: 100%; border-radius: 6px; }
#modalBody h2 { margin-top: 0; color: var(--accent); }
.dep-list, .scen-list { margin: 8px 0; padding-left: 0; list-style: none; }
.dep-list li, .scen-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.scen-list code { color: var(--accent); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent2); color: #fff; padding: 10px 18px; border-radius: 6px; z-index: 60; }
.toast.hidden { display: none; }
.toast.err { background: var(--danger); }
.loading { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  main#browse { grid-template-columns: 1fr; }
  .cart { position: static; max-height: 320px; }
  .build-grid { grid-template-columns: 1fr; }
}
