:root {
  --bg: #07090b;
  --text: #ece6dc;
  --muted: #9aa4aa;
  --accent: #e2bb7c;
  --accent-ink: #1a1208;
  --panel: rgba(11, 15, 18, 0.68);
  --line: rgba(255, 255, 255, 0.1);
  --field: rgba(255, 255, 255, 0.06);
  --good: #9fd6a8;
  --guess: #ff5fa8;
  --hot: #ff7a45; --warm: #f2b25c; --cool: #8fb8ff; --cold: #7d8b96;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
}
body.engraving {
  --bg: #efe6d3;
  --text: #2a1c14;
  --muted: #6e5a48;
  --accent: #a8321f;
  --accent-ink: #fbf6ec;
  --panel: rgba(246, 239, 226, 0.9);
  --line: rgba(42, 28, 20, 0.22);
  --field: rgba(42, 28, 20, 0.05);
  --good: #2f6b3a;
  --guess: #1f57c3;
  --hot: #b3301b; --warm: #a8641c; --cool: #3a5f8f; --cold: #6e5a48;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#view { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; outline: none; }

#grain {
  position: fixed; inset: 0; pointer-events: none; opacity: 0.07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
body.engraving #grain { opacity: 0.16; mix-blend-mode: multiply; }

/* ---------------------------------------------------------------- top bar */
.top {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; padding: max(12px, env(safe-area-inset-top)) 16px 0; pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { font: 600 19px/1 var(--serif); letter-spacing: 0.02em; white-space: nowrap; padding-top: 8px; }
.brand span { font-style: italic; font-weight: 500; color: var(--muted); }
.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 2px; }
.seg button {
  font: 500 12px/1 var(--sans); color: var(--muted); background: none; border: 0; border-radius: 999px;
  padding: 7px 11px; cursor: pointer; min-width: 30px;
}
.seg button[aria-pressed='true'] { background: var(--text); color: var(--bg); }

/* ---------------------------------------------------------------- overlays */
#scale {
  position: fixed; left: 16px; top: calc(max(12px, env(safe-area-inset-top)) + 46px);
  display: flex; flex-direction: column; gap: 5px; opacity: 0; transition: opacity 0.5s; pointer-events: none;
}
#scale.on { opacity: 1; }
#scale .bar { height: 7px; border: 1.5px solid var(--text); border-top: 0; transition: width 0.08s linear; }
#scale span { font: 500 11px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

#pin { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity 0.4s; }
#pin.on { opacity: 1; }
#pin i {
  position: absolute; left: -15px; top: -15px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--accent); box-shadow: 0 0 18px var(--accent); animation: ping 1.6s ease-out infinite;
}
@keyframes ping { 0% { transform: scale(0.5); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }

/* the latest wrong guess: a ring where it is when it's tiny or not drawn, an arrow at the edge
   when it's off screen */
#gpin { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity 0.3s; }
#gpin.on { opacity: 1; }
#gpin i {
  position: absolute; left: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--guess); box-shadow: 0 0 14px var(--guess);
}
#gpin .arrow {
  position: absolute; left: -9px; top: -9px; width: 0; height: 0; display: none;
  border: 9px solid transparent; border-left: 16px solid var(--guess); border-right: 0;
  filter: drop-shadow(0 0 6px var(--guess)); transform-origin: 9px 9px;
}
#gpin.edge i { display: none; }
#gpin.edge .arrow { display: block; }
#gpin span {
  position: absolute; left: 16px; top: -9px; white-space: nowrap; font: 600 11px/1 var(--sans);
  color: var(--guess); letter-spacing: 0.04em; text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg);
}
#gpin.flip span { left: auto; right: 16px; }

/* ---------------------------------------------------------------- dock */
#dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 16px);
  width: min(560px, calc(100vw - 24px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  padding: 14px 16px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
body.engraving #dock { box-shadow: 0 1px 0 rgba(42, 28, 20, 0.08), 0 16px 40px rgba(70, 45, 20, 0.18); }
#dock.shake { animation: shake 0.42s; }
@keyframes shake { 20%, 60% { transform: translateX(calc(-50% - 7px)); } 40%, 80% { transform: translateX(calc(-50% + 7px)); } }

.ladder { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ladder li {
  font: 500 10.5px/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  padding-top: 7px; border-top: 2px solid var(--line); opacity: 0.55; transition: all 0.4s;
}
.ladder li.on { opacity: 1; border-top-color: var(--muted); }
.ladder li.now { color: var(--text); border-top-color: var(--accent); }

#prompt { margin: 0 0 12px; font: 500 23px/1.2 var(--serif); min-height: 1.2em; }

/* Find it: the name to find, a line of guidance, no answer box; the ladder narrows in three steps */
#findHint { display: none; margin: -6px 0 12px; font-size: 13.5px; line-height: 1.35; color: var(--muted); }
body.find #findHint { display: block; }
body.find #prompt::before {
  content: 'Find'; display: block; margin-bottom: 5px; font: 600 10.5px/1 var(--sans); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--accent);
}
body.find #guessForm { display: none; }
body.find .ladder { grid-template-columns: repeat(3, 1fr); }
body.find #view { cursor: crosshair; }

/* In-body Globle: what the latest wrong guess tells you, and the ones before it */
#fb { margin: -4px 0 10px; padding-left: 10px; border-left: 2px solid var(--guess); }
#fb[hidden] { display: none; }
.fbHead { margin: 0 0 2px; display: flex; gap: 8px; align-items: baseline; }
#fbName { font: 600 13px/1.2 var(--sans); color: var(--guess); }
#fbName:empty { display: none; }
#fbHeat { font: 600 10.5px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
#fbHeat[data-band='hot'] { color: var(--hot); }
#fbHeat[data-band='warm'] { color: var(--warm); }
#fbHeat[data-band='cool'] { color: var(--cool); }
#fbHeat[data-band='cold'] { color: var(--cold); }
#fbText { margin: 0; font-size: 14px; line-height: 1.35; }
#trail { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#trail:empty { display: none; }
#trail li {
  font: 500 11.5px/1 var(--sans); color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 9px 5px 7px; display: flex; gap: 6px; align-items: center;
}
#trail li::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--guess); opacity: var(--o, 0.5); }
#guessForm { display: flex; gap: 8px; }
#guess {
  flex: 1; min-width: 0; font: 400 16px/1 var(--sans); color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
#guess:focus { border-color: var(--accent); }
#guess::placeholder { color: var(--muted); }
button { font: 600 14px/1 var(--sans); cursor: pointer; }
#guessForm button, #nextBtn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 0 18px; min-height: 44px;
}
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions button {
  flex: 1; min-height: 40px; border-radius: 12px; background: none; color: var(--text); border: 1px solid var(--line);
}
.actions button.quiet { flex: 0 0 auto; padding: 0 16px; color: var(--muted); }
.actions button:disabled { opacity: 0.4; cursor: default; }

body[data-revealed='1'] .ask { display: none; }
body[data-revealed='1'] .ladder { opacity: 0.6; }
#card { display: none; }
body[data-revealed='1'] #card { display: block; }
#card > * { opacity: 0; transform: translateY(8px); transition: opacity 0.6s, transform 0.6s; }
#card.in > * { opacity: 1; transform: none; }
#card.in > :nth-child(2) { transition-delay: 0.08s; }
#card.in > :nth-child(3) { transition-delay: 0.2s; }
#card.in > :nth-child(4) { transition-delay: 0.32s; }
#card.in > :nth-child(5) { transition-delay: 0.44s; }
.verdict { margin: 0; font: 600 11px/1 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--good); white-space: pre; }
#cardName { margin: 6px 0 0; font: 600 44px/1 var(--serif); letter-spacing: 0.01em; }
.also { margin: 4px 0 0; font: italic 500 18px/1.3 var(--serif); color: var(--muted); }
.fact { margin: 10px 0 14px; color: var(--text); opacity: 0.9; }
.cardActions { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
#cardWiki { color: var(--accent); font-weight: 600; text-decoration: none; border-bottom: 1px solid currentColor; padding-bottom: 1px; }

/* ---------------------------------------------------------------- chrome */
#curtain { position: fixed; inset: 0; background: var(--bg); opacity: 0; pointer-events: none; transition: opacity 0.35s; }
#curtain.on { opacity: 1; }
#loading {
  position: fixed; inset: 0; display: grid; place-content: center; gap: 14px; justify-items: center;
  background: var(--bg); transition: opacity 0.8s; font: italic 500 18px var(--serif); color: var(--muted);
}
#loading.done { opacity: 0; pointer-events: none; }
.lbar { width: 180px; height: 2px; background: var(--line); overflow: hidden; }
.lbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.credit {
  position: fixed; left: 0; right: 0; bottom: max(4px, env(safe-area-inset-bottom)); text-align: center;
  font: 400 9.5px/1.2 var(--sans); color: var(--muted); opacity: 0.6; pointer-events: none; padding: 0 12px;
}
.credit a { color: inherit; pointer-events: auto; padding: 6px 2px; }

#fps { position: fixed; right: 16px; top: calc(max(12px, env(safe-area-inset-top)) + 92px); font: 600 12px/1 var(--sans); color: var(--accent); pointer-events: none; }

@media (max-width: 480px) {
  .brand span { display: none; }
  #prompt { font-size: 21px; }
  #cardName { font-size: 38px; }
  .ladder li { font-size: 9.5px; letter-spacing: 0.03em; }
}
@media (prefers-reduced-motion: reduce) {
  #pin i { animation: none; }
  #dock.shake { animation: none; }
}
