:root {
  --paper: #f6f2e9;
  --ink: #1d1d1f;
  --muted: #7a776f;
  --gold: #b8975a;
  --red: #e5484d;
  --green: #2fa36b;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--sans); }
body { overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; cursor: pointer; }

/* HUD */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.back {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; color: var(--muted); text-decoration: none; white-space: nowrap;
  background: rgba(246,242,233,.8); padding: 6px 10px; border-radius: 999px; border: 1px solid #e4dccb;
}
.back:hover { color: var(--ink); border-color: #cfc7b6; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid #d8d2c4; background: rgba(255,255,255,.7);
  font-family: var(--mono); font-size: 12px; display: grid; place-items: center; padding: 0;
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn[hidden] { display: none; }

.score {
  position: fixed; left: 50%; top: max(52px, calc(env(safe-area-inset-top) + 40px)); transform: translateX(-50%); z-index: 9;
  font-family: var(--serif); font-weight: 500; font-size: 72px; line-height: 1; color: var(--ink);
  font-variant-numeric: lining-nums tabular-nums; pointer-events: none;
  text-shadow: 0 0 12px var(--paper), 0 0 2px var(--paper), 0 2px 0 rgba(246,242,233,.9);
  transition: opacity .2s;
}
.score.hide { opacity: 0; }
.score.bump { animation: bump .28s ease-out; }
@keyframes bump { 35% { transform: translateX(-50%) scale(1.14); color: var(--green); } }

/* overlays */
.overlay {
  position: fixed; inset: 0; z-index: 30; display: none; place-items: center; padding: 16px;
  background: rgba(246,242,233,.66); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.overlay.open { display: grid; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; } }
.overlay .card {
  width: min(500px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: #fffdf8; border: 1px solid #e4dccb; border-radius: 14px; padding: 30px 30px 26px;
  box-shadow: 0 30px 80px rgba(60,50,30,.18);
  animation: rise .3s ease-out;
}
.overlay .card.small { width: min(420px, 100%); }
@keyframes rise { from { transform: translateY(10px); } }
.eyebrow { font-size: 11.5px; font-weight: 500; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); margin: 0 0 10px; }
.eyebrow.alert { color: var(--red); }
h1, h2 { font-family: var(--serif); font-weight: 500; line-height: 1.05; margin: 0; }
h1 { font-size: clamp(38px, 9vw, 50px); }
h2 { font-size: clamp(30px, 7vw, 40px); }
.lede { color: #55524b; font-size: 15.5px; line-height: 1.55; margin: 12px 0 0; }
.howto { margin: 16px 0 0; padding: 0 0 0 18px; color: #55524b; font-size: 14.5px; line-height: 1.65; }
.howto b { color: var(--ink); font-weight: 600; }
.actions { display: flex; align-items: center; gap: 12px 14px; margin-top: 24px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--ink); background: var(--ink); color: #fff; padding: 11px 22px; border-radius: 999px;
  font-size: 13px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; text-decoration: none;
  transition: transform .08s, opacity .15s;
}
.btn:hover { opacity: .88; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: #cfc7b6; }
.best { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.fine { font-size: 13px; color: var(--muted); margin: 16px 0 0; }

.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }
.results div { background: var(--paper); border-radius: 10px; padding: 12px 8px; text-align: center; }
.results div.andi { background: #f3ecdc; }
.results div.andi b { color: var(--gold); }
.results b { display: block; font-family: var(--serif); font-size: 34px; font-weight: 500; line-height: 1.1; font-variant-numeric: lining-nums tabular-nums; }
.results span { font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }

#toasts { position: fixed; left: 50%; bottom: max(84px, calc(env(safe-area-inset-bottom) + 76px)); transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: toast-in .2s ease-out; max-width: calc(100vw - 32px); text-align: center; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 560px) {
  .hud { padding-left: 12px; padding-right: 12px; }
  .score { font-size: 64px; }
  .overlay .card { padding: 24px 20px 20px; }
  .howto { font-size: 14px; }
  .results b { font-size: 30px; }
  .btn { padding: 11px 18px; }
}
