:root {
  color-scheme: dark;
  --night: #23203a;
  --night-deep: #171629;
  --panel: #2d2948;
  --cream: #f6efd9;
  --muted: #aaa6bd;
  --coral: #ff806b;
  --mint: #80dfbd;
  --gold: #f4c96e;
  --line: rgba(246, 239, 217, 0.16);
  font-family:
    Inter, "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo,
    system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--night-deep);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(
      circle at 10% 7%,
      rgba(128, 223, 189, 0.09),
      transparent 24rem
    ),
    radial-gradient(
      circle at 92% 2%,
      rgba(255, 128, 107, 0.12),
      transparent 28rem
    ),
    var(--night-deep);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.page-shell {
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto;
}

.game-header {
  min-height: 142px;
  padding: 24px 0 22px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(140px, 0.7fr) minmax(340px, 2fr) auto;
  align-items: end;
  gap: 28px;
}

.back-link {
  min-height: 44px;
  color: var(--mint);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: 800 0.7rem/1 ui-monospace, Consolas, monospace;
  letter-spacing: 0.13em;
}

.back-link span {
  font-size: 1.25rem;
  transition: transform 0.18s ease;
}

.back-link:hover span {
  transform: translateX(-4px);
}

.eyebrow,
.overlay-kicker {
  margin: 0;
  color: var(--mint);
  font: 800 0.61rem/1.3 ui-monospace, Consolas, monospace;
  letter-spacing: 0.16em;
}

.title-block h1 {
  margin: 8px 0 5px;
  font-size: clamp(2.5rem, 5vw, 4.8rem);
  line-height: 0.92;
  letter-spacing: -0.075em;
}

.title-block h1 span {
  color: var(--coral);
}

.title-block > p:last-child {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.help-button {
  min-width: 108px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(128, 223, 189, 0.42);
  border-radius: 999px;
  background: rgba(45, 41, 72, 0.7);
  color: var(--cream);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.help-button span {
  margin-right: 6px;
  color: var(--mint);
  font: 900 0.9rem/1 ui-monospace, Consolas, monospace;
}

.help-button:hover {
  border-color: var(--mint);
  background: rgba(128, 223, 189, 0.12);
}

.game-layout {
  padding: 24px 0 30px;
}

.play-panel {
  min-width: 0;
}

.score-strip {
  min-height: 66px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(45, 41, 72, 0.9);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
}

.score-strip > div {
  min-width: 0;
  padding: 0 22px;
  border-left: 1px solid var(--line);
  text-align: center;
}

.score-strip > div:first-child {
  border-left: 0;
}

.score-strip span,
.best-line {
  display: block;
  color: var(--muted);
  font: 750 0.55rem/1.2 ui-monospace, Consolas, monospace;
  letter-spacing: 0.12em;
}

.score-strip strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.82rem, 1.6vw, 1rem);
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(41, 38, 61, 0.45);
  background: #dad1b8;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24);
}

#game-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 50 / 34;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#game-canvas:active {
  cursor: grabbing;
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  padding: clamp(16px, 4vw, 42px);
  background: rgba(23, 22, 41, 0.55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
}

.overlay-card {
  width: min(460px, 92%);
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid rgba(246, 239, 217, 0.24);
  background:
    linear-gradient(
      145deg,
      rgba(57, 51, 83, 0.96),
      rgba(35, 32, 58, 0.97)
    );
  box-shadow: 0 24px 70px rgba(18, 17, 31, 0.42);
  text-align: center;
}

.overlay-card h2 {
  margin: 10px 0 12px;
  font-size: clamp(1.65rem, 4vw, 2.5rem);
  letter-spacing: -0.05em;
}

.overlay-card > p:not(.overlay-kicker, .result-message, .best-line) {
  margin: 0 0 22px;
  color: #dad6e7;
  font-size: clamp(0.75rem, 1.6vw, 0.9rem);
  line-height: 1.75;
}

.overlay-card small {
  display: block;
  margin-top: 14px;
  color: #8c88a1;
  font: 700 0.58rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 0;
  background: var(--coral);
  color: #221f35;
  box-shadow: inset 0 -5px rgba(122, 49, 49, 0.22);
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.03em;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 -5px rgba(122, 49, 49, 0.22),
    0 8px 0 rgba(23, 22, 41, 0.32);
}

.canvas-corner {
  position: absolute;
  z-index: 2;
  width: 32px;
  height: 32px;
  pointer-events: none;
}

.canvas-corner-top {
  top: 13px;
  left: 13px;
  border-top: 2px solid rgba(255, 249, 232, 0.7);
  border-left: 2px solid rgba(255, 249, 232, 0.7);
}

.canvas-corner-bottom {
  right: 13px;
  bottom: 13px;
  border-right: 2px solid rgba(255, 249, 232, 0.7);
  border-bottom: 2px solid rgba(255, 249, 232, 0.7);
}

.result-score {
  margin: 20px 0 9px;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
}

.result-score strong {
  color: var(--gold);
  font-size: clamp(3.6rem, 9vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: -0.08em;
}

.result-score span {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.result-message {
  min-height: 42px;
  margin: 14px 0;
  color: #dbd7e8;
  font-size: 0.8rem;
  line-height: 1.6;
}

.best-line {
  margin: 0 0 20px;
}

.best-line strong {
  display: inline;
  color: var(--mint);
  font-size: 0.72rem;
}

.help-dialog {
  width: min(500px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: clamp(24px, 5vw, 38px);
  border: 1px solid rgba(246, 239, 217, 0.24);
  background:
    linear-gradient(145deg, #393353, #23203a);
  color: var(--cream);
  box-shadow: 0 30px 90px rgba(8, 8, 15, 0.58);
}

.help-dialog::backdrop {
  background: rgba(16, 15, 29, 0.76);
  backdrop-filter: blur(3px);
}

.help-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.help-heading button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(23, 22, 41, 0.45);
  color: var(--cream);
  cursor: pointer;
  font-size: 1.4rem;
}

.help-dialog h2 {
  margin: 8px 0 22px;
  font-size: clamp(1.7rem, 6vw, 2.4rem);
  letter-spacing: -0.04em;
}

.help-dialog ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.help-dialog li {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: start;
  gap: 12px;
}

.help-dialog li span {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold);
  display: grid;
  place-items: center;
  font: 800 0.55rem/1 ui-monospace, Consolas, monospace;
}

.help-dialog li p {
  margin: 3px 0 0;
  color: #d7d3e3;
  font-size: 0.8rem;
  line-height: 1.65;
}

.keyboard-note {
  margin: 22px 0 0;
  color: #8f8aa3;
  font: 650 0.61rem/1.6 ui-monospace, Consolas, monospace;
}

footer {
  min-height: 68px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  color: #77738d;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  font: 700 0.55rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.1em;
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 24px, 660px);
  }

  .game-header {
    min-height: 138px;
    padding-top: 18px;
    grid-template-columns: 1fr auto;
    gap: 12px 18px;
  }

  .back-link {
    grid-column: 1;
    grid-row: 1;
  }

  .help-button {
    grid-column: 2;
    grid-row: 1;
  }

  .title-block {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .title-block h1 {
    font-size: clamp(2.55rem, 13vw, 4rem);
  }

  .title-block > p:last-child {
    max-width: 330px;
    font-size: 0.73rem;
    line-height: 1.5;
  }

  .game-layout {
    padding-top: 16px;
  }

  .score-strip {
    min-height: 60px;
    padding: 0 8px;
  }

  .score-strip > div {
    padding: 0 8px;
  }

  .score-strip span {
    font-size: 0.48rem;
    letter-spacing: 0.07em;
  }

  .score-strip strong {
    font-size: 0.72rem;
  }

  #game-canvas {
    min-height: 230px;
    object-fit: contain;
  }

  .game-overlay {
    padding: 12px;
  }

  .overlay-card {
    padding: 20px;
  }

  .overlay-card h2 {
    margin-bottom: 8px;
  }

  .overlay-card > p:not(.overlay-kicker, .result-message, .best-line) {
    margin-bottom: 14px;
    font-size: 0.72rem;
    line-height: 1.55;
  }

  .primary-button {
    min-height: 52px;
  }

  .overlay-card small {
    margin-top: 9px;
  }

  footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 430px) {
  .page-shell {
    width: calc(100% - 18px);
  }

  .game-header {
    min-height: 128px;
  }

  .help-button {
    min-width: 96px;
    padding-inline: 12px;
  }

  .title-block h1 {
    font-size: 2.65rem;
  }

  .title-block > p:last-child {
    display: none;
  }

  .game-layout {
    padding-top: 12px;
  }

  .overlay-card {
    width: min(320px, 96%);
    padding: 16px 18px;
  }

  .overlay-card h2 {
    font-size: 1.4rem;
  }

  .overlay-card small {
    font-size: 0.52rem;
  }

  .result-score {
    margin-top: 12px;
  }

  .result-score strong {
    font-size: 3.2rem;
  }

  .result-message {
    min-height: 0;
    margin: 10px 0;
  }

  .best-line {
    margin-bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
