/* =========================================================
   Lucid Blocks — Fusion Guide
   ========================================================= */

:root {
  --bg:            #0a0c11;
  --bg-grad:       radial-gradient(1200px 700px at 12% -12%, rgba(124, 92, 255, .16), transparent 62%),
                   radial-gradient(1000px 620px at 92% 0%, rgba(70, 229, 183, .10), transparent 58%);
  --surface:       #12151d;
  --surface-2:     #171b25;
  --surface-3:     #1d222e;
  --line:          #262c3a;
  --line-soft:     #1e232f;
  --text:          #e9ecf4;
  --text-dim:      #a7b0c4;
  --text-mute:     #6f7a91;
  --accent:        #8b6bff;
  --accent-soft:   rgba(139, 107, 255, .16);
  --accent-line:   rgba(139, 107, 255, .45);
  --mint:          #3fdcae;
  --mint-soft:     rgba(63, 220, 174, .14);
  --amber:         #ffb454;
  --amber-soft:    rgba(255, 180, 84, .12);
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:     0 12px 30px -12px rgba(0, 0, 0, .7);
  --shadow-lg:     0 40px 80px -30px rgba(0, 0, 0, .85);
  --radius:        14px;
  --radius-sm:     10px;
  --mono:          "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans:          "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --topbar-h:      64px;
  --tile:          #0d1017;
}

[data-theme="light"] {
  --bg:            #f2f3f7;
  --bg-grad:       radial-gradient(1100px 640px at 10% -14%, rgba(124, 92, 255, .14), transparent 60%),
                   radial-gradient(900px 560px at 94% -4%, rgba(37, 190, 148, .12), transparent 58%);
  --surface:       #ffffff;
  --surface-2:     #f7f8fb;
  --surface-3:     #eef0f6;
  --line:          #dfe3ec;
  --line-soft:     #e9ecf3;
  --text:          #131722;
  --text-dim:      #4b566b;
  --text-mute:     #79839a;
  --accent:        #6a45f0;
  --accent-soft:   rgba(106, 69, 240, .10);
  --accent-line:   rgba(106, 69, 240, .35);
  --mint:          #12a37a;
  --mint-soft:     rgba(18, 163, 122, .12);
  --amber:         #b4700d;
  --amber-soft:    rgba(180, 112, 13, .12);
  --shadow-sm:     0 1px 2px rgba(20, 24, 40, .07);
  --shadow-md:     0 14px 32px -16px rgba(24, 28, 48, .30);
  --shadow-lg:     0 40px 80px -32px rgba(24, 28, 48, .38);
  --tile:          #f1f2f7;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.02em; }
code { font-family: var(--mono); font-size: .92em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.skip-link {
  position: fixed;
  top: 8px; left: 8px;
  z-index: 200;
  padding: 10px 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ---------- Topbar ---------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  height: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; flex: none; }
.brand-mark {
  width: 30px; height: 30px;
  display: grid;
  grid-template: 1fr 1fr / 1fr 1fr;
  gap: 3px;
  transform: rotate(45deg);
}
.brand-mark i { border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(2) { background: var(--mint); }
.brand-mark i:nth-child(3) { background: color-mix(in srgb, var(--accent) 45%, transparent); }
.brand-mark i:nth-child(4) { background: color-mix(in srgb, var(--mint) 55%, transparent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }
.brand-text small { color: var(--text-mute); font: 500 10px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; }

.searchbar {
  flex: 1;
  max-width: 640px;
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.searchbar:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.searchbar .icon { color: var(--text-mute); }
.searchbar input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: none;
  border: 0;
  outline: 0;
  font-size: 14px;
}
.searchbar input::placeholder { color: var(--text-mute); }
.searchbar input::-webkit-search-cancel-button { display: none; }
.search-kbd {
  padding: 2px 7px;
  color: var(--text-mute);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: 500 11px var(--mono);
}
.searchbar:focus-within .search-kbd { display: none; }
.search-clear { display: grid; place-items: center; padding: 4px; color: var(--text-mute); background: none; border: 0; border-radius: 6px; }
.search-clear:hover { color: var(--text); background: var(--surface-3); }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.ghost-btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  transition: color .15s, border-color .15s, background .15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent-line); background: var(--surface-2); }
.ghost-btn.icon-only { width: 38px; padding: 0; justify-content: center; }
.ghost-btn .moon { display: none; }
[data-theme="light"] .ghost-btn .moon { display: block; }
[data-theme="light"] .ghost-btn .sun { display: none; }

/* ---------- Layout ---------------------------------------------------- */

.layout {
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 20px 80px;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  padding: 24px 0 24px;
}
.sidebar-scroll {
  height: 100%;
  overflow-y: auto;
  padding-right: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.filter-group + .filter-group { margin-top: 26px; }
.filter-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 11px;
  color: var(--text-mute);
  font: 500 10px var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
}
.link-btn { padding: 0; color: var(--accent); background: none; border: 0; font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.link-btn:hover { text-decoration: underline; }

.chip-rail { display: flex; flex-direction: column; gap: 3px; }
.cat-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  color: var(--text-dim);
  background: none;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13.5px;
  text-align: left;
  transition: background .14s, color .14s;
}
.cat-chip:hover { color: var(--text); background: var(--surface-2); }
.cat-chip.active { color: var(--text); background: var(--accent-soft); border-color: var(--accent-line); }
.cat-swatch { width: 8px; height: 8px; border-radius: 3px; flex: none; background: var(--cat, var(--accent)); }
.cat-chip .count { margin-left: auto; color: var(--text-mute); font: 500 11px var(--mono); }
.cat-chip.active .count { color: var(--accent); }

.segmented {
  display: flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segmented button {
  flex: 1;
  padding: 6px 4px;
  color: var(--text-mute);
  background: none;
  border: 0;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .14s, color .14s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); }

.chip-cloud { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-chip {
  padding: 4px 9px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  font: 500 11px var(--mono);
  transition: background .14s, color .14s, border-color .14s;
}
.tag-chip:hover { color: var(--text); border-color: var(--accent-line); }
.tag-chip.active { color: #fff; background: var(--accent); border-color: var(--accent); }
[data-theme="light"] .tag-chip.active { color: #fff; }

.legend-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; color: var(--text-mute); font-size: 12.5px; }
.legend-list li { display: flex; align-items: center; gap: 9px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.solved { background: var(--mint); box-shadow: 0 0 8px var(--mint-soft); }
.dot.unsolved { background: var(--text-mute); opacity: .5; }

/* ---------- Content head ---------------------------------------------- */

.content { padding-top: 24px; min-width: 0; }

.stat-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  flex: 1 1 150px;
  padding: 12px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.stat b { display: block; font-size: 24px; font-weight: 600; letter-spacing: -.03em; line-height: 1.1; }
.stat span { color: var(--text-mute); font: 500 10px var(--mono); letter-spacing: .13em; text-transform: uppercase; }
.stat.accent b { color: var(--accent); }
.stat.mint b { color: var(--mint); }

.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; min-height: 28px; }
.active-filters:empty { display: none; }
.pill-removable {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px 4px 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  font: 500 11.5px var(--mono);
}
.pill-removable b { color: var(--text); font-weight: 600; }
.pill-removable .x { display: grid; place-items: center; width: 18px; height: 18px; color: var(--text-mute); background: none; border: 0; border-radius: 50%; }
.pill-removable .x:hover { color: var(--text); background: var(--surface-3); }
.pill-removable .x svg { width: 12px; height: 12px; }
.reset-all { margin-left: 2px; color: var(--accent); background: none; border: 0; font-size: 12px; font-weight: 500; }
.reset-all:hover { text-decoration: underline; }

/* ---------- Result grid ----------------------------------------------- */

.results {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  color: inherit;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform .16s cubic-bezier(.2,.7,.3,1), border-color .16s, box-shadow .16s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--shadow-md); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-md); }

.card-thumb {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  background: var(--tile);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.card-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: .5;
  pointer-events: none;
}
.card-thumb img, .thumb-img {
  position: relative;
  z-index: 1;
  width: 66%;
  height: 66%;
  object-fit: contain;
  image-rendering: pixelated;
}
.thumb-fallback { position: relative; z-index: 1; color: var(--text-mute); font: 600 26px var(--mono); text-transform: uppercase; }

.card-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.01em;
  text-transform: capitalize;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: auto; color: var(--text-mute); font: 500 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.card-cat { display: inline-flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-energy { margin-left: auto; white-space: nowrap; }
.card-flag {
  position: absolute;
  top: 10px; right: 10px;
  z-index: 2;
  min-width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  color: var(--mint);
  background: color-mix(in srgb, var(--mint) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--mint) 40%, transparent);
  border-radius: 99px;
  font: 600 10.5px var(--mono);
}

.empty {
  grid-column: 1 / -1;
  padding: 70px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty h3 { font-size: 19px; margin-bottom: 6px; }
.empty p { margin: 0; color: var(--text-mute); font-size: 14px; }

.load-more-wrap { display: flex; justify-content: center; margin-top: 26px; }
.load-more {
  padding: 11px 26px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
}
.load-more:hover { border-color: var(--accent-line); background: var(--surface-2); }

/* ---------- Drawer ---------------------------------------------------- */

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(4, 6, 11, .55);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
[data-theme="light"] .drawer-scrim { background: rgba(20, 24, 40, .32); }
@keyframes fade { from { opacity: 0; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 90;
  width: min(560px, 100vw);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .28s cubic-bezier(.3,.8,.3,1), visibility .28s;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.drawer.open { transform: none; visibility: visible; }
.drawer::-webkit-scrollbar { width: 10px; }
.drawer::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.drawer-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.drawer-kicker { flex: 1; min-width: 0; color: var(--text-mute); font: 500 10px var(--mono); letter-spacing: .16em; text-transform: uppercase; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font: 500 10px var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
}
.badge.solved { color: var(--mint); background: var(--mint-soft); }
.badge.unsolved { color: var(--amber); background: var(--amber-soft); }

.drawer-body { padding: 22px 24px 60px; }

.hero { display: flex; gap: 18px; align-items: center; }
.hero-thumb {
  position: relative;
  width: 104px; height: 104px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.hero-thumb img { width: 70%; height: 70%; object-fit: contain; image-rendering: pixelated; }
.hero-thumb .thumb-fallback { font-size: 40px; }
.hero h2 { font-size: clamp(24px, 4vw, 32px); line-height: 1.1; text-transform: capitalize; }
.hero-sub { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px; }

.tag { padding: 3px 9px; color: var(--text-dim); background: var(--surface-3); border-radius: 99px; font: 500 11px var(--mono); }
.tag.cat { color: var(--cat, var(--accent)); background: color-mix(in srgb, var(--cat, var(--accent)) 14%, transparent); }

.section { margin-top: 30px; }
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
  color: var(--text-mute);
  font: 500 10px var(--mono);
  letter-spacing: .17em;
  text-transform: uppercase;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.formula {
  display: grid;
  gap: 10px;
  padding: 18px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.formula-inputs { display: grid; grid-template-columns: 1fr 26px 1fr; align-items: center; gap: 8px; }
.formula .op { display: grid; place-items: center; color: var(--text-mute); font: 400 20px var(--mono); }
.formula-eq {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--accent);
  font: 400 18px var(--mono);
}
.formula-eq::before, .formula-eq::after { content: ""; height: 1px; background: var(--line); }
.formula-output .ing { padding: 14px 10px; }

.ing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
  transition: border-color .15s, transform .15s;
}
.ing:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.ing.is-output { border-color: var(--accent-line); background: var(--accent-soft); }
.ing-thumb { width: 52px; height: 52px; display: grid; place-items: center; background: var(--tile); border: 1px solid var(--line-soft); border-radius: 9px; overflow: hidden; }
.ing-thumb img { width: 74%; height: 74%; object-fit: contain; image-rendering: pixelated; }
.ing-thumb .thumb-fallback { font-size: 20px; }
.ing-name { font-size: 12.5px; font-weight: 600; line-height: 1.25; text-transform: capitalize; }
.ing-count { color: var(--accent); font: 600 12px var(--mono); }
.ing.is-output .ing-count { color: var(--accent); }

.steps { margin: 16px 0 0; padding: 0; list-style: none; counter-reset: s; }
.steps li {
  counter-increment: s;
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 12px;
  padding: 10px 0;
  color: var(--text-dim);
  font-size: 13.5px;
  border-top: 1px solid var(--line-soft);
}
.steps li::before {
  content: counter(s);
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 7px;
  font: 600 11px var(--mono);
}
.steps strong { color: var(--text); text-transform: capitalize; }

.callout {
  margin-top: 16px;
  padding: 12px 14px;
  color: var(--text-dim);
  background: var(--amber-soft);
  border: 1px solid color-mix(in srgb, var(--amber) 28%, transparent);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.callout strong { color: var(--text); }

/* Alternative formulas ------------------------------------------------- */

.alt-block { margin-top: 22px; }
.alt-heading {
  margin-bottom: 10px;
  color: var(--text-mute);
  font: 500 10px var(--mono);
  letter-spacing: .13em;
  text-transform: uppercase;
}
.alt-list { display: flex; flex-direction: column; gap: 5px; }
.alt-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: border-color .14s, background .14s;
}
.alt-row:hover { border-color: var(--accent-line); background: var(--surface-3); }
.alt-row.active { border-color: var(--accent); background: var(--accent-soft); }
.alt-rank { color: var(--text-mute); font: 600 10px var(--mono); }
.alt-row.active .alt-rank { color: var(--accent); }
.alt-inputs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.alt-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.alt-thumb {
  width: 26px; height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--tile);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}
.alt-thumb img { width: 78%; height: 78%; object-fit: contain; image-rendering: pixelated; }
.alt-thumb .thumb-fallback { font-size: 11px; }
.alt-name { font-size: 12px; font-weight: 500; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alt-count { color: var(--text-mute); font: 600 10.5px var(--mono); flex: none; }
.alt-op { color: var(--text-mute); font: 400 12px var(--mono); flex: none; }
.alt-yield { color: var(--mint); font: 600 11px var(--mono); white-space: nowrap; }

.unsolved-note {
  padding: 20px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 13.5px;
}
.unsolved-note strong { color: var(--text); }

.spec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 8px; }
.spec { padding: 11px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.spec dt { color: var(--text-mute); font: 500 9.5px var(--mono); letter-spacing: .13em; text-transform: uppercase; }
.spec dd { margin: 3px 0 0; font: 600 15px var(--mono); letter-spacing: -.01em; }

.essence { display: flex; flex-direction: column; gap: 7px; }
.essence-row { display: grid; grid-template-columns: 86px 1fr 34px; align-items: center; gap: 10px; }
.essence-row .label { color: var(--text-dim); font-size: 12.5px; text-transform: capitalize; }
.essence-row .bar { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.essence-row .bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--mint)); }
.essence-row .val { color: var(--text-mute); font: 500 11px var(--mono); text-align: right; }
.essence-row.zero { opacity: .38; }
.essence-toggle { margin-top: 12px; }

.used-list { display: flex; flex-direction: column; gap: 6px; }
.used-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: border-color .14s, background .14s;
}
.used-row:hover { border-color: var(--accent-line); background: var(--surface-3); }
.used-thumb { width: 34px; height: 34px; flex: none; display: grid; place-items: center; background: var(--tile); border: 1px solid var(--line-soft); border-radius: 8px; overflow: hidden; }
.used-thumb img { width: 76%; height: 76%; object-fit: contain; image-rendering: pixelated; }
.used-thumb .thumb-fallback { font-size: 14px; }
.used-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.used-formula { color: var(--text-mute); font: 500 10.5px var(--mono); white-space: nowrap; }

.file-line { color: var(--text-mute); font: 500 11px var(--mono); word-break: break-all; }

/* ---------- Modal ------------------------------------------------------ */

.modal {
  width: min(640px, calc(100vw - 32px));
  max-height: min(84vh, 780px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(4, 6, 11, .62); backdrop-filter: blur(3px); }
.modal-body { padding: 0 26px 30px; }
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.modal-head h2 { font-size: 21px; }
.modal p { color: var(--text-dim); font-size: 14px; }
.how-steps { margin: 18px 0 0; padding: 0; list-style: none; counter-reset: h; }
.how-steps li {
  counter-increment: h;
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 12px;
  padding: 11px 0;
  color: var(--text-dim);
  font-size: 13.5px;
  border-top: 1px solid var(--line-soft);
}
.how-steps li::before {
  content: counter(h);
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  font: 600 11px var(--mono);
}
.how-steps strong { color: var(--text); }
.modal-note { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); font-size: 12.5px !important; color: var(--text-mute) !important; }

/* ---------- Responsive ------------------------------------------------- */

@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .sidebar {
    position: static;
    height: auto;
    padding: 18px 0 4px;
  }
  .sidebar-scroll { overflow: visible; padding-right: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 22px; align-items: start; }
  .filter-group + .filter-group { margin-top: 0; }
  .filter-group.legend { display: none; }
  .content { padding-top: 12px; }
}

@media (max-width: 720px) {
  .topbar-inner { padding: 0 12px; gap: 10px; }
  .brand-text { display: none; }
  .ghost-btn span { display: none; }
  .ghost-btn { width: 38px; padding: 0; justify-content: center; }
  .layout { padding: 0 12px 60px; }
  .results { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .drawer { width: 100vw; border-left: 0; }
  .stat b { font-size: 20px; }
  .essence-row { grid-template-columns: 72px 1fr 32px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
