:root {
  --bg-deep: #000000;
  --bg-panel: #0a0a0a;
  --phosphor: #e8a54b;
  --phosphor-dim: #a66f2a;
  --phosphor-glow: rgba(232, 165, 75, 0.45);
  --coffee: #6b3a1f;
  --coffee-foam: #c4a574;
  --cream: #f0d9b5;
  --danger: #d45a3a;
  --ok: #7cb87c;
  --ink: #1a1410;
  --scan: rgba(0, 0, 0, 0.18);
  --font-pixel: "Press Start 2P", monospace;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-deep);
  color: var(--phosphor);
  font-family: var(--font-mono);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  background: #000000;
}

.crt {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  isolation: isolate;
}

.crt__glow {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 40%,
    var(--phosphor-glow) 0%,
    transparent 55%
  );
  opacity: 0.12;
  z-index: 0;
  animation: ambient-pulse 6s ease-in-out infinite;
}

.crt__scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 5;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    var(--scan) 2px,
    var(--scan) 4px
  );
  opacity: 0.35;
  mix-blend-mode: multiply;
}

.crt__vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 6;
  background: radial-gradient(
    ellipse at center,
    transparent 45%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

@keyframes ambient-pulse {
  0%,
  100% {
    opacity: 0.1;
  }
  50% {
    opacity: 0.18;
  }
}

.shell {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: boot-in 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes boot-in {
  from {
    opacity: 0;
    filter: brightness(2) blur(2px);
    transform: scale(1.02);
  }
  to {
    opacity: 1;
    filter: none;
    transform: none;
  }
}

.masthead {
  text-align: center;
  padding: 0.25rem 0.5rem 0;
}

.masthead__prompt {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  color: var(--phosphor-dim);
  letter-spacing: 0.04em;
}

.masthead__prompt::before {
  content: "$ ";
  color: var(--ok);
}

.masthead__brand {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(1.15rem, 4.5vw, 1.65rem);
  line-height: 1.35;
  letter-spacing: 0.06em;
  color: var(--cream);
  text-shadow:
    0 0 12px var(--phosphor-glow),
    0 0 28px rgba(232, 165, 75, 0.25);
  animation: brand-flicker 4.5s steps(2, end) infinite;
}

@keyframes brand-flicker {
  0%,
  96%,
  100% {
    opacity: 1;
  }
  97% {
    opacity: 0.82;
  }
  98% {
    opacity: 1;
  }
  99% {
    opacity: 0.9;
  }
}

.masthead__tag {
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--phosphor-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stage {
  position: relative;
  border: 2px solid var(--phosphor-dim);
  background: var(--ink);
  box-shadow:
    0 0 0 1px rgba(232, 165, 75, 0.15),
    0 0 40px rgba(232, 165, 75, 0.08),
    inset 0 0 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  aspect-ratio: 480 / 720;
  max-height: min(72dvh, 720px);
  user-select: none;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.65rem 0.75rem 0.5rem;
  pointer-events: none;
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  line-height: 1.6;
  color: var(--cream);
  text-shadow: 0 1px 0 #000, 0 0 8px rgba(0, 0, 0, 0.8);
  background: linear-gradient(180deg, rgba(12, 10, 8, 0.75), transparent);
}

.hud__row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.45rem;
}

.hud strong {
  color: var(--phosphor);
  font-weight: 400;
}

.hud__coffee {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: center;
}

.hud__label,
.hud__pct {
  font-size: 0.48rem;
}

.meter {
  height: 8px;
  border: 1px solid var(--phosphor-dim);
  background: #1a120c;
  position: relative;
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--coffee), #a05a2c 55%, var(--coffee-foam));
  transform-origin: left center;
  transition: transform 0.12s linear;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

.meter__fill.is-low {
  background: linear-gradient(90deg, #5a2010, var(--danger));
  animation: low-pulse 0.6s steps(2, end) infinite;
}

@keyframes low-pulse {
  50% {
    filter: brightness(1.25);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 6, 4, 0.78);
  backdrop-filter: blur(1px);
  transition: opacity 0.25s ease;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(100%, 360px);
  text-align: center;
  animation: panel-up 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.panel[hidden] {
  display: none;
}

@keyframes panel-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.panel__boot {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  color: var(--ok);
  letter-spacing: 0.04em;
}

.panel__title {
  margin: 0 0 0.85rem;
  font-family: var(--font-pixel);
  font-size: clamp(0.85rem, 3.5vw, 1.05rem);
  line-height: 1.45;
  color: var(--cream);
  text-shadow: 0 0 16px var(--phosphor-glow);
}

.panel__title--death {
  color: var(--danger);
  text-shadow: 0 0 14px rgba(212, 90, 58, 0.45);
  animation: death-glitch 0.8s steps(2, end) 2;
}

@keyframes death-glitch {
  0%,
  100% {
    transform: none;
  }
  20% {
    transform: translate(-2px, 1px);
  }
  40% {
    transform: translate(2px, -1px);
  }
  60% {
    transform: translate(-1px, 0);
  }
}

.panel__copy {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--phosphor);
  opacity: 0.92;
}

.panel__tips {
  margin: 0 0 1.15rem;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--phosphor-dim);
  line-height: 1.7;
}

.panel__tips li::before {
  content: "> ";
  color: var(--phosphor);
}

.panel__cta {
  margin: 0 0 1.1rem;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--phosphor-dim);
}

.cta {
  display: inline-block;
  margin-left: 0.15rem;
  padding: 0.12rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(232, 165, 75, 0.45);
  box-shadow: 0 0 12px rgba(232, 165, 75, 0.12);
  letter-spacing: 0.02em;
  user-select: all;
}

.panel__hi {
  margin: 1rem 0 0;
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--phosphor-dim);
}

.panel__hi span {
  color: var(--phosphor);
}

.panel__newbest {
  margin: 0 0 0.85rem;
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--ok);
  animation: brand-flicker 1.2s steps(2, end) infinite;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 1rem;
  margin: 0 0 1.1rem;
  text-align: left;
}

.stats dt {
  margin: 0;
  font-size: 0.65rem;
  color: var(--phosphor-dim);
  letter-spacing: 0.06em;
}

.stats dd {
  margin: 0.15rem 0 0;
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: var(--cream);
}

.btn {
  appearance: none;
  border: 2px solid var(--phosphor);
  background: transparent;
  color: var(--cream);
  font-family: var(--font-pixel);
  font-size: 0.62rem;
  line-height: 1.4;
  padding: 0.85rem 1rem;
  width: 100%;
  cursor: pointer;
  text-shadow: 0 0 8px var(--phosphor-glow);
  transition:
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
  box-shadow: 0 0 0 0 transparent;
}

.btn:hover,
.btn:focus-visible {
  background: rgba(232, 165, 75, 0.12);
  box-shadow: 0 0 18px rgba(232, 165, 75, 0.2);
  outline: none;
}

.btn:active {
  background: rgba(232, 165, 75, 0.22);
  transform: translateY(1px);
}

.btn + .btn {
  margin-top: 0.55rem;
}

.btn--ghost {
  border-color: var(--phosphor-dim);
  color: var(--phosphor-dim);
  text-shadow: none;
}

.foot {
  text-align: center;
  font-size: 0.7rem;
  color: var(--phosphor-dim);
}

.foot p {
  margin: 0;
}

.foot kbd {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  border: 1px solid var(--phosphor-dim);
  padding: 0.05rem 0.3rem;
  color: var(--phosphor);
}

.foot .cta {
  margin-left: 0.2rem;
  font-size: 0.72rem;
  padding: 0.05rem 0.35rem;
}

@media (max-width: 420px) {
  .crt {
    padding: 0.65rem;
  }

  .masthead__tag {
    display: none;
  }

  .hud {
    font-size: 0.48rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .crt__glow,
  .masthead__brand,
  .panel,
  .shell,
  .panel__title--death,
  .panel__newbest,
  .meter__fill.is-low {
    animation: none !important;
  }
}
