:root {
  --bg: #240812;
  --wine: #3a0d20;
  --red: #ff334f;
  --pink: #ff4fa3;
  --soft: #ffb4d2;
  --paper: #f7eaf0;
  --pixel: "Courier New", Courier, ui-monospace, monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--paper);
}

body { min-height: 100%; font-family: var(--sans); }

body.is-playing {
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

body.is-playing .app,
body.is-playing .screen-play {
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
}

button, a { touch-action: manipulation; }

:focus-visible {
  outline: 2px solid var(--soft);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.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;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--bg);
}

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

.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.18) 0 1px,
    transparent 1px 4px
  );
  opacity: 0.35;
}

.noise {
  position: absolute;
  inset: 0;
  opacity: 0.1;
  background-image:
    linear-gradient(90deg, transparent 0 40%, rgba(255, 79, 163, 0.15) 40% 41%, transparent 41%),
    repeating-linear-gradient(0deg, rgba(247, 234, 240, 0.05) 0 2px, transparent 2px 7px);
  animation: grain 7s steps(2, end) infinite;
}

body.is-paused .noise { animation-play-state: paused; }

@keyframes grain {
  0%, 100% { opacity: 0.08; }
  50% { opacity: 0.16; }
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  min-height: 100dvh;
}

body.is-playing .app {
  height: 100%;
  min-height: 0;
}

.screen {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
}

.screen-play {
  width: min(640px, 100%);
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  position: relative;
}

.panel {
  width: min(440px, 100%);
  background: rgba(36, 8, 18, 0.92);
  border: 2px solid rgba(247, 234, 240, 0.45);
  padding: 22px 18px 20px;
}

.panel-results { width: min(520px, 100%); }

.brand {
  margin: 0;
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft);
}

.back {
  margin: 8px 0 0;
}

.back a {
  color: var(--paper);
  font-size: 14px;
}

h1, .banner-title {
  font-family: var(--pixel);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

h1 {
  margin: 14px 0 8px;
  font-size: clamp(28px, 8vw, 42px);
}

.tagline, .intro, .level-name, .control-list, .results-message {
  font-size: 16px;
  line-height: 1.45;
}

.tagline { margin: 0 0 8px; color: var(--soft); }
.intro { margin: 0 0 8px; }
.level-name {
  margin: 0 0 16px;
  font-family: var(--pixel);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-label {
  margin: 18px 0 6px;
  font-family: var(--pixel);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 400;
}

.control-list {
  margin: 0;
  padding-left: 18px;
}

.control-list li + li { margin-top: 6px; }

.meta-row, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}

.best { margin: 0; color: var(--soft); }

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 0;
}

.btn-primary, .btn-ghost {
  min-height: 48px;
  padding: 10px 16px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 2px solid var(--paper);
  background: var(--red);
  color: var(--bg);
  font-family: var(--pixel);
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn-primary:hover { background: var(--pink); }

.btn-ghost {
  border: 2px solid var(--soft);
  background: transparent;
  color: var(--paper);
  font-family: var(--pixel);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas:
    "score lives pause"
    "streak phase round";
  gap: 2px 10px;
  align-items: center;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: rgba(36, 8, 18, 0.94);
  border-bottom: 2px solid rgba(247, 234, 240, 0.28);
  font-size: 14px;
  font-weight: 700;
}

.hud p { margin: 0; }
.hud-score { grid-area: score; }
.hud-lives { grid-area: lives; letter-spacing: 0.12em; }
.hud-pause { grid-area: pause; min-height: 40px; padding: 6px 10px; }
.hud-streak { grid-area: streak; color: var(--soft); font-weight: 600; }
.hud-phase { grid-area: phase; text-align: center; }
.hud-round { grid-area: round; text-align: right; }

.prompt-panel {
  flex: 0 0 auto;
  margin: 8px 10px 0;
  padding: 10px 12px;
  background: var(--wine);
  border: 2px solid var(--paper);
}

.kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft);
}

.prompt {
  margin: 4px 0 0;
  font-size: clamp(18px, 4.8vw, 26px);
  font-weight: 700;
  line-height: 1.25;
}

.status {
  margin: 6px 0 0;
  min-height: 2.6em;
  font-size: 15px;
  line-height: 1.35;
}

.status strong,
.status span { display: block; }
.status.is-ok strong { color: var(--soft); }
.status.is-bad strong { color: var(--paper); }
.status.is-bad::before,
.status.is-miss::before {
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 0.06em;
}
.status.is-bad::before { content: "WRONG  "; }
.status.is-miss::before { content: "MISSED  "; }

.field {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  margin: 8px 10px 12px;
  overflow: hidden;
  background: rgba(36, 8, 18, 0.78);
  border: 2px solid rgba(247, 234, 240, 0.4);
  box-shadow: inset 0 0 0 1px rgba(255, 51, 79, 0.35);
  touch-action: none;
}

.catcher {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 160px;
  height: 44px;
  pointer-events: none;
  border: 2px solid var(--paper);
  background: var(--wine);
  box-shadow: inset 0 0 0 2px var(--red), 0 0 12px rgba(255, 51, 79, 0.4);
}

.pip {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border: 2px solid var(--paper);
  background: transparent;
  vertical-align: -1px;
}

.pip.is-on { background: var(--red); }

.token {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--wine);
  border: 2px solid var(--paper);
  pointer-events: none;
}

.token-text {
  display: block;
  padding: 8px 10px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
  color: var(--paper);
}

.banner {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 4;
  transform: translate(-50%, -50%);
  width: min(280px, 86%);
  padding: 16px 12px;
  text-align: center;
  background: var(--bg);
  border: 2px solid var(--red);
}

.banner-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft);
}

.banner-title {
  margin: 6px 0 0;
  font-size: 28px;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 4, 12, 0.72);
}

.pause-card {
  width: min(320px, 100%);
  padding: 18px 16px;
  background: var(--bg);
  border: 2px solid var(--paper);
  text-align: center;
}

.pause-card h2 {
  margin: 0 0 6px;
  font-family: var(--pixel);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pause-card .btn { width: 100%; margin-top: 8px; }

.results-message { margin: 8px 0 0; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 0;
}

.stats div {
  margin: 0;
  padding: 8px 10px;
  background: var(--wine);
  border: 2px solid rgba(247, 234, 240, 0.35);
}

.stats dt {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--soft);
}

.stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 700;
}

#results-best { margin-top: 12px; }

.review { margin-top: 8px; }

.review h3 {
  margin: 16px 0 6px;
  font-family: var(--pixel);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.review-note {
  margin: 0 0 8px;
  color: var(--soft);
  font-size: 14px;
}

.review-item {
  margin: 0 0 8px;
  padding: 10px 12px;
  background: rgba(58, 13, 32, 0.92);
  border: 2px solid rgba(247, 234, 240, 0.35);
}

.review-expr {
  margin: 0;
  font-weight: 700;
}

.review-item p { margin: 4px 0 0; line-height: 1.4; }

.review-example { color: var(--soft); }

@media (max-width: 380px) {
  .token-text { font-size: 13px; padding: 7px 8px; }
  .prompt { font-size: 18px; }
  .hud { font-size: 13px; }
}

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

@media (min-width: 720px) {
  .screen-play { height: 100dvh; }
}
