:root {
  color-scheme: dark;
  --bg: #07060d;
  --fg: rgba(255, 255, 255, 0.88);
  --dim: rgba(255, 255, 255, 0.46);
  --line: rgba(255, 255, 255, 0.16);
  --hover: rgba(255, 255, 255, 0.07);
  --card: rgba(16, 13, 30, 0.76);
  --brand: linear-gradient(100deg, #ffb87a, #ff66a8 45%, #8f6bff 75%, #52dbff);
  --gutter: 24px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Shown without JS or WebGL. Delayed so it doesn't flash before main.js runs. */
.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 clamp(56px, 16vw, 180px)/1 ui-rounded, system-ui, -apple-system, sans-serif;
  letter-spacing: -0.02em;
  background: var(--brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: fade-in 0.5s 0.6s both;
}
.has-gl .fallback { display: none; }
html:not(.has-gl) .hud,
html:not(.has-gl) .hint { display: none; }

/* ---- top bar ---------------------------------------------------------- */

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  pointer-events: none;
}
.top > * { pointer-events: auto; }

.intro {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
}
.timer {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, transform 0.3s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: rotate(-90deg); }
.icon-btn:focus-visible,
.btn:focus-visible,
.links a:focus-visible { outline: 2px solid #8f6bff; outline-offset: 2px; }

/* ---- bottom bar ------------------------------------------------------- */

.bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  pointer-events: none;
}
.bottom > * { pointer-events: auto; }

.hint {
  margin: 0;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.06em;
  transition: opacity 0.6s;
}
.hint.gone { opacity: 0; }
.hint .touch { display: none; }
@media (pointer: coarse) {
  .hint .mouse { display: none; }
  .hint .touch { display: inline; }
}

.links { display: flex; gap: 18px; }
.links a {
  color: var(--dim);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s;
}
.links a:hover { color: var(--fg); }
.links a[href=""] { display: none; }

/* ---- win card --------------------------------------------------------- */

.win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.win[hidden] { display: none; }

.card {
  pointer-events: auto;
  width: min(340px, 100%);
  padding: 24px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}
.eyebrow {
  margin: 0;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.time {
  margin: 4px 0 2px;
  font-size: 46px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.best {
  min-height: 1.4em;
  margin: 0 0 18px;
  color: var(--dim);
  font-size: 13px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.btn {
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, filter 0.2s;
}
.btn:hover { background: var(--hover); }
.btn.primary {
  border-color: transparent;
  background: var(--brand);
  color: #15101f;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.94); } }

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .bottom {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
  }
}
