:root {
  --bg: #13110f;
  --bg-2: #1b1714;
  --card: #211c18;
  --card-2: #2a241f;
  --line: #3a3029;
  --text: #f1e9dc;
  --muted: #a99c8b;
  --gold: #e0ad4f;
  --gold-2: #f4c76f;
  --sc: #4fc98d;
  --sn: #e7b93e;
  --ec: #ec5b52;
  --exo: #79b8ff;
  --over: #f39a4a;
  --radius: 12px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(224, 173, 79, 0.1), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(121, 184, 255, 0.05), transparent 60%),
    var(--bg);
}

a {
  color: var(--gold-2);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h3 {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.6rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

kbd {
  font: 0.78rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--card-2);
}

:focus-visible {
  outline: 2px solid var(--gold-2);
  outline-offset: 2px;
}

/* ───── top bar ───── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(19, 17, 15, 0.85);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand h1 {
  font-size: 1.15rem;
  color: var(--gold-2);
}

.tagline {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--muted);
  user-select: none;
}

.toggle input {
  accent-color: var(--gold);
  width: 16px;
  height: 16px;
}

/* ───── layout ───── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem);
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

.workshop,
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 2px;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

/* ───── buttons ───── */

.btn {
  font: inherit;
  font-size: 0.88rem;
  color: var(--bg);
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 0.42rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
  background: var(--gold-2);
}

.btn.ghost {
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}

.btn.ghost:hover {
  border-color: var(--gold);
}

.btn.on {
  color: var(--bg);
  background: var(--gold);
  border-color: var(--gold);
}

.btn.small {
  font-size: 0.8rem;
  padding: 0.28rem 0.6rem;
  color: var(--text);
  background: var(--card-2);
  border-color: var(--line);
}

.btn.small:hover {
  border-color: var(--gold);
}

.btn.small.on {
  color: var(--bg);
  background: var(--gold);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ───── search ───── */

.search-card {
  position: relative;
  padding: 0.6rem;
  z-index: 10;
}

.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: var(--muted);
  pointer-events: none;
}

#search {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.7rem 0.9rem 0.7rem 2.4rem;
}

#search:focus {
  border-color: var(--gold);
  outline: none;
  box-shadow: 0 0 0 3px rgba(224, 173, 79, 0.18);
}

.search-results {
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  top: calc(100% - 0.3rem);
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.search-results li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.5rem;
  border-radius: 7px;
  cursor: pointer;
}

.search-results li.active,
.search-results li:hover {
  background: rgba(224, 173, 79, 0.14);
}

.search-results li.none {
  display: block;
  color: var(--muted);
  cursor: default;
}

.r-meta {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

/* ───── item ───── */

.item-head {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 0.4rem 1rem;
  align-items: center;
}

.item-icon {
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, rgba(224, 173, 79, 0.18), transparent 70%);
}

.item-title h2 {
  font-size: 1.35rem;
}

.item-title p {
  margin: 0.2rem 0 0;
}

.item-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.gauges {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.75rem;
  margin: 1rem 0;
}

.gauge {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  min-width: 0;
}

.gauge-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.gauge-value {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.gauge.reliquat .gauge-value {
  color: var(--gold-2);
}

.bar {
  position: relative;
  height: 9px;
  border-radius: 6px;
  background: var(--card-2);
  overflow: hidden;
  margin: 0.45rem 0 0.3rem;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6d8f5a, var(--sc));
  border-radius: 6px;
  transition: width 0.35s ease;
}

.bar-fill.hot {
  background: linear-gradient(90deg, var(--sc), var(--sn) 55%, var(--ec));
}

.bar-mark {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(241, 233, 220, 0.35);
}

@media (max-width: 640px) {
  .gauges {
    grid-template-columns: 1fr 1fr;
  }
  .gauge.wide {
    grid-column: 1 / -1;
  }
}

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

table.lines {
  width: 100%;
  border-collapse: collapse;
}

.lines th,
.lines td {
  padding: 0.38rem 0.5rem;
  border-bottom: 1px solid rgba(58, 48, 41, 0.6);
  text-align: left;
  vertical-align: middle;
}

.lines thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.lines tbody th {
  font-weight: 500;
  white-space: nowrap;
}

.lines .num {
  text-align: right;
}

.value-cell {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 6.5rem;
}

.val {
  font-size: 1.05rem;
  font-weight: 600;
}

.range {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.lines tr.empty .val,
.lines tr.empty th {
  color: var(--muted);
  opacity: 0.7;
}

.lines tr.over .val {
  color: var(--over);
}

.lines tr.exo th,
.lines tr.exo .val {
  color: var(--exo);
}

.lines tr.target {
  background: rgba(224, 173, 79, 0.06);
}

.tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  vertical-align: 1px;
}

.over-tag {
  color: var(--over);
}

.exo-tag {
  color: var(--exo);
}

.delta {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 6px;
  animation: pop 0.45s ease-out;
}

.delta.up {
  color: var(--sc);
  background: rgba(79, 201, 141, 0.12);
}

.delta.down {
  color: var(--ec);
  background: rgba(236, 91, 82, 0.12);
}

@keyframes pop {
  0% {
    transform: translateY(4px) scale(0.9);
    opacity: 0;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

.runes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

td.runes {
  display: table-cell;
}

td.runes .rune {
  margin: 2px 0.3rem 2px 0;
}

.rune {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.18rem 0.45rem 0.18rem 0.22rem;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s, background 0.12s;
  vertical-align: middle;
}

.rune:hover {
  border-color: var(--gold);
  background: #322a23;
}

.rune:active {
  transform: translateY(1px) scale(0.98);
}

.rune img {
  width: 28px;
  height: 28px;
}

.rune-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rune.blocked {
  opacity: 0.45;
  cursor: not-allowed;
}

.chip {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.chip.good {
  color: var(--sc);
}

.chip.mid {
  color: var(--sn);
}

.chip.bad {
  color: var(--ec);
}

.chip.lock {
  color: var(--muted);
}

.note {
  margin: 0.6rem 0 0;
}

.exo {
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--line);
}

.exo h3 {
  color: var(--exo);
  margin-bottom: 0.2rem;
}

.exo p {
  margin: 0 0 0.6rem;
}

.exo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

select,
.val-input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.32rem 0.5rem;
}

select:focus,
.val-input:focus {
  border-color: var(--gold);
  outline: none;
}

.val-input {
  width: 6rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ───── sidebar ───── */

.result-card {
  border-left: 4px solid var(--line);
  transition: border-color 0.2s;
}

.result-card.sc {
  border-left-color: var(--sc);
}

.result-card.sn {
  border-left-color: var(--sn);
}

.result-card.ec,
.result-card.blocked {
  border-left-color: var(--ec);
}

.result-card p {
  margin: 0.3rem 0;
}

.result-label {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0 0 0.2rem !important;
  animation: pop 0.3s ease-out;
}

.result-card.sc .result-label {
  color: var(--sc);
}

.result-card.sn .result-label {
  color: var(--sn);
}

.result-card.ec .result-label,
.result-card.blocked .result-label {
  color: var(--ec);
}

.result-card.idle .result-label {
  color: var(--gold-2);
}

.result-rune {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.changes {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.changes li {
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.15rem 0.55rem;
  border-radius: 7px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.changes li.up,
.h-changes .up {
  color: var(--sc);
}

.changes li.down,
.h-changes .down {
  color: var(--ec);
}

.changes li.rel,
.h-changes .rel {
  color: var(--gold-2);
}

.truth {
  border-top: 1px dashed var(--line);
  padding-top: 0.4rem;
  margin-top: 0.6rem !important;
}

.stack {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
  margin: 0.4rem 0;
}

.seg.sc,
.dot.sc {
  background: var(--sc);
}

.seg.sn,
.dot.sn {
  background: var(--sn);
}

.seg.ec,
.dot.ec {
  background: var(--ec);
}

.seg {
  transition: width 0.3s ease;
}

.stack-legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.3rem;
}

.facts {
  margin: 0.7rem 0;
  display: grid;
  gap: 0.25rem;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.86rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.payers,
.rune-list {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.2rem;
  font-size: 0.86rem;
}

.payers li {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

.rune-list li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.detail-actions > span {
  flex-basis: 100%;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin: 0.2rem 0 0.4rem;
}

.tile {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.45rem 0.5rem;
  text-align: center;
}

.tile-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tile-label {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.tile.sc .tile-value {
  color: var(--sc);
}

.tile.sn .tile-value {
  color: var(--sn);
}

.tile.ec .tile-value {
  color: var(--ec);
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  font-size: 0.84rem;
}

.history li {
  display: grid;
  grid-template-columns: 2.4rem 20px 2.2rem 1fr;
  gap: 0.4rem;
  align-items: center;
  padding: 0.22rem 0;
  border-bottom: 1px solid rgba(58, 48, 41, 0.5);
}

.history li.sep {
  display: block;
  color: var(--gold);
  font-size: 0.78rem;
  padding: 0.4rem 0 0.2rem;
}

.history .n {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  border-radius: 5px;
  padding: 1px 0;
  color: var(--bg);
}

.badge.sc {
  background: var(--sc);
}

.badge.sn {
  background: var(--sn);
}

.badge.ec {
  background: var(--ec);
}

.h-changes span {
  margin-right: 0.35rem;
  white-space: nowrap;
}

.loading,
.error {
  color: var(--muted);
  margin: 0;
}

.error {
  color: var(--ec);
}

/* ───── footer ───── */

.footer {
  max-width: 1500px;
  margin: 0.5rem auto 2rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  font-size: 0.8rem;
  color: var(--muted);
}

.footer p {
  margin: 0.3rem 0;
  max-width: 900px;
}

.footer strong {
  color: var(--text);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
