:root {
  --bg: #050608;
  --ink: #f8fafc;
  --muted: rgba(226, 232, 240, 0.64);
  --glass: rgba(8, 11, 18, 0.34);
  --glass-border: rgba(255, 255, 255, 0.12);
  --warm: #ef9f27;
  --coral: #e24b4a;
  --rose: #d4537e;
  --ice: #85b7eb;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-drag: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 2px solid rgba(133, 183, 235, 0.85);
  outline-offset: 3px;
}

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

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 47%, rgba(133, 183, 235, 0.09), transparent 30%),
    radial-gradient(circle at 50% 58%, rgba(226, 75, 74, 0.08), transparent 33%),
    linear-gradient(180deg, #070910 0%, #040507 100%);
}

#canvas-container,
#canvas-container canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

#canvas-container {
  z-index: 1;
}

.grain,
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grain {
  z-index: 2;
  opacity: 0.13;
  mix-blend-mode: screen;
  background-image:
    linear-gradient(115deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 9px),
    linear-gradient(25deg, rgba(255,255,255,0.06) 0 1px, transparent 1px 11px);
  background-size: 17px 17px, 23px 23px;
  animation: grain-drift 14s steps(8) infinite;
}

.vignette {
  z-index: 3;
  background:
    radial-gradient(circle at 50% 50%, transparent 34%, rgba(5, 6, 8, 0.28) 68%, rgba(3, 4, 6, 0.86) 100%),
    linear-gradient(90deg, rgba(5, 6, 8, 0.42), transparent 22%, transparent 78%, rgba(5, 6, 8, 0.42));
}

.entry-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 50%, rgba(133, 183, 235, 0.08), transparent 32%),
    rgba(5, 6, 8, 0.78);
  backdrop-filter: blur(16px) saturate(115%);
  -webkit-backdrop-filter: blur(16px) saturate(115%);
  opacity: 1;
  visibility: visible;
  transition:
    opacity 780ms ease,
    visibility 780ms ease;
}

.entry-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.entry-inner {
  width: min(92vw, 520px);
  display: grid;
  justify-items: center;
  gap: 24px;
  text-align: center;
}

.entry-title {
  max-width: 18ch;
  color: rgba(248, 250, 252, 0.9);
  font-size: clamp(2rem, 7vw, 4.8rem);
  font-weight: 200;
  line-height: 0.98;
  text-wrap: balance;
}

.entry-touch-note {
  margin-top: -8px;
  color: rgba(186, 213, 238, 0.7);
  font-size: 0.95rem;
  font-weight: 300;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.entry-btn {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  color: rgba(248, 250, 252, 0.76);
  background: rgba(8, 11, 18, 0.38);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition:
    border-color 180ms ease,
    color 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

.entry-btn.primary {
  color: rgba(255, 233, 205, 0.96);
  border-color: rgba(239, 159, 39, 0.34);
  background: rgba(239, 159, 39, 0.12);
}

.entry-btn:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.controls {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.icon-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0) scale(0.96);
}

.icon-btn:focus-visible {
  outline: 2px solid rgba(133, 183, 235, 0.85);
  outline-offset: 3px;
}

.icon-btn.active {
  color: var(--warm);
  background: rgba(239, 159, 39, 0.12);
  box-shadow: 0 0 22px rgba(239, 159, 39, 0.2);
}

.about-panel {
  position: fixed;
  top: calc(max(18px, env(safe-area-inset-top)) + 72px);
  right: max(18px, env(safe-area-inset-right));
  z-index: 6;
  width: min(320px, calc(100vw - 36px));
  padding: 20px 46px 20px 20px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: rgba(248, 250, 252, 0.78);
  background: rgba(8, 11, 18, 0.54);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.about-panel p {
  font-size: 0.9rem;
  font-weight: 300;
  line-height: 1.52;
}

.about-panel p + p {
  margin-top: 10px;
}

.about-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.about-close:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.takeover-cue {
  position: fixed;
  left: 50%;
  bottom: max(40px, env(safe-area-inset-bottom));
  z-index: 6;
  color: rgba(248, 250, 252, 0.74);
  font-size: 1rem;
  font-weight: 300;
  text-shadow: 0 0 18px rgba(133, 183, 235, 0.36);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition:
    opacity 900ms ease,
    transform 900ms ease;
}

.takeover-cue.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.debug-readout {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 6;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(226, 232, 240, 0.7);
  background: rgba(8, 11, 18, 0.42);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.status-readout {
  display: none;
}

.fallback-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 12;
  width: min(520px, calc(100vw - 40px));
  padding: 28px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: rgba(248, 250, 252, 0.84);
  background: rgba(8, 11, 18, 0.72);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  transform: translate(-50%, -50%);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

.fallback-panel p {
  font-size: 0.98rem;
  font-weight: 300;
  line-height: 1.5;
}

.fallback-panel p:first-child {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 400;
}

.fallback-panel p + p {
  margin-top: 10px;
}

body.fallback-active .controls,
body.fallback-active .takeover-cue,
body.fallback-active .debug-readout {
  display: none !important;
}

body.ui-hidden .controls,
body.ui-hidden .about-panel,
body.ui-hidden .takeover-cue,
body.ui-hidden .debug-readout {
  display: none !important;
}

@keyframes grain-drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-23px, 17px, 0); }
}

@media (max-width: 720px) {
  .controls {
    top: auto;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .icon-btn {
    width: 46px;
    height: 46px;
  }

  .entry-inner {
    gap: 20px;
  }

  .entry-title {
    max-width: 14ch;
  }

  .entry-actions {
    width: min(100%, 320px);
    display: grid;
    grid-template-columns: 1fr;
  }

  .entry-btn {
    width: 100%;
  }

  .about-panel {
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 82px);
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100dvh - 122px);
    overflow: auto;
  }

  .takeover-cue {
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 74px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
