/* Almanac of the Wilds — field-journal design system.
   Tokens first (light "daylight page" + dark "lamplight journal"), then page chrome, then the
   specimen card frame and small components shared by every module. */

/* ---------- fonts (self-hosted copies of the Google Fonts families; see pipeline/vendor.mjs) ---------- */
@font-face { font-family: "IM Fell English SC"; src: url(../vendor/fonts/im-fell-english-sc-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IM Fell English"; src: url(../vendor/fonts/im-fell-english-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IM Fell English"; src: url(../vendor/fonts/im-fell-english-latin-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(../vendor/fonts/alegreya-sans-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(../vendor/fonts/alegreya-sans-latin-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(../vendor/fonts/alegreya-sans-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(../vendor/fonts/alegreya-sans-latin-700-normal.woff2) format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(../vendor/fonts/ibm-plex-mono-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(../vendor/fonts/ibm-plex-mono-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }

/* ---------- tokens ---------- */
:root {
  --paper: #efe6d2;
  --paper-deep: #e2d5b8;
  --paper-card: #f7f0de;
  --paper-glass: rgba(239, 230, 210, 0.9);
  --ink: #2b2620;
  --ink-faded: #6b5f4f;
  --ink-faint: rgba(43, 38, 32, 0.16);
  --ink-hair: rgba(43, 38, 32, 0.3);
  /* watercolor pigments */
  --sky: #6f98b8;
  --moss: #7a9a5a;
  --ochre: #c89a4a;
  --rust: #b5573b;
  --slate: #5f6f7a;
  --frost: #a9c6d8;
  --gold: #b8913a;
  --gold-hi: #f1d58a;
  --tape: rgba(226, 212, 172, 0.78);
  --tape-edge: rgba(150, 128, 80, 0.25);
  --shadow-card: 0 1px 1px rgba(70, 50, 20, 0.12), 0 10px 24px -12px rgba(70, 50, 20, 0.5);
  --shadow-float: 0 1px 1px rgba(70, 50, 20, 0.1), 0 14px 32px -16px rgba(70, 50, 20, 0.55);
  --highlight: rgba(200, 154, 74, 0.3);
  /* type */
  --display: "IM Fell English SC", "IM Fell DW Pica SC", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --display-text: "IM Fell English", "IM Fell DW Pica", "Palatino Linotype", Palatino, Georgia, serif;
  --body: "Alegreya Sans", "Gill Sans", "Gill Sans MT", Seravek, "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  /* layout */
  --topbar-h: 62px;
  --drawer-w: 430px;
  --lensbox-w: 236px;
  --gutter: 16px;
  --radius: 3px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #1f1b16;
  --paper-deep: #15120e;
  --paper-card: #2a241c;
  --paper-glass: rgba(31, 27, 22, 0.9);
  --ink: #e9dfc8;
  --ink-faded: #ab9d84;
  --ink-faint: rgba(233, 223, 200, 0.14);
  --ink-hair: rgba(233, 223, 200, 0.28);
  --sky: #85afd0;
  --moss: #93b56f;
  --ochre: #deb25e;
  --rust: #d4724f;
  --slate: #8396a3;
  --frost: #bdd9eb;
  --gold: #d8b25a;
  --gold-hi: #fbe7a6;
  --tape: rgba(196, 176, 128, 0.3);
  --tape-edge: rgba(240, 220, 170, 0.12);
  --shadow-card: 0 1px 1px rgba(0, 0, 0, 0.4), 0 14px 30px -12px rgba(0, 0, 0, 0.75);
  --shadow-float: 0 1px 1px rgba(0, 0, 0, 0.4), 0 16px 34px -14px rgba(0, 0, 0, 0.8);
  --highlight: rgba(222, 178, 94, 0.22);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--ink-hair); text-underline-offset: 2px; }
a:hover { text-decoration-style: solid; text-decoration-color: var(--rust); }
button { font: inherit; color: inherit; }
kbd { font: 500 11px/1 var(--mono); padding: 2px 5px; border: 1px solid var(--ink-hair); border-bottom-width: 2px; border-radius: 3px; background: var(--paper-card); color: var(--ink-faded); }
:focus-visible { outline: 2px solid var(--rust); outline-offset: 2px; }
.muted { color: var(--ink-faded); }
[hidden] { display: none !important; }
.ic { display: inline-flex; flex: none; line-height: 0; }

#board { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#board.dragging { cursor: grabbing; }
#board:focus-visible { outline: 3px solid var(--rust); outline-offset: -5px; }

/* ---------- top bar: a ledger header ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 8px max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left));
  background: linear-gradient(var(--paper), var(--paper-glass));
  border-bottom: 1.5px solid var(--ink);
  box-shadow: 0 3px 0 -2px var(--paper), 0 4px 0 -2px var(--ink-hair);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: none; }
.brand-mark { width: 40px; height: 40px; color: var(--ink); flex: none; }
.brand-text h1 { margin: 0; font: 400 26px/1 var(--display); letter-spacing: 0.02em; white-space: nowrap; }
.brand-text .amp { font-family: var(--display-text); font-style: italic; font-size: 0.72em; color: var(--ink-faded); text-transform: none; letter-spacing: 0; padding: 0 0.1em; }
.brand-sub { margin: 3px 0 0; font: italic 13px/1 var(--display-text); color: var(--ink-faded); white-space: nowrap; }

.tracks { flex: 1 1 auto; display: flex; gap: 8px; min-width: 0; overflow-x: auto; scrollbar-width: none; justify-content: safe center; }
.tracks::-webkit-scrollbar { display: none; }
.track {
  flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 3px 10px 3px 9px; border-left: 1px solid var(--ink-hair);
}
.track:first-child { border-left: 0; }
.track-label { font: 500 10.5px/1.1 var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faded); white-space: nowrap; }
.track-value { font: 500 15px/1.1 var(--mono); white-space: nowrap; }

.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.panel-buttons { display: flex; gap: 2px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
  color: var(--ink); font: 500 14px/1 var(--body);
}
.tool-btn:hover { border-color: var(--ink-hair); background: var(--highlight); }
.tool-btn[aria-pressed="true"], .tool-btn.active { border-color: var(--ink); background: var(--paper-card); box-shadow: inset 0 -2px 0 var(--ochre); }
.fantasy-btn[aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--sky); color: var(--ink); }

/* search */
.search { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 9px; color: var(--ink-faded); pointer-events: none; }
#search-input {
  width: 230px; height: 36px; padding: 0 30px 0 32px;
  font: 15px var(--body); color: var(--ink);
  background: var(--paper-card); border: 1px solid var(--ink-hair); border-radius: var(--radius);
  box-shadow: inset 0 1px 2px rgba(60, 40, 10, 0.08);
}
#search-input::placeholder { color: var(--ink-faded); font-style: italic; }
#search-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--highlight); }
#search-input::-webkit-search-cancel-button { display: none; }
.search-kbd { position: absolute; right: 8px; pointer-events: none; }
#search-input:focus ~ .search-kbd { display: none; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; display: none;
  background: var(--paper-card); border: 1px solid var(--ink); box-shadow: var(--shadow-float); padding: 4px; max-height: 60vh; overflow: auto;
}
.search.has-results .search-results { display: block; }
.search-item { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; width: 100%; padding: 7px 9px; border: 0; background: transparent; text-align: left; cursor: pointer; border-radius: 2px; }
.search-item.active, .search-item:hover { background: var(--highlight); }
.search-label { font: 15px var(--body); }
.search-sub { font: italic 12.5px var(--display-text); color: var(--ink-faded); white-space: nowrap; }
.search-empty { padding: 8px 10px; font: italic 14px var(--display-text); color: var(--ink-faded); }

/* ---------- lens index card ---------- */
.lensbox {
  position: fixed; z-index: 15;
  top: calc(var(--topbar-h) + 22px); left: max(var(--gutter), env(safe-area-inset-left));
  width: var(--lensbox-w); max-height: calc(100vh - var(--topbar-h) - 74px);
  /* the lens list scrolls; the legend for the active lens stays pinned below it, always on screen */
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--paper-card);
  border: 1px solid var(--ink-hair);
  box-shadow: var(--shadow-card);
  padding: 14px 14px 12px;
  transform: rotate(-0.5deg);
}
.lensbox::before { /* tape */
  content: ""; position: absolute; top: -11px; left: 50%; width: 92px; height: 24px; margin-left: -46px;
  background: var(--tape); transform: rotate(2.5deg);
  clip-path: polygon(0 8%, 4% 0, 9% 10%, 14% 0, 20% 6%, 100% 0, 97% 50%, 100% 100%, 92% 92%, 85% 100%, 0 100%, 3% 50%);
  border: 0; box-shadow: 0 0 0 1px var(--tape-edge);
}
.lensbox-head { flex: none; display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--ink); padding-bottom: 6px; margin-bottom: 6px; box-shadow: 0 2px 0 -1px var(--paper-card), 0 3px 0 -1px var(--ink-hair); }
.lensbox-title { margin: 0; font: 400 21px/1 var(--display); letter-spacing: 0.03em; }
.lensbox-hint { margin-left: auto; font: italic 12px var(--display-text); color: var(--ink-faded); }
.lensbox-hint kbd { font-style: normal; }
.lensbox-toggle { display: none; }
.lens-list { flex: 1 1 auto; min-height: 150px; overflow-y: auto; scrollbar-width: thin; margin-right: -8px; padding-right: 8px; }
.lens-group { padding: 4px 0 2px; }
.lens-group + .lens-group { border-top: 1px dashed var(--ink-faint); margin-top: 4px; }
.lens-group-name { font: 500 10.5px/1 var(--body); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faded); padding: 6px 4px 4px; }
.lens-btn {
  position: relative; display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 6px 8px; margin: 1px 0; border: 0; background: transparent; text-align: left; cursor: pointer; border-radius: 2px; isolation: isolate;
}
.lens-btn .ic { color: var(--ink-faded); }
.lens-btn:hover::before, .lens-btn.active::before {
  content: ""; position: absolute; inset: 1px -2px; z-index: -1;
  background: var(--highlight); border-radius: 46% 10% 38% 12% / 30% 60% 20% 50%;
}
.lens-btn.active::before { background: color-mix(in srgb, var(--ochre) 34%, transparent); }
.lens-btn.active .ic { color: var(--ink); }
.lens-btn.active .lens-name { font-weight: 700; }
.lens-names { display: flex; flex-direction: column; min-width: 0; }
.lens-name { font: 500 15px/1.15 var(--body); }
.lens-game { font: italic 12.5px/1.15 var(--display-text); color: var(--ink-faded); }

.legend { flex: 0 1 auto; max-height: 46%; min-height: 110px; overflow-y: auto; scrollbar-width: thin; border-top: 1px solid var(--ink-hair); margin-top: 8px; padding-top: 9px; }
.legend:empty { display: none; }
.legend-head { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.legend-title { font: 400 16px/1.1 var(--display); }
.legend-game { font: italic 13px var(--display-text); color: var(--ink-faded); }
.legend-note { margin: 8px 0 0; font-size: 12.5px; line-height: 1.38; color: var(--ink-faded); }
.legend-flag { margin: 6px 0 0; font: italic 12.5px/1.3 var(--display-text); color: var(--rust); }
.legend-swatches { display: flex; flex-direction: column; gap: 4px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.swatch { width: 22px; height: 13px; flex: none; border-radius: 40% 55% 45% 60% / 60% 40% 55% 45%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); opacity: 0.85; }
.swatch.nodata { background: repeating-linear-gradient(135deg, transparent 0 3px, var(--ink-hair) 3px 4px), var(--paper-deep); }
.legend-ramp .ramp-bar { height: 12px; border-radius: 6px 3px 7px 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); opacity: 0.88; }
.legend-ramp .ramp-labels { display: flex; justify-content: space-between; font: 11.5px var(--mono); color: var(--ink-faded); margin-top: 3px; }

/* ---------- zoom controls ---------- */
.zoom-controls { position: fixed; z-index: 14; right: max(var(--gutter), env(safe-area-inset-right)); bottom: 96px; display: flex; flex-direction: column; border: 1px solid var(--ink-hair); background: var(--paper-card); box-shadow: var(--shadow-card); transition: right 0.28s ease; }
.zoom-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; color: var(--ink); }
.zoom-btn + .zoom-btn { border-top: 1px solid var(--ink-faint); }
.zoom-btn:hover { background: var(--highlight); }
body.drawer-open .zoom-controls { right: calc(var(--drawer-w) + var(--gutter)); }

/* ---------- card drawer ---------- */
.drawer {
  position: fixed; z-index: 25; top: calc(var(--topbar-h) + 4px); right: 0; bottom: 30px;
  width: var(--drawer-w); max-width: 100vw;
  display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform 0.32s cubic-bezier(0.2, 0.7, 0.2, 1);
  pointer-events: none;
}
.drawer.open { transform: none; pointer-events: auto; }
.drawer-bar { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 18px; background: var(--paper-glass); border-bottom: 1px solid var(--ink-faint); backdrop-filter: blur(2px); }
.drawer-crumbs { flex: 1; min-width: 0; font: italic 13px var(--display-text); color: var(--ink-faded); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-btn { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px; background: var(--paper-card); border: 1px solid var(--ink-hair); border-radius: var(--radius); cursor: pointer; font: 500 13.5px var(--body); box-shadow: var(--shadow-card); }
.drawer-btn:hover { border-color: var(--ink); }
.drawer-btn.icon-only { width: 30px; padding: 0; justify-content: center; margin-left: auto; }
.drawer-stack { position: relative; flex: 1; min-height: 0; }
.drawer-page {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin;
  padding: 10px 14px 30px 18px;
  transform: translate(calc(var(--depth, 0) * -14px), calc(var(--depth, 0) * 10px)) rotate(calc(var(--depth, 0) * -1.6deg));
  transition: transform 0.3s ease, opacity 0.3s ease, filter 0.3s;
  overscroll-behavior: contain;
}
.drawer-page:not(.top) { opacity: 0.9; filter: saturate(0.6) brightness(0.97); pointer-events: none; overflow: hidden; }
.drawer-page.top { animation: card-in 0.36s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes card-in { from { transform: translate(30px, 14px) rotate(3deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- panel sheet (left) ---------- */
.sheet {
  position: fixed; z-index: 24; top: calc(var(--topbar-h) + 12px); left: max(var(--gutter), env(safe-area-inset-left)); bottom: 42px;
  width: min(400px, calc(100vw - 2 * var(--gutter)));
  background: var(--paper-card); border: 1px solid var(--ink-hair); box-shadow: var(--shadow-float);
  display: flex; flex-direction: column;
  transform: translateX(calc(-100% - 40px)); transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.sheet.open { transform: none; }
.sheet-bar { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px 18px; border-bottom: 1.5px solid var(--ink); }
.sheet-title { margin: 0; font: 400 22px/1 var(--display); }
.sheet-body { flex: 1; overflow: auto; padding: 14px 18px 20px; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 22; pointer-events: none; /* below the card drawer (25) */
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 10px 7px; max-width: 260px;
  background: var(--paper-card); border: 1px solid var(--ink); box-shadow: var(--shadow-card);
  font-size: 13.5px; line-height: 1.25;
}
.tooltip strong { font: 400 15px var(--display); letter-spacing: 0.02em; }
.tt-coord { font: 11.5px var(--mono); color: var(--ink-faded); }
.tt-val { font-style: italic; color: var(--ink); }

/* ---------- footer ---------- */
.foot {
  position: fixed; z-index: 16; bottom: 0; left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 4px 14px calc(5px + env(safe-area-inset-bottom));
  font-size: 12.5px; color: var(--ink-faded); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--paper-glass); border: 1px solid var(--ink-faint); border-bottom: 0;
}
.foot strong { color: var(--ink); font-weight: 500; }
.foot-sep { padding: 0 4px; opacity: 0.6; }

/* ---------- boot ---------- */
.boot { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--paper); transition: opacity 0.6s ease; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-card { display: flex; align-items: center; gap: 12px; font: italic 18px var(--display-text); color: var(--ink-faded); }
.boot.failed .boot-card { color: var(--rust); }
.quill { width: 36px; height: 2px; background: var(--ink); border-radius: 2px; transform-origin: left; animation: quill 1.1s ease-in-out infinite alternate; }
@keyframes quill { from { transform: scaleX(0.15); } to { transform: scaleX(1); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 60; left: 50%; bottom: 46px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 8px 14px; background: var(--paper-card); border: 1px solid var(--ink); box-shadow: var(--shadow-float); font-size: 14px; transition: opacity 0.4s, transform 0.4s; }
.toast.warn { border-left: 4px solid var(--rust); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* =====================================================================================
   Specimen card — app.ui.card({...})
   ===================================================================================== */
.card {
  --accent: var(--moss);
  position: relative;
  margin: 18px 6px 22px;
  padding: 10px 0 14px;
  background:
    radial-gradient(120% 70% at 20% 0%, rgba(255, 255, 255, 0.22), transparent 60%),
    var(--paper-card);
  border: 1px solid var(--ink-hair);
  box-shadow: var(--shadow-card);
  transform: rotate(var(--tilt, 0deg));
  color: var(--ink);
}
:root[data-theme="dark"] .card { background: radial-gradient(120% 70% at 20% 0%, rgba(255, 230, 180, 0.05), transparent 60%), var(--paper-card); }
.card::after { /* inner hairline frame, like a printed specimen label */
  content: ""; position: absolute; inset: 5px; border: 0.5px solid var(--ink-faint); pointer-events: none;
}
.card .tape {
  position: absolute; z-index: 3; top: -12px; left: -14px; width: 92px; height: 26px;
  background: var(--tape); transform: rotate(-32deg);
  clip-path: polygon(0 10%, 5% 0, 10% 12%, 16% 2%, 100% 0, 96% 50%, 100% 100%, 90% 88%, 84% 100%, 0 100%, 4% 52%);
  box-shadow: 0 0 0 1px var(--tape-edge);
}
.card-art {
  position: relative; height: 128px; margin: 0 10px; overflow: hidden;
  border: 1px solid var(--ink-hair); background: var(--paper);
}
.card-art canvas, .card-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-art img { filter: sepia(0.18) saturate(0.92) contrast(0.98); }
:root[data-theme="dark"] .card-art img { filter: sepia(0.1) saturate(0.9) brightness(0.92); }
.card-art::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 24px rgba(80, 55, 20, 0.22); pointer-events: none; }
.art-credit { position: absolute; z-index: 1; right: 0; bottom: 0; max-width: 90%; padding: 1px 6px; font-size: 10.5px; background: var(--paper-glass); color: var(--ink-faded); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 18px 6px; border-bottom: 1px solid var(--ink); margin: 0 10px; padding-left: 8px; padding-right: 8px; }
.card-titles { flex: 1; min-width: 0; }
.card-title { margin: 0; font: 400 27px/1.05 var(--display); letter-spacing: 0.01em; text-wrap: balance; outline: none; }
.card-type { margin-top: 4px; font: italic 14px/1.2 var(--display-text); color: var(--ink-faded); }
.rarity { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; padding-top: 2px; min-width: 52px; }
.rarity-mark { font-size: 20px; line-height: 1; color: var(--accent); }
.rarity-label { font: 500 10px/1 var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faded); }
.rarity-common .rarity-mark { color: var(--ink-faded); }
.rarity-uncommon .rarity-mark { color: var(--moss); }
.rarity-rare .rarity-mark { color: var(--rust); }
.rarity-legendary .rarity-mark, .rarity-legendary .card-title {
  background: linear-gradient(100deg, var(--gold) 0%, var(--gold-hi) 18%, var(--gold) 36%, #8a6a24 52%, var(--gold) 70%, var(--gold-hi) 86%, var(--gold) 100%);
  background-size: 260% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: gold-leaf 5.5s linear infinite;
}
.rarity-legendary { border-color: color-mix(in srgb, var(--gold) 70%, transparent); box-shadow: var(--shadow-card), 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent); }
.rarity-legendary .card-head { border-bottom-color: var(--gold); }
@keyframes gold-leaf { from { background-position: 0% 0; } to { background-position: 260% 0; } }

.card-stats { padding: 8px 18px 4px; display: flex; flex-direction: column; }
.stat-row { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; column-gap: 6px; padding: 3px 0; }
.stat-label { font: 500 14px/1.25 var(--body); font-variant: small-caps; letter-spacing: 0.04em; color: var(--ink-faded); text-transform: lowercase; }
.stat-game { display: inline-block; margin-right: 6px; font: italic 13px var(--display-text); text-transform: none; font-variant: normal; color: var(--ink); letter-spacing: 0; }
.stat-game::after { content: " ·"; color: var(--ink-faded); }
.stat-leader { border-bottom: 1.5px dotted var(--ink-hair); transform: translateY(-4px); min-width: 12px; }
.stat-value { font: 500 14.5px/1.25 var(--mono); text-align: right; white-space: nowrap; }
.stat-value .unit { margin-left: 3px; font-size: 12px; color: var(--ink-faded); }
.stat-value .approx { margin-right: 2px; color: var(--rust); }
.stat-value.missing { font: italic 13.5px var(--display-text); color: var(--ink-faded); }
.stat-note { grid-column: 1 / -1; font-size: 12px; color: var(--ink-faded); margin-top: -1px; }
.card-body { padding: 6px 18px; }
.card-body h3 { margin: 12px 0 6px; font: 400 16px/1.1 var(--display); letter-spacing: 0.03em; border-bottom: 1px dashed var(--ink-hair); padding-bottom: 3px; }
.flavour { position: relative; margin: 10px 18px 6px; padding: 8px 4px 2px 22px; border-top: 1px solid var(--ink-faint); }
.flavour::before { content: "❧"; position: absolute; left: 0; top: 7px; font-size: 16px; color: var(--accent); }
.flavour p { margin: 0; font: italic 15.5px/1.42 var(--display-text); color: var(--ink); }
.flavour cite { display: block; margin-top: 4px; font: normal 12px var(--body); color: var(--ink-faded); text-align: right; }
.credits { margin: 8px 18px 0; padding-top: 6px; border-top: 1px dotted var(--ink-hair); font-size: 11.5px; line-height: 1.4; color: var(--ink-faded); }
.credits-label { font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 10px; margin-right: 6px; }
.stamp {
  position: absolute; z-index: 2; right: 18px; top: 92px; transform: rotate(-13deg);
  width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center;
  border: 2.5px solid var(--rust); box-shadow: inset 0 0 0 3px var(--paper-card), inset 0 0 0 4px var(--rust);
  color: var(--rust); opacity: 0.78; mix-blend-mode: multiply; pointer-events: none;
}
:root[data-theme="dark"] .stamp { mix-blend-mode: screen; }
.stamp span { font: 400 15px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; }
.card.sober { transform: none; border-left: 4px solid var(--rust); }
.card.sober .card-title { font-family: var(--body); font-weight: 700; font-size: 22px; }
.card.loading { min-height: 220px; display: grid; place-items: center; }
.card-loading { display: flex; align-items: center; gap: 10px; font: italic 16px var(--display-text); color: var(--ink-faded); }

/* sparkline + pips */
.sparkline { display: block; max-width: 100%; height: auto; overflow: visible; }
.sparkline text { font: 9.5px var(--mono); fill: var(--ink-faded); }
.sparkline .spark-val { fill: var(--ink); }
.sparkline .spark-empty { font: italic 12px var(--display-text); }
.pips { display: inline-flex; align-items: center; gap: 3px; }
.pips i { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--ink); }
.pips i.on { background: var(--ink); }
.pips-label { margin-left: 6px; font-size: 12.5px; color: var(--ink-faded); }
.pips-none { font: italic 12.5px var(--display-text); color: var(--ink-faded); }

/* ---------- responsive: phone ---------- */
/* seven panel buttons + the theme toggle: below ~1680px their labels would squeeze the national tracks out,
   so show icons only (each button keeps its title tooltip and aria name) */
@media (max-width: 1680px) {
  .tool-label { display: none; }
  .tool-btn { padding: 0 8px; }
}
@media (max-width: 1100px) {
  .brand-sub { display: none; }
  #search-input { width: 180px; }
}
@media (max-width: 760px) {
  :root { --topbar-h: 52px; --gutter: 12px; }
  .topbar { flex-wrap: wrap; gap: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
  /* two rows: brand + national tracks, then the tool buttons */
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-bottom: 3px; }
  .brand { gap: 6px; order: 0; }
  .brand-mark { width: 26px; height: 26px; }
  .brand-text h1 { font-size: 17px; }
  .tool-btn { padding: 0 6px; height: 34px; }
  .topbar:has(.search:focus-within) .brand { display: none; }
  .top-actions { gap: 2px; order: 2; flex-basis: 100%; justify-content: space-between; margin-left: 0; }
  .search:focus-within { flex: 1; }
  .top-actions:has(.search:focus-within) { flex: 1; }
  .top-actions:has(.search:focus-within) > :not(.search) { display: none; }
  #search-input { width: 38px; padding: 0 0 0 30px; cursor: pointer; }
  #search-input:focus { width: 100%; padding-right: 8px; cursor: text; }
  #search-input::placeholder { color: transparent; }
  #search-input:focus::placeholder { color: var(--ink-faded); }
  .search-icon { left: 11px; }
  .search-kbd { display: none; }
  .search-results { position: fixed; left: var(--gutter); right: var(--gutter); top: 54px; }
  .tracks { order: 1; flex: 1 1 0; justify-content: flex-start; gap: 0; padding-top: 0;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); padding-right: 24px; }
  .track { flex-direction: column; align-items: flex-start; gap: 0; padding: 0 8px; }
  .track-label { font-size: 9px; letter-spacing: 0.08em; }
  .track-value { font-size: 12.5px; }

  .lensbox {
    top: auto; bottom: 30px; left: 0; right: 0; width: auto; transform: none; max-height: 46vh;
    padding: 6px var(--gutter) 6px; border-left: 0; border-right: 0; border-bottom: 0;
    background: var(--paper-glass); backdrop-filter: blur(3px);
  }
  .lensbox::before { display: none; }
  .lensbox-head { border: 0; box-shadow: none; margin: 0; padding: 0 0 4px; }
  .lensbox-title { font-size: 16px; }
  .lensbox-hint { display: none; }
  .lensbox-toggle { display: inline-block; margin-left: auto; height: 32px; min-width: 52px; padding: 0 12px; border: 1px solid var(--ink-hair); background: var(--paper-card); border-radius: var(--radius); font: 500 13px var(--body); cursor: pointer; }
  .lensbox-head { align-items: center; }
  .lens-list { flex: none; min-height: 0; margin-right: 0; padding-right: 0; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding-bottom: 2px; scroll-padding-inline: 40px;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 22px), transparent); }
  .lens-list::-webkit-scrollbar { display: none; }
  .lens-group { display: contents; }
  .lens-group-name { display: none; }
  .lens-btn { flex: none; width: auto; padding: 6px 10px; border: 1px solid var(--ink-hair); background: var(--paper-card); }
  .lens-btn.active { border-color: var(--ink); }
  .lens-btn:hover::before, .lens-btn.active::before { inset: 2px; }
  .lens-game { display: none; }
  /* compact one-line key for the active lens, always visible; "Key" expands the full legend */
  .legend { max-height: none; min-height: 0; margin-top: 4px; padding-top: 4px; }
  .lensbox:not(.expanded) .legend { display: flex; align-items: center; gap: 8px; overflow: hidden; }
  .lensbox:not(.expanded) .legend-head { flex: none; margin: 0; max-width: 34%; }
  .lensbox:not(.expanded) .legend-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .lensbox:not(.expanded) .legend-game, .lensbox:not(.expanded) .legend-note, .lensbox:not(.expanded) .legend-flag, .lensbox:not(.expanded) .legend-sub { display: none; }
  .lensbox:not(.expanded) .legend > :not(.legend-head) { flex: 1; min-width: 0; max-height: 34px; overflow: hidden; }
  .lensbox:not(.expanded) .legend-swatches { flex-direction: row; flex-wrap: nowrap; gap: 10px; overflow-x: auto; scrollbar-width: none; }
  .lensbox:not(.expanded) .legend-item { flex: none; font-size: 12px; white-space: nowrap; }
  .lensbox:not(.expanded) .legend-ramp + .legend-ramp, .lensbox:not(.expanded) .legend-swatches ~ .legend-swatches { display: none; }
  .lensbox.expanded .legend { display: block; max-height: 30vh; overflow-y: auto; }
  .zoom-controls { display: none; }

  .drawer { top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 74vh; transform: translateY(105%); background: linear-gradient(transparent, var(--paper) 46px); z-index: 26; }
  .drawer-bar { padding: 8px var(--gutter) 0; }
  .drawer-page { padding: 4px 10px 40px; }
  .card { margin: 14px 4px 18px; }
  .card-title { font-size: 24px; }
  .sheet { top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 78vh; transform: translateY(105%); }
  .sheet.open { transform: none; }
  .foot { font-size: 11px; padding: 3px 10px calc(4px + env(safe-area-inset-bottom)); }
  .foot .foot-rest { display: none; }
}

/* touch: comfortable tap targets */
@media (pointer: coarse) {
  .lens-btn { min-height: 44px; }
  .lensbox-toggle { min-height: 44px; min-width: 52px; }
  .drawer-btn { height: 40px; min-width: 40px; }
  .drawer-btn.icon-only { width: 40px; }
  .zoom-btn { width: 40px; height: 40px; }
  .foot a { display: inline-block; padding: 10px 2px; margin: -10px 0; }
  .alm-btn { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
