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

* {
  box-sizing: border-box;
}

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

body {
  background: #08110f;
  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: #08110f;
}

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

#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: #68f0ae;
  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: #91a8a1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.46rem, 1vw, 0.64rem);
  font-weight: 750;
}

.metrics strong {
  color: #f3fff9;
  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(145, 168, 161, 0.22);
}

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

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

.panel[hidden] {
  display: none;
}

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

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

.panel .eyebrow {
  color: #68f0ae;
  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: #91a8a1;
  font-size: clamp(0.62rem, 1.65vw, 0.78rem);
}

.panel button,
#touch-controls button {
  min-height: 44px;
  border: 1px solid rgba(104, 240, 174, 0.64);
  border-radius: 6px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.panel button {
  min-width: 11rem;
  margin-top: 0.65rem;
  padding: 0.68rem 1.15rem;
}

.panel button.primary,
.panel button:hover {
  border-color: #68f0ae;
  background: #68f0ae;
  color: #06120e;
}

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

#notice {
  position: absolute;
  top: 20%;
  left: 50%;
  z-index: 3;
  margin: 0;
  transform: translateX(-50%);
  color: #ffd166;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  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;
}

#touch-controls {
  position: absolute;
  right: 0.75rem;
  bottom: 0.7rem;
  left: 0.75rem;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

#touch-controls button {
  display: inline-flex;
  min-width: 8rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  background: rgba(6, 18, 14, 0.86);
  color: #f3fff9;
  pointer-events: auto;
  touch-action: none;
}

#right-button {
  border-color: rgba(116, 192, 252, 0.72) !important;
}

#touch-controls span {
  color: #68f0ae;
  font-size: 1.2rem;
}

#right-button span {
  color: #74c0fc;
}

#touch-controls strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
}

@media (hover: hover) and (pointer: fine) {
  #touch-controls {
    opacity: 0.62;
  }
}

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

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

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

  #touch-controls {
    right: 0.45rem;
    bottom: 0.35rem;
    left: 0.45rem;
  }

  #touch-controls button {
    min-width: 6.2rem;
    min-height: 38px;
    padding: 0.35rem 0.55rem;
  }

  body[data-game-state="ready"] #hud,
  body[data-game-state="ready"] #touch-controls,
  body[data-game-state="complete"] #hud,
  body[data-game-state="complete"] #touch-controls {
    display: none;
  }
}

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