:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07110f;
}

* {
  box-sizing: border-box;
}

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #07110f;
  touch-action: none;
}

#game-shell {
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: min(100%, calc(100vh * 16 / 9));
  max-height: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #07110f;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: pointer;
}

#game-canvas:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: -3px;
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.game-mark {
  position: absolute;
  top: 1.15rem;
  left: 1.3rem;
  margin: 0;
  color: #6ef2b1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.56rem, 1.4vw, 0.8rem);
  font-weight: 850;
}

.metrics {
  position: absolute;
  top: 0.9rem;
  right: 1.3rem;
  display: flex;
  gap: clamp(0.65rem, 2.2vw, 1.45rem);
}

.metrics p {
  display: grid;
  gap: 0.08rem;
  min-width: 3.8rem;
  margin: 0;
  text-align: right;
}

.metrics span {
  color: #8ea49e;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.46rem, 1vw, 0.64rem);
  font-weight: 750;
}

.metrics strong {
  color: #f4fff9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.7rem, 1.7vw, 0.96rem);
}

.progress {
  position: absolute;
  top: 4rem;
  right: 1.3rem;
  left: 1.3rem;
  height: 3px;
  overflow: hidden;
  background: rgba(142, 164, 158, 0.22);
}

#progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: #6ef2b1;
  transform-origin: left;
}

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 5;
  width: min(34rem, calc(100% - 2rem));
  transform: translate(-50%, -50%);
  padding: clamp(1rem, 3vw, 1.65rem);
  border: 1px solid rgba(110, 242, 177, 0.58);
  border-radius: 8px;
  background: rgba(5, 18, 15, 0.96);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.58);
  text-align: center;
}

.panel[hidden],
.crash[hidden] {
  display: none;
}

.panel h1,
.panel h2 {
  margin: 0.35rem 0 0.75rem;
  color: #f4fff9;
  font-size: clamp(1.75rem, 6vw, 3rem);
  letter-spacing: 0;
  line-height: 1;
}

.panel p {
  max-width: 29rem;
  margin: 0.55rem auto;
  color: #c9d8d3;
  font-size: clamp(0.72rem, 2vw, 0.94rem);
  line-height: 1.45;
}

.panel .eyebrow {
  color: #6ef2b1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.54rem, 1.45vw, 0.7rem);
  font-weight: 850;
}

.panel .hint,
.panel .best {
  color: #8ea49e;
  font-size: clamp(0.62rem, 1.65vw, 0.78rem);
}

.mode-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.panel button {
  min-width: 9.5rem;
  min-height: 44px;
  padding: 0.68rem 1.1rem;
  border: 1px solid rgba(110, 242, 177, 0.62);
  border-radius: 6px;
  background: transparent;
  color: #c9d8d3;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.panel button.primary,
.panel button:hover {
  border-color: #6ef2b1;
  background: #6ef2b1;
  color: #06130f;
}

.panel button:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: 3px;
}

.crash {
  position: absolute;
  top: 23%;
  left: 50%;
  z-index: 4;
  display: grid;
  min-width: min(20rem, calc(100% - 2rem));
  transform: translateX(-50%);
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 107, 107, 0.62);
  border-radius: 6px;
  background: rgba(35, 7, 11, 0.94);
  color: #fff4f4;
  text-align: center;
}

.crash strong,
.crash span,
#notice,
#tap-hint {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.crash strong {
  color: #ff8f8f;
  font-size: clamp(0.8rem, 2vw, 1rem);
}

.crash span {
  margin-top: 0.18rem;
  color: #d6c4c4;
  font-size: clamp(0.6rem, 1.5vw, 0.72rem);
}

#notice {
  position: absolute;
  top: 20%;
  left: 50%;
  z-index: 3;
  margin: 0;
  transform: translateX(-50%);
  color: #ffd166;
  font-size: clamp(0.66rem, 1.9vw, 0.92rem);
  font-weight: 900;
  text-align: center;
  opacity: 0;
  transition: opacity 140ms ease;
  pointer-events: none;
}

#notice.visible {
  opacity: 1;
}

#tap-hint {
  position: absolute;
  right: 1.3rem;
  bottom: 1rem;
  z-index: 2;
  margin: 0;
  color: rgba(244, 255, 249, 0.56);
  font-size: clamp(0.54rem, 1.35vw, 0.7rem);
  font-weight: 850;
  pointer-events: none;
}

@media (max-width: 640px), (max-height: 420px) {
  .game-mark {
    top: 0.65rem;
    left: 0.75rem;
  }

  .metrics {
    top: 0.5rem;
    right: 0.75rem;
  }

  .progress {
    top: 2.8rem;
    right: 0.75rem;
    left: 0.75rem;
  }

  #tap-hint {
    right: 0.75rem;
    bottom: 0.6rem;
  }

  .panel {
    width: calc(100% - 1rem);
    padding: 0.5rem 0.7rem;
  }

  .panel h1,
  .panel h2 {
    margin: 0.14rem 0 0.32rem;
    font-size: clamp(1.42rem, 6vw, 2rem);
  }

  .panel p {
    margin: 0.25rem auto;
    line-height: 1.3;
  }

  .mode-actions {
    margin-top: 0.4rem;
  }

  .panel button {
    min-height: 40px;
    padding: 0.45rem 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #notice {
    transition: none;
  }
}
