/* Build Small Roulette — "dusk on the trail" field-guide theme.
   The embedded Space is the star: chrome stays dark, thin, and disciplined.
   Boldness is spent in one place — the specimen field-tag + dotted trail + compass. */
:root {
  --bark: #20281f;          /* deep forest, near-black — persistent bars */
  --bark-2: #161a14;        /* stage backdrop */
  --parchment: #f3ead6;     /* warm paper — journal panels + text on bark */
  --blaze: #e2602a;         /* trail-blaze orange — Next + active, used sparingly */
  --lichen: #b8c4a9;        /* muted sage — secondary/data text */
  --moss: #3a5a40;          /* forest — track badge */
  --ink: #2a2620;           /* text on parchment */
  --line: rgba(184,196,169,.20);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-mono: "Space Mono", ui-monospace, "SFMono-Regular", monospace;
  --font-body: system-ui, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
/* The HTML `hidden` attribute must win over any class that sets `display`
   (e.g. .overlay/.topbar set display:flex). Without this, hidden overlays
   still paint a full-screen scrim and swallow every click. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 var(--font-body);
  color: var(--ink); background: var(--bark-2);
  display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; overflow: hidden;
}

/* ---- persistent bars ---- */
.topbar, .bottombar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bark); color: var(--parchment); padding: 9px 14px; z-index: 5;
}
.topbar { border-bottom: 2px solid var(--blaze); }           /* the trail blaze */
.bottombar {
  font: 12px/1 var(--font-mono); letter-spacing: .02em;
  border-top: 1.5px dotted rgba(184,196,169,.4);             /* the trail line */
}
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.tb-right { display: flex; align-items: center; gap: 8px; }

.emoji {
  font-size: 18px; line-height: 1; flex: 0 0 auto;
  width: 30px; height: 30px; display: grid; place-items: center;
  background: rgba(243,234,214,.08); border: 1px solid var(--line); border-radius: 9px;
}
.title {
  font: 600 19px/1.1 var(--font-display); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.track-badge {
  font: 700 10px/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 4px; flex: 0 0 auto;
  background: var(--moss); color: #eafdf0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.hf-likes {
  font: 400 12px/1 var(--font-mono); color: var(--lichen);
  text-decoration: none; white-space: nowrap; flex: 0 0 auto;
}
.hf-likes:hover { color: var(--parchment); }

/* ---- buttons ---- */
.btn {
  font: inherit; cursor: pointer; border: 0; border-radius: 9px;
  background: transparent; color: inherit; padding: 8px 10px;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.btn-icon {
  font-size: 17px; line-height: 1; width: 38px; height: 36px;
  background: rgba(243,234,214,.08); border: 1px solid var(--line);
}
.btn-icon:hover { background: rgba(243,234,214,.16); }
.btn-icon.on { background: var(--blaze); border-color: var(--blaze); animation: pop .32s ease; }
.btn-icon:active { transform: scale(.9); }
.btn-next {
  font: 700 14px/1 var(--font-body); letter-spacing: .01em;
  background: var(--blaze); color: #fff; padding: 11px 18px; display: inline-flex; gap: 7px; align-items: center;
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
.btn-next:hover { filter: brightness(1.06); }
.btn-next:active { transform: translateY(1px); }
.btn-next .compass { display: inline-block; font-size: 15px; transition: transform .45s cubic-bezier(.34,1.56,.64,1); }
.btn-next:hover .compass { transform: rotate(72deg); }
.btn-ghost { color: var(--parchment); opacity: .8; }
.btn-ghost:hover { opacity: 1; background: rgba(243,234,214,.08); }

.progress { margin-left: auto; color: var(--lichen); white-space: nowrap; }
.auth { display: flex; align-items: center; gap: 7px; }
.avatar { border-radius: 50%; border: 1px solid var(--line); }

@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.22); } 100% { transform: scale(1); } }

/* ---- stage + iframe ---- */
.stage {
  position: relative; background-color: var(--bark-2); overflow: hidden;
  background-image:
    linear-gradient(rgba(184,196,169,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(184,196,169,.045) 1px, transparent 1px); /* field-notebook grid */
  background-size: 28px 28px;
}
.stage iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
  opacity: 0; transition: opacity .4s ease;
}
.stage iframe.ready { opacity: 1; }

.loader, .fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--parchment);
  text-align: center; padding: 24px;
}
.loader { font: 400 14px/1.4 var(--font-mono); color: var(--lichen); letter-spacing: .04em; }
.loader::after { content: " ·"; animation: blink 1.1s steps(3, end) infinite; }
@keyframes blink { 0% { opacity: .2; } 50% { opacity: 1; } 100% { opacity: .2; } }
.fallback strong { font: 600 22px/1.2 var(--font-display); }
.fallback p { max-width: 32ch; margin: 0; color: var(--lichen); }
.fallback-emoji { font-size: 44px; }
.fallback-actions { display: flex; gap: 10px; }
.fallback .btn { background: var(--blaze); color: #fff; }
.fallback .btn-ghost { background: rgba(243,234,214,.12); color: var(--parchment); }

/* ---- drawer (the field journal) ---- */
.drawer {
  position: fixed; top: 0; right: 0; width: min(380px, 92vw); height: 100%;
  background: var(--parchment); color: var(--ink); z-index: 20; padding: 18px; overflow: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,.35); border-left: 3px solid var(--blaze);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.drawer-head strong { font: 600 19px/1 var(--font-display); }
.drawer-head .btn-ghost { color: var(--ink); }
.drawer-empty { color: rgba(42,38,32,.7); }
.saved-row { display: flex; gap: 11px; align-items: center; padding: 9px; border-radius: 10px; cursor: pointer; }
.saved-row:hover { background: rgba(42,38,32,.07); }
.saved-thumb {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  font-size: 18px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.saved-meta { flex: 1; min-width: 0; }
.saved-title { display: block; font: 600 15px/1.2 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-sub { font: 400 11px/1 var(--font-mono); color: rgba(42,38,32,.6); text-transform: uppercase; letter-spacing: .08em; }
.saved-row .btn-ghost { color: var(--ink); opacity: .55; }
.saved-row .btn-ghost:hover { opacity: 1; background: rgba(42,38,32,.08); }

/* ---- overlay (shortcuts) ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(22,26,20,.9); color: var(--parchment);
  z-index: 30; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.overlay-card {
  max-width: 320px; background: var(--bark); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.overlay-card h3 { font: 600 20px/1 var(--font-display); margin: 0 0 14px; }
.keys { list-style: none; padding: 0; margin: 0 0 18px; font: 13px/1 var(--font-mono); }
.keys li { display: flex; gap: 8px; align-items: center; padding: 6px 0; color: var(--lichen); }
kbd {
  background: rgba(243,234,214,.1); border: 1px solid var(--line); border-radius: 5px;
  padding: 2px 7px; font: 12px/1 var(--font-mono); color: var(--parchment); min-width: 18px; text-align: center;
}

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%);
  background: var(--bark); color: var(--parchment); border: 1px solid var(--line);
  padding: 11px 16px; border-radius: 10px; z-index: 40; max-width: 90vw; text-align: center;
  font: 13px/1.3 var(--font-mono); box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ---- accessibility floor ---- */
.btn:focus-visible, .saved-row:focus-visible, a:focus-visible {
  outline: 2px solid var(--blaze); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
  .stage iframe { opacity: 1; }
}

/* ---- mobile ---- */
@media (max-width: 620px) {
  .title { font-size: 17px; }
  .btn-next { padding: 11px 14px; }
  .bottombar { gap: 8px; flex-wrap: wrap; }
  .hf-likes { display: none; }
  .progress { margin-left: 0; order: 9; flex-basis: 100%; }
}
