@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/PressStart2P-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #02040c;
  --text: #e8e4d8;
  --muted: #a8b0c4;
  --accent: #e8b86d;
  --danger: #d08080;
  --panel: rgba(18, 28, 48, 0.78);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Press Start 2P", monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

body.page {
  overflow: auto;
  touch-action: auto;
  user-select: auto;
  -webkit-user-select: auto;
  height: auto;
  min-height: 100dvh;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  background: var(--bg);
}

.stage {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--bg);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.sine-scroll {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 4.3%;
  top: auto;
  bottom: 1.2%;
  pointer-events: none;
  z-index: 4;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 14px 16px;
  background: rgba(12, 18, 32, 0.55);
  overflow: auto;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(92%, 420px);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 3px solid rgba(232, 228, 216, 0.28);
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.panel h1 {
  margin: 0 0 12px;
  font-size: clamp(12px, 3.6vw, 16px);
  color: var(--accent);
  letter-spacing: 1px;
}

.panel p {
  margin: 0 0 10px;
  font-size: clamp(8px, 2.4vw, 11px);
  line-height: 1.7;
  color: var(--muted);
}

.panel .hint {
  margin-top: 16px;
  font-size: clamp(12px, 3.8vw, 16px);
  color: var(--accent);
  animation: blink 1.4s step-end infinite;
}

.offline-banner {
  margin: 0 0 12px !important;
  color: var(--danger) !important;
}

.scores {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  font-size: clamp(8px, 2.4vw, 11px);
  line-height: 1.85;
}

.scores li {
  display: grid;
  grid-template-columns: 36px 52px 1fr auto;
  gap: 8px;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 6px 0;
}

.scores .rank {
  color: var(--accent);
}

.nick-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  touch-action: auto;
}

.nick-form input {
  font-family: inherit;
  font-size: clamp(16px, 5vw, 20px);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 8px;
  padding: 14px;
  border: 3px solid rgba(232, 228, 216, 0.35);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

.nick-form button {
  font-family: inherit;
  font-size: clamp(12px, 3.4vw, 14px);
  padding: 16px;
  border: 3px solid var(--accent);
  background: rgba(232, 184, 109, 0.25);
  color: var(--text);
  cursor: pointer;
}

.nick-form button:disabled {
  opacity: 0.5;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.12) 2px,
    rgba(0, 0, 0, 0.12) 3px
  );
  z-index: 5;
}

.hiscore-page {
  max-width: 560px;
  margin: 0 auto;
  padding: max(24px, var(--safe-t)) 18px max(40px, var(--safe-b));
  text-align: center;
}

.hiscore-page h1 {
  margin: 12px 0 20px;
  font-size: clamp(18px, 6vw, 28px);
  line-height: 1.45;
  color: var(--accent);
}

.hiscore-page h2 {
  margin: 0 0 24px;
  font-size: clamp(10px, 3vw, 14px);
  color: var(--muted);
  letter-spacing: 2px;
}

.hiscore-list {
  list-style: none;
  margin: 0 0 32px;
  padding: 0;
  text-align: left;
}

.hiscore-list li {
  display: grid;
  grid-template-columns: 48px 72px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid rgba(232, 228, 216, 0.08);
  font-size: clamp(8px, 2.4vw, 12px);
  line-height: 1.6;
}

.hiscore-list .rank {
  color: var(--accent);
}

.hiscore-list .pts {
  text-align: right;
  color: var(--text);
}

.hiscore-list .km {
  color: var(--muted);
  font-size: 0.85em;
}

.hiscore-list .empty {
  display: block;
  text-align: center;
  color: var(--muted);
  grid-template-columns: 1fr;
}

.play-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 16px 36px;
  border: 3px solid var(--accent);
  background: rgba(232, 184, 109, 0.2);
  color: var(--text);
  text-decoration: none;
  font-size: clamp(12px, 3.6vw, 16px);
}

.play-btn:active {
  background: rgba(232, 184, 109, 0.4);
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

@media (display-mode: standalone), (display-mode: fullscreen) {
  #app {
    padding-bottom: max(var(--safe-b), 8px);
  }
}
