:root {
  color-scheme: dark;
  --bg: #10100e;
  --panel: #191a17;
  --panel-2: #22241f;
  --ink: #f4efe0;
  --muted: #b5b09f;
  --soft: #7f8176;
  --line: #3b3a32;
  --amber: #e7b34d;
  --teal: #40b9b0;
  --green: #57d66d;
  --red: #d66b55;
  --blue: #4da3ff;
  --common: #d7d9d0;
  --epic: #b985ff;
  --legendary: #f1b84f;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
  background:
    linear-gradient(180deg, rgba(64, 185, 176, 0.12), transparent 260px),
    radial-gradient(circle at 85% 0%, rgba(231, 179, 77, 0.16), transparent 34rem),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--amber);
  background: var(--amber);
  color: #18140d;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--teal);
  padding: 0;
  min-height: 0;
}

.topbar {
  min-height: 82px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(16, 16, 14, 0.84);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3vw, 2.5rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quick-nav {
  position: sticky;
  top: 82px;
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 10px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(16, 16, 14, 0.9);
  backdrop-filter: blur(12px);
}

.quick-nav a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: rgba(34, 36, 31, 0.9);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.quick-nav a.active,
.quick-nav a[aria-current="page"] {
  border-color: var(--amber);
  background: var(--amber);
  color: #18140d;
}

.app-shell {
  padding: 16px clamp(14px, 3vw, 34px) 28px;
}

.view-page {
  display: none;
}

.view-page.active {
  display: block;
}

.catalog-panel,
.plan-panel,
.info-page {
  min-width: 0;
  max-width: 1480px;
  margin: 0 auto;
}

.page-heading {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 26, 23, 0.82);
  padding: 14px;
}

.page-heading h2 {
  font-size: 1.25rem;
}

.info-drawer {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 26, 23, 0.76);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.info-drawer > summary {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}

.info-drawer > summary::-webkit-details-marker {
  display: none;
}

.info-drawer > summary::after {
  content: "+";
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 900;
}

.info-drawer[open] > summary {
  border-bottom: 1px solid var(--line);
}

.info-drawer[open] > summary::after {
  content: "-";
}

.info-drawer .eyebrow {
  display: block;
  margin-bottom: 3px;
  font-size: 0.7rem;
}

.summary-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.intel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  padding: 14px;
}

.bench-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  padding: 14px;
}

.intel-card,
.bench-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 21, 17, 0.9);
  padding: 12px;
}

.intel-card.wide {
  grid-column: 1 / -1;
}

.intel-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.intel-card h3 {
  margin: 0;
  font-size: 1rem;
}

.bench-card {
  display: flex;
  flex-direction: column;
}

.bench-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.bench-card-head > div:nth-child(2) {
  flex: 1;
  min-width: 0;
}

.bench-icon {
  width: 52px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c0d0b;
}

.bench-icon svg {
  width: 34px;
  height: 34px;
  fill: var(--muted);
  stroke: var(--muted);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bench-icon-weapon svg { fill: var(--amber); stroke: var(--amber); }
.bench-icon-gear svg { fill: var(--blue); stroke: var(--blue); }
.bench-icon-medical svg { fill: var(--green); stroke: var(--green); }
.bench-icon-explosive svg { fill: var(--red); stroke: var(--red); }
.bench-icon-refiner svg { fill: var(--epic); stroke: var(--epic); }
.bench-icon-utility svg { fill: var(--teal); stroke: var(--teal); }

.bench-card-head h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.bench-card-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.bench-level + .bench-level {
  margin-top: 8px;
}

.compact-empty {
  padding: 12px;
  font-size: 0.86rem;
}

.intel-card p {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.intel-tips,
.target-grid,
.map-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intel-tips span {
  border-left: 3px solid var(--teal);
  background: var(--panel-2);
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.compact-list {
  margin: 0 0 12px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.86rem;
}

.compact-list li + li {
  margin-top: 4px;
}

.target-chip {
  min-height: 48px;
  display: grid;
  align-content: center;
  gap: 2px;
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--ink);
  text-align: left;
}

.target-chip span {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.target-chip:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.embedded-map-card {
  padding: 12px;
}

.map-tabs {
  margin-bottom: 10px;
}

.map-tab {
  min-height: 34px;
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--ink);
}

.map-tab.active {
  border-color: var(--amber);
  background: var(--amber);
  color: #18140d;
}

.cache-map-frame {
  width: 100%;
  height: min(68vh, 680px);
  min-height: 420px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0d0b;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 150px;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 16, 14, 0.9);
  backdrop-filter: blur(12px);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141511;
  color: var(--ink);
  padding: 0 12px;
}

.catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.craft-card,
.material-card,
.selected-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 26, 23, 0.92);
  box-shadow: var(--shadow);
}

.craft-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  min-height: 176px;
}

.thumb {
  width: 78px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: #0c0d0b;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.craft-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.craft-title {
  display: flex;
  gap: 8px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 6px;
}

.craft-title h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
}

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.recipe {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: start;
  gap: 6px;
  margin: 4px 0 8px;
}

.recipe span,
.recipe-item {
  background: var(--panel-2);
  border-left: 3px solid var(--soft);
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
  padding: 4px 7px;
  font-size: 0.76rem;
  color: var(--ink);
  min-height: 0;
  font-weight: 400;
  cursor: pointer;
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: left;
  white-space: normal;
}

.recipe-item:hover {
  background: #2a2d25;
}

.recipe-title {
  margin-top: 6px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.recipe-block {
  margin-bottom: 8px;
}

.craft-source-row {
  margin-top: auto;
  padding-top: 8px;
}

.craft-source-row a,
.material-source-links a {
  font-size: 0.82rem;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-actions.stacked {
  align-items: flex-start;
  flex-direction: column;
}

.plan-control {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.plan-control > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stepper {
  display: grid;
  grid-template-columns: 34px 44px 34px;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.stepper button {
  min-height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--panel-2);
  color: var(--ink);
}

.stepper output {
  text-align: center;
  font-weight: 800;
}

.plan-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  overflow: visible;
}

.plan-panel .summary-band,
.plan-panel > section:first-of-type {
  grid-column: 1 / -1;
}

.plan-panel .source-note {
  grid-column: 1 / -1;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.summary-band div {
  min-height: 62px;
  display: grid;
  place-items: center;
  text-align: center;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
}

.metric {
  display: block;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
}

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

#generatedAt {
  color: var(--soft);
  font-size: 0.72rem;
}

.selected-list,
.materials-list {
  display: grid;
  gap: 8px;
}

.selected-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
}

.selected-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-card,
.material-info-card {
  padding: 10px;
  border-left-width: 4px;
}

.material-info-head {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.material-info-head h3 {
  margin-bottom: 6px;
}

.material-info-thumb {
  width: 74px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c0d0b;
}

.material-info-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.material-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.material-head h3 {
  margin-bottom: 5px;
  font-size: 1rem;
}

.qty {
  text-align: right;
  font-weight: 900;
  color: var(--amber);
}

.owned-control {
  display: grid;
  grid-template-columns: 1fr 82px;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.owned-control input {
  min-height: 34px;
}

.hints {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.88rem;
}

.hints li + li {
  margin-top: 5px;
}

.source-note {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 0.85rem;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.material-source-links {
  margin-top: 16px;
}

a {
  color: var(--teal);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(90px);
  background: var(--ink);
  color: #17130c;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 800;
  transition: transform 160ms ease;
  z-index: 10;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.rarity-Common { border-left-color: var(--common) !important; }
.rarity-Uncommon { border-left-color: var(--green) !important; }
.rarity-Rare { border-left-color: var(--blue) !important; }
.rarity-Epic { border-left-color: var(--epic) !important; }
.rarity-Legendary { border-left-color: var(--legendary) !important; }

.rarity-label.rarity-Common {
  color: var(--common);
  border-color: rgba(215, 217, 208, 0.38);
  background: rgba(215, 217, 208, 0.08);
}

.rarity-label.rarity-Uncommon {
  color: var(--green);
  border-color: rgba(87, 214, 109, 0.46);
  background: rgba(87, 214, 109, 0.1);
}

.rarity-label.rarity-Rare {
  color: var(--blue);
  border-color: rgba(77, 163, 255, 0.46);
  background: rgba(77, 163, 255, 0.1);
}

.rarity-label.rarity-Epic {
  color: var(--epic);
  border-color: rgba(185, 133, 255, 0.48);
  background: rgba(185, 133, 255, 0.1);
}

.rarity-label.rarity-Legendary {
  color: var(--legendary);
  border-color: rgba(241, 184, 79, 0.5);
  background: rgba(241, 184, 79, 0.12);
}

@media (max-width: 980px) {
  .plan-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  body {
    padding-bottom: 64px;
    scroll-padding-top: 92px;
  }

  .topbar {
    position: static;
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }

  .topbar .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.55rem;
  }

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

  .top-actions button {
    min-height: 36px;
  }

  .app-shell {
    padding: 10px 8px 22px;
  }

  .quick-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 9;
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-top: 1px solid var(--line);
    border-bottom: 0;
    background: rgba(16, 16, 14, 0.96);
    backdrop-filter: blur(12px);
  }

  .quick-nav a {
    flex: 1;
    justify-content: center;
    padding: 0 6px;
  }

  .controls {
    position: sticky;
    z-index: 4;
    top: 0;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px;
  }

  .controls .search {
    grid-column: 1 / -1;
  }

  .craft-card {
    grid-template-columns: 64px minmax(0, 1fr);
    min-height: 0;
  }

  .thumb {
    width: 64px;
  }

  .catalog {
    grid-template-columns: 1fr;
  }

  .craft-title {
    align-items: flex-start;
  }

  .pill {
    font-size: 0.68rem;
  }

  .card-actions.stacked {
    gap: 6px;
  }

  .summary-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-band div {
    min-height: 54px;
    font-size: 0.7rem;
  }

  .metric {
    font-size: 1.15rem;
  }

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

  .selected-row .stepper {
    justify-self: stretch;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .material-info-head {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .material-info-thumb {
    width: 58px;
  }

  .info-drawer > summary {
    min-height: 54px;
    padding: 10px;
  }

  .summary-hint {
    display: none;
  }

  .intel-grid,
  .bench-grid {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .cache-map-frame {
    height: 72vh;
    min-height: 360px;
  }
}
