:root {
  color-scheme: dark;
  --ink: #07100c;
  --paper: #f4f2e8;
  --muted: #99aa9f;
  --line: rgba(191, 255, 208, 0.16);
  --acid: #b8ff55;
  --acid-strong: #84ff35;
  --coral: #ff6b4a;
  --stage-width: min(100%, 720px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ink);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  background:
    radial-gradient(circle at 18% 8%, rgba(96, 255, 132, 0.08), transparent 30rem),
    radial-gradient(circle at 82% 72%, rgba(255, 107, 74, 0.07), transparent 28rem),
    #07100c;
}

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

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--acid);
  outline-offset: 4px;
}

.game-shell {
  width: min(100%, 920px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) max(24px, env(safe-area-inset-bottom));
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
}

.topline,
.footerline {
  width: var(--stage-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--paper);
  text-decoration: none;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.brand b {
  color: var(--acid);
  font-weight: 700;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border: 2px solid var(--acid);
  border-radius: 2px;
  box-shadow: 10px 0 0 -2px var(--acid), 20px 0 0 -2px rgba(184, 255, 85, 0.48);
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 18px;
}

.desktop-hint,
.footerline {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.text-button {
  border: 0;
  padding: 8px 0;
  color: var(--paper);
  background: transparent;
  cursor: pointer;
}

kbd {
  display: inline-grid;
  min-width: 1.65em;
  min-height: 1.65em;
  place-items: center;
  border: 1px solid rgba(244, 242, 232, 0.28);
  border-radius: 4px;
  color: var(--paper);
  background: rgba(244, 242, 232, 0.06);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72em;
}

.stage {
  position: relative;
  width: var(--stage-width);
  aspect-ratio: 9 / 10;
  overflow: hidden;
  border: 1px solid rgba(184, 255, 85, 0.24);
  border-radius: 22px;
  background: #08110d;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
  isolation: isolate;
  touch-action: none;
  animation: stage-in 620ms cubic-bezier(0.2, 0.75, 0.2, 1) both;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #08110d;
}

.state-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(28px, 7vw, 72px);
  background: linear-gradient(180deg, rgba(4, 11, 7, 0.28), rgba(4, 11, 7, 0.92));
  backdrop-filter: blur(6px);
  transition: opacity 180ms ease, visibility 180ms ease, background 180ms ease;
  z-index: 3;
}

.state-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.state-copy {
  width: min(100%, 520px);
  transform: translateY(0);
  animation: copy-in 520ms 120ms cubic-bezier(0.2, 0.75, 0.2, 1) both;
}

.kicker {
  margin: 0 0 18px;
  color: var(--acid);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.64rem, 1.9vw, 0.76rem);
  letter-spacing: 0.17em;
}

.state-copy h1 {
  max-width: 9ch;
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(2.45rem, 10vw, 5.3rem);
  line-height: 0.92;
  letter-spacing: -0.08em;
  text-wrap: balance;
}

#overlay-body {
  max-width: 39ch;
  margin: 22px 0 30px;
  color: #b9c8be;
  font-size: clamp(0.86rem, 2.2vw, 1rem);
  line-height: 1.75;
}

.start-button {
  width: min(100%, 330px);
  min-height: 58px;
  padding: 0 18px 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 4px;
  color: #0a160d;
  background: var(--acid);
  font-weight: 800;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.start-button:hover {
  background: #ccff7d;
  transform: translateY(-2px);
}

.start-button:active {
  transform: translateY(0) scale(0.99);
}

.keyline {
  margin: 17px 0 0;
  color: #7e9084;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  line-height: 1.8;
}

.stage-actions {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 4;
  display: flex;
  gap: 8px;
}

.round-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(244, 242, 232, 0.18);
  border-radius: 50%;
  color: var(--paper);
  background: rgba(7, 16, 12, 0.72);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.round-button:hover:not(:disabled) {
  border-color: rgba(184, 255, 85, 0.62);
  color: var(--acid);
}

.round-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  gap: 5px;
  user-select: none;
}

.touch-key,
.touch-core {
  border-radius: 16px;
}

.touch-key {
  border: 1px solid rgba(184, 255, 85, 0.24);
  color: var(--paper);
  background: rgba(184, 255, 85, 0.06);
  font-size: 1.25rem;
  cursor: pointer;
  touch-action: manipulation;
}

.touch-key:active {
  color: #0a160d;
  background: var(--acid);
  transform: scale(0.96);
}

.touch-up { grid-column: 2; grid-row: 1; }
.touch-left { grid-column: 1; grid-row: 2; }
.touch-core {
  grid-column: 2;
  grid-row: 2;
  background: rgba(244, 242, 232, 0.04);
}
.touch-right { grid-column: 3; grid-row: 2; }
.touch-down { grid-column: 2; grid-row: 3; }

.footerline {
  min-height: 18px;
}

.footerline p {
  margin: 0;
}

@keyframes stage-in {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes copy-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .game-shell {
    align-content: start;
    gap: 12px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .desktop-hint,
  .footerline p:first-child,
  .keyline {
    display: none;
  }

  .stage {
    border-radius: 16px;
  }

  .state-overlay {
    align-items: end;
    padding: 30px 24px 34px;
  }

  .state-copy h1 {
    font-size: clamp(2.35rem, 13vw, 4rem);
  }

  #overlay-body {
    margin: 16px 0 22px;
    line-height: 1.6;
  }

  .start-button {
    min-height: 54px;
  }

  .stage-actions {
    top: 12px;
    right: 12px;
  }

  .round-button {
    width: 42px;
    height: 42px;
  }

  .touch-controls {
    display: grid;
  }

  .footerline {
    justify-content: center;
  }
}

@media (max-height: 760px) and (orientation: landscape) {
  .game-shell {
    width: min(100%, 1280px);
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr auto;
    align-content: center;
  }

  .topline,
  .footerline {
    grid-column: 1 / -1;
  }

  .stage {
    width: min(74vh, 720px);
  }

  .touch-controls {
    align-self: center;
  }
}

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