/* Bricolage Grotesque (SIL Open Font License, see assets/fonts/), variable: wght 200-800, opsz 12-96 */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('assets/fonts/bricolage-grotesque-latin.woff') format('woff');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --ui: #c4f8e6;
  --ui-dim: rgba(196, 248, 230, 0.62);
  --hud: #ffffff;
  --hud-dim: rgba(196, 248, 230, 0.62);
  --panel: rgba(6, 14, 24, 0.62);
  --panel-line: rgba(196, 248, 230, 0.18);
  --accent: #7ff0d0;
  --letterbox: #06101a;
  --s: 1;
  --font: 'Bricolage Grotesque', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--letterbox);
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ui);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: background-color 0.3s;
}

#stage {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
}

#game { display: block; width: 100%; height: 100%; }

/* UI is authored in world units (720 wide, height set by JS) and scaled with the canvas.
 * --safe-top/--safe-bottom convert the phone's safe-area insets into those units. */
#ui {
  position: absolute;
  left: 0; top: 0;
  width: 720px; height: 1280px;
  transform-origin: 0 0;
  transform: scale(var(--s));
  pointer-events: none;
  --safe-top: calc(env(safe-area-inset-top, 0px) / var(--s));
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) / var(--s));
}
#ui button { pointer-events: auto; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; }
.hud-score {
  position: absolute; left: 0; right: 0; top: calc(56px + var(--safe-top)); text-align: center;
  font-weight: 800; font-variation-settings: 'opsz' 96; font-size: 104px; line-height: 1;
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums;
  color: var(--hud); text-shadow: 0 4px 30px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s;
}
.hud-score.pop { transform: scale(1.12); }

.mute {
  position: absolute; right: 28px; top: calc(30px + var(--safe-top)); width: 60px; height: 60px;
  border-radius: 50%; border: 1.5px solid var(--panel-line); background: var(--panel);
  color: var(--ui); font-size: 26px; cursor: pointer;
}
.mute.off { opacity: 0.45; text-decoration: line-through; }
@keyframes pulse { 50% { opacity: 0.45; } }

.banner {
  position: absolute; left: 0; right: 0; top: calc(190px + var(--safe-top)); text-align: center;
  opacity: 0; transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
}
.banner.show { opacity: 1; transform: none; }
.banner-world { display: block; font-size: 17px; letter-spacing: 0.5em; margin-right: -0.5em; color: var(--hud-dim); font-weight: 700; }
.banner-name { display: block; font-size: 48px; font-weight: 700; letter-spacing: -0.01em; color: var(--hud); text-shadow: 0 2px 24px rgba(0,0,0,0.35); margin-top: 6px; }

/* ---------- Start: title only ---------- */
.start {
  position: absolute; left: 0; right: 0; top: 0; height: 52%;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.45s ease, transform 0.6s cubic-bezier(.3,.7,.3,1);
}
.start.gone { opacity: 0; transform: translateY(-60px) scale(0.96); pointer-events: none; }
.title {
  font-weight: 800; font-variation-settings: 'opsz' 96;
  margin: 0; font-size: 142px; line-height: 0.9; letter-spacing: -0.045em; color: #fff; white-space: nowrap;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  animation: title-in 0.9s cubic-bezier(.2,.8,.2,1) both;
}
.title .eyes { display: inline-flex; gap: 0.05em; margin: 0 0.04em; }
/* the two O's are a pair of eyes: white eyeballs whose pupils glance left and right, then blink */
.title .eye {
  position: relative; display: inline-block;
  width: 0.62em; height: 0.72em; border-radius: 50%;
  background: #f5f9ff;
  overflow: hidden;
  transform-origin: 50% 55%;
}
.title .eye b {
  position: absolute; left: 50%; top: 50%;
  width: 0.27em; height: 0.29em; margin: -0.145em 0 0 -0.135em;
  border-radius: 50%; background: #0b1322;
  /* moved by ui.js to random spots (left/right/up/down), gliding or darting */
  transition: transform var(--look-ms, 260ms) cubic-bezier(.3,.7,.3,1);
}
.title .eye b::after { /* a small catch-light so the pupil reads as a glossy eye */
  content: ""; position: absolute; left: 22%; top: 18%;
  width: 28%; height: 28%; border-radius: 50%; background: #f5f9ff;
}
/* one blink: lids snap shut, stay closed a moment, reopen (triggered at random by ui.js) */
@keyframes eye-blink {
  0% { transform: scaleY(1); }
  30%, 55% { transform: scaleY(0.06); }
  100% { transform: scaleY(1); }
}
.title .eye.blink { animation: eye-blink 230ms ease-in-out; }
@media (prefers-reduced-motion: reduce) { .title .eye, .title .eye b { animation: none; } }
@keyframes title-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ---------- Game over ---------- */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.panel {
  pointer-events: auto;
  background: linear-gradient(160deg, rgba(10, 22, 34, 0.8), rgba(4, 10, 18, 0.66));
  border: 1.5px solid var(--panel-line);
  border-radius: 34px;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.panel.over { width: 600px; padding: 54px 48px 44px; animation: panel-in 0.35s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes panel-in { from { opacity: 0; transform: translateY(30px) scale(0.96); } to { opacity: 1; transform: none; } }
.over-title {
  font-weight: 800; font-variation-settings: 'opsz' 96;
  font-size: 118px; line-height: 0.86; letter-spacing: -0.045em; margin: 0; color: #fff;
  text-shadow: 0 0 44px rgba(255, 90, 110, 0.35);
}
.cause { margin-top: 18px; font-size: 24px; font-weight: 400; color: var(--ui-dim); min-height: 28px; }
.scoreboard {
  margin-top: 34px; display: grid; grid-template-columns: 1.4fr 1fr; align-items: stretch;
  border-radius: 24px; overflow: hidden; border: 1.5px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.045);
}
.score-main, .score-best { padding: 22px 14px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-best { border-left: 1.5px solid rgba(255, 255, 255, 0.08); background: rgba(0, 0, 0, 0.12); }
.lbl { font-size: 16px; font-weight: 700; letter-spacing: 0.38em; margin-right: -0.38em; color: var(--ui-dim); }
.val {
  font-weight: 800; font-variation-settings: 'opsz' 96;
  font-size: 128px; line-height: 0.95; letter-spacing: -0.045em; color: #fff; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.val-sm { font-weight: 800; font-size: 60px; line-height: 1; color: var(--ui); margin-top: 10px; font-variant-numeric: tabular-nums; }
.badge {
  margin-top: 14px; font-size: 14px; font-weight: 800; letter-spacing: 0.22em; padding: 7px 12px 6px 15px;
  border-radius: 999px; color: #06121b; background: var(--ui); box-shadow: 0 0 18px var(--accent);
}
.btn {
  margin: 38px auto 0; display: block; width: 100%;
  font-family: var(--font); font-weight: 800;
  font-size: 30px; letter-spacing: 0.3em; padding: 26px 0 26px 0.3em;
  color: #06121b; background: var(--ui); border: none; border-radius: 999px; cursor: pointer;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.06), 0 0 44px rgba(127, 240, 208, 0.38);
  transition: transform 0.12s;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 6px; }

.panel.over:has(.lb:not([hidden])) .over-title { font-size: 92px; }
.panel.over:has(.lb:not([hidden])) .scoreboard { margin-top: 24px; }
.panel.over:has(.lb:not([hidden])) .val { font-size: 104px; }
.panel.over:has(.lb:not([hidden])) .btn { margin-top: 26px; }

/* ---------- Leaderboard ---------- */
.lb { margin-top: 24px; text-align: left; }
.lb-label { display: block; font-size: 22px; font-weight: 600; color: #fff; margin-bottom: 14px; text-align: center; }
.lb-row { display: flex; gap: 12px; }
.lb-row input {
  flex: 1; min-width: 0; font-family: var(--font); font-size: 30px; font-weight: 600; color: #fff;
  background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.18); border-radius: 18px;
  padding: 16px 20px; outline: none; user-select: text; -webkit-user-select: text;
}
.lb-row input::placeholder { color: rgba(255, 255, 255, 0.35); }
.lb-row input:focus { border-color: var(--ui); }
.lb-save {
  font-family: var(--font); font-weight: 800; font-size: 22px; letter-spacing: 0.12em;
  padding: 0 24px; border: none; border-radius: 18px; color: #06121b; background: var(--ui); cursor: pointer;
}
.lb-err { min-height: 26px; margin-top: 8px; font-size: 19px; color: #ff9aa8; text-align: center; }
.lb-rank { display: flex; align-items: baseline; justify-content: center; gap: 14px; flex-wrap: wrap; }
.lb-rank-l { font-size: 16px; font-weight: 700; letter-spacing: 0.32em; color: var(--ui-dim); }
.lb-rank b { font-size: 64px; font-weight: 800; letter-spacing: -0.03em; color: var(--ui); font-variant-numeric: tabular-nums; line-height: 1; }
.lb-rank span:last-child { font-size: 20px; color: var(--ui-dim); }
.lb.busy .lb-rank b { opacity: 0.5; animation: pulse 1.2s infinite; }
.lb-top { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 6px; }
.lb-top li {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 16px; border-radius: 14px; background: rgba(255, 255, 255, 0.04);
  font-size: 24px; color: #fff;
}
.lb-top li.me { background: var(--ui); color: #06121b; }
.lb-top .pos { font-weight: 800; opacity: 0.6; font-variant-numeric: tabular-nums; }
.lb-top .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-top .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-note { min-height: 0; margin-top: 12px; font-size: 18px; line-height: 1.35; color: var(--ui-dim); text-align: center; }
.lb-note:empty { display: none; }
/* while the keyboard is up, keep the panel near the top so the field stays visible */
#overScreen.typing { align-items: flex-start; padding-top: calc(60px + var(--safe-top)); }

.loading { font-size: 22px; letter-spacing: 0.4em; color: var(--ui-dim); animation: pulse 1.4s infinite; }
#loading { background: var(--letterbox); }

/* ---------- Footer credit ---------- */
.credit {
  position: absolute; left: 0; right: 0; bottom: calc(22px + var(--safe-bottom)); text-align: center;
  font-size: 15px; font-weight: 700; letter-spacing: 0.36em; margin-right: -0.36em; color: var(--hud-dim);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

/* ---------- Jumpscare ---------- */
.scare { position: absolute; inset: 0; background: #000; overflow: hidden; z-index: 20; }
.scare video { width: 100%; height: 100%; object-fit: cover; object-position: 50% 32%; display: block; }
.scare.hit video { animation: scare-lunge 0.5s cubic-bezier(.2,1.6,.4,1) both, scare-shake 0.09s linear 0.08s 6; }
.scare.hit::after {
  content: ""; position: absolute; inset: 0; background: #fff; pointer-events: none;
  animation: scare-flash 0.35s ease-out both;
}
@keyframes scare-lunge { from { transform: scale(1.6); } to { transform: scale(1.04); } }
@keyframes scare-shake {
  0% { translate: 0 0; } 25% { translate: -14px 8px; } 50% { translate: 12px -10px; }
  75% { translate: -8px -6px; } 100% { translate: 0 0; }
}
@keyframes scare-flash { 0% { opacity: 0.9; background: #fff; } 40% { opacity: 0.5; background: #8a0010; } 100% { opacity: 0; } }

/* Full leaderboard stays within the safe viewport; only its list scrolls. */
.trophy { left: 28px; right: auto; }
.trophy svg { width: 26px; height: 26px; display: block; margin: auto; pointer-events: none; }
.lb-all { display: block; margin: 18px auto 0; padding: 12px 18px; border: 0; background: transparent; color: var(--ui); font: 700 20px var(--font); letter-spacing: .1em; cursor: pointer; }
[hidden] { display: none !important; }
.lb-sheet { position: absolute; inset: 0; z-index: 30; pointer-events: auto; background: rgba(3, 9, 16, .85); padding: calc(36px + var(--safe-top)) 28px calc(36px + var(--safe-bottom)); display: flex; }
.lb-sheet-panel { display: flex; flex-direction: column; min-height: 0; width: 100%; padding: 28px; border: 2px solid var(--panel-line); border-radius: 30px; background: #091923; }
.lb-sheet h2 { text-align: center; font-size: 40px; margin: 0; }
.lb-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; margin-top: 20px; }
.lb-scroll * { touch-action: pan-y; }
.lb-sheet .lb-top { margin-top: 0; }
.lb-sheet .lb-me { border-top: 2px solid var(--panel-line); padding-top: 18px; margin-top: 18px; }
.lb-sheet .pos { min-width: 0; }
.lb-sheet .lb-top li { grid-template-columns: 64px 1fr auto; }

html:has(.lb-sheet:not([hidden])), body:has(.lb-sheet:not([hidden])), #stage:has(.lb-sheet:not([hidden])) { touch-action: pan-y; }
.lb-sheet-panel > :not(.lb-scroll) { flex-shrink: 0; }
