:root {
  --ink: #173f45;
  --paper: #effdf8;
  --line: #b9ebe0;
  --green: #16b7aa;
  --blue: #2f9fd6;
  --yellow: #ffd166;
  --orange: #ff8b5e;
  --red: #ef476f;
  --mint: #d9fff3;
  --cream: #fff8e8;
  --shadow: 0 24px 70px rgba(23, 63, 69, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: #fff;
}

button {
  font: inherit;
}

.app {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 34px);
}

.screen {
  display: none;
  width: min(1120px, 100%);
}

.screen--active {
  display: block;
}

.menu {
  position: relative;
  overflow: hidden;
  width: min(680px, 100%);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 46px);
  border: 3px solid rgba(22, 183, 170, 0.55);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.9) 48%, rgba(255, 248, 232, 0.58) 100%),
    url("assets/menu-ambience.png") center / cover no-repeat;
  box-shadow: var(--shadow);
  text-align: center;
}

.menu > * {
  position: relative;
  z-index: 1;
}

.menu::after {
  position: absolute;
  inset: auto 0 0 0;
  height: 7px;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange));
  content: "";
}

.kicker {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: #0f5f63;
  font-size: clamp(2.1rem, 7vw, 4.35rem);
  line-height: 0.98;
}

h2 {
  font-size: clamp(2rem, 6vw, 3.7rem);
}

.intro {
  max-width: 55ch;
  margin: 20px auto 0;
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  line-height: 1.55;
}

.control-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 24px 0;
}

.control-hints span {
  padding: 8px 12px;
  border: 2px solid rgba(22, 183, 170, 0.38);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 0.95rem;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.action-button,
.pad {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  font-weight: 900;
  touch-action: manipulation;
  box-shadow: 0 8px 0 rgba(36, 49, 63, 0.2);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.primary-button {
  min-height: 52px;
  padding: 0 24px;
  background: linear-gradient(180deg, #1dd3c6, var(--green));
  font-size: 1.05rem;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.primary-button:hover,
.secondary-button:hover,
.action-button:hover,
.pad:hover {
  filter: brightness(1.04);
}

.primary-button:active,
.secondary-button:active,
.action-button:active,
.pad:active,
.pad.is-pressed,
.action-button.is-pressed {
  transform: translateY(5px);
  box-shadow: 0 3px 0 rgba(36, 49, 63, 0.24);
}

.secondary-button {
  min-height: 46px;
  padding: 0 18px;
  background: linear-gradient(180deg, #fff8e8, #ffd166);
  color: var(--ink);
  font-size: 0.98rem;
}

.game-layout {
  display: grid;
  gap: 12px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(88px, 0.8fr) minmax(88px, 0.8fr) minmax(180px, 2fr);
  gap: 10px;
  align-items: stretch;
}

.hud-stat,
.noise-panel {
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid rgba(22, 183, 170, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 28px rgba(23, 63, 69, 0.12);
  backdrop-filter: blur(8px);
}

.hud-label {
  display: block;
  color: #5b6a75;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.25rem, 2.8vw, 1.8rem);
  line-height: 1;
}

.status-strip {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(170px, 0.65fr);
  gap: 10px;
  align-items: center;
}

.status-strip span {
  min-width: 0;
  padding: 9px 12px;
  overflow: hidden;
  border: 2px solid rgba(22, 183, 170, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 22px rgba(23, 63, 69, 0.1);
  color: #23565c;
  font-size: clamp(0.84rem, 2vw, 0.98rem);
  font-weight: 900;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-strip .is-ready {
  border-color: rgba(255, 139, 94, 0.72);
  background: rgba(255, 248, 232, 0.96);
  color: #8c3c26;
}

.noise-panel {
  display: grid;
  grid-template-columns: auto minmax(70px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.noise-panel .hud-label {
  grid-row: 1;
}

.noise-bar {
  height: 18px;
  overflow: hidden;
  border: 2px solid rgba(23, 63, 69, 0.72);
  border-radius: 999px;
  background: #eafff8;
}

.noise-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange), var(--red));
  transition: width 120ms linear;
}

.play-area {
  position: relative;
  overflow: hidden;
  border: 3px solid rgba(23, 63, 69, 0.82);
  border-radius: 8px;
  background: var(--mint);
  box-shadow: var(--shadow);
}

.play-area::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(105deg, transparent 0%, rgba(255, 255, 255, 0.2) 42%, transparent 58%);
  opacity: 0.45;
  transform: translateX(-120%);
  animation: playSweep 6s ease-in-out infinite;
  content: "";
  pointer-events: none;
}

@keyframes playSweep {
  0%,
  50% {
    transform: translateX(-120%);
  }

  78%,
  100% {
    transform: translateX(120%);
  }
}

#gameCanvas {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: calc(100dvh - 320px);
  min-height: 260px;
  background: var(--mint);
}

.mobile-controls {
  display: grid;
  grid-template-columns: 62px 62px 62px minmax(112px, 170px);
  grid-template-rows: 56px 56px;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
  user-select: none;
}

.pad {
  min-width: 56px;
  min-height: 56px;
  background: linear-gradient(180deg, #54c4ec, var(--blue));
  font-size: 1.25rem;
}

.pad-up {
  grid-column: 2;
  grid-row: 1;
}

.pad-left {
  grid-column: 1;
  grid-row: 2;
}

.pad-down {
  grid-column: 2;
  grid-row: 2;
}

.pad-right {
  grid-column: 3;
  grid-row: 2;
}

.action-button {
  grid-column: 4;
  grid-row: 1 / span 2;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 42%),
    linear-gradient(180deg, #ffad7d, var(--orange));
  font-size: clamp(1rem, 4vw, 1.25rem);
}

.action-button.is-ready {
  animation: actionPulse 900ms ease-in-out infinite;
  filter: brightness(1.08);
}

@keyframes actionPulse {
  0%,
  100% {
    box-shadow: 0 8px 0 rgba(36, 49, 63, 0.2), 0 0 0 0 rgba(255, 139, 94, 0.34);
  }

  50% {
    box-shadow: 0 8px 0 rgba(36, 49, 63, 0.2), 0 0 0 7px rgba(255, 139, 94, 0);
  }
}

.final-score {
  display: inline-grid;
  gap: 2px;
  min-width: 140px;
  margin: 22px 0;
  padding: 12px 20px;
  border: 2px solid rgba(22, 183, 170, 0.38);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.final-score span {
  color: #5b6a75;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.final-score strong {
  font-size: 2.1rem;
  line-height: 1;
}

.score-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(560px, 100%);
  margin: 0 auto 18px;
}

.score-breakdown h3 {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: #0f5f63;
  font-size: 1.05rem;
  line-height: 1.1;
}

.score-detail {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 58px;
  padding: 8px 10px;
  border: 2px solid rgba(22, 183, 170, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  text-align: left;
}

.score-detail img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.score-detail strong,
.score-detail span {
  display: block;
  min-width: 0;
}

.score-detail strong {
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.12;
}

.score-detail span {
  margin-top: 3px;
  color: #5b6a75;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.1;
}

.score-detail b {
  color: var(--green);
  font-size: 0.9rem;
  white-space: nowrap;
}

.score-detail--penalty b {
  color: var(--red);
}

.score-save-status {
  min-height: 22px;
  margin: 0 auto 14px;
  color: #315f64;
  font-size: 0.95rem;
  font-weight: 800;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  width: min(420px, 100%);
  max-height: 260px;
  margin: 14px auto 18px;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.leaderboard-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border: 2px solid rgba(22, 183, 170, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  text-align: left;
}

.leaderboard-list li::before {
  display: none;
  content: none;
}

.leaderboard-rank {
  flex: 0 0 32px;
  min-width: 32px;
  color: var(--green);
  font-weight: 900;
  text-align: center;
}

.leaderboard-rank--cup {
  display: inline-grid;
  width: 32px;
  height: 28px;
  place-items: center;
}

.leaderboard-rank--cup svg {
  display: block;
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 2px 0 rgba(23, 63, 69, 0.18));
}

.leaderboard-rank--1 {
  color: #d9a21b;
}

.leaderboard-rank--2 {
  color: #aab4c4;
}

.leaderboard-rank--3 {
  color: #b87333;
}

.leaderboard-list strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player:hover,
.leaderboard-player:focus-visible {
  color: #0f777a;
  text-decoration: underline;
}

.leaderboard-score {
  flex: 0 0 auto;
  color: #5b6a75;
  font-size: 0.9rem;
  font-weight: 900;
  white-space: nowrap;
}

.leaderboard-list .leaderboard-empty {
  display: block;
  text-align: center;
}

.leaderboard-list .leaderboard-empty::before {
  content: "";
}

@media (min-width: 820px) {
  .mobile-controls {
    width: max-content;
    margin-left: auto;
  }
}

@media (max-width: 680px) {
  .app {
    align-items: start;
    padding: 10px;
  }

  .menu {
    padding: 22px 16px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .noise-panel {
    grid-column: 1 / -1;
  }

  .status-strip {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  #gameCanvas {
    max-height: none;
    min-height: 300px;
  }

  .mobile-controls {
    grid-template-columns: 56px 56px 56px minmax(98px, 1fr);
    grid-template-rows: 52px 52px;
  }

  .pad {
    min-width: 52px;
    min-height: 52px;
  }

  .score-breakdown {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 390px) {
  .mobile-controls {
    grid-template-columns: 48px 48px 48px minmax(86px, 1fr);
    grid-template-rows: 48px 48px;
    gap: 6px;
  }

  .pad {
    min-width: 48px;
    min-height: 48px;
  }
}
