:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --text: #1c1f24;
  --text-muted: #5b6472;
  --border: #dde1e6;
  --accent: #2c3e50;
  --hover: #eef1f4;
  --selected: #e3ecf7;
  --chip-bg: #eef1f4;
  --banner-bg: #fff8e1;
  --banner-border: #e8d178;
  --shadow: 0 4px 16px rgba(0,0,0,0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel-bg: #1b1f26;
    --text: #e7eaee;
    --text-muted: #9aa4b2;
    --border: #2c323c;
    --accent: #a9c4e6;
    --hover: #242a33;
    --selected: #263447;
    --chip-bg: #242a33;
    --banner-bg: #2c2712;
    --banner-border: #6b5b1f;
    --shadow: 0 4px 20px rgba(0,0,0,0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #14171c;
  --panel-bg: #1b1f26;
  --text: #e7eaee;
  --text-muted: #9aa4b2;
  --border: #2c323c;
  --accent: #a9c4e6;
  --hover: #242a33;
  --selected: #263447;
  --chip-bg: #242a33;
  --banner-bg: #2c2712;
  --banner-border: #6b5b1f;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --text: #1c1f24;
  --text-muted: #5b6472;
  --border: #dde1e6;
  --accent: #2c3e50;
  --hover: #eef1f4;
  --selected: #e3ecf7;
  --chip-bg: #eef1f4;
  --banner-bg: #fff8e1;
  --banner-border: #e8d178;
  --shadow: 0 4px 16px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.3rem;
}

.topbar-title p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.promotion-btn {
  background: #a97a1f;
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.promotion-btn:hover { background: #8f6717; }

.caveat-banner {
  background: var(--banner-bg);
  border-bottom: 1px solid var(--banner-border);
  padding: 8px 20px;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#searchBox {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  width: 220px;
}
#searchBox:focus { outline: 2px solid var(--accent); }

.filter-toggle {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.filter-toggle.active {
  background: #a97a1f;
  border-color: #a97a1f;
  color: #fff;
}

.duration-progress {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.72rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--chip-bg);
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
}
.legend-item.dimmed { opacity: 0.35; }
.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.content-row {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

/* ---- Map (pannable canvas) ---- */
.map-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--bg);
}

.map {
  height: 100%;
  width: 100%;
  overflow: auto;
  padding: 28px 40px;
}

.map-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: max-content;
  min-width: 100%;
}

.root-row {
  position: relative;
  z-index: 1;
  margin-bottom: 44px;
  display: flex;
  justify-content: center;
}

.root-card {
  width: 210px;
  background: var(--accent);
  color: var(--panel-bg);
  border-radius: 12px;
  padding: 16px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  position: relative;
}
.root-card .root-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
  display: block;
  margin-bottom: 6px;
}
.root-card .root-name { font-weight: 700; font-size: 1rem; line-height: 1.3; }
.root-card.selected { outline: 3px solid #c8951a; }

.clusters-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
}

.group-cluster {
  flex-shrink: 0;
  margin-right: 40px;
}

.cluster-label {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 10px;
  padding-left: 2px;
}
.cluster-label .cluster-count { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; margin-left: 6px; }

.cluster-columns {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.column {
  flex-shrink: 0;
  width: 230px;
  background: color-mix(in srgb, var(--group-color, var(--border)) 5%, transparent);
  border-top: 3px solid var(--group-color, var(--border));
  border-radius: 8px;
  padding: 10px;
}

.column-header {
  padding: 2px 2px 10px;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.column-header .column-count { font-weight: 400; color: var(--text-muted); font-size: 0.72rem; margin-left: 4px; }

.column-body { padding-bottom: 4px; }

.card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.1s ease, transform 0.1s ease;
  position: relative;
}
.card:hover { border-color: var(--accent); }
.card.selected { border-color: #c8951a; border-width: 2px; box-shadow: 0 0 0 1px #c8951a; }
.card.optional { border-style: dashed; opacity: 0.8; }
.card.optional:hover { opacity: 1; }

.card-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 6px;
}
.card-name .badge-star { color: #c8951a; margin-right: 3px; }

.optional-chip {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  background: transparent;
  border: 1px dashed var(--text-muted);
  color: var(--text-muted);
  font-style: italic;
}

.card-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

.count-chip {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--chip-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.dur-chip {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--chip-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.dur-chip.known { background: #1c5a7a; color: #fff; border-color: #1c5a7a; }
.dur-chip.unknown {
  background: transparent;
  color: #b5791a;
  border: 1px dashed #b5791a;
}

.scarcity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.scarcity-dot.tier-high { background: #c0392b; }
.scarcity-dot.tier-medium { background: #d38a1f; }
.scarcity-dot.tier-low-medium { background: #6a9e3f; }
.scarcity-dot.tier-low { background: #2e8b57; }
.scarcity-dot.tier-varies { background: #8e8e8e; }
.scarcity-dot.tier-unknown { background: #555; }

mark {
  background: #ffe58f;
  color: #1c1f24;
  border-radius: 2px;
  padding: 0 1px;
}

/* ---- Drawer (pushes the map instead of overlaying it) ---- */
.drawer {
  width: 0;
  max-width: 45vw;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-left: 1px solid transparent;
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.2s ease;
}
.drawer.open {
  width: 420px;
  border-left-color: var(--border);
}

.drawer-inner { width: 420px; }

.drawer-close {
  position: sticky;
  top: 0;
  float: right;
  margin: 14px 14px 0 0;
  background: var(--chip-bg);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-muted);
  z-index: 1;
}

.drawer-content {
  padding: 20px 26px 40px;
  clear: both;
}

.detail-placeholder {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 40px;
  text-align: center;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.detail-header h2 { margin: 0; font-size: 1.4rem; }

.cat-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 14px;
}

.headline-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0 20px;
}

.headline-chip {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 150px;
}
.headline-chip .label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 3px;
}
.headline-chip .value { font-size: 1rem; font-weight: 600; }
.headline-chip .sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

.ssgt-banner {
  background: #3a2c0d;
  background: color-mix(in srgb, #a97a1f 18%, var(--panel-bg));
  border: 1px solid #a97a1f;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: 0.85rem;
}
.ssgt-banner strong { display: block; margin-bottom: 3px; }

.detail-section { margin-bottom: 20px; }
.detail-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 6px;
}
.detail-section p { margin: 0; line-height: 1.5; font-size: 0.92rem; }

.summary-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.contact-hq {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--chip-bg);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---- Promotion overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }

.overlay-panel {
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 28px 30px;
  max-width: 640px;
  width: 92%;
  max-height: 84vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
}

.overlay-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
}

.overlay-sub { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 18px; }

.promo-group { margin-bottom: 18px; }
.promo-group h4 { margin: 0 0 8px; font-size: 0.85rem; }
.promo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.87rem;
  border: 1px solid var(--border);
  margin-bottom: 6px;
}
.promo-item:hover { background: var(--hover); }
.promo-item.static { cursor: default; }
.promo-item.static:hover { background: none; }

.tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.tag.confirmed { background: #1c7a3f; color: #fff; }
.tag.likely { background: #a97a1f; color: #fff; }
.tag.prereq { background: #4a6a9a; color: #fff; }
.tag.combo { background: #7a4aa9; color: #fff; }

@media (max-width: 760px) {
  .drawer.open { width: 100%; max-width: 100%; }
  .drawer-inner { width: 100%; }
  #searchBox { width: 140px; }
}
