:root {
  --bg-deep: #131c37;
  --bg-surface: #1c2952;
  --ink: #101423;
  --ink-soft: #3f4a6b;
  --text-light: #e7e7e7;
  --card: #f3f3f3;
  --line: #768ae2;
  --line-soft: #c9d3ff;
  --accent: #1976d2;
  --accent-2: #284a9a;
  --shadow: 0 14px 30px rgba(4, 12, 28, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", sans-serif;
  color: var(--text-light);
  position: relative;
  isolation: isolate;
  background: var(--bg-deep);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  background: radial-gradient(circle at 20% 20%, #27386f 0, transparent 32%),
    radial-gradient(circle at 80% -10%, #1d73d444 0, transparent 34%),
    url("https://www.milkywayidle.com/static/media/background.92b38e14.svg") center/cover,
    var(--bg-deep);
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(60px);
  opacity: 0.28;
  pointer-events: none;
  z-index: -1;
}

.bg-orb-a {
  width: 420px;
  height: 420px;
  background: #2a72d1;
  top: -100px;
  right: -80px;
}

.bg-orb-b {
  width: 460px;
  height: 460px;
  background: #4a58a8;
  bottom: -140px;
  left: -120px;
}

.page {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 42px 0 80px;
  position: relative;
  z-index: 1;
}

.site-footer {
  margin-top: 40px;
  text-align: center;
  font-size: 0.8rem;
  color: #8899cc;
}
.site-footer a {
  color: #a0b0e8;
  text-decoration: none;
}
.site-footer a:hover {
  color: #d4ddff;
  text-decoration: underline;
}
.site-footer-sep {
  margin: 0 8px;
  opacity: 0.5;
}

.hero {
  margin-bottom: 20px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #b8c2ea;
  font-size: 0.78rem;
  margin: 0;
  font-weight: 600;
}

h1 {
  font-family: "Fraunces", serif;
  font-size: clamp(1.9rem, 4.6vw, 3.8rem);
  line-height: 1.04;
  margin: 10px 0 14px;
  max-width: none;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  color: #f1f4ff;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  white-space: nowrap;
}

.hero-copy {
  margin: 0;
  color: #d4ddff;
  max-width: 720px;
}

.panel {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-top: 16px;
  padding: 20px;
  color: var(--ink);
}

.reveal {
  animation: reveal 560ms ease both;
}

.reveal:nth-of-type(2) {
  animation-delay: 80ms;
}

.reveal:nth-of-type(3) {
  animation-delay: 120ms;
}

.reveal:nth-of-type(4) {
  animation-delay: 160ms;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.controls-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.controls-grid > label {
  display: flex;
  flex-direction: column;
}

label span {
  display: block;
  margin-bottom: 7px;
  font-size: 0.86rem;
  color: var(--ink-soft);
  font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  box-sizing: border-box;
  height: 43px;
  border-radius: 4px;
  border: 1px solid #9fb0f2;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}

textarea {
  width: 100%;
  border-radius: 4px;
  border: 1px solid #9fb0f2;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
}

input:focus {
  outline: 2px solid #4d88e780;
  border-color: var(--accent);
}

textarea:focus {
  outline: 2px solid #4d88e780;
  border-color: var(--accent);
}

.controls-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.load-data-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.load-data-group .status {
  flex: 1;
  min-width: 0;
}

.controls-grid + .controls-actions {
  margin-top: 14px;
}

.qty-field-wrap {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.qty-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.qty-input-row #quantity {
  width: 120px;
  min-width: 0;
  flex-shrink: 1;
}

.qty-presets {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.qty-presets-row {
  display: flex;
  gap: 4px;
}

.qty-preset-btn {
  padding: 3px 9px;
  font-size: 0.8rem;
  border: 1px solid #b0bef7;
  background: #eef1ff;
  color: #2e3f9e;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.4;
}

.qty-preset-btn:hover {
  background: #d8deff;
  border-color: #6678d4;
}

.user-data-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.user-data-panel-title {
  font-family: "Fraunces", serif;
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #1b2444;
}

.user-data-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.user-data-stack {
  display: grid;
  gap: 16px;
}

.user-data-card {
  padding: 16px;
  border: 1px solid #d1daf8;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(236, 240, 255, 0.66), rgba(247, 248, 255, 0.96));
}

.user-data-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.user-data-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.section-toggle-btn {
  border: 1px solid #a3b5ea;
  background: #f3f6ff;
  color: #29438f;
  border-radius: 999px;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 140ms, background-color 140ms, color 140ms;
}

.section-toggle-btn:hover {
  background: #e9efff;
  border-color: #8ea3df;
}

.section-toggle-btn:focus-visible {
  outline: 2px solid #4d88e780;
  outline-offset: 2px;
}

.collapsible-body[hidden] {
  display: none;
}

.user-data-layout[hidden] {
  display: none;
}

.user-data-copy {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 0.84rem;
  line-height: 1.45;
  /* max-width: 44ch; */
}

.coming-soon-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eaf0ff;
  border: 1px solid #c6d4ff;
  color: #4962b7;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.user-data-field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.user-data-field {
  display: block;
}

.user-data-field-grid-gear {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.gear-split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.gear-split-column {
  min-width: 0;
}

.gear-split-column-skill-items {
  border-left: 1px solid #cfd8f8;
  padding-left: 14px;
}

.user-data-divider {
  border-top: 1px solid #cfd8f8;
  margin: 14px 0 10px;
}

.user-data-subtitle {
  margin: 0 0 10px;
  color: #2f3c74;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Settings button */
.btn-settings {
  margin-left: auto;
  font-size: 0.82rem;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.btn-settings:hover {
  background: var(--card);
  color: var(--ink);
}
.btn-help {
  font-size: 0.82rem;
  padding: 4px 9px;
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}
.btn-help:hover {
  background: var(--card);
  color: var(--ink);
}

/* Settings modal */
.settings-modal {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  padding: 0;
  width: min(480px, 92vw);
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
}
.settings-modal::backdrop {
  background: rgba(10, 14, 35, 0.55);
  backdrop-filter: blur(2px);
}
.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.settings-modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.settings-modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.settings-modal-close:hover { color: var(--ink); background: var(--line-soft); }
.settings-modal-body {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Shortcuts table inside the modal */
.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.shortcuts-table td {
  padding: 7px 8px;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
}
.shortcuts-table tr:last-child td { border-bottom: none; }
.shortcuts-table td:first-child { white-space: nowrap; padding-right: 16px; }
.shortcuts-table td:last-child { color: var(--ink-soft); }
kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink);
}
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-section-title {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--ink);
}
.settings-field span {
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.settings-field input[type="text"],
.settings-field input[type="file"] {
  width: 100%;
  box-sizing: border-box;
}

/* Hide icon frames + collapse gaps when icons are disabled */
body.icons-disabled .item-icon-frame {
  display: none;
}

body.icons-disabled .node-line {
  gap: 0;
}

body.icons-disabled .material-name-cell {
  gap: 0;
}

/* Inventory hints row */
.inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.inventory-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
}

.inventory-userscript-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: #22a06b;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
  transition: color 120ms;
}

.toolasha-action-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-left: auto;
}

.inventory-userscript-link:hover { color: #1a8c55; }

.inventory-userscript-link.toolasha-ready {
  padding: 6px 12px;
  border: 1px solid #1a8c55;
  border-radius: 999px;
  background: #e8f6ef;
  color: #1a8c55;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(20, 88, 56, 0.12);
}

.inventory-userscript-link.toolasha-ready:hover {
  color: #146b43;
  background: #ddf1e7;
  border-color: #146b43;
}

.inventory-userscript-link.toolasha-ready:active {
  background: #d0eadc;
}

.inventory-userscript-link.toolasha-ready.toolasha-pending {
  color: #5b7d6d;
  background: #edf5f1;
  border-color: #9ac4ae;
  box-shadow: none;
  cursor: wait;
}

/* Inventory hints row */
.inventory-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.hint-chip {
  display: inline-block;
  font-size: 0.78rem;
  font-family: monospace;
  background: #e8ecf8;
  color: #3b4a7a;
  border: 1px solid #c5cce8;
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
}

.btn-link-sm {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 120ms;
}

.btn-link-sm:hover { color: #1a64b8; }

.toolasha-btn {
  margin-left: auto;
  white-space: nowrap;
  padding: 6px 12px;
  border: 1px solid #1a8c55;
  border-radius: 999px;
  background: #e8f6ef;
  color: #1a8c55;
  text-decoration: none;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(20, 88, 56, 0.12);
}

.toolasha-btn:hover {
  color: #146b43;
  background: #ddf1e7;
  border-color: #146b43;
}

.toolasha-btn:active {
  background: #d0eadc;
}

.toolasha-note {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: #9aa;
}

.toolasha-note--header {
  flex-basis: auto;
  max-width: 36ch;
  text-align: right;
}

.label-hint {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.btn {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 130ms ease, filter 130ms ease, box-shadow 130ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 8px 16px rgba(13, 32, 74, 0.25);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(180deg, #2f8ded, var(--accent));
  color: #ffffff;
  border-color: #1a64b8;
}

.btn-secondary {
  background: linear-gradient(180deg, #5f76ca, #495ca4);
  color: #f5f8ff;
  border-color: #3e5192;
}

.btn-secondary.btn-active {
  background: linear-gradient(180deg, #3a508f, #2d3f70);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.3);
  outline: 2px solid #a0b4ff;
  outline-offset: 1px;
}

.btn-sm {
  padding: 2px 10px;
  font-size: 0.82rem;
}

.btn-clear {
  padding: 2px 10px;
  font-size: 0.82rem;
  border: 1px solid #c97a7a;
  background: #fff0f0;
  color: #a03030;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.4;
}

.btn-clear:hover {
  background: #fde0e0;
  border-color: #a03030;
}

.panel-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.panel-header-row h2 {
  margin: 0;
}

.panel-header-row .section-toggle-btn {
  margin-left: auto;
}

/* Queue list */
.queue-list-wrap {
  margin-top: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--bg);
}

.queue-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.queue-list-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.9rem;
}

.queue-item-label {
  flex: 1;
  font-weight: 500;
  color: var(--ink);
}

.queue-item-qty {
  cursor: text;
  border-bottom: 1px dashed var(--ink-soft);
  padding-bottom: 1px;
}

.queue-item-qty:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.queue-item-qty-input {
  width: 4.5ch;
  font: inherit;
  font-weight: 600;
  text-align: right;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0 3px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.queue-item-reorder {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.queue-item-move {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.55rem;
  padding: 0 3px;
  line-height: 1;
  border-radius: 3px;
}

.queue-item-move:hover:not(:disabled) {
  color: var(--accent);
  background: var(--accent-muted, #eef);
}

.queue-item-move:disabled {
  opacity: 0.25;
  cursor: default;
}

.queue-item-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
}

.queue-item-remove:hover {
  color: #b8412d;
  background: #fff0f0;
}

.item-history {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 4px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.history-chip:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.history-chip .item-icon-frame {
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

.history-chip .item-icon {
  width: 20px;
  height: 20px;
}

.price-age {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-right: auto;
}

/* Per-item tree label in multi-item mode */
.queue-tree-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 4px;
  padding: 4px 8px;
  background: var(--bg);
  border-left: 3px solid #6678d4;
  border-radius: 0 4px 4px 0;
}

/* Per-item breakdown rows in materials table */
.breakdown-chevron {
  display: inline-block;
  margin-right: 5px;
  font-size: 0.7rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.15s;
  user-select: none;
  vertical-align: middle;
}

.breakdown-chevron.expanded {
  transform: rotate(90deg);
}

.material-breakdown-row td {
  padding-top: 2px;
  padding-bottom: 2px;
  background: var(--bg);
  border-top: none;
}

.material-breakdown-cell {
  padding-left: 2.4rem !important;
  font-size: 0.82rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}

.material-breakdown-cell .item-icon-frame {
  width: 14px;
  height: 14px;
}

.material-breakdown-cell .item-icon {
  width: 14px;
  height: 14px;
}

.materials-summary {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 4px;
  display: inline-block;
}

.materials-summary--ok {
  background: #eafaf0;
  color: #1e7a40;
  border: 1px solid #90d4aa;
}

.materials-summary--missing {
  background: #fff7e6;
  color: #8a5a00;
  border: 1px solid #e0b94a;
}

.status {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin: 7px 0 0;
  font-family: "Fraunces", serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1f2a4d;
}

.stat-bonuses {
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.6;
}

.stat-bonuses p {
  margin: 0;
}

.bonuses-panel .stat-label {
  margin-bottom: 10px;
}

.stat-bonuses-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1f2a4d;
  line-height: 1.6;
}

h2 {
  font-family: "Fraunces", serif;
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #1b2444;
}

.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree li {
  position: relative;
  margin: 0;
}

/* Nested list: indented.
   padding-left must be >= connector width (26px) so ::before/::after
   stay inside the padding box and are not clipped by overflow:hidden. */
.tree ul ul {
  margin-left: 24px;
  padding-left: 28px;
  margin-top: 4px;
}

/* L-shaped elbow for every child */
.tree ul ul > li::before {
  content: '';
  position: absolute;
  top: 0;
  left: -26px;
  width: 26px;
  height: 27px;
  border-left: 2px solid #a8b8f1;
  border-bottom: 2px solid #a8b8f1;
  border-bottom-left-radius: 5px;
  box-sizing: border-box;
}

/* Extend vertical bar downward only for non-last children */
.tree ul ul > li:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 27px;
  left: -26px;
  width: 2px;
  bottom: 0;
  background: #a8b8f1;
}

.item-icon-frame {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #b8c4f2 0%, #cdd5f8 100%);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 3px;
  box-shadow: inset 0 1px 2px rgba(118, 138, 226, 0.15);
}

.item-icon {
  width: 100%;
  height: 100%;
  display: block;
}

.node-toggle {
  margin-left: auto;
  padding: 0 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  color: var(--line);
  line-height: 1;
  flex-shrink: 0;
  transition: color 120ms;
}

.node-toggle:hover {
  color: var(--accent);
}

/* Children list — animates via max-height trick */
.node-children {
  overflow: hidden;
  max-height: 9999px;
  transition: max-height 250ms ease, opacity 200ms ease;
  opacity: 1;
}

.node-children--collapsed {
  max-height: 0 !important;
  opacity: 0;
}

.node-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid #a8b8f1;
  background: #ffffff;
}

/* Base materials: dashed border + muted background */
.node-line--base {
  background: #f5f7ff;
  border-color: var(--line-soft);
  border-style: dashed;
  color: var(--ink-soft);
}

/* Material availability highlighting (requires inventory data) */
.node-line--have-none {
  background: #fff0f0;
  border-color: #f0a0a0;
  border-style: dashed;
}

.node-line--have-partial {
  background: #fffbe6;
  border-color: #ddb830;
  border-style: dashed;
}

.node-line--have-all {
  background: #f0fff4;
  border-color: #80c8a0;
  border-style: dashed;
}

.node-line--subtree-missing {
  border-left: 3px solid #ddb830;
}

.material-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-meta {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.skill-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: #dde5ff;
  border: 1px solid #b0bef7;
  color: #2e3f9e;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.skill-badge--met {
  background: #e7f7ec;
  border-color: #95d2a7;
  color: #1f7a3f;
}

.skill-badge--missing {
  background: #ffecec;
  border-color: #f0b0b0;
  color: #b8412d;
}

.node-line--base .skill-badge {
  background: #eef0fa;
  border-color: var(--line-soft);
  color: var(--ink-soft);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #a9b8ee;
  border-radius: 6px;
  overflow: hidden;
}

th,
td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid #d2dbfa;
}

#skills th,
#skills td {
  text-align: center;
}

th {
  background: #e9eeff;
  color: #1c2750;
}

tr.row-missing {
  background: #fff5f5;
}

.price-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.price-cell--loading {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

tfoot tr[data-totals-row] {
  border-top: 2px solid var(--line);
}

tfoot tr[data-totals-row] td {
  padding-top: 7px;
  padding-bottom: 7px;
  background: var(--bg);
}

.totals-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tfoot tr[data-totals-row] [data-total-cost] {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}

tr.row-missing td:nth-child(5) {
  font-weight: 600;
  color: #b8412d;
}

tr.row-missing td:nth-child(5)::before {
  content: "⚠ ";
  font-size: 0.78rem;
}

tr.row-skill-met {
  background: #f4fbf6;
}

tr.row-skill-missing {
  background: #fff5f5;
}

.skill-status-cell {
  font-weight: 700;
  text-align: center;
}

.skill-actions-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.skill-status-cell--ok {
  color: #1f7a3f;
}

.skill-status-cell--bad {
  color: #b8412d;
}

/* Best Drinks section */
.best-teas-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.apply-drinks-btn {
  margin-top: 10px;
  padding: 5px 14px;
  font-size: 0.85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.apply-drinks-btn:hover {
  opacity: 0.88;
}

.best-tea-row td {
  vertical-align: middle;
}

.best-tea-row {
  background: var(--card);
}

.best-tea-row--equipped {
  background: color-mix(in srgb, var(--card) 80%, #1e7a40 20%);
}

.best-tea-equipped-badge {
  font-size: 1rem;
  font-weight: 700;
  color: #1e7a40;
}

.best-tea-rank {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink-soft);
  text-align: center;
  width: 2rem;
}

tr.best-tea-row:first-child .best-tea-rank {
  color: #b8860b;
}

tr.best-tea-row:nth-child(2) .best-tea-rank {
  color: #888;
}

tr.best-tea-row:nth-child(3) .best-tea-rank {
  color: #8b4513;
}

#bestTeas table {
  width: 100%;
}

#bestTeas table th:nth-child(1),
#bestTeas table td:nth-child(1) {
  width: 2.5rem;
}

#bestTeas table th:nth-child(2),
#bestTeas table td:nth-child(2) {
  min-width: 160px;
}

#bestTeas table th:nth-child(3),
#bestTeas table td:nth-child(3) {
  min-width: 140px;
}

.best-tea-bonus {
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}

.best-tea-name {
  white-space: nowrap;
  min-width: 160px;
}

.best-tea-name-inner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.buff-desc {
  display: block;
  font-size: 0.85rem;
}

.buff-desc--speed {
  color: #1e7a40;
}

.buff-desc--level {
  color: #5a6abf;
}

.best-tea-applies {
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-transform: capitalize;
}

.skill-status-cell--unknown {
  color: var(--ink-soft);
}

.notes {
  margin: 0;
  padding-left: 18px;
  color: var(--ink-soft);
}

/* Step-by-step crafting order */
.craft-order-list {
  counter-reset: craft-step;
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.craft-order-step {
  counter-increment: craft-step;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid #a8b8f1;
  background: #ffffff;
}

.craft-order-step .step-time {
  margin-left: auto;
  font-weight: 600;
  color: var(--ink);
}

.craft-order-step::before {
  content: counter(craft-step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e9eeff;
  border: 1px solid #b0bef7;
  color: #2e3f9e;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.craft-order-empty {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0;
}

body.icons-disabled .craft-order-step {
  gap: 0;
}

@media (max-width: 760px) {
  .page {
    width: min(1100px, 95vw);
    padding-top: 26px;
  }

  h1 {
    font-size: clamp(1.25rem, 7.1vw, 1.95rem);
    letter-spacing: 0.02em;
  }

  .panel {
    border-radius: 16px;
    padding: 16px;
  }

  .user-data-layout,
  .user-data-field-grid,
  .user-data-field-grid-gear {
    grid-template-columns: 1fr;
  }

  .gear-split-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .gear-split-column-skill-items {
    border-left: none;
    border-top: 1px solid #cfd8f8;
    padding-left: 0;
    padding-top: 10px;
  }

  .user-data-card-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── Print / PDF layout ──────────────────────────────────────── */
@media print {
  /* Force light background and black ink */
  *, *::before, *::after {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  /* Hide non-result UI */
  .bg-orb,
  .hero,
  .controls-panel,
  .bonuses-panel,
  #bestTeasSection,
  .section-toggle-btn,
  .btn-sm,
  .price-age,
  .site-footer,
  dialog,
  .item-history,
  .notes {
    display: none !important;
  }

  body {
    font-size: 11pt;
  }

  .page {
    width: 100%;
    padding: 0;
    margin: 0;
  }

  /* Clean up panels for paper */
  .panel {
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    padding: 12px !important;
    margin-bottom: 16px !important;
    page-break-inside: avoid;
  }

  /* Stats row — keep compact */
  .panel.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
  }

  /* Make panel headers stand out */
  .panel-header-row h2,
  .panel h2 {
    font-size: 13pt;
    border-bottom: 1px solid #999;
    padding-bottom: 4px;
    margin-bottom: 8px;
  }

  /* Tables */
  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
  }
  th, td {
    border: 1px solid #ccc !important;
    padding: 4px 8px !important;
  }
  thead {
    background: #f0f0f0 !important;
  }
  tr { page-break-inside: avoid; }

  /* Tree */
  .tree ul { page-break-inside: avoid; }
  .node-line {
    font-size: 10pt;
    padding: 2px 0;
  }

  /* Craft order list */
  .craft-order-list {
    font-size: 10pt;
  }
  .craft-order-step {
    padding: 3px 0;
    border-bottom: 1px solid #eee !important;
  }

  /* Skill badges — print as plain text */
  .skill-badge {
    border: 1px solid #ccc !important;
    font-size: 8pt;
  }

  /* Collapse expanded bodies even if JS has them collapsed */
  .collapsible-body[hidden] {
    display: block !important;
  }

  /* Page break hints */
  .panel.stats,
  #craft-order,
  #tree { page-break-after: auto; }
}
