/* ============================================================
   Old World Tech Tree — Redesign
   Dark slate + gold leaf, editorial. Three directions:
   data-direction = editorial | atlas | codex
   ============================================================ */

/* Self-hosted fonts — same files Google serves, copied locally so the first
   paint isn't a FOUT (flash of fallback). font-display: block keeps text
   invisible for up to ~3s rather than swapping in mid-render; cached on
   reload via the service worker. */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 500 700;
  font-display: block;
  src: url(fonts/cormorant-garamond.woff2) format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: block;
  src: url(fonts/inter.woff2) format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500 600;
  font-display: block;
  src: url(fonts/jetbrains-mono.woff2) format('woff2');
}

:root {
  /* Core palette (oklch, dark slate w/ warm gold) */
  --bg:           oklch(0.18 0.012 80);
  --bg-elev:      oklch(0.22 0.012 78);
  --bg-elev-2:    oklch(0.25 0.013 78);
  --panel:        oklch(0.21 0.012 78);
  --line:         oklch(0.32 0.012 80);
  --line-strong:  oklch(0.40 0.014 80);
  --line-faint:   oklch(0.28 0.010 80);

  --text:         oklch(0.94 0.008 80);
  --text-soft:    oklch(0.82 0.010 80);
  --text-muted:   oklch(0.62 0.012 80);
  --text-dim:     oklch(0.48 0.012 80);

  --gold:         oklch(0.82 0.13 82);
  --gold-soft:    oklch(0.70 0.10 82);
  --gold-deep:    oklch(0.55 0.08 80);
  --gold-glow:    oklch(0.82 0.13 82 / 0.18);

  --state-onpath: oklch(0.70 0.10 252);
  --state-onpath-deep: oklch(0.42 0.09 252);
  --state-done:   oklch(0.74 0.13 148);
  --state-done-deep: oklch(0.40 0.08 148);
  --state-avail:  oklch(0.82 0.13 82);

  --radius-card: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 0 rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.25);
  --shadow-md: 0 1px 0 rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.35);

  --font-serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --font-sans: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-w: 340px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 20% -10%, oklch(0.26 0.02 70 / .55), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, oklch(0.24 0.02 250 / .25), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

/* (Removed the decorative parchment-grid overlay — it was barely visible
   on a dark background, carried no information, and hit a Chromium
   rendering bug that tinted it red.) */

/* ============== TOPBAR ============== */
.topbar {
  position: sticky; top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 22px;
  background: linear-gradient(to bottom, oklch(0.16 0.012 80 / .92), oklch(0.16 0.012 80 / .82));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  color: var(--gold);
  background: radial-gradient(circle at 30% 30%, oklch(0.32 0.05 80), oklch(0.20 0.02 80));
  border: 1px solid var(--gold-deep);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / .08), var(--shadow-sm);
}
.brand-eyebrow {
  font-family: var(--font-sans);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}
.brand-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  line-height: 1;
  color: var(--text);
  letter-spacing: 0.01em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Topbar items share a 34 px row height — stats, nation dropdown, and action
   buttons all align center on the same baseline. Labels sit inline before the
   value rather than stacked above it. */
.nation-field {
  display: inline-flex; align-items: center; gap: 8px;
}
.field-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  font-weight: 600;
}
.nation-select {
  appearance: none;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  height: 34px;
  padding: 0 28px 0 12px;
  font: inherit;
  font-size: 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 150px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4l3 3 3-3' fill='none' stroke='%23d4b25b' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.nation-select:hover, .nation-select:focus {
  border-color: var(--gold-deep);
  outline: none;
}

.totals { display: flex; gap: 8px; }
.stat {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px;
  padding: 0 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.stat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-icon {
  width: 18px; height: 18px;
  opacity: 0.85;
  color: var(--gold-soft);
}
.stat-laws { color: var(--gold-soft); }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--bg-elev); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-ghost { padding: 7px 10px; }
.btn-primary {
  background: linear-gradient(to bottom, var(--gold), var(--gold-soft));
  border-color: var(--gold-soft);
  color: oklch(0.16 0.02 80);
  font-weight: 600;
}
.btn-primary:hover { background: linear-gradient(to bottom, oklch(0.86 0.13 82), var(--gold)); color: oklch(0.12 0.02 80); border-color: var(--gold); }
.btn-block { width: 100%; }
.btn-outline {
  border-color: var(--gold-deep);
  color: var(--gold);
  background: oklch(0.22 0.02 80 / .4);
}
.btn-outline:hover { background: oklch(0.28 0.04 80 / .55); border-color: var(--gold-soft); color: var(--gold); }
.btn-sidebar-toggle { display: inline-flex; }

/* Collapsed-sidebar layout: board takes the full row, sidebar slides offscreen.
   The toggle button stays in the topbar and re-opens it. */
body.sidebar-collapsed .layout {
  grid-template-columns: 1fr;
}
body.sidebar-collapsed .sidebar {
  display: none;
}

/* ============== LAYOUT ============== */
.layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  gap: 0;
  min-height: calc(100vh - 70px);
  position: relative;
  z-index: 1;
}
.board {
  padding: 12px 22px 16px;
  min-width: 0;
}
.board-footer {
  margin-top: 10px;
  display: flex; justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--line-faint);
  padding-top: 7px;
}
.board-footer em { font-style: normal; color: var(--gold-soft); }

/* ============== COST HEADERS ============== */
.cost-headers {
  display: grid;
  grid-template-columns: repeat(8, minmax(152px, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.cost-header {
  position: relative;
  text-align: center;
  padding: 4px 6px 5px;
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, oklch(0.24 0.013 80 / .8), oklch(0.20 0.012 80 / .6));
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--gold-deep);
}
.cost-header-eyebrow {
  display: block;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.cost-header-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  color: var(--gold);
  display: inline-flex; align-items: center; gap: 4px;
}
.cost-header-value img { width: 14px; height: 14px; opacity: .9; }

/* ============== TREE GRID ============== */
.tree-wrap {
  position: relative;
  overflow-x: auto; /* fall through to horizontal scroll when the column floor
                       below no longer fits the board width */
  /* hover/lift on the top row pushes a 22px shadow outward — leave room so it
     isn't clipped by overflow on the y-axis (overflow-x:auto implies y-clip) */
  padding: 14px 0 8px;
  margin: -14px 0 -8px;
}
.connections {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}
.tech-grid {
  position: relative;
  display: grid;
  /* Floor of 152 px per column gives names like "Administration" enough room
     to fit at the auto-shrunk 13 px size; below that the board scrolls
     horizontally. */
  grid-template-columns: repeat(8, minmax(152px, 1fr));
  grid-auto-rows: minmax(46px, auto);
  gap: 6px;
  z-index: 2;
}

/* ============== TECH NODE ============== */
.tech-node {
  position: relative;
  display: flex; align-items: stretch;
  background: linear-gradient(to bottom, oklch(0.24 0.013 80), oklch(0.20 0.013 80));
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
  /* No overflow:hidden here — the corner order badge sits at top:-8 / left:-8
     and needs to peek outside the card. The icon panel clips itself instead. */
}
.tech-node::after {
  /* hairline gold-leaf inset */
  content: "";
  position: absolute; inset: 0;
  border-radius: var(--radius-card);
  pointer-events: none;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / .04);
}
.tech-node:hover {
  border-color: var(--gold-deep);
  transform: translateY(-1px);
  z-index: 5;
  box-shadow: 0 0 0 1px var(--gold-deep), 0 8px 22px rgba(0,0,0,.55);
}

.tech-icon {
  flex-shrink: 0;
  width: 40px;
  align-self: stretch;
  background: oklch(0.16 0.01 80);
  border-right: 1px solid var(--line);
  /* Clip the icon image to the card's rounded-left corners; the card itself
     does not use overflow:hidden so the order badge can extend outside. */
  border-radius: calc(var(--radius-card) - 1px) 0 0 calc(var(--radius-card) - 1px);
  display: grid; place-items: center;
  overflow: hidden;
}
.tech-icon img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: -webkit-optimize-contrast;
}
.tech-icon-fallback {
  font-family: var(--font-serif);
  color: var(--gold-soft);
  font-size: 18px;
}
.tech-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.08;
  flex: 1;
  min-width: 0;
  align-self: center;
  padding: 6px 9px;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
}
/* JS adds this when the name would otherwise wrap; smaller font claws back
   some width so it stays on one line. */
.tech-name.is-shrunk { font-size: 13px; line-height: 1.05; }
.tech-name.is-tiny   { font-size: 11.5px; line-height: 1.05; }

/* Tech cards intentionally don't show unlock chips inline — the tooltip
   shows full unit/improvement/law/project/bonus detail on hover. */

/* corner cost delta badge */
.tech-delta {
  position: absolute;
  bottom: 4px; right: 4px;
  background: oklch(0.20 0.02 80 / .92);
  border: 1px solid var(--gold-deep);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  /* Off by default — the topbar "Costs" toggle (body.show-costs) reveals it. */
  display: none;
}
body.show-costs .tech-delta { display: block; }

/* Inline switch inside a ghost button. Pre-existing button styles handle the
   pill outline; .toggle-track is the little slider next to the label. */
.btn-toggle { display: inline-flex; align-items: center; gap: 8px; }
.btn-toggle .toggle-track {
  position: relative;
  display: inline-block;
  width: 26px; height: 14px;
  border-radius: 8px;
  background: oklch(0.18 0.012 80);
  border: 1px solid var(--line-strong);
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.btn-toggle .toggle-thumb {
  position: absolute;
  top: 1px; left: 1px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform .15s, background .15s;
}
.btn-toggle.is-active {
  color: var(--gold);
  border-color: var(--gold-deep);
}
.btn-toggle.is-active .toggle-track {
  background: oklch(0.30 0.06 80 / .65);
  border-color: var(--gold-soft);
}
.btn-toggle.is-active .toggle-thumb {
  transform: translateX(12px);
  background: var(--gold);
  box-shadow: 0 0 6px oklch(0.82 0.13 82 / .55);
}

/* order number badge */
.tech-order {
  position: absolute;
  top: -8px; left: -8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(to bottom, var(--gold), var(--gold-soft));
  color: oklch(0.16 0.02 80);
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  border: 1px solid oklch(0.30 0.04 80);
  z-index: 6;
}

/* ============== STATES ============== */
.tech-node.available {
  border-color: var(--state-avail);
  box-shadow: 0 0 0 1px oklch(0.82 0.13 82 / .55), 0 0 20px oklch(0.82 0.13 82 / .14);
}
.tech-node.available .tech-icon { border-color: var(--state-avail); }
@keyframes availPulse {
  0%, 100% { box-shadow: 0 0 0 1px oklch(0.82 0.13 82 / .55), 0 0 16px oklch(0.82 0.13 82 / .08); }
  50% { box-shadow: 0 0 0 1px oklch(0.82 0.13 82 / .85), 0 0 28px oklch(0.82 0.13 82 / .22); }
}
.tech-node.available { animation: availPulse 2.6s ease-in-out infinite; }

.tech-node.on-path {
  background: linear-gradient(to bottom, oklch(0.27 0.05 252), oklch(0.21 0.04 252));
  border-color: var(--state-onpath);
}
.tech-node.on-path .tech-icon { border-color: var(--state-onpath); }
.tech-node.on-path .tech-name { color: oklch(0.95 0.03 252); }

.tech-node.completed {
  background: linear-gradient(to bottom, oklch(0.28 0.06 148), oklch(0.21 0.05 148));
  border-color: var(--state-done);
}
.tech-node.completed .tech-icon { border-color: var(--state-done); }
.tech-node.completed .tech-name { color: oklch(0.95 0.04 148); }
.tech-node.completed::before {
  content: "✓";
  position: absolute; top: 6px; right: 8px;
  font-size: 11px;
  color: var(--state-done);
  font-weight: 700;
}

/* Starting techs share the green "completed" styling — no separate FREE badge needed. */

.tech-node.prereq-preview {
  outline: 2px dashed var(--gold);
  outline-offset: 3px;
  animation: none;
}

/* ============== BONUS CARDS ============== */
.bonus-section { margin-top: 40px; }
.section-header { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.section-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold-soft);
}
.section-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 24px;
  margin: 0;
  color: var(--text);
}
.section-desc { color: var(--text-muted); margin: 2px 0 0; font-size: 12px; }

.bonus-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-color: var(--line-strong) transparent;
}
.bonus-col {
  display: flex; flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 142px;
}
.bonus-col-header {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--gold);
  padding: 6px 8px;
  background: oklch(0.20 0.012 80);
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--gold-deep);
  border-radius: var(--radius-sm);
  display: flex; justify-content: center; align-items: center; gap: 4px;
}
.bonus-col-header img { width: 12px; height: 12px; }

.bonus-card {
  position: relative;
  display: flex;
  align-items: stretch;
  background: linear-gradient(to bottom, oklch(0.23 0.013 80), oklch(0.19 0.013 80));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
  opacity: 0.55;
  overflow: hidden;
  min-height: 56px;
}
.bonus-card.available { opacity: 1; border-color: var(--gold-deep); }
.bonus-card.on-path { opacity: 1; background: linear-gradient(to bottom, oklch(0.27 0.05 252), oklch(0.21 0.04 252)); border-color: var(--state-onpath); }
.bonus-card.completed { opacity: 1; background: linear-gradient(to bottom, oklch(0.28 0.06 148), oklch(0.21 0.05 148)); border-color: var(--state-done); }
.bonus-card:hover { border-color: var(--gold-soft); transform: translateY(-1px); }

.bonus-card-icon {
  flex-shrink: 0;
  width: 52px;
  align-self: stretch;
  background: oklch(0.16 0.01 80);
  border-right: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--gold-soft);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
}
.bonus-card-icon img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.bonus-card-body {
  flex: 1; min-width: 0;
  padding: 7px 9px;
  display: flex; flex-direction: column; justify-content: center;
  gap: 2px;
}
.bonus-card-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 12px;
  line-height: 1.15;
  color: var(--text);
}
.bonus-card-desc {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ============== SIDEBAR ============== */
.sidebar {
  background: linear-gradient(to bottom, oklch(0.20 0.012 80), oklch(0.17 0.012 80));
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: calc(100vh - 70px);
  position: sticky;
  top: 70px;
  height: calc(100vh - 70px);
}
.sidebar-header {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.sidebar-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold-soft);
}
.sidebar-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 22px;
  margin: 2px 0 0;
  color: var(--text);
}
.sidebar-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 22px; cursor: pointer;
  display: none;
  line-height: 1; padding: 4px 8px;
  border-radius: 6px;
}
.sidebar-close:hover { color: var(--text); background: var(--bg-elev); }

.sidebar-actions { display: none; } /* legacy slot, content moved to bottom */

.sidebar-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 4px 14px 14px;
  scrollbar-color: var(--line-strong) transparent;
}
.sidebar-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  padding: 8px 4px 6px;
  display: flex; justify-content: space-between;
}
.muted { color: var(--text-dim); font-family: var(--font-mono); }

.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.order-item {
  display: grid;
  grid-template-columns: 28px 40px 1fr auto;
  align-items: stretch; /* let the icon stretch top-to-bottom */
  gap: 8px;
  padding: 0 10px 0 0;
  min-height: 42px;
  background: oklch(0.21 0.012 80);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  transition: background .12s, border-color .12s;
  cursor: pointer;
}
.order-num, .order-name, .order-cost { align-self: center; }
.order-num { padding-left: 10px; }
.order-icon {
  align-self: stretch;
  width: 40px;
  height: 100%;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: oklch(0.16 0.01 80);
  object-fit: cover;
}
.order-item:hover { background: oklch(0.24 0.013 80); border-color: var(--line-strong); }
.order-item.completed { border-left: 3px solid var(--state-done); background: oklch(0.22 0.04 148 / .35); }
.order-item.bonus { border-style: dashed; }
.order-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
}
.order-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-cost { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.order-cost.free { color: var(--state-done); text-decoration: line-through; }

.order-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}
.order-empty-icon {
  font-size: 26px;
  color: var(--gold-deep);
  margin-bottom: 8px;
}
.order-empty p { font-size: 12px; line-height: 1.4; max-width: 220px; margin: 0 auto; }

/* Bottom action row: Clear plan (destructive, left) | Simulate (subdued, right).
   Both rare actions, neither competes with the Plan list above. */
.sidebar-foot-actions {
  padding: 10px 14px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.sidebar-clear,
.sidebar-sim {
  appearance: none;
  font: 600 12px/1.2 var(--font-sans);
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
  display: inline-flex; align-items: center; gap: 5px;
}
.sidebar-clear {
  background: oklch(0.22 0.04 28 / .25);
  border: 1px solid oklch(0.42 0.08 28);
  color: oklch(0.78 0.12 28);
}
.sidebar-clear:hover {
  color: oklch(0.86 0.16 28);
  border-color: oklch(0.60 0.14 28);
  background: oklch(0.30 0.08 28 / .45);
}
.sidebar-sim {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-muted);
}
.sidebar-sim:hover {
  color: var(--gold);
  border-color: var(--gold-deep);
  background: oklch(0.22 0.04 80 / .25);
}

.sidebar-footer {
  padding: 10px 18px 14px;
  border-top: 1px solid var(--line-faint);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}

/* ============== TOOLTIP ============== */
.tooltip {
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  background: linear-gradient(to bottom, oklch(0.18 0.013 80 / .98), oklch(0.14 0.012 80 / .98));
  border: 1px solid var(--gold-deep);
  border-radius: 10px;
  padding: 14px;
  min-width: 240px;
  max-width: 320px;
  box-shadow: 0 14px 40px rgba(0,0,0,.7);
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .12s;
  transform-origin: top left;
}
.tooltip.show { opacity: 1; visibility: visible; }
.tooltip h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 4px;
  color: var(--gold);
  display: flex; align-items: center; gap: 8px;
}
.tooltip h3 img {
  width: 64px; height: 64px;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: oklch(0.16 0.01 80);
}
.tooltip .tt-meta { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); letter-spacing: 0.04em; }
.tooltip .tt-section {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--line);
}
.tooltip .tt-section h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin: 0 0 4px;
  color: var(--text-muted);
}
.tooltip .tt-section-ic {
  width: 14px; height: 14px; vertical-align: -2px;
  margin-right: 2px;
}
.tooltip .tt-list { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); }
.tooltip .tt-row { display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-row .tt-icon {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: oklch(0.16 0.01 80);
  object-fit: cover;
  flex-shrink: 0;
}
/* White-silhouette glyphs read better with a slight dark backing and no
   border-radius cropping that would clip the tips of bows / weapons. */
.tooltip .tt-row .tt-icon-glyph {
  background: oklch(0.20 0.013 80);
  object-fit: contain;
  padding: 1px;
}
.tooltip .tt-row-label { line-height: 1.2; }
.tooltip .tt-bonus-row { display: block; line-height: 1.35; }
.tooltip .tt-bonus-row strong { color: var(--gold-soft); font-weight: 600; }
.tt-yield-ic {
  display: inline-block;
  width: 14px; height: 14px;
  vertical-align: -3px;
  margin: 0 2px;
}
.bonus-card-desc .tt-yield-ic { width: 12px; height: 12px; vertical-align: -2px; }

/* ============== TWEAKS PANEL ============== */
.tweaks-panel {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 300;
  width: 280px;
  background: oklch(0.16 0.012 80 / .98);
  border: 1px solid var(--gold-deep);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,.7);
  overflow: hidden;
}
.tweaks-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: oklch(0.20 0.013 80);
  border-bottom: 1px solid var(--line);
}
.tweaks-header h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 16px; color: var(--gold);
}
.tweaks-close {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 18px; cursor: pointer;
  line-height: 1;
}
.tweaks-close:hover { color: var(--text); }
.tweaks-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 14px; }
.tweak-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.tweak-segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  background: oklch(0.20 0.012 80);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
}
.tweak-segmented button {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 4px;
  border-radius: 4px;
  cursor: pointer;
}
.tweak-segmented button:hover { color: var(--text); }
.tweak-segmented button.is-active {
  background: linear-gradient(to bottom, var(--gold), var(--gold-soft));
  color: oklch(0.16 0.02 80);
  font-weight: 600;
}
.tweak-hint { font-size: 11px; color: var(--text-muted); margin: 8px 2px 0; line-height: 1.4; }

/* ============== MODAL ============== */
.modal { position: fixed; inset: 0; z-index: 400; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); }
.modal-panel {
  position: relative;
  width: min(880px, 92vw);
  max-height: 84vh;
  margin: 6vh auto;
  background: linear-gradient(to bottom, oklch(0.22 0.013 80), oklch(0.17 0.012 80));
  border: 1px solid var(--gold-deep);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: start;
  margin-bottom: 6px;
}
.modal-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.2em; color: var(--gold-soft); }
.modal-header h2 { font-family: var(--font-serif); font-weight: 600; font-size: 24px; margin: 2px 0 0; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-desc { color: var(--text-muted); font-size: 12px; margin: 0 0 14px; max-width: 60ch; }
.modal-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.modal-results-wrap { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.modal-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 10.5px; color: var(--text-muted);
  border-top: 1px solid var(--line);
  padding-top: 10px; margin-top: 12px;
  letter-spacing: 0.04em;
}
.modal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sim-dot { width: 10px; height: 10px; border-radius: 99px; display: inline-block; }
.sim-dot-band { width: 16px; height: 4px; border-radius: 2px; background: var(--gold-soft); opacity: 0.7; }

:root {
  --sim-min: oklch(0.74 0.13 148);
  --sim-avg: oklch(0.70 0.10 252);
  --sim-max: oklch(0.66 0.16 28);
}

.sim-row {
  background: oklch(0.20 0.012 80);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px 14px;
}
.sim-row-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.sim-row-name {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--gold);
  font-weight: 600;
}
.sim-row-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.sim-row-status.sim-fail { color: var(--state-onpath); }
.sim-row-stats {
  display: inline-flex; gap: 10px; align-items: baseline;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-soft);
}
.sim-stat-avg { font-size: 15px; color: var(--sim-avg); font-weight: 600; }
.sim-stat-sigma { color: var(--gold-soft); }
.sim-stat-range { color: var(--text-muted); }

.sim-row-bar {
  position: relative;
  height: 18px;
  background: oklch(0.16 0.01 80);
  border-radius: 9px;
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.sim-band-range {
  position: absolute; top: 6px; height: 6px;
  background: oklch(0.42 0.012 80 / .7);
  border-radius: 3px;
}
.sim-band-sigma {
  position: absolute; top: 2px; height: 14px;
  background: var(--gold-soft);
  opacity: 0.42;
  border-radius: 4px;
}
.sim-marker {
  position: absolute; top: 1px; bottom: 1px;
  width: 3px;
  border-radius: 2px;
  transform: translateX(-50%);
}
.sim-marker-min { background: var(--sim-min); }
.sim-marker-avg { background: var(--sim-avg); }
.sim-marker-max { background: var(--sim-max); }

.sim-row-axis {
  position: relative;
  height: 14px;
  margin-top: -8px;
}
.sim-axis-tick {
  position: absolute;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}
.sim-axis-tick.sim-axis-avg { color: var(--sim-avg); }

.sim-row-bar .sim-progress {
  position: absolute; inset: 0;
  background: linear-gradient(to right, oklch(0.35 0.04 252), oklch(0.45 0.04 252));
  border-radius: 9px;
  transition: width .15s ease;
}

/* ============== VERSION WARNING (kept simple) ============== */
.version-warning {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  background: linear-gradient(to bottom, var(--gold), var(--gold-soft));
  color: oklch(0.16 0.02 80);
  padding: 8px 40px 8px 14px;
  font-size: 12px;
  text-align: center;
  font-weight: 500;
  display: none;
}

/* =====================================================
   DIRECTION VARIANTS
   ===================================================== */

/* --- ATLAS: cartographer / atlas vibe --- */
body[data-direction="atlas"] {
  background:
    radial-gradient(1200px 600px at 20% -10%, oklch(0.30 0.04 70 / .55), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, oklch(0.24 0.02 240 / .25), transparent 60%),
    oklch(0.20 0.018 70);
}
body[data-direction="atlas"] {
  --line: oklch(0.34 0.020 70);
  --line-faint: oklch(0.30 0.014 70);
}
body[data-direction="atlas"] .tree-wrap {
  background: none;
  padding: 10px 4px;
  border-radius: 12px;
  border: 1px solid var(--line-faint);
}
body[data-direction="atlas"] .tech-node {
  background: linear-gradient(to bottom, oklch(0.26 0.025 70), oklch(0.21 0.020 70));
  border-radius: 6px;
}
body[data-direction="atlas"] .tech-node::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(to bottom, var(--gold-deep), transparent);
  opacity: .6;
}
body[data-direction="atlas"] .cost-header {
  background: oklch(0.26 0.03 70);
  border-radius: 4px;
  border-bottom: 3px double var(--gold-deep);
}

/* --- CODEX: ultra-dense, table-row feel --- */
body[data-direction="codex"] .tech-grid {
  gap: 4px;
  grid-auto-rows: minmax(64px, auto);
}
body[data-direction="codex"] .tech-head,
body[data-density="compact"] .tech-head {
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}
body[data-direction="codex"] .tech-name,
body[data-density="compact"] .tech-name {
  width: 100%;
  line-height: 1.1;
  font-size: 11.5px;
}
body[data-direction="codex"] .cost-headers { gap: 4px; }
body[data-direction="codex"] .tech-node {
  padding: 5px 6px;
  border-radius: 4px;
  grid-template-rows: auto 1fr;
}
body[data-direction="codex"] .tech-icon { width: 28px; height: 28px; }
body[data-direction="codex"] .tech-icon img { width: 24px; height: 24px; }
body[data-direction="codex"] .tech-name { font-size: 12px; }
body[data-direction="codex"] .unlock-chip { font-size: 9px; padding: 0 4px; }
body[data-direction="codex"] .unlock-chip .glyph { display: none; }
body[data-direction="codex"] .tech-order { width: 18px; height: 18px; font-size: 10px; top: -6px; left: -6px; }
body[data-direction="codex"] .tech-delta { font-size: 9px; padding: 0 3px; }

/* --- DENSITY --- */
body[data-density="spacious"] .tech-grid { gap: 14px; grid-auto-rows: minmax(108px, auto); }
body[data-density="spacious"] .cost-headers { gap: 14px; }
body[data-density="compact"] .tech-grid { gap: 6px; grid-auto-rows: minmax(78px, auto); }
body[data-density="compact"] .cost-headers { gap: 6px; }
body[data-density="compact"] .tech-node { padding: 6px 7px; }

/* --- CONNECTIONS --- */
body[data-connections="hidden"] .connections { display: none; }
body[data-connections="ink"] .connection-line { stroke: oklch(0.55 0.014 80); stroke-width: 1.4; opacity: 0.55; }
body[data-connections="gold"] .connection-line { stroke: var(--gold-deep); stroke-width: 1.6; opacity: 0.7; }
.connection-line.on-path { stroke: var(--state-onpath) !important; opacity: 1 !important; stroke-width: 2 !important; }
.connection-line.completed { stroke: var(--state-done) !important; opacity: 1 !important; stroke-width: 2 !important; }

/* --- SHAPE: medallion --- */
body[data-shape="medallion"] .tech-icon { border-radius: 50%; width: 42px; height: 42px; }
body[data-shape="medallion"] .tech-icon img { width: 36px; height: 36px; }
body[data-shape="medallion"] .tech-node { border-radius: 14px; }

/* =====================================================
   RESPONSIVE — mobile
   ===================================================== */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 300px; }
  :root { --sidebar-w: 300px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    height: 80vh;
    border-left: none;
    border-top: 1px solid var(--gold-deep);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
    transition: transform .28s ease;
    z-index: 100;
    box-shadow: 0 -20px 50px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: translateY(0); }
  .sidebar-close { display: block; }
  .btn-sidebar-toggle { display: inline-flex; }
  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
  }
  .brand-title { font-size: 18px; }
  .brand { flex: 1; }
  .topbar-meta { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .nation-field { flex: 1 1 140px; }
  .totals { flex: 1 1 auto; }
  .stat { flex: 1; min-width: 0; }
  .topbar-actions { flex: 1 1 100%; justify-content: flex-end; }

  .tech-grid {
    grid-template-columns: repeat(8, 96px);
    overflow-x: auto;
  }
  .board {
    overflow-x: auto;
  }
  .cost-headers { grid-template-columns: repeat(8, 96px); }
}

@media (max-width: 600px) {
  .tech-grid, .cost-headers { grid-template-columns: repeat(8, 84px); gap: 5px; }
  .tech-name { font-size: 12px; }
  .unlock-chip { font-size: 9px; }
  .tech-icon { width: 28px; height: 28px; }
  .tech-icon img { width: 24px; height: 24px; }
}
