:root {
  --bg: #120e0b;
  --stone: #1c1612;
  --stone-2: #251d17;
  --iron: #3a2f26;
  --bronze: #a8875a;
  --bronze-dim: #6e5a3f;
  --parchment: #dccdae;
  --ash: #9c8f7b;
  --blood: #9b1d17;
  --blood-hi: #c8322a;
  --ember: #e0773a;
  --good: #7fa356;
  --warn: #c9a13a;
  --bad: #b8443a;
  --q-magic: #7a93ff;
  --q-rare: #e6d15a;
  --q-legendary: #d97a2b;
  --q-unique: #c9a978;
  --q-mythic: #b48cff;
  --q-set: #4cc08a;
  --q-normal: #cfc6b4;
  --radius-s: 4px;
  --radius-m: 8px;
  --tab-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(155, 29, 23, 0.18), transparent 60%),
    radial-gradient(80% 50% at 100% 110%, rgba(168, 135, 90, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--parchment);
  font-family: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--bronze); }
h1, h2, h3, .cinzel {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; color: var(--bronze); }
h3 { font-size: 0.98rem; }
p { margin: 0.4em 0; }
small, .muted { color: var(--ash); }
.muted { font-size: 0.92rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 14px; }
.page { padding: calc(env(safe-area-inset-top) + 12px) 0 calc(var(--tab-h) + env(safe-area-inset-bottom) + 28px); }
.page.no-tabs { padding-bottom: 40px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 70%, rgba(18, 14, 11, 0));
  padding: calc(env(safe-area-inset-top) + 8px) 0 10px;
  margin-top: calc(-1 * (env(safe-area-inset-top) + 12px));
}
.topbar .row { display: flex; align-items: center; gap: 10px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  font-size: 0.8rem; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--iron); color: var(--ash); background: var(--stone);
}
.chip.realm-seasonal { border-color: #5a2a1d; color: #e2a27e; }
.chip.realm-eternal { border-color: #3c4a5e; color: #a9bad3; }
.wordmark { font-family: 'Cinzel', serif; font-size: 1.6rem; color: var(--parchment); }
.wordmark span { color: var(--blood-hi); }

.build-select {
  width: 100%; margin-top: 10px; background: var(--stone); border: 1px solid var(--iron);
  border-radius: var(--radius-s); padding: 8px 10px; color: var(--parchment);
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--iron); background: var(--stone-2); color: var(--parchment);
  padding: 9px 14px; border-radius: var(--radius-s); cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
.btn.primary {
  background: linear-gradient(#a8241d, #7a1611); border-color: #c8322a; color: #fff3e6;
  font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: 0.03em;
  box-shadow: inset 0 1px 0 rgba(255, 210, 180, 0.25), 0 2px 10px rgba(155, 29, 23, 0.35);
}
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 0.9rem; }
.btn.icon { width: 42px; padding: 0; font-size: 1.2rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .grow { flex: 1; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--stone-2), var(--stone));
  border: 1px solid var(--iron);
  border-radius: var(--radius-m);
  padding: 14px;
  margin: 12px 0;
  position: relative;
}
.panel.framed::before {
  content: ''; position: absolute; inset: 3px; border: 1px solid rgba(168, 135, 90, 0.18);
  border-radius: 6px; pointer-events: none;
}
.panel h2 { margin-bottom: 8px; }
.section-gap { height: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 0.95rem; }
.kv dt { color: var(--ash); }
.kv dd { margin: 0; }

/* ---------- the "next point" sigil ---------- */
.next {
  border: 1px solid #5a221a;
  background:
    radial-gradient(140% 120% at 0% 0%, rgba(200, 50, 42, 0.16), transparent 55%),
    linear-gradient(180deg, #241812, #18110d);
  border-radius: var(--radius-m);
  padding: 14px;
  margin: 12px 0;
}
.next .count { font-family: 'Cinzel', serif; color: var(--ember); font-size: 0.9rem; }
.next .what { font-family: 'Cinzel', serif; font-size: 1.3rem; margin: 2px 0 4px; line-height: 1.25; }
.next .where { color: var(--ash); font-size: 0.95rem; }
.next .desc { font-size: 0.95rem; margin-top: 6px; }
.next .controls { display: grid; grid-template-columns: 52px 1fr 64px; gap: 8px; margin-top: 12px; }
.next .done { color: var(--good); font-family: 'Cinzel', serif; }
.progressbar { height: 6px; background: #0d0a08; border: 1px solid var(--iron); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progressbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blood), var(--ember)); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid rgba(58, 47, 38, 0.7); display: flex; gap: 10px; align-items: baseline; }
.list li:last-child { border-bottom: 0; }
.list .n { font-variant-numeric: tabular-nums; color: var(--bronze-dim); min-width: 2.2em; text-align: right; font-size: 0.9rem; }
.list .body { flex: 1; min-width: 0; }
.list li.spent { opacity: 0.45; }
.list li.is-next { background: rgba(155, 29, 23, 0.12); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.list .sub { color: var(--ash); font-size: 0.88rem; }
.rank { color: var(--ash); font-size: 0.85rem; white-space: nowrap; }

/* ---------- gear slots ---------- */
.slot {
  border: 1px solid var(--iron); border-radius: var(--radius-m); margin: 10px 0;
  background: var(--stone); overflow: hidden;
}
.slot > summary { list-style: none; cursor: pointer; padding: 11px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.slot > summary::-webkit-details-marker { display: none; }
.slot .slot-name { font-family: 'Cinzel', serif; font-size: 0.82rem; color: var(--bronze); }
.slot .target-line { font-weight: 500; }
.slot .have-line { font-size: 0.92rem; color: var(--ash); grid-column: 1 / -1; }
.slot .slot-body { padding: 0 12px 12px; }
.score {
  font-family: 'Cinzel', serif; font-weight: 700; font-size: 0.95rem; min-width: 44px; text-align: center;
  border-radius: var(--radius-s); padding: 2px 6px; border: 1px solid var(--iron); color: var(--ash);
}
.score.good { color: #cfe8b0; border-color: #4f6a35; background: rgba(127, 163, 86, 0.12); }
.score.mid { color: #f0dd9a; border-color: #6e5a24; background: rgba(201, 161, 58, 0.1); }
.score.low { color: #f2b0a6; border-color: #6e2a22; background: rgba(184, 68, 58, 0.12); }
.meter { height: 4px; background: #0d0a08; grid-column: 1 / -1; border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; }
.tiers { margin: 6px 0 0; padding-left: 1.3em; }
.tiers li { margin: 2px 0; }
.label { color: var(--ash); font-size: 0.85rem; margin-top: 10px; }
.miss li::marker { color: var(--bad); }
.hit li::marker { color: var(--good); }
.step li::marker { color: var(--ember); }
ul.plain { margin: 4px 0; padding-left: 1.2em; }

/* ---------- item tooltip (the signature element) ---------- */
.tip {
  --q: var(--q-legendary);
  border: 1px solid color-mix(in srgb, var(--q) 55%, #000);
  background: linear-gradient(180deg, #17120f, #0f0c0a);
  border-radius: var(--radius-s);
  margin: 8px 0;
  box-shadow: 0 0 0 1px #000, 0 6px 18px rgba(0, 0, 0, 0.45);
}
.tip .tip-head {
  padding: 8px 10px 7px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--q) 34%, #120e0b), color-mix(in srgb, var(--q) 10%, #120e0b));
  border-bottom: 1px solid color-mix(in srgb, var(--q) 50%, #000);
}
.tip .tip-name { font-family: 'Cinzel', serif; font-weight: 700; color: var(--q); line-height: 1.2; }
.tip .tip-type { font-size: 0.85rem; color: var(--ash); }
.tip .tip-body { padding: 8px 10px 10px; font-size: 0.95rem; }
.tip .aff { display: flex; gap: 8px; align-items: baseline; margin: 2px 0; }
.tip .aff::before { content: '◆'; font-size: 0.6rem; color: var(--bronze-dim); transform: translateY(-2px); }
.tip .aff.ga::before { content: '★'; font-size: 0.8rem; color: #f3c14b; }
.tip .aff.temper::before { content: '⚒'; font-size: 0.8rem; color: #8fb2d9; }
.tip .aff.sock::before { content: '◇'; font-size: 0.8rem; color: var(--ash); }
.tip .aspect { color: var(--q-legendary); margin-top: 6px; font-style: italic; }
.tip.q-magic { --q: var(--q-magic); }
.tip.q-rare { --q: var(--q-rare); }
.tip.q-legendary { --q: var(--q-legendary); }
.tip.q-unique { --q: var(--q-unique); }
.tip.q-mythic { --q: var(--q-mythic); }
.tip.q-set { --q: var(--q-set); }
.tip.q-normal { --q: var(--q-normal); }
.qc-magic { color: var(--q-magic); } .qc-rare { color: var(--q-rare); } .qc-legendary { color: var(--q-legendary); }
.qc-unique { color: var(--q-unique); } .qc-mythic { color: var(--q-mythic); } .qc-set { color: var(--q-set); }

.verdict { font-family: 'Cinzel', serif; font-weight: 700; font-size: 1.1rem; }
.verdict.equip_now { color: #b9e08f; }
.verdict.upgrade_with_work { color: #f0d27a; }
.verdict.sidegrade { color: #d9c6a0; }
.verdict.keep_for_aspect { color: var(--q-legendary); }
.verdict.salvage { color: #e79a90; }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; text-align: center; margin: 10px 0; }
.versus .big { font-family: 'Cinzel', serif; font-size: 1.6rem; }

/* ---------- paragon board ---------- */
.board-wrap { background: #0c0907; border: 1px solid var(--iron); border-radius: var(--radius-m); padding: 6px; }
.board-wrap svg { width: 100%; height: auto; display: block; }
.board-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.board-tabs .btn { white-space: nowrap; flex: none; }
.board-tabs .btn.on { border-color: var(--bronze); color: #fff; background: #2e231a; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.82rem; color: var(--ash); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.pulse { animation: pulse 1.4s ease-in-out infinite; }

/* ---------- forms ---------- */
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 0.88rem; color: var(--ash); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; background: #0f0b09; border: 1px solid var(--iron); border-radius: var(--radius-s);
  padding: 10px; color: var(--parchment);
}
.field textarea { min-height: 150px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- character cards ---------- */
.char-card { display: block; text-decoration: none; color: inherit; }
.char-card .panel { margin: 10px 0; }
.char-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; text-align: center; }
.char-card .stats b { display: block; font-family: 'Cinzel', serif; color: var(--parchment); font-size: 1.05rem; }
.char-card .stats span { font-size: 0.8rem; color: var(--ash); }
.class-mark { font-family: 'Cinzel', serif; color: var(--blood-hi); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: linear-gradient(180deg, #1a1410, #0e0b09);
  border-top: 1px solid var(--iron);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .inner { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tab-h); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ash); font-size: 0.75rem;
}
.tabbar a .ico { font-size: 1.25rem; line-height: 1; filter: grayscale(0.4); }
.tabbar a.on { color: var(--parchment); }
.tabbar a.on .ico { filter: none; }
.tabbar a.on::after { content: ''; width: 18px; height: 2px; background: var(--blood-hi); border-radius: 2px; margin-top: 2px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; border: 1px solid #c8322a;
  background: radial-gradient(circle at 35% 30%, #c8322a, #6d120e); color: #fff;
  font-size: 1.5rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(18, 14, 11, 0.9);
  cursor: pointer;
}

/* ---------- advisor ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.msg { padding: 10px 12px; border-radius: var(--radius-m); max-width: 92%; font-size: 0.97rem; }
.msg.user { align-self: flex-end; background: #2a1c15; border: 1px solid #4a2a1e; }
.msg.assistant { align-self: flex-start; background: var(--stone); border: 1px solid var(--iron); }
.msg ul { margin: 4px 0; padding-left: 1.2em; }
.msg p:first-child { margin-top: 0; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 24;
  background: linear-gradient(rgba(18, 14, 11, 0), var(--bg) 30%); padding: 18px 0 8px;
}
.composer .wrap { display: flex; gap: 8px; }
.composer textarea {
  flex: 1; min-height: 44px; max-height: 140px; resize: none; background: #0f0b09; border: 1px solid var(--iron);
  border-radius: var(--radius-s); padding: 10px; color: var(--parchment);
}
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.quick .btn { flex: none; white-space: nowrap; }
.page.with-composer { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 120px); }

/* ---------- sheet / modal ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 3, 2, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet .card {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: linear-gradient(180deg, #221a14, #15100d);
  border: 1px solid var(--iron); border-bottom: 0; border-radius: 12px 12px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet .card { border-radius: 12px; border-bottom: 1px solid var(--iron); }
}
.sheet .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: var(--radius-s); border: 1px solid var(--iron); background: #000; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px);
  z-index: 60; background: #2a1c15; border: 1px solid var(--bronze-dim); padding: 10px 14px; border-radius: var(--radius-s);
  max-width: 90vw; font-size: 0.95rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.toast.error { border-color: var(--bad); background: #2b1411; }

.empty { text-align: center; padding: 28px 12px; color: var(--ash); }
.empty .cinzel { color: var(--parchment); font-size: 1.1rem; display: block; margin-bottom: 6px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: currentColor; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
details.fold > summary { cursor: pointer; color: var(--bronze); font-family: 'Cinzel', serif; font-size: 0.95rem; padding: 4px 0; }
.runes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.rune { display: flex; align-items: center; justify-content: space-between; gap: 6px; border: 1px solid var(--iron); border-radius: var(--radius-s); padding: 6px 8px; background: #0f0b09; }
.rune b { font-family: 'Cinzel', serif; }
.rune .have { color: var(--good); } .rune .lack { color: var(--bad); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .btn { min-height: 30px; width: 30px; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  .pulse, .spinner { animation: none; }
  .btn:active { transform: none; }
}

.versus3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin: 12px 0 4px; }
.versus3 .big { font-family: 'Cinzel', serif; font-size: 1.5rem; line-height: 1.1; }
.chip.odds-sure { border-color: #4f6a35; color: #cfe8b0; }
.chip.odds-likely { border-color: #6e5a24; color: #f0dd9a; }
.chip.odds-gamble { border-color: #6e2a22; color: #f2b0a6; }
.tiers .chip { margin-left: 4px; white-space: nowrap; }

.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.rtile { position: relative; }
.rtap { width: 100%; background: #0f0b09; border: 1px solid var(--iron); border-radius: var(--radius-s); padding: 6px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; color: inherit; }
.rtap img { width: 40px; height: 40px; opacity: 0.45; filter: grayscale(0.6); }
.rtile.own .rtap { border-color: var(--bronze-dim); background: #1d1611; }
.rtile.own .rtap img { opacity: 1; filter: none; }
.rtile.need .rtap { box-shadow: inset 0 0 0 1px rgba(200, 50, 42, 0.8); }
.rname { font-size: 0.8rem; font-weight: 700; }
.rqty { position: absolute; top: 3px; right: 5px; font-family: 'Cinzel', serif; font-size: 0.85rem; color: #fff; text-shadow: 0 1px 2px #000; }
.rminus { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--iron); background: #2a1c15; color: var(--parchment); font-size: 0.9rem; line-height: 1; padding: 0; cursor: pointer; }

.thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.thumb { position: relative; width: 72px; height: 72px; border: 1px solid var(--iron); border-radius: var(--radius-s); overflow: hidden; display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span { position: absolute; left: 3px; bottom: 2px; font-size: 0.75rem; background: rgba(0,0,0,.7); padding: 0 4px; border-radius: 3px; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.75); color: #fff; font-size: 0.75rem; padding: 0; cursor: pointer; }

.tip .aff.ench::before { content: '↻'; font-size: 0.8rem; color: #c9a6ff; }
.tip .aff.trans::before { content: '⧉'; font-size: 0.8rem; color: #9fd3c7; }
.tip .tag { font-size: 0.72rem; border: 1px solid var(--iron); border-radius: 999px; padding: 0 6px; color: var(--ash); }
.tip .tag.cap { border-color: #8a5a1e; color: #f0b46a; }

.chip.src-mx { border-color: #6b3d1a; color: #f0a35c; }

.chip.src-iv { border-color: #3c4a5e; color: #a9bad3; }
.lib-filters .field select { padding: 8px; }
