/**
 * FABLE — interface
 * =================
 * One sheet, ordered the way the eye meets things: base → HUD → log → prompts
 * → project card → overlays → fallback → narrow screens. Every panel
 * shares the same recipe: dark glass, a one-pixel lit edge, corners cut with
 * clip-path.
 */

/* ─────────────────────────────────────────────────────────────  base  ── */

:root {
  --bg: #05070f;
  --ink: #e9effc;
  --ink-dim: #b7c6e4;
  --muted: #8093b8;
  --line: rgba(150, 185, 255, 0.16);
  --line-strong: rgba(150, 185, 255, 0.34);
  --glass: rgba(11, 17, 33, 0.74);
  --glass-solid: #0b1121;
  --accent: #6fb6ff;
  --accent-dim: #3f6fa8;
  --gold: #ffd23f;
  --danger: #ff6b7d;
  --ok: #4ee6b8;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --cut: 10px;
  --ui: 'Sora', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body { touch-action: none; }
body.fallback-mode { overflow: auto; touch-action: auto; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}
#scene.grabbing { cursor: grabbing; }
#scene.pointing { cursor: pointer; }

button, input, a { font-family: inherit; }

/* Present for screen readers and crawlers, absent from the picture. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  box-shadow: var(--shadow);
}

/* Cut corners — the visual signature of the panels. */
.cut {
  clip-path: polygon(
    var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut)
  );
}

/* The HUD fades in over the first frames rather than snapping on. */
body.booting .hud,
body.booting .quests,
body.booting .filters,
body.booting .markers,
body.booting .prompt { opacity: 0; pointer-events: none; }
.hud, .quests, .filters, .markers { transition: opacity 0.8s ease 0.25s; }

/* ──────────────────────────────────────────────────────────────  HUD  ── */

.hud {
  position: fixed;
  z-index: 20;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.hud-top {
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
}

.hud > * { pointer-events: auto; }

/* Player card ----------------------------------------------------------- */

.player {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px 12px 12px;
  min-width: 320px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  box-shadow: var(--shadow);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.player-sigil {
  position: relative;
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
}
.player-sigil svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: rgba(111, 182, 255, 0.1);
  stroke: var(--accent);
  stroke-width: 1.4;
  filter: drop-shadow(0 0 6px rgba(111, 182, 255, 0.5));
}
.player-level {
  position: relative;
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  color: #dcecff;
  text-shadow: 0 0 10px rgba(111, 182, 255, 0.7);
}
.player-body { flex: 1; min-width: 0; }

.player-line {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 7px;
}
.player-handle {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--ink);
}
.player-rank {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-transform: uppercase;
}

.xp-bar {
  position: relative;
  height: 5px;
  border-radius: 3px;
  background: rgba(140, 175, 255, 0.14);
  overflow: hidden;
}
.xp-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #3f8fd8, var(--accent) 60%, #b9e4ff);
  box-shadow: 0 0 10px rgba(111, 182, 255, 0.65);
  transition: width 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.xp-legend {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.seals {
  display: grid;
  grid-template-columns: repeat(4, 8px);
  gap: 4px;
  flex: none;
}
.seals i {
  width: 8px;
  height: 8px;
  border-radius: 1px;
  background: rgba(140, 175, 255, 0.16);
  transform: rotate(45deg);
  transition: background 0.4s, box-shadow 0.4s;
}
.seals i.on {
  background: var(--c, var(--accent));
  box-shadow: 0 0 8px var(--c, var(--accent));
}

/* Toolbar buttons ------------------------------------------------------- */

.tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  font-size: 12px;
  letter-spacing: 0.03em;
  color: var(--ink-dim);
  text-decoration: none;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s;
}
.tool:hover, .tool:focus-visible {
  color: #fff;
  border-color: var(--line-strong);
  background: rgba(28, 42, 74, 0.8);
  transform: translateY(-1px);
}
.tool[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-dim); }
.tool-key {
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  background: rgba(111, 182, 255, 0.12);
  border: 1px solid rgba(111, 182, 255, 0.24);
  border-radius: 3px;
}
.tool.muted .tool-key { color: var(--muted); background: rgba(140, 175, 255, 0.08); border-color: var(--line); }

/* ─────────────────────────────────────────────────────────────  log  ── */

.quests {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  width: 268px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  box-shadow: var(--shadow);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.3s;
}

.quests-head {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}
.quests-title {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.quests-count { font-family: var(--mono); font-size: 11px; color: var(--accent); }

.quests-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 12px;
  display: grid;
  gap: 7px;
  max-height: 46vh;
  overflow: auto;
  scrollbar-width: thin;
}
.quests.collapsed .quests-list { display: none; }

.quest {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 9px;
  align-items: start;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-dim);
}
.quest-box {
  margin-top: 2px;
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  transform: rotate(45deg);
  position: relative;
  transition: background 0.3s, border-color 0.3s;
}
.quest.done .quest-box { background: var(--ok); border-color: var(--ok); box-shadow: 0 0 8px rgba(78, 230, 184, 0.6); }
.quest.done .quest-name { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(128, 147, 184, 0.5); }
.quest-name { display: block; }
.quest-prog { font-family: var(--mono); font-size: 10.5px; color: var(--accent); opacity: 0.85; }
.quest.done .quest-prog { color: var(--ok); }

/* ─────────────────────────────────────────────────────────  prompts  ── */

.prompt {
  position: fixed;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  z-index: 18;
  padding: 9px 16px;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: rgba(8, 13, 26, 0.82);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  white-space: nowrap;
}
.prompt.show { opacity: 1; transform: translate(-50%, 0); }
.prompt kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  margin-right: 4px;
  color: var(--accent);
  background: rgba(111, 182, 255, 0.12);
  border: 1px solid rgba(111, 182, 255, 0.28);
  border-radius: 3px;
}
.prompt b { color: var(--c, var(--accent)); font-weight: 600; }

/* Beacons projected from the 3D scene ----------------------------------- */

.markers { position: fixed; inset: 0; z-index: 15; pointer-events: none; }

.marker {
  position: absolute;
  left: 0; top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 6px;
  font-size: 12px;
  color: var(--ink);
  background: rgba(8, 13, 26, 0.7);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  transition: opacity 0.3s, border-color 0.2s, background 0.2s;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}
.marker:hover { border-color: var(--c); background: rgba(16, 24, 44, 0.9); }
.marker-sigil {
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  font-size: 13px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  text-shadow: 0 0 8px var(--c);
}
.marker-text { display: flex; flex-direction: column; line-height: 1.2; }
.marker-name { font-weight: 500; letter-spacing: 0.01em; }
.marker-sub {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.13em;
  color: var(--muted);
  text-transform: uppercase;
}
.marker.awake .marker-sub { color: color-mix(in srgb, var(--c) 65%, var(--muted)); }
.marker.awake .marker-name { color: #fff; }
.marker.awake { border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.marker.near { background: rgba(20, 30, 54, 0.92); border-color: var(--c); }
.marker.dim { filter: saturate(0.35); }
.marker .marker-seal { color: var(--c); font-size: 10px; letter-spacing: 0.1em; }

/* Virtual stick --------------------------------------------------------- */

/* Anchored, not summoned: a stick that appears where the thumb happens to land
   cannot be aimed for, and it competes with the drag that orbits the camera.
   This one is always in the same corner, and the lower-left corner is kept
   clear of every panel below. */
.stick {
  position: fixed;
  z-index: 19;
  left: max(16px, calc(env(safe-area-inset-left) + 10px));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  width: 128px; height: 128px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(8, 13, 26, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  place-items: center;
  pointer-events: none;
  opacity: 0.46;
  transition: opacity 0.2s;
}
.stick.active { opacity: 1; }
.stick i {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(111, 182, 255, 0.28);
  border: 1px solid var(--accent);
  box-shadow: 0 0 18px rgba(111, 182, 255, 0.45);
  transform: translate(var(--dx, 0px), var(--dy, 0px));
}
body.touch .stick { display: grid; }

/* ──────────────────────────────────────────────────────────  filters  ── */

.filters {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 176px;
  padding: 12px 12px 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  box-shadow: var(--shadow);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

.filters-title {
  margin: 0 0 10px 2px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 2px);
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.filters-title::after {
  content: "▾";
  margin-left: auto;
  font-size: 9px;
  opacity: 0.7;
  transition: transform 0.18s;
}
/* Folded, the rail is just its own title — one tap to get the lens back. */
.filters.collapsed { width: max-content; }
.filters.collapsed .filters-title { margin-bottom: 0; }
.filters.collapsed .filters-title::after { transform: rotate(-90deg); }
.filters.collapsed .filters-list,
.filters.collapsed .filters-clear { display: none; }

.filters-list { display: grid; gap: 5px; }

.filter-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  font-size: 12px;
  text-align: left;
  color: var(--ink-dim);
  background: none;
  border: 1px solid var(--line);
  cursor: pointer;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.filter-chip:hover { color: #fff; border-color: var(--line-strong); }
.filter-chip i {
  flex: none;
  width: 7px; height: 7px;
  background: rgba(140, 175, 255, 0.3);
  transform: rotate(45deg);
  transition: background 0.25s, box-shadow 0.25s;
}
.filter-chip b { font-weight: 500; }
.filter-chip span {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
}
.filter-chip[aria-pressed="true"] {
  color: #fff;
  border-color: var(--accent-dim);
  background: rgba(111, 182, 255, 0.12);
}
.filter-chip[aria-pressed="true"] i {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.filter-chip[aria-pressed="true"] span { color: var(--accent); }

.filters-clear {
  width: 100%;
  margin-top: 9px;
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 1px dashed var(--line);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.filters-clear:hover { color: var(--ink); border-color: var(--line-strong); }
.filters-clear[hidden] { display: none; }

/* ─────────────────────────────────────────────────────  notifications  ── */

.toasts {
  position: fixed;
  top: max(96px, calc(env(safe-area-inset-top) + 96px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px 10px 12px;
  min-width: 240px;
  background: rgba(10, 16, 32, 0.96);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
}
.toast.out { animation: toast-out 0.35s ease-in both; }
.toast-icon {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  font-size: 15px;
  color: var(--c, var(--gold));
  background: color-mix(in srgb, var(--c, var(--gold)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c, var(--gold)) 40%, transparent);
  text-shadow: 0 0 10px var(--c, var(--gold));
}
.toast-kind {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--c, var(--gold));
}
.toast-name { display: block; font-size: 14px; font-weight: 500; }
.toast-desc { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px) scale(0.98); }
}

/* ───────────────────────────────────────────────────  project card  ── */

.dossier {
  position: fixed;
  top: 0; right: 0;
  z-index: 30;
  width: min(452px, 100vw);
  height: 100%;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) 0;
  transform: translateX(102%);
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
.dossier.show { transform: none; }
.dossier[hidden] { display: block; visibility: hidden; }
.dossier.show[hidden] { visibility: visible; }

.dossier-inner {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 28px;
  background: linear-gradient(180deg, rgba(13, 20, 38, 0.94), rgba(7, 11, 22, 0.96));
  border: 1px solid var(--line);
  border-left: 1px solid color-mix(in srgb, var(--c, var(--accent)) 45%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.55);
  scrollbar-width: thin;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 26px 100%, 0 calc(100% - 26px));
}

.dossier-head { display: flex; align-items: flex-start; gap: 14px; }
.dossier-sigil {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  flex: none;
  font-size: 22px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  text-shadow: 0 0 14px var(--c);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.dossier h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
}
.dossier-klass {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--c);
}
.dossier .close {
  margin-left: auto;
  width: 32px; height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.dossier .close:hover { color: #fff; border-color: var(--line-strong); }

.dossier-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ok);
  background: rgba(78, 230, 184, 0.1);
  border: 1px solid rgba(78, 230, 184, 0.28);
}
.dossier-status.wip { color: var(--gold); background: rgba(255, 210, 63, 0.1); border-color: rgba(255, 210, 63, 0.3); }
.dossier-status::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }

.dossier-tag {
  margin: 16px 0 0;
  font-size: 16.5px;
  line-height: 1.45;
  color: #fff;
  font-weight: 500;
}
.dossier-lore {
  margin: 10px 0 0;
  padding-left: 12px;
  border-left: 2px solid color-mix(in srgb, var(--c) 40%, transparent);
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 1px;
  margin: 20px 0 0;
  background: var(--line);
  border: 1px solid var(--line);
}
.stat { padding: 10px 11px; background: rgba(9, 14, 28, 0.9); }
.stat b {
  display: block;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--c);
  letter-spacing: -0.01em;
}
.stat span { display: block; margin-top: 3px; font-size: 10.5px; line-height: 1.3; color: var(--muted); }

.dossier-body { margin: 20px 0 0; }
.dossier-body p {
  margin: 0 0 13px;
  font-size: 13.8px;
  line-height: 1.62;
  color: var(--ink-dim);
}

.section-label {
  margin: 22px 0 10px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.stack { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.stack li {
  padding: 4px 9px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
}

.links { display: grid; gap: 8px; margin-top: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, color 0.2s;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
}
.btn:hover { transform: translateY(-1px); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }
.btn.primary {
  color: #06101f;
  font-weight: 600;
  background: linear-gradient(120deg, var(--c, var(--accent)), color-mix(in srgb, var(--c, var(--accent)) 62%, #ffffff));
  border-color: transparent;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--c, var(--accent)) 28%, transparent);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); border-color: rgba(255, 107, 125, 0.3); }
.btn.danger:hover { background: rgba(255, 107, 125, 0.1); }
.btn .kind {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  opacity: 0.7;
  text-transform: uppercase;
}

.dossier-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.dossier-foot b { color: var(--c); }

/* ────────────────────────────────────────────────────────  overlays  ── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 5, 11, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s;
}
.overlay.show { opacity: 1; }
.overlay[hidden] { display: none; }

.overlay-panel {
  width: min(980px, 100%);
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(13, 20, 38, 0.97), rgba(7, 11, 22, 0.98));
  border: 1px solid var(--line-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  transform: translateY(12px) scale(0.99);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  clip-path: polygon(0 18px, 18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%);
}
.overlay.show .overlay-panel { transform: none; }
.overlay-panel.narrow { width: min(560px, 100%); }

.overlay-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 26px 16px;
  border-bottom: 1px solid var(--line);
}
.overlay-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.overlay-sub { margin: 5px 0 0; font-size: 12.5px; color: var(--muted); }
.overlay .close {
  margin-left: auto;
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.overlay .close:hover { color: #fff; border-color: var(--line-strong); }

.overlay-body {
  padding: 20px 26px 26px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Codex grid ------------------------------------------------------------ */

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

.codex-card {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 15px 15px 14px;
  text-align: left;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid var(--line);
  border-top: 2px solid color-mix(in srgb, var(--c) 55%, transparent);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%);
}
.codex-card:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.06); }
.codex-card.locked { opacity: 0.62; }
/* Left out by the current filter — dimmed, never hidden, always clickable. */
.codex-card.dimmed { opacity: 0.4; }
.codex-card.dimmed:hover { opacity: 0.75; }
.codex-card-head { display: flex; align-items: center; gap: 9px; }
.codex-card .sig {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  font-size: 14px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 36%, transparent);
}
.codex-card h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.codex-card .klass {
  margin: 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.codex-card p { margin: 0; font-size: 12.2px; line-height: 1.45; color: var(--ink-dim); }
.codex-card .foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}
.codex-card .foot .seal { color: var(--c); }
.codex-card .foot .seal.off { color: var(--muted); }
/* Inside a card, actions sit on one or two lines, never a stack. */
.codex-card .links { display: flex; flex-wrap: wrap; gap: 6px; }
.codex-card .links .btn { flex: 1 1 auto; }

/* Achievements ---------------------------------------------------------- */

.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(214px, 1fr));
  gap: 9px;
}
.ach {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 11px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
}
.ach i {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  font-style: normal;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  transform: rotate(45deg);
}
.ach i span { transform: rotate(-45deg); }
.ach.on { border-color: rgba(255, 210, 63, 0.3); background: rgba(255, 210, 63, 0.05); }
.ach.on i { color: var(--gold); border-color: rgba(255, 210, 63, 0.5); box-shadow: 0 0 12px rgba(255, 210, 63, 0.25); }
.ach b { display: block; font-size: 12.5px; font-weight: 500; }
.ach span.d { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

.codex-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  margin-bottom: 20px;
  background: var(--line);
  border: 1px solid var(--line);
}
.codex-summary div { padding: 12px 14px; background: rgba(9, 14, 28, 0.9); }
.codex-summary b {
  display: block;
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  color: var(--accent);
}
.codex-summary span { display: block; margin-top: 2px; font-size: 10.5px; color: var(--muted); }

/* Controls -------------------------------------------------------------- */

.keys { margin: 0; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.keys > div {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(9, 14, 28, 0.92);
}
.keys dt { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.keys dd { margin: 0; font-size: 12.5px; color: var(--ink-dim); text-align: right; }
.keys span { color: var(--muted); font-size: 11px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  padding: 3px 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--accent);
  background: rgba(111, 182, 255, 0.1);
  border: 1px solid rgba(111, 182, 255, 0.26);
  border-radius: 3px;
}
.help-note { margin: 16px 0 18px; font-size: 12px; line-height: 1.55; color: var(--muted); }
.help-note code {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: rgba(111, 182, 255, 0.1);
  padding: 1px 5px;
}

/* ─────────────────────────────────────────────────  no-WebGL fallback  ── */

.fallback {
  position: relative;
  z-index: 70;
  min-height: 100%;
  padding: 60px 24px 90px;
  background: var(--bg);
  overflow-y: auto;
}
.fallback[hidden] { display: none; }
.fallback-inner { max-width: 760px; margin: 0 auto; }
.fallback h1 {
  margin: 0 0 8px;
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 300;
  letter-spacing: -0.01em;
}
.fallback-lede { margin: 0 0 40px; color: var(--muted); font-size: 14.5px; }
.fallback-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px; }
.fallback-list li {
  padding: 20px 22px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-left: 2px solid var(--c, var(--accent));
}
.fallback-list h2 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.fallback-klass {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--c, var(--accent));
  margin: 0 0 10px !important;
}
.fallback-list p { margin: 0 0 8px; font-size: 13.5px; line-height: 1.6; color: var(--ink-dim); }
.fallback-list a { color: var(--accent); }
.fallback-foot { margin-top: 46px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.fallback-foot a { color: var(--accent); }

/* ────────────────────────────────────────────────────  narrow screens  ── */

@media (max-width: 900px) {
  .dossier { width: 100vw; padding: 0; }
  .dossier-inner {
    padding: max(18px, env(safe-area-inset-top)) 18px 92px;
    border-left: 0;
    border-top: 2px solid color-mix(in srgb, var(--c, var(--accent)) 50%, transparent);
    clip-path: none;
  }
  .quests { width: 220px; }
  .quests-list { max-height: 30vh; }
}

@media (max-width: 720px) {
  .hud-top { flex-direction: column; align-items: stretch; gap: 8px; }
  .player { min-width: 0; padding: 9px 14px 9px 9px; gap: 10px; }
  .player-sigil { width: 38px; height: 38px; }
  .player-level { font-size: 14px; }
  .tools { justify-content: flex-start; }
  .tool-label { display: none; }
  .tool { padding: 8px 10px; }
  /* The log used to span the full width and sat straight on top of the stick. */
  .quests {
    width: min(56vw, 250px);
    left: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, calc(env(safe-area-inset-bottom) + 6px));
  }
  .quests-list { max-height: 22vh; grid-auto-rows: min-content; }
  .quests.collapsed { width: max-content; margin-left: auto; }
  .prompt { bottom: auto; top: max(150px, calc(env(safe-area-inset-top) + 150px)); font-size: 12px; }
  .toasts { top: auto; bottom: 34%; width: min(92vw, 340px); }
  .toast { min-width: 0; width: 100%; }
  /* Ten labels on a 390px screen: cap them so a long name cannot run off the
     edge or bury the map under text. */
  .marker { font-size: 11px; padding: 4px 9px 4px 5px; max-width: 46vw; }
  .marker-name, .marker-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .marker-sub { font-size: 7.5px; letter-spacing: 0.08em; }
  /* Sits above the stick, never beside it: on a phone the rail is anchored to
     the top of the screen and given a ceiling, so it cannot grow down into the
     corner the thumb owns. */
  .filters {
    width: 128px;
    top: max(132px, calc(env(safe-area-inset-top) + 132px));
    transform: none;
    max-height: calc(100dvh - 340px);
    overflow-y: auto;
    padding: 9px 9px;
  }
  .filter-chip { padding: 6px 7px; font-size: 11px; gap: 7px; }
  .filter-chip span { display: none; }
  .codex-grid { grid-template-columns: 1fr; }
  .overlay { padding: 10px; }
  .overlay-head { padding: 16px 18px 14px; }
  .overlay-body { padding: 16px 18px 22px; }
  .keys > div { flex-direction: column; align-items: flex-start; gap: 6px; }
  .keys dd { text-align: left; }
}

/* Phone held sideways: almost no vertical room. The log goes, the stick shrinks
   and the rail gets a tighter ceiling rather than overflowing the screen. */
@media (max-height: 560px) {
  .quests { display: none; }
  .stick { width: 104px; height: 104px; }
  .stick i { width: 42px; height: 42px; }
  .filters {
    top: max(92px, calc(env(safe-area-inset-top) + 92px));
    transform: none;               /* the base rule centres it on the viewport */
    max-height: calc(100dvh - 180px);
    overflow-y: auto;
  }
}

/* Hover does not exist under a finger: avoid sticky states. */
@media (hover: none) {
  .tool:hover, .btn:hover, .codex-card:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.05s !important;
  }
}
