/* ═══ HELHEIMRS — components ═══ */

/* ── Buttons: stone slabs that press in ── */
.btn {
  --btn-bg: var(--stone-grad-2);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  font-family: var(--font-body); font-weight: 700; font-size: var(--fs-sm);
  color: var(--fg-strong); background: var(--btn-bg);
  border: 1px solid var(--line-strong); border-radius: var(--r-1);
  clip-path: var(--clip-facet); --facet: 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), inset 0 -2px 0 rgba(0,0,0,.45);
  transition: transform var(--t-fast) var(--ease-stone), box-shadow var(--t-ui) var(--ease-stone), background var(--t-ui), color var(--t-ui);
  position: relative; white-space: nowrap; text-decoration: none; user-select: none;
}
.btn:hover { text-decoration: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.1), inset 0 -2px 0 rgba(0,0,0,.45), var(--glow-inset-soft); border-color: var(--line-glow); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 2px 6px rgba(0,0,0,.6); }
.btn--primary { --btn-bg: var(--emerald-grad); color: var(--accent-fg); border-color: rgba(47,211,154,.6); box-shadow: inset 0 1px 0 rgba(255,255,255,.35), inset 0 -2px 0 rgba(0,0,0,.25), inset 0 0 20px rgba(255,255,255,.18); }
.btn--primary:hover { box-shadow: inset 0 1px 0 rgba(255,255,255,.45), inset 0 0 28px rgba(255,255,255,.3); }
:root[data-theme="light"] .btn--primary { border-color: rgba(15,107,79,.7); }
.btn--ghost { --btn-bg: transparent; border-color: var(--line-glow); color: var(--accent-text); box-shadow: none; }
.btn--ghost:hover { background: rgba(47,211,154,.06); }
.btn--danger { --btn-bg: linear-gradient(180deg, #7A241A, #4A1510); border-color: rgba(194,58,43,.5); color: #FBEDEA; box-shadow: inset 0 1px 0 rgba(255,255,255,.12), inset 0 -2px 0 rgba(0,0,0,.45); }
.btn--sm { min-height: 34px; padding: 0 var(--s-4); font-size: var(--fs-xs); }
.btn--lg { min-height: 56px; padding: 0 var(--s-7); font-size: var(--fs-md); --facet: 12px; }
.btn--icon { padding: 0; width: 44px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn .ico { width: 18px; height: 18px; }

/* ── Inputs: carved grooves ── */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field label, .label { font-size: var(--fs-sm); font-weight: 700; color: var(--fg-strong); }
.field .hint { font-size: var(--fs-xs); color: var(--fg-muted); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: var(--s-2) var(--s-4);
  background: var(--bg); color: var(--fg-strong);
  border: 1px solid var(--line-strong); border-radius: var(--r-1);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.55), inset 0 -1px 0 rgba(255,255,255,.04);
  transition: border-color var(--t-ui), box-shadow var(--t-ui);
}
:root[data-theme="light"] .input, :root[data-theme="light"] .select, :root[data-theme="light"] .textarea { box-shadow: inset 0 2px 5px rgba(0,0,0,.12); }
.input::placeholder, .textarea::placeholder { color: var(--fg-faint); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: inset 0 2px 6px rgba(0,0,0,.55), var(--glow); }
:root[data-theme="light"] .input:focus-visible, :root[data-theme="light"] .select:focus-visible, :root[data-theme="light"] .textarea:focus-visible { box-shadow: inset 0 2px 5px rgba(0,0,0,.12), var(--glow); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.8; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%239EA39C' stroke-width='1.5'/></svg>"); background-repeat: no-repeat; background-position: left 14px center; padding-inline-end: 36px; }
.input.is-error { border-color: var(--ember-soft); }
.error-msg { color: var(--danger); font-size: var(--fs-xs); }
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.check:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--r-1); }
.check input { appearance: none; width: 18px; height: 18px; border: 1px solid var(--line-strong); background: var(--bg); clip-path: var(--clip-hex); position: relative; }
.check input:checked { background: var(--emerald); box-shadow: var(--glow-soft); }
.switch { position: relative; width: 44px; height: 24px; background: var(--bg-elev-2); border: 1px solid var(--line-strong); border-radius: var(--r-pill); cursor: pointer; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--fg-muted); transition: transform var(--t-ui) var(--ease-stone), background var(--t-ui); }
.switch[aria-checked="true"] { border-color: var(--line-glow); }
.switch[aria-checked="true"]::after { transform: translateX(-20px); background: var(--emerald); box-shadow: var(--glow); }

/* ── Eyebrow / kicker (one definition; emerald stays reserved for .lit / .accent) ── */
.kicker { color: var(--fg-muted); font-size: var(--fs-sm); font-weight: 600; margin: 0 0 var(--s-2); }
.sec-head .kicker { margin: 0; }

/* ── Chips / tags ── */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--fg); background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--r-1); clip-path: var(--clip-facet); --facet: 6px;
  cursor: pointer; transition: color var(--t-ui), background var(--t-ui), border-color var(--t-ui) var(--ease-stone), box-shadow var(--t-ui); white-space: nowrap;
}
.chip:hover { border-color: var(--line-glow); color: var(--fg-strong); }
.chip[aria-pressed="true"], .chip[aria-checked="true"], .chip.is-on { background: rgba(47,211,154,.12); color: var(--accent-text); border-color: var(--line-glow); box-shadow: var(--glow-inset-soft); }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; font-size: var(--fs-xs); color: var(--fg-muted); border: 1px solid var(--line); border-radius: var(--r-1); background: rgba(255,255,255,.02); }
.tag--accent { color: var(--accent-text); border-color: var(--line-glow); }
.tag--danger { color: var(--danger); border-color: rgba(194,58,43,.4); background: var(--danger-bg); }
.tag--stone { background: var(--bg-elev-2); color: var(--fg); }

/* ── Cards: carved slabs ── */
.slab {
  position: relative; background: var(--stone-grad); border: 1px solid var(--line);
  --facet: 14px; clip-path: var(--clip-facet); padding: var(--s-5);
  box-shadow: var(--shadow-stone);
  transition: transform var(--t-slow) var(--ease-stone), border-color var(--t-slow);
}
.slab--glow { border-color: var(--line-glow); box-shadow: var(--shadow-stone), var(--glow-inset); }
.slab--pad-0 { padding: 0; }
/* emerald light tracing the edge on hover (uses two gradient borders) */
.slab-trace { position: relative; }
.slab-trace::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  clip-path: var(--clip-facet);
  background: linear-gradient(90deg, transparent 0%, var(--emerald) 50%, transparent 100%) top / 200% 1px no-repeat,
              linear-gradient(90deg, transparent 0%, var(--emerald) 50%, transparent 100%) bottom / 200% 1px no-repeat,
              linear-gradient(180deg, transparent 0%, var(--emerald) 50%, transparent 100%) left / 1px 200% no-repeat,
              linear-gradient(180deg, transparent 0%, var(--emerald) 50%, transparent 100%) right / 1px 200% no-repeat;
  opacity: 0; transition: opacity var(--t-ui);
}
.slab-trace:hover::before, .slab-trace:focus-within::before { opacity: 1; animation: trace 1.6s linear infinite; }
@keyframes trace { 0% { background-position: 200% top, -100% bottom, left -100%, right 200%; } 100% { background-position: -100% top, 200% bottom, left 200%, right -100%; } }
@media (prefers-reduced-motion: reduce) { .slab-trace:hover::before { animation: none; background: none; box-shadow: var(--glow-inset); } }

/* pointed-arch frame (portal echo) for featured media */
.arch { clip-path: var(--clip-arch); position: relative; }
.arch-frame { position: relative; padding: 2px; background: linear-gradient(180deg, var(--emerald), var(--jade) 70%, transparent); clip-path: var(--clip-arch); }
.arch-frame > * { clip-path: var(--clip-arch); }

/* ── Avatars ── */
.avatar { width: 40px; height: 40px; clip-path: var(--clip-hex); background: var(--bg-elev-2); display: inline-grid; place-items: center; font-family: var(--font-display); font-weight: 800; color: var(--accent-text); font-size: var(--fs-sm); flex: none; }
.avatar--lg { width: 96px; height: 96px; font-size: var(--fs-2xl); }
.avatar--sm { width: 28px; height: 28px; font-size: var(--fs-xs); }
.avatar-ring { display: inline-grid; place-items: center; padding: 2px; background: var(--emerald-grad); clip-path: var(--clip-hex); }

/* ── Tabs ── */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; padding-bottom: 1px; }
.tab { position: relative; padding: var(--s-3) var(--s-4); font-weight: 600; color: var(--fg-muted); background: none; border: 0; white-space: nowrap; transition: color var(--t-ui); }
.tab:hover { color: var(--fg-strong); }
.tab[aria-selected="true"] { color: var(--accent-text); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: var(--s-3); bottom: 0; height: 2px; background: var(--emerald); }

/* ── Modal (stone window) ── */
.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--bg-veil); backdrop-filter: blur(6px); display: grid; place-items: center; padding: var(--gutter); animation: fade var(--t-ui) both; }
.modal { --facet: 14px; position: relative; width: min(100%, 640px); max-height: calc(100vh - 2 * var(--gutter)); overflow: auto; background: var(--stone-grad); border: 1px solid var(--line-strong); clip-path: var(--clip-facet); padding: var(--s-6); box-shadow: var(--shadow-stone), var(--glow-inset); animation: rise var(--t-slow) var(--ease-out) both; }
.modal--wide { width: min(100%, 1040px); }
.modal__close { position: absolute; top: var(--s-3); inset-inline-end: var(--s-3); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── Tooltip / glossary ── */
.term { border-bottom: 1px dotted var(--line-glow); color: var(--accent-text); cursor: help; position: relative; }
.term-en { font-family: var(--font-latin); font-style: normal; font-size: .85em; color: var(--fg-muted); margin-inline-start: .3em; direction: ltr; unicode-bidi: isolate; }
.tip { position: fixed; left: 0; top: 0; z-index: var(--z-modal); max-width: 300px; padding: var(--s-3) var(--s-4); font-size: var(--fs-sm); line-height: 1.7; background: var(--bg-elev-2); color: var(--fg); border: 1px solid var(--line-glow); clip-path: var(--clip-facet); --facet: 8px; box-shadow: var(--shadow-stone), var(--glow-inset-soft); pointer-events: none; animation: fade var(--t-fast) both; }
.tip b { color: var(--fg-strong); display: block; }
.tip .term-en { display: block; margin: 0; }

/* ── Toast (fallback when ravens disabled) ── */
.toasts { position: fixed; bottom: calc(72px + var(--s-4)); inset-inline-start: var(--s-4); z-index: var(--z-raven); display: flex; flex-direction: column; gap: var(--s-2); width: min(360px, calc(100vw - 2 * var(--s-4))); }
.toast { background: var(--bg-elev-2); border: 1px solid var(--line-glow); clip-path: var(--clip-facet); --facet: 8px; padding: var(--s-3) var(--s-4); box-shadow: var(--shadow-stone), var(--glow-inset-soft); animation: rise var(--t-ui) var(--ease-out) both; }
.toast b { display: block; color: var(--fg-strong); }
.toast--danger { border-color: rgba(194,58,43,.6); box-shadow: inset 0 0 0 1px rgba(194,58,43,.45), inset 0 0 18px rgba(194,58,43,.16); }
.toast--success b { color: var(--accent-text); }

/* ── Loading: rune ring filling with emerald ── */
.rune-ring { --n: 12; position: relative; width: 84px; height: 84px; display: grid; place-items: center; overflow: hidden; }
.rune-ring span { position: absolute; inset: 0; display: grid; place-items: start center; font-family: var(--font-rune); font-size: 15px; color: var(--ornament); transform: rotate(calc(var(--i) * (360deg / var(--n)))); animation: runefill 1.8s calc(var(--i) * 150ms) infinite; }
@keyframes runefill { 0%, 70%, 100% { color: var(--ornament); text-shadow: none; } 20% { color: var(--emerald); text-shadow: 0 0 10px var(--emerald); } }
.rune-ring::after { content: ""; width: 10px; height: 10px; background: var(--emerald); clip-path: var(--clip-hex); animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: .5; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.15); } }
.loading { display: grid; place-items: center; gap: var(--s-4); padding: var(--s-9) 0; color: var(--fg-muted); }
.skeleton { background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev-2) 50%, var(--bg-elev) 75%); background-size: 200% 100%; animation: shimmer 1.6s infinite; min-height: 1em; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .rune-ring span, .rune-ring::after, .skeleton { animation: none; } }

/* ── Empty state with the Gatekeeper ── */
.empty { display: grid; justify-items: center; text-align: center; gap: var(--s-4); padding: var(--s-8) var(--s-5); border: 1px dashed var(--line-strong); clip-path: var(--clip-facet); }
.empty .keeper { width: 120px; opacity: .85; }
.empty :is(h2,h3) { margin: 0; }
.empty p { color: var(--fg-muted); margin: 0; }

/* ── Stat / rune-glow strip ── */
.glow-strip { display: flex; align-items: center; gap: var(--s-5); flex-wrap: wrap; padding: var(--s-4) var(--s-5); border: 1px solid var(--line-glow); background: linear-gradient(90deg, rgba(47,211,154,.08), transparent 60%); clip-path: var(--clip-facet); --facet: 10px; box-shadow: var(--glow-inset); }
.glow-strip .num { font-family: var(--font-display); font-weight: 900; font-size: var(--fs-2xl); color: var(--emerald); text-shadow: 0 0 14px rgba(47,211,154,.6); line-height: 1; }
:root[data-theme="light"] .glow-strip .num { color: var(--jade); }

/* ── Skull difficulty ── */
/* difficulty is drawn, not typed: an inline currentColor skull that takes the brand tint */
.skulls { display: inline-flex; gap: 3px; align-items: center; }
.skulls i { display: inline-grid; width: 14px; height: 14px; color: var(--ornament); opacity: .5; }
.skulls i svg { width: 100%; height: 100%; display: block; }
.skulls i.on { opacity: 1; color: var(--emerald); filter: drop-shadow(0 0 4px rgba(47,211,154,.7)); }
:root[data-theme="light"] .skulls i.on { color: var(--jade); filter: none; }

/* ── Shield seats ── */
.shields { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.shield { width: 34px; height: 40px; clip-path: var(--clip-shield); background: var(--bg-elev-2); display: grid; place-items: center; font-size: var(--fs-2xs); font-weight: 800; color: var(--accent-text); border-top: 2px solid var(--line-strong); position: relative; }
.shield--free { background: rgba(47,211,154,.08); box-shadow: inset 0 0 0 1px rgba(47,211,154,.35); }
.shield--taken { background: var(--bg-elev-3); color: var(--fg-strong); }
.shield--taken::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,.08), transparent); }

/* ── Stone divider with runes ── */
.divider { display: flex; align-items: center; gap: var(--s-4); color: var(--ornament); margin: var(--s-7) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line-strong), transparent); }
.divider .rune { font-size: var(--rune-sm); }

/* ── Breadcrumbs ── */
.crumbs { display: flex; flex-wrap: wrap; gap: var(--s-2); font-size: var(--fs-sm); color: var(--fg-muted); margin-bottom: var(--s-5); }
.crumbs a { color: var(--fg-muted); }
.crumbs li { list-style: none; display: flex; gap: var(--s-2); }
.crumbs li:not(:last-child)::after { content: "᛫"; font-family: var(--font-rune); color: var(--ornament); }
.crumbs ul { display: contents; padding: 0; margin: 0; }

/* ── Progress (emerald fissure) ── */
.fissure { position: fixed; top: 0; inset-inline-end: 0; width: 3px; height: 100vh; z-index: var(--z-nav); background: rgba(255,255,255,.04); pointer-events: none; }
.fissure > i { display: block; width: 100%; height: var(--p, 0%); background: linear-gradient(180deg, var(--emerald), var(--jade)); box-shadow: var(--glow-strong); transition: height 120ms linear; }

/* ── Key hint ── */
kbd { font-family: var(--font-latin); font-size: .75em; padding: 2px 7px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--r-1); background: var(--bg-elev); color: var(--fg-muted); direction: ltr; unicode-bidi: isolate; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th, .tbl td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); text-align: start; }
.tbl th { color: var(--fg-strong); font-weight: 700; background: rgba(255,255,255,.02); }
.tbl td { font-variant-numeric: tabular-nums; }

/* ── Stat blocks (bestiary) ── */
.statblock { --facet: 14px; background: var(--stone-grad); border: 1px solid var(--line-strong); clip-path: var(--clip-facet); padding: var(--s-5); position: relative; }
.statblock::before, .statblock::after { content: ""; position: absolute; inset-inline: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--emerald), transparent); opacity: .7; }
.statblock::before { top: 0; } .statblock::after { bottom: 0; }
.statblock :is(h2,h3) { font-size: var(--fs-2xl); margin: 0; }
.statblock .sub { color: var(--fg-muted); font-style: italic; font-size: var(--fs-sm); }
.statblock .abil { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s-2); text-align: center; margin: var(--s-4) 0; border-block: 1px solid var(--line-glow); padding: var(--s-3) 0; }
.statblock .abil b { display: block; color: var(--accent-text); font-family: var(--font-latin); font-size: var(--fs-xs); }
.statblock .abil span { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-lg); color: var(--fg-strong); }
.statblock .line { margin: 2px 0; font-size: var(--fs-sm); }
.statblock .line b { color: var(--fg-strong); }
.statblock .act { margin-top: var(--s-4); }
.statblock .act :is(h3,h4) { color: var(--accent-text); border-bottom: 1px solid var(--line-glow); padding-bottom: 4px; }
.cr { display: inline-grid; place-items: center; width: 52px; height: 52px; clip-path: var(--clip-hex); background: var(--emerald-grad); color: var(--accent-fg); font-family: var(--font-display); font-weight: 900; }
.cr small { font-size: var(--fs-2xs); font-weight: 700; line-height: 1; }

/* ── Speech (gatekeeper guide) ── */
.speech { position: relative; background: var(--bg-elev-2); border: 1px solid var(--line-glow); padding: var(--s-3) var(--s-4); font-size: var(--fs-sm); clip-path: var(--clip-facet); --facet: 8px; max-width: 280px; box-shadow: var(--glow-inset-soft); }

/* ── Ornamental rune band ── */
.rune-band { font-family: var(--font-rune); letter-spacing: .6em; color: var(--ornament); font-size: 13px; white-space: nowrap; overflow: hidden; text-align: center; user-select: none; direction: ltr; }
.rune-band--lit { color: var(--accent-text); opacity: .6; }

/* ── Coarse pointers: every control reaches the 44px target the style guide promises ── */
@media (pointer: coarse) {
  .btn--sm, .chip, .tab, .sound-btn { min-height: 44px; }
  .btn--icon, .hdr__tools .btn--icon { width: 44px; min-height: 44px; }
  .switch { width: 56px; height: 32px; }
  .switch::after { width: 24px; height: 24px; top: 3px; }
  .switch[aria-checked="true"]::after { transform: translateX(-24px); }
  .tag { min-height: 28px; }
}

/* ── realm intro: what a place is, in plain words, and where its name comes from ── */
.realm-plain { display: grid; gap: var(--s-1); margin-top: var(--s-3); max-width: 68ch; font-size: var(--fs-sm); }
.realm-plain p { margin: 0; line-height: 1.9; color: var(--fg); }
.realm-plain b { color: var(--accent-text); }
.realm-why summary { cursor: pointer; width: fit-content; min-height: 32px; display: flex; align-items: center; color: var(--fg-muted); font-size: var(--fs-xs); text-decoration: underline dotted; text-underline-offset: 4px; }
.realm-why summary:hover { color: var(--accent-text); }
.realm-why[open] summary { color: var(--accent-text); }
.realm-why p { margin: var(--s-1) 0 0; padding-inline-start: var(--s-3); border-inline-start: 2px solid var(--line-glow); color: var(--fg-muted); line-height: 1.9; font-size: var(--fs-sm); }
.q-head .realm-plain, .pg-niflheim .realm-plain { margin-inline: auto; text-align: start; }
