/* Companion for Valheim Wiki - design system ("Carved and rune-lit").
   Tokens + shell + shared components. Section-specific layout goes in css/sections/<key>.css,
   scoped under body.section-<key>. Never restyle these shared classes globally from a section file,
   and never hardcode a hex there - tokens only. Contract: apps/hub/wiki/DESIGN.md */

:root {
  --bg: #0d1511;
  --bg-deep: #070b09;
  --surface-1: #141f19;
  --surface-2: #1b2921;
  --rim: #2c4034;
  --ink: #eae0c8;
  --ink-dim: #b9c2b4;
  --ink-faint: #7c8a80;
  --accent: #7fb3d5;
  --ember: #e8763a;
  --danger: #c2452f;
  --radius: 14px;
  --radius-sm: 9px;

  /* Biome color axis - same hues the map uses (DESIGN.md). Reference ONLY via ctx.biome_chip(). */
  --biome-meadows: #7fb3d5;
  --biome-blackforest: #7fa650;
  --biome-swamp: #9dbb3a;
  --biome-mountain: #a8d8e8;
  --biome-plains: #e0a93e;
  --biome-mistlands: #54d6c0;
  --biome-ashlands: #e05038;
  --biome-deepnorth: #cfeffa;
  --biome-ocean: #3e93be;

  --font-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --header-h: 60px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

::selection { background: rgba(127, 179, 213, .3); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

body.wk {
  margin: 0;
  min-height: 100vh;
  color: var(--ink-dim);
  font: 400 .95rem/1.6 var(--font-body);
  background:
    radial-gradient(900px 560px at 88% -8%, rgba(127, 179, 213, .08), transparent 60%),
    radial-gradient(760px 480px at -8% 40%, rgba(232, 118, 58, .06), transparent 58%),
    linear-gradient(180deg, var(--bg), var(--bg-deep) 45%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); line-height: 1.25; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: .01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code {
  font: 500 .85em/1 ui-monospace, "SF Mono", Consolas, monospace;
  background: var(--bg-deep); border: 1px solid var(--rim); border-radius: 5px; padding: 1px 6px;
}
kbd {
  font: 600 .7rem/1 var(--font-body); color: var(--ink-faint);
  border: 1px solid var(--rim); border-radius: 4px; padding: 2px 5px; background: var(--bg-deep);
}

.wk-skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #0a1620; padding: 8px 14px; border-radius: 0 0 8px 0; font-weight: 600;
}
.wk-skip:focus { left: 0; }

/* ---- header ---- */

.wk-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  height: var(--header-h); padding: 0 max(16px, env(safe-area-inset-left));
  background: rgba(9, 14, 11, .86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rim);
}

.wk-logo {
  display: flex; align-items: center; gap: 9px; flex: 0 0 auto;
  font: 600 1.02rem/1 var(--font-display); color: var(--ink); text-decoration: none; letter-spacing: .02em;
}
.wk-logo:hover { text-decoration: none; }
.wk-logo b { color: var(--accent); }
.wk-logo-text { display: flex; flex-direction: column; gap: 1px; }
.wk-logo-eyebrow {
  font: 500 .58rem/1 var(--font-body); letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint);
}
.wk-logo-mark {
  display: inline-flex; color: var(--accent); flex: 0 0 auto;
  filter: drop-shadow(0 0 6px rgba(127, 179, 213, .45));
  transition: transform .25s ease, filter .25s ease;
}
.wk-logo:hover .wk-logo-mark {
  transform: rotate(-8deg) scale(1.07);
  filter: drop-shadow(0 0 11px rgba(127, 179, 213, .7));
}
.wk-footer-brand .wk-logo-mark { width: 30px; height: 30px; animation: wk-rune-float 6s ease-in-out infinite; }
.wk-footer-brand .wk-logo-mark svg { width: 100%; height: 100%; }
@keyframes wk-rune-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

.wk-nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; }
.wk-nav::-webkit-scrollbar { display: none; }
.wk-nav a {
  padding: 8px 12px; border-radius: 8px; white-space: nowrap;
  color: var(--ink-faint); font-weight: 500; font-size: .87rem;
}
.wk-nav a:hover { color: var(--ink); background: var(--surface-1); text-decoration: none; }
.wk-nav a.active { color: var(--accent); background: rgba(127, 179, 213, .12); }

.wk-search-btn {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 7px 12px; border-radius: 10px; cursor: pointer;
  background: var(--surface-1); border: 1px solid var(--rim); color: var(--ink-faint);
  font: 500 .85rem/1 var(--font-body);
}
.wk-search-btn:hover { background: var(--surface-2); color: var(--ink); }
.wk-search-btn svg { display: block; }

.wk-theme-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 38px; height: 38px; padding: 0; border-radius: 10px; cursor: pointer;
  background: var(--surface-1); border: 1px solid var(--rim); color: var(--ink-faint);
  transition: background .12s ease, color .12s ease;
}
.wk-theme-btn:hover { background: var(--surface-2); color: var(--accent); }
.wk-theme-ico { display: none; line-height: 0; }
.wk-theme-ico svg { display: block; }
:root:not([data-theme="light"]) .wk-theme-btn .wk-ico-sun { display: inline-flex; }
[data-theme="light"] .wk-theme-btn .wk-ico-moon { display: inline-flex; }

.wk-menu-btn { display: none; }

/* ---- search overlay ---- */

.wk-search-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4, 7, 5, .72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: min(14vh, 120px) 16px 16px;
}
.wk-search-panel {
  max-width: 620px; margin: 0 auto;
  background: var(--surface-1); border: 1px solid var(--rim); border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55); overflow: hidden;
}
#wk-search-input {
  width: 100%; padding: 16px 18px; border: 0; outline: 0;
  background: transparent; color: var(--ink); font: 500 1.05rem var(--font-body);
  border-bottom: 1px solid var(--rim);
}
.wk-search-results { max-height: min(50vh, 420px); overflow-y: auto; }
.wk-search-results a {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: var(--ink-dim);
}
.wk-search-results a:hover, .wk-search-results a.sel { background: var(--surface-2); text-decoration: none; }
.wk-search-results img, .wk-search-results .wk-tile-fallback { width: 34px; height: 34px; }
.wk-search-results .sub { color: var(--ink-faint); font-size: .8rem; margin-left: auto; white-space: nowrap; }
.wk-search-empty { padding: 18px; color: var(--ink-faint); text-align: center; }

/* ---- layout ---- */

.wk-main { max-width: 1180px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-left)) 64px; }

.wk-breadcrumbs {
  max-width: 1180px; margin: 14px auto 0; padding: 0 16px;
  font-size: .82rem; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.wk-breadcrumbs a { color: var(--ink-faint); }
.wk-breadcrumbs a:hover { color: var(--accent); }
.wk-breadcrumbs .sep { opacity: .5; }

.wk-section-head { margin: 26px 0 14px; }
.wk-section-head h2 { margin: 0; }
.wk-section-head p { margin: 4px 0 0; color: var(--ink-faint); font-size: .88rem; }

.wk-section { scroll-margin-top: calc(var(--header-h) + 14px); }

.wk-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

/* ---- components ---- */

/* Carved-wood panel, not glass: flat surface fill, a hairline rim, and a faint warm top-edge
   highlight (inset box-shadow) evoking firelight from above - the app's RunestoneCard, on the web. */
.wk-card {
  display: block; padding: 14px 16px; color: var(--ink-dim);
  background: var(--surface-1); border: 1px solid var(--rim); border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(232, 118, 58, .08);
}
a.wk-card { transition: transform .12s ease, border-color .12s ease, background .12s ease; }
a.wk-card:hover {
  text-decoration: none; transform: translateY(-2px);
  background: var(--surface-2); border-color: rgba(127, 179, 213, .4);
}

.wk-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--rim); color: var(--ink-dim);
  vertical-align: middle;
}
a.wk-chip:hover { text-decoration: none; background: var(--surface-1); }

/* Biome axis chips - ctx.biome_chip() sets .wk-chip--<slug>; each rule below just points --biome at
   the matching token (DESIGN.md), so the shared .wk-chip--biome rule does all the actual styling. */
.wk-chip--biome { --biome: var(--accent); color: var(--biome); border-color: color-mix(in srgb, var(--biome) 45%, transparent); background: color-mix(in srgb, var(--biome) 14%, transparent); }
.wk-chip--meadows { --biome: var(--biome-meadows); }
.wk-chip--blackforest { --biome: var(--biome-blackforest); }
.wk-chip--swamp { --biome: var(--biome-swamp); }
.wk-chip--mountain { --biome: var(--biome-mountain); }
.wk-chip--plains { --biome: var(--biome-plains); }
.wk-chip--mistlands { --biome: var(--biome-mistlands); }
.wk-chip--ashlands { --biome: var(--biome-ashlands); }
.wk-chip--deepnorth { --biome: var(--biome-deepnorth); }
.wk-chip--ocean { --biome: var(--biome-ocean); }

.wk-crosslink img, .wk-crosslink .wk-tile, .wk-crosslink .wk-tile-fallback { width: 20px; height: 20px; font-size: .75rem; }
.wk-crosslink--dead { color: var(--ink-faint); opacity: .7; }

.wk-statbar { display: flex; align-items: center; gap: 10px; margin: 5px 0; }
.wk-statbar-label { flex: 0 0 9.5em; font-size: .82rem; color: var(--ink-faint); }
.wk-statbar-track {
  flex: 1 1 auto; height: 7px; border-radius: 999px; overflow: hidden;
  background: rgba(255, 255, 255, .06);
}
.wk-statbar-fill {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, transparent), var(--accent));
}
.wk-statbar-value { flex: 0 0 4.5em; text-align: right; font-size: .84rem; color: var(--ink); font-weight: 600; }

.wk-table-wrap {
  overflow-x: auto; border: 1px solid var(--rim); border-radius: var(--radius);
  background: var(--surface-1);
}
.wk-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.wk-table th {
  text-align: left; padding: 10px 14px; color: var(--ink-faint); font-weight: 600;
  font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--rim); white-space: nowrap;
}
.wk-table td { padding: 9px 14px; border-bottom: 1px solid rgba(255, 255, 255, .05); vertical-align: middle; }
.wk-table tbody tr:last-child td { border-bottom: 0; }
.wk-table tbody tr:hover { background: rgba(255, 255, 255, .025); }

.wk-tile { border-radius: var(--radius-sm); background: var(--surface-2); object-fit: contain; }
.wk-tile-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tile-size, 64px); height: var(--tile-size, 64px); border-radius: var(--radius-sm); flex: 0 0 auto;
  background: var(--surface-2); border: 1px solid var(--rim);
  color: var(--accent); font: 700 1.15rem var(--font-display);
  box-shadow: 0 0 0 1px rgba(127, 179, 213, .12) inset;
}

.wk-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--rim); background: var(--surface-1); color: var(--ink);
  font: 600 .9rem var(--font-body); text-decoration: none;
}
.wk-btn:hover { background: var(--surface-2); text-decoration: none; }
.wk-btn--ember {
  background: linear-gradient(135deg, var(--ember), #b8501f); color: #1c0d05; border-color: transparent;
}
.wk-btn--ember:hover { filter: brightness(1.08); }

.wk-empty { text-align: center; padding: 80px 20px; color: var(--ink-faint); }

/* generic page hero (index pages): headline + optional intro paragraph */
.wk-hero { padding: 30px 0 10px; }
.wk-hero h1 { margin-bottom: .35em; }
.wk-hero > p { max-width: 62ch; color: var(--ink-faint); }

/* ---- home (wiki/home.py) - minimal now, will get its own design pass once every section exists ---- */
body.section-home .home-kicker {
  font: 600 .74rem/1 var(--font-body); letter-spacing: .14em; text-transform: uppercase;
  color: var(--ember); margin: 0 0 10px;
}
body.section-home .home-tiles { margin: 22px 0 30px; }
body.section-home .home-tile h3 { margin-bottom: 4px; }
body.section-home .home-tile p { margin: 0; color: var(--ink-faint); font-size: .85rem; }
body.section-home .home-appcard { max-width: 640px; }
body.section-home .home-appcard .wk-btn { margin-top: 6px; }

/* ---- footer ---- */

.wk-footer {
  border-top: 1px solid var(--rim); margin-top: 40px;
  background: linear-gradient(180deg, transparent, rgba(232, 118, 58, .04));
  padding: 36px max(16px, env(safe-area-inset-left)) 28px;
}
.wk-footer-inner {
  max-width: 1180px; margin: 0 auto; display: grid; gap: 28px;
  grid-template-columns: 1.2fr 1.4fr .8fr; align-items: start;
}
.wk-footer-brand { display: flex; gap: 12px; align-items: flex-start; color: var(--ink-faint); font-size: .85rem; }
.wk-footer-brand b { color: var(--ink); font-family: var(--font-display); }
.wk-footer-cta p { color: var(--ink-faint); font-size: .88rem; margin-bottom: 10px; }
.wk-footer-cta .wk-btn { margin: 0 8px 8px 0; }
.wk-footer-links { display: flex; flex-direction: column; gap: 8px; font-size: .88rem; }
.wk-footer-links a { color: var(--ink-faint); }
.wk-footer-links a:hover { color: var(--accent); }
.wk-footer-legal { max-width: 1180px; margin: 24px auto 0; font-size: .75rem; color: var(--ink-faint); }

/* ---- responsive ---- */

@media (max-width: 1100px) {
  .wk-footer-inner { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .wk-nav {
    position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 49;
    flex-direction: column; gap: 0; padding: 8px;
    background: rgba(9, 14, 11, .98); border-bottom: 1px solid var(--rim);
    display: none;
  }
  .wk-nav.open { display: flex; }
  .wk-nav a { padding: 12px 14px; font-size: 1rem; }
  .wk-search-hint, .wk-search-btn kbd { display: none; }
  .wk-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0; border-radius: 10px; cursor: pointer;
    background: var(--surface-1); border: 1px solid var(--rim); color: var(--ink-dim);
  }
  .wk-header { gap: 8px; justify-content: space-between; }
  .wk-logo-eyebrow { display: none; }
  .wk-footer-inner { grid-template-columns: 1fr; }
  .wk-statbar-label { flex-basis: 7.5em; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  a.wk-card { transition: none; }
  .wk-logo-mark, .wk-footer-brand .wk-logo-mark { animation: none; transition: none; }
  .wk-logo:hover .wk-logo-mark { transform: none; }
}

/* ============================================================================
   LIGHT THEME - data-theme="light" on <html> (stamped pre-paint from localStorage 'wk-theme'; dark
   is the brand default in :root above). Only the shared TOKENS and the few hardcoded dark shell
   surfaces are re-pointed here - section CSS uses the tokens, so it gets the light theme for free.
   Biome axis colors stay IDENTICAL in both themes (DESIGN.md).
   ============================================================================ */
[data-theme="light"] {
  --bg: #eef0e6;
  --bg-deep: #e2e6d8;
  --surface-1: #ffffff;
  --surface-2: #f5f2e6;
  --rim: rgba(26, 38, 24, .14);
  --ink: #1a2216;
  --ink-dim: #384532;
  --ink-faint: #62705c;
  --accent: #2f6f92;
  --ember: #a8531f;
}
[data-theme="light"] .wk-header { background: rgba(238, 240, 230, .88); }
[data-theme="light"] .wk-nav { background: rgba(238, 240, 230, .98); }
[data-theme="light"] .wk-search-overlay { background: rgba(20, 28, 18, .3); }
[data-theme="light"] .wk-statbar-track { background: rgba(20, 28, 18, .1); }
[data-theme="light"] .wk-table td { border-bottom-color: rgba(20, 28, 18, .07); }
[data-theme="light"] .wk-table tbody tr:hover { background: rgba(20, 28, 18, .03); }
[data-theme="light"] .wk-search-panel { box-shadow: 0 20px 54px rgba(20, 30, 20, .18); }
[data-theme="light"] .wk-btn--ember { color: #fff8ee; }
[data-theme="light"] .wk-card { box-shadow: inset 0 1px 0 rgba(168, 83, 31, .10); }
