/* Path of Valheiman wiki.
   Layout: fixed header, grouped side index on the left, one reading column; tables scroll in their own box.
   Look: northern fjord in fog. Cool slate neutrals, azurite blue for links and action,
   rune gold reserved for keystones and the brand mark, item rarity colours as in the game. */
:root {
  --bg: #edf1f0;
  --surface: #f8faf9;
  --sunk: #e3e9e7;
  --ink: #17201e;
  --muted: #5a6764;
  --faint: #8a9693;
  --line: #d3dbd8;
  --accent: #1b6a96;
  --accent-ink: #ffffff;
  --accent-soft: #d9e9f1;
  --gold: #8f6410;
  --gold-soft: #f1e5c8;
  --magic: #2f63c4;
  --rare: #9a7400;
  --unique: #b4501a;
  --shadow: 0 1px 2px rgba(23, 32, 30, .06), 0 8px 24px rgba(23, 32, 30, .06);
  --scrim: rgba(10, 16, 18, .35);
  --map-bg: #f4f7f6;
  --map-line: rgba(40, 60, 56, .22);
  --map-dim: #d2d9d6;

  --font-display: "Alegreya SC", "Palatino Linotype", Georgia, serif;
  --font-body: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, "Courier New", monospace;

  --step--1: .875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.3rem;
  --step-4: clamp(2.6rem, 6vw, 4rem);

  --header-h: 60px;
  --side-w: 248px;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1416;
    --surface: #141c1f;
    --sunk: #0a0f11;
    --ink: #e2e9e6;
    --muted: #97a5a1;
    --faint: #6c7a77;
    --line: #253137;
    --accent: #63b6e2;
    --accent-ink: #08131a;
    --accent-soft: #15303d;
    --gold: #e0b45a;
    --gold-soft: #33280f;
    --magic: #84abff;
    --rare: #ecca52;
    --unique: #ff9257;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --scrim: rgba(0, 0, 0, .55);
    --map-bg: #0b1113;
    --map-line: rgba(190, 210, 220, .16);
    --map-dim: #253036;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1416;
  --surface: #141c1f;
  --sunk: #0a0f11;
  --ink: #e2e9e6;
  --muted: #97a5a1;
  --faint: #6c7a77;
  --line: #253137;
  --accent: #63b6e2;
  --accent-ink: #08131a;
  --accent-soft: #15303d;
  --gold: #e0b45a;
  --gold-soft: #33280f;
  --magic: #84abff;
  --rare: #ecca52;
  --unique: #ff9257;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --scrim: rgba(0, 0, 0, .55);
  --map-bg: #0b1113;
  --map-line: rgba(190, 210, 220, .16);
  --map-dim: #253036;
  color-scheme: dark;
}

/* ---------- base */
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 72px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.6 var(--font-body);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
code, kbd { font-family: var(--font-mono); font-size: .8em; }
code { padding: .1em .35em; border-radius: 4px; background: var(--sunk); overflow-wrap: anywhere; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; }
h1 { font: 700 var(--step-3)/1.1 var(--font-display); letter-spacing: .01em; margin: 4px 0 8px; }
h2 { font: 700 var(--step-2)/1.2 var(--font-display); margin: 40px 0 12px; }
h3 { font-size: var(--step-1); font-weight: 700; margin: 0 0 6px; }
h4 { font-size: var(--step-0); font-weight: 700; margin: 0 0 4px; }
h1 .en, h2 .en { display: inline-block; font: 500 var(--step--1)/1 var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--faint); vertical-align: middle; }
.en { color: var(--muted); font-weight: 400; font-size: .92em; }
html.no-en .en { display: none; }
.muted { color: var(--muted); font-size: var(--step--1); }
.lore { color: var(--muted); font-style: italic; font-size: var(--step--1); }
.lead { color: var(--muted); font-size: var(--step-1); margin: 0 0 8px; max-width: 62ch; }
p, li { max-width: 72ch; }
a.term { color: inherit; text-decoration: underline dotted var(--accent); text-underline-offset: 3px; }
a.term:hover { color: var(--accent); }
.term { color: var(--accent); }
.hide { display: none !important; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; padding: 8px 12px; background: var(--accent); color: var(--accent-ink); border-radius: 6px; }
.skip:focus { left: max(16px, env(safe-area-inset-left, 0px)); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- header */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--header-h);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand .mark { width: 26px; height: 26px; color: var(--gold); stroke-width: 2.4; }
.brand-name { font: 700 1.15rem/1 var(--font-display); letter-spacing: .02em; }
.brand-tag { font-size: var(--step--1); color: var(--muted); padding-left: 8px; border-left: 1px solid var(--line); }
.tools { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
  font: 600 var(--step--1) var(--font-body); letter-spacing: .04em; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn[aria-pressed="false"] { color: var(--faint); text-decoration: line-through; }
.menu-btn { display: none; }

/* ---------- search (header and home) */
.search { position: relative; flex: 1; max-width: 520px; }
.search input, .filter-input input {
  width: 100%; height: 40px; padding: 0 44px 0 38px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
  font: inherit; font-size: var(--step--1);
}
.search input:focus, .filter-input input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search-ico { position: absolute; left: 11px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); padding: 1px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--faint); background: var(--surface); }
.search input:focus ~ .kbd { display: none; }
.hits {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40; margin: 0; padding: 6px; list-style: none;
  max-height: min(70vh, 520px); overflow-y: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.hits a { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.hits a small { flex-shrink: 0; color: var(--faint); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.hits a:hover, .hits a.on { background: var(--accent-soft); }
.hits mark { background: none; color: var(--accent); font-weight: 700; }
.hits .empty { padding: 10px; color: var(--muted); }

/* ---------- shell: side index + reading column */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.side {
  position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  height: calc(100vh - var(--header-h)); overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  padding: 24px 12px 24px max(16px, env(safe-area-inset-left, 0px));
  border-right: 1px solid var(--line);
}
.side-group { display: flex; flex-direction: column; gap: 2px; }
.side-label { margin: 0 0 4px 10px; font-size: .74rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.side a { padding: 6px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: var(--step--1); }
.side a:hover { background: var(--sunk); }
.side a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-foot { margin: auto 0 0 10px; font-size: .78rem; color: var(--faint); }
.scrim { display: none; }

main {
  min-width: 0; width: 100%; max-width: 1180px; overflow-wrap: break-word;
  padding-block: 24px 56px;
  padding-left: clamp(16px, 4vw, 48px);
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main.wide { max-width: none; }
.crumbs { margin: 0; font-size: var(--step--1); color: var(--faint); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.foot { margin-top: 56px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--faint); font-size: var(--step--1); max-width: 72ch; }

/* heading anchors added by app.js */
.anchor { margin-left: 8px; color: var(--faint); text-decoration: none; font-family: var(--font-body); font-size: .7em; opacity: 0; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

/* ---------- home */
.hero { padding: 24px 0 8px; max-width: 760px; }
.eyebrow { margin: 0 0 8px; font-size: .8rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.hero-title { font-size: var(--step-4); margin: 0 0 12px; }
.hero-text { font-size: var(--step-1); color: var(--muted); margin: 0 0 20px; }
.hero-text b { color: var(--ink); }
.hero-search { max-width: 640px; }
.hero-search input { height: 52px; font-size: var(--step-0); padding-left: 44px; background: var(--surface); box-shadow: var(--shadow); }
.hero-search .search-ico { left: 14px; width: 20px; height: 20px; }
.home-group h2 { font-size: var(--step-1); margin-top: 36px; }
.starts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.start {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
.start:hover { border-color: var(--accent); }
.start-title { font: 700 var(--step-1)/1.2 var(--font-display); color: var(--accent); }
.start-text { color: var(--muted); font-size: var(--step--1); }
.section-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); column-gap: 24px; border-top: 1px solid var(--line); }
.section-link {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 4px;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; min-width: 0;
}
.section-link:hover .sl-title { color: var(--accent); }
.sl-title { font-weight: 700; }
.sl-title .en { font-size: var(--step--1); }
.sl-text { color: var(--muted); font-size: var(--step--1); }
.sl-count { color: var(--faint); font-size: .8rem; letter-spacing: .04em; }
.note { margin-top: 40px; padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.note h2 { margin-top: 0; font-size: var(--step-1); }

/* ---------- page tools */
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.toc a { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); text-decoration: none; font-size: var(--step--1); color: var(--ink); }
.toc a:hover { border-color: var(--accent); color: var(--accent); }
.toc.letters a { min-width: 34px; text-align: center; }
.filters {
  position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top, 0px)); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center;
  margin: 8px 0 16px; padding-block: 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.filter-input { position: relative; flex: 1 1 280px; min-width: 0; }
.filter-input input { padding-right: 12px; }
.pick { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sel { color: var(--muted); font-size: var(--step--1); white-space: nowrap; }
.filters select {
  height: 40px; min-width: 0; max-width: 220px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; font-size: var(--step--1);
}
.count { color: var(--muted); font-size: var(--step--1); }

/* ---------- cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 12px; }
.node, .term-card, .area {
  min-width: 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.node p, .term-card p { margin: 6px 0; }
.node .meta { margin-top: 0; color: var(--muted); font-size: var(--step--1); }
.node.keystone { background: linear-gradient(var(--gold), var(--gold)) top / 100% 3px no-repeat, var(--surface); }
.node.keystone h3 { font-family: var(--font-display); color: var(--gold); }
.term-card { margin-bottom: 10px; }
.area { margin: 12px 0; }
.area h4 { font-family: var(--font-display); font-size: var(--step-1); }
h2.letter { margin: 28px 0 10px; color: var(--gold); }
.node:target, .term-card:target, tr:target td { box-shadow: inset 0 0 0 2px var(--accent); }
ul.opts { margin: 8px 0 0; padding-left: 18px; }
ul.opts li { margin: 4px 0; }
ul.opts a.more { font-size: .85em; white-space: nowrap; }
ul.tiers { margin: 0; padding: 0; list-style: none; font-size: var(--step--1); white-space: nowrap; }
details { margin: 8px 0; }
details summary { cursor: pointer; color: var(--accent); font-size: var(--step--1); }

/* ---------- tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .97rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: var(--sunk); color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:hover td { background: var(--accent-soft); }
tr:last-child td { border-bottom: 0; }
td.n { text-align: right; color: var(--muted); }

/* ---------- scaling page */
.formula { padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 8px 8px 0; }
.formula code { background: none; padding: 0; font-size: .95rem; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.seg { height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: var(--step--1); cursor: pointer; }
.seg:hover { border-color: var(--accent); }
.seg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.calc { display: grid; grid-template-columns: max-content minmax(0, 260px); gap: 10px 14px; align-items: center; max-width: 520px; }
.calc label { color: var(--muted); font-size: var(--step--1); }
.calc select, .calc input[type="number"] { height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.calc .check { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; color: var(--ink); }
.calc-out { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 4px; }
.calc-out .muted { flex-basis: 100%; margin: 0; }
.big { display: flex; flex-direction: column; min-width: 140px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.big-label { font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.big-value { font: 700 var(--step-2)/1.1 var(--font-display); color: var(--accent); }

/* ---------- icons from the mod */
.ico { width: 32px; height: 32px; flex-shrink: 0; border-radius: 6px; vertical-align: middle; object-fit: cover; background: var(--sunk); }
.ico-l { width: 40px; height: 40px; border-radius: 8px; }
.ico-s { width: 20px; height: 20px; border-radius: 4px; margin-right: 6px; }
.with-ico { display: flex; align-items: center; gap: 10px; min-width: 0; }
.block { display: block; }
.ing { display: inline-flex; align-items: center; }

/* ---------- rarity colours (as in game) */
.r-magic { color: var(--magic); }
.r-rare { color: var(--rare); }
.r-unique { color: var(--unique); }

/* ---------- glossary tooltip */
.tip {
  position: absolute; z-index: 60; max-width: 340px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font-size: var(--step--1); line-height: 1.5; pointer-events: none;
}
.tip b { display: block; margin-bottom: 2px; }

/* ---------- back to top */
.totop {
  position: fixed; z-index: 25;
  right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); cursor: pointer;
}
.totop svg { width: 20px; height: 20px; }
.totop:hover { color: var(--accent); border-color: var(--accent); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; font-size: var(--step--1); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

@media (prefers-reduced-motion: no-preference) {
  .side { transition: transform .2s ease; }
}

/* ---------- tablet and phone */
@media (max-width: 960px) {
  .menu-btn { display: inline-grid; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; z-index: 35; left: 0; top: calc(var(--header-h) + env(safe-area-inset-top, 0px)); bottom: 0;
    width: min(300px, 86vw); height: auto; background: var(--surface); border-right: 1px solid var(--line);
    transform: translateX(-102%); visibility: hidden;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  body.menu-open .side { transform: none; visibility: visible; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 34; background: var(--scrim); }
  .scrim[hidden] { display: none; }
  main { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
}
@media (max-width: 680px) {
  :root { --step-3: 1.9rem; --header-h: 56px; }
  .brand-name, .brand-tag, .kbd { display: none; }
  .top { gap: 8px; }
  .search { max-width: none; }
  .tools .icon-btn { min-width: 36px; }
  .filters { position: static; }
  .pick { flex: 1 1 160px; }
  .filters select { max-width: none; flex: 1 1 auto; }
  .top .hits { position: fixed; left: max(8px, env(safe-area-inset-left, 0px)); right: max(8px, env(safe-area-inset-right, 0px)); top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 4px); }
  /* Tables become stacked records; app.js copies each column header into data-label. */
  .tablewrap.stack { overflow: visible; border: 0; background: none; }
  .stack table, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack thead { display: none; }
  .stack tr { margin-bottom: 10px; padding: 6px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
  .stack td { border: 0; padding: 6px 14px; }
  .stack td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
  .stack td:empty { display: none; }
  ul.tiers { white-space: normal; }
  .calc { grid-template-columns: minmax(0, 1fr); }
}
