:root {
  color-scheme: dark;
  --ink: #f9f5ff;
  --muted: #c9c4e5;
  --panel: rgba(25, 17, 66, 0.8);
  --panel-edge: rgba(193, 174, 255, 0.36);
  --accent: #f8d46d;
  --accent-strong: #ffb84d;
  --sky: #100b31;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--sky);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% -15%, rgba(132, 105, 255, 0.42), transparent 37rem),
    radial-gradient(circle at 100% 100%, rgba(34, 154, 199, 0.22), transparent 32rem),
    linear-gradient(160deg, #171047 0%, #0b1237 55%, #130b31 100%);
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(100%, 496px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.masthead {
  text-align: center;
  padding-top: 2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #b7a8fb;
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.2em;
}

h1 {
  margin: 0;
  color: #fff8d9;
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  font-size: clamp(1.65rem, 7.5vw, 2.05rem);
  line-height: 1.18;
  letter-spacing: 0.06em;
  text-shadow: 0 0 20px rgba(242, 212, 110, 0.28);
}

.lede {
  margin: 7px auto 0;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.5;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 24px;
  background: linear-gradient(150deg, rgba(48, 35, 108, 0.84), rgba(13, 19, 57, 0.9));
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.29), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.score-item {
  min-height: 50px;
  padding: 7px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(196, 182, 255, 0.2);
  border-radius: 14px;
  background: rgba(11, 9, 42, 0.46);
}

.score-item span {
  color: #c2bae9;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.score-item strong {
  color: #ffffff;
  font-size: 1.22rem;
  font-variant-numeric: tabular-nums;
}

.score-item--best strong {
  color: var(--accent);
}

.stage-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border: 1px solid rgba(235, 232, 255, 0.42);
  border-radius: 18px;
  background: #11143d;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 0 20px rgba(150, 125, 255, 0.18);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

canvas:focus-visible {
  outline: 3px solid #ffe28a;
  outline-offset: -5px;
}

.canvas-gloss {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(118deg, rgba(255, 255, 255, 0.09), transparent 22%, transparent 72%, rgba(70, 184, 255, 0.08));
}

.game-status {
  min-height: 1.5em;
  margin: 0;
  color: #e3ddff;
  font-size: 0.77rem;
  line-height: 1.45;
  text-align: center;
}

.actions {
  display: grid;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  color: #2d1b22;
  font: inherit;
  font-size: 0.96rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #ffec9c 0%, #f9c65e 52%, #ffa847 100%);
  box-shadow: 0 4px 0 #b66c34, 0 10px 22px rgba(252, 177, 72, 0.24);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.primary-button:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b66c34, 0 4px 12px rgba(252, 177, 72, 0.2);
}

.primary-button:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 3px;
}

.controls-help {
  min-height: 44px;
  padding: 5px 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 12px;
  color: #cfc8f3;
  background: rgba(9, 13, 44, 0.43);
}

.controls-help p {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.4;
  text-align: center;
}

.controls-help b {
  color: #fff4bd;
}

.tap-mark {
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
}

footer {
  margin-top: auto;
  padding: 2px 4px;
  color: #aaa4cc;
  font-size: 0.67rem;
  line-height: 1.4;
  text-align: center;
}

@media (min-width: 700px) {
  .game-shell {
    padding-top: 28px;
    padding-bottom: 24px;
  }

  .game-card {
    padding: 14px;
  }
}

@media (min-width: 760px) {
  .game-shell {
    width: min(100%, 820px);
    gap: 10px;
    padding-top: 20px;
    padding-bottom: 16px;
  }

  .masthead {
    text-align: left;
  }

  .lede {
    margin-left: 0;
  }

  .game-card {
    width: min(100%, 772px);
    align-self: center;
    display: grid;
    grid-template-columns: minmax(315px, 390px) minmax(238px, 1fr);
    grid-template-areas:
      "stage scores"
      "stage status"
      "stage actions"
      "stage controls";
    column-gap: 16px;
    row-gap: 12px;
    align-items: start;
  }

  .stage-frame {
    grid-area: stage;
    width: 100%;
    justify-self: center;
  }

  .scoreboard {
    grid-area: scores;
    grid-template-columns: 1fr;
  }

  .game-status {
    grid-area: status;
    padding: 5px 2px;
    text-align: left;
  }

  .actions {
    grid-area: actions;
  }

  .controls-help {
    grid-area: controls;
    min-height: 60px;
  }

  .controls-help p {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
