/* ------------------------------------------------------------------ tokens */
:root {
  /* Palette from yssvikingstudies.com: aubergine, mauve greys, sky blue. */
  --bg: #1d1229;
  --panel: #281a39;
  --panel-2: #33244a;
  --line: #4a3d5c;
  --ink: #f6f6f6;
  --ink-dim: #c3bfc7;
  --accent: #bde9fb;
  --accent-ink: #281a39;
  --accent-soft: rgba(189, 233, 251, 0.14);
  --rune: #eae0da;
  --radius: 10px;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --header-h: 80px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--rune); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; }

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

/* ------------------------------------------------------------------ header */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #2e1f42, #281a39);
}
.site-header__title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.site-header__mark {
  font-size: 26px;
  color: var(--rune);
  letter-spacing: 2px;
  line-height: 1;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.site-header h1 { margin: 0; font-size: 21px; line-height: 1.15; letter-spacing: 0.04em; }
.site-header p { margin: 0; font-size: 12.5px; color: var(--ink-dim); }
.site-header__kicker {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent) !important;
}
.site-header__kicker a { color: var(--accent); text-decoration: none; }
.site-header__kicker a:hover { text-decoration: underline; }
.site-header__kicker span { margin: 0 4px; color: var(--ink-dim); }
.site-header__actions { display: flex; gap: 8px; flex: none; }
.site-header__actions .ghost-button { text-decoration: none; }
a.site-header__mark { text-decoration: none; }
.site-header__title > div { min-width: 0; }
.site-header__kicker, .site-header h1, .site-header__title p:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 700px) {
  .site-header { padding: 0 14px; gap: 10px; }
  .site-header__actions a.ghost-button { display: none; }
  .site-header__org { display: none; }
  .site-header h1 { font-size: 19px; }
  .site-header__mark { font-size: 22px; padding: 5px 8px; }
}

.ghost-button {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.ghost-button:hover { border-color: var(--accent); color: #fff; background: var(--accent-soft); }
.ghost-button--small { padding: 4px 10px; font-size: 12px; }

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  height: calc(100% - var(--header-h));
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.filters { padding: 14px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.filters input, .filters select {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters__row { display: flex; align-items: center; justify-content: space-between; }
.filters__count { font-size: 12px; color: var(--ink-dim); }

.stone-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.stone-list__empty { padding: 18px 10px; color: var(--ink-dim); font-size: 13px; }

.stone-card__button {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "signum runes" "name runes" "meta runes";
  gap: 1px 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.stone-card__button:hover { background: var(--panel-2); border-color: var(--line); }
.stone-card.is-selected .stone-card__button {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.stone-card__signum { grid-area: signum; font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); }
.stone-card__name { grid-area: name; font-family: var(--serif); font-size: 16px; }
.stone-card__meta { grid-area: meta; font-size: 12px; color: var(--ink-dim); }
.stone-card__runes {
  grid-area: runes;
  align-self: center;
  max-width: 78px;
  overflow: hidden;
  color: var(--rune);
  opacity: 0.55;
  font-size: 15px;
  letter-spacing: 1px;
  white-space: nowrap;
}

.sidebar__foot {
  margin: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-dim);
}

/* --------------------------------------------------------------------- map */
.map { height: 100%; background: #fafaf8; }
.map.tiles-offline {
  background:
    radial-gradient(circle at 42% 34%, #3a2b4f 0%, #281a39 45%, #1d1229 100%);
}
.leaflet-container { background: #fafaf8; font-family: var(--sans); }
.leaflet-control-attribution {
  background: rgba(40, 26, 57, 0.85) !important;
  color: var(--ink-dim) !important;
  font-size: 10.5px;
}
.leaflet-control-attribution a { color: var(--rune) !important; }
.leaflet-bar a {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
.leaflet-bar a:hover { background: var(--panel-2) !important; }

.stone-marker { transition: transform 0.15s, opacity 0.2s; cursor: pointer; }
.stone-marker svg { width: 26px; height: 34px; overflow: visible; }
.stone-marker__body {
  fill: #6f6a60;
  stroke: #281a39;
  stroke-width: 1.4;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.55));
}
.stone-marker__runes { stroke: var(--rune); stroke-width: 1.3; fill: none; opacity: 0.85; }
.stone-marker.era-pre-viking .stone-marker__body { fill: #7b8a7a; }
.stone-marker.is-hovered, .stone-marker:hover { transform: scale(1.18); }
.stone-marker.is-selected .stone-marker__body { fill: var(--accent); stroke: #281a39; }
.stone-marker.is-selected { transform: scale(1.3); }
.stone-marker.is-dimmed { opacity: 0.22; }

.stone-cluster {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(40, 26, 57, 0.92);
  border: 2px solid var(--rune);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  color: var(--rune);
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s;
}
.stone-cluster:hover { transform: scale(1.08); border-color: var(--accent); color: #fff; }

.stone-tooltip {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5) !important;
  font-size: 12.5px;
}
.stone-tooltip::before { border-top-color: var(--line) !important; }

/* ------------------------------------------------------------ detail panel */
.detail {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: 470px;
  max-width: 100%;
  height: calc(100% - var(--header-h));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 46px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 1200;
}
.detail.is-open { transform: none; }
.detail__content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

.detail__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.detail__signum {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.detail__title { margin: 0; font-size: 24px; }
.detail__subtitle { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-dim); }
.detail__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.detail__close:hover { border-color: var(--accent); color: #fff; }

.viewer { position: relative; border-bottom: 1px solid var(--line); background: var(--bg); }
.viewer__canvas { height: 360px; width: 100%; }
.viewer__canvas canvas { display: block; width: 100%; height: 100%; }
.viewer__status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.viewer__status.is-busy { opacity: 1; background: rgba(29, 18, 41, 0.72); }
.viewer__tools {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}
.tool {
  padding: 6px 11px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: rgba(40, 26, 57, 0.82);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.tool:hover { border-color: var(--accent); }
.tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.viewer__hint {
  position: absolute;
  right: 56px;
  top: 14px;
  margin: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(29, 18, 41, 0.6);
  font-size: 11px;
  color: var(--ink-dim);
  pointer-events: none;
}

.detail__body { padding: 18px; }
.detail__summary { margin-top: 0; }

.inscription {
  margin: 18px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.inscription h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.04em; }
.inscription__note { color: var(--ink-dim); font-size: 11.5px; font-family: var(--sans); }
.inscription__runes {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.5;
  letter-spacing: 3px;
  color: var(--rune);
  word-break: break-word;
}
.inscription__latin { overflow-wrap: anywhere; margin: 0 0 6px; font-family: var(--serif); font-style: italic; color: var(--ink-dim); }
.inscription__translation { margin: 0; font-family: var(--serif); font-size: 15.5px; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.fact dt { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-dim); }
.fact dd { overflow-wrap: anywhere; margin: 2px 0 0; font-size: 13.5px; }

/* ------------------------------------------------------------------ dialog */
.about {
  max-width: 560px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  padding: 22px 24px;
}
.about::backdrop { background: rgba(20, 12, 29, 0.7); }
.about h2 { margin-top: 0; }
.about h3 { font-size: 14px; margin-bottom: 4px; }
.about ul { padding-left: 18px; font-size: 13.5px; }
.about li { margin-bottom: 6px; }
.about p { font-size: 13.5px; }

/* ----------------------------------------------------------- bottom sheet */
.sheet-handle { display: none; }

/* ------------------------------------------------------------ small screens */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr; }

  /* The list becomes a sheet over the map: a bar along the bottom that
     pulls up to fill most of the screen. */
  .sidebar {
    --peek: 60px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(82vh, 100% - var(--header-h) - 12px);
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform 0.28s ease;
    z-index: 1100;
  }
  .sidebar.is-open { transform: none; }
  body.detail-open .sidebar { transform: translateY(100%); }

  .sheet-handle {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "grip grip" "label hint";
    align-items: center;
    gap: 2px 10px;
    height: var(--peek);
    padding: 8px 18px 10px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .sheet-handle__grip {
    grid-area: grip;
    justify-self: center;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
  }
  .sheet-handle__label { grid-area: label; font-family: var(--serif); font-size: 16px; }
  .sheet-handle__hint { grid-area: hint; font-size: 12px; color: var(--ink-dim); }
  .sidebar.is-open .sheet-handle__hint { visibility: hidden; }

  .sidebar__foot { display: none; }
  .leaflet-bottom { bottom: 60px; }

  .detail { top: 0; width: 100%; height: 100%; }
  .viewer__canvas { height: 46vh; }
  .facts { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------- svg runes */
.rune-svg { display: block; max-width: 100%; height: auto; color: var(--rune); }
.stone-card__runes .rune-svg { height: 20px; width: auto; opacity: 0.6; }
.inscription__runes { margin: 0 0 10px; }
.inscription__runes .rune-svg { width: 100%; }

/* ------------------------------------------------- scans and viewer modes */
.viewer__canvas--scan { padding: 0; }
.scan-frame { display: block; width: 100%; height: 100%; border: 0; background: var(--bg); }

.viewer__modes {
  position: absolute;
  left: 12px;
  top: 10px;
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(40, 26, 57, 0.86);
  backdrop-filter: blur(4px);
}
.mode {
  padding: 5px 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.mode:hover { color: var(--ink); }
.mode[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.viewer__credit {
  margin: 0;
  padding: 7px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 11.5px;
  color: var(--ink-dim);
}

.chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.chip--scan { border-color: var(--rune); color: var(--rune); }

.inscription--empty .inscription__translation { color: var(--ink-dim); font-style: italic; }
