:root {
  color-scheme: light;
  --ink: #173329;
  --paper: #fffaf0;
  --panel: rgba(255, 250, 240, 0.9);
  --line: rgba(23, 51, 41, 0.16);
  --coral: #d95d39;
  --gold: #f3c85a;
  --teal: #24736a;
  --grass: #45a857;
  --shadow: rgba(32, 44, 37, 0.24);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(247, 204, 94, 0.22), transparent 34%),
    linear-gradient(225deg, rgba(36, 115, 106, 0.18), transparent 42%),
    #f4eadb;
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

.preloader {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: #77d4eb;
  opacity: 1;
  visibility: visible;
  transition:
    opacity 260ms ease,
    visibility 260ms ease;
}

.preloader-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.preloader-logo {
  width: min(42vw, 240px);
  height: min(42vw, 240px);
  object-fit: contain;
}

body.preload-done .preloader {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

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

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(8px, 2vmin, 14px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

@supports (height: 100dvh) {
  .app-shell {
    min-height: 100dvh;
  }
}

.top-bar {
  min-height: 52px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 250, 240, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(36, 34, 29, 0.12);
  backdrop-filter: blur(10px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 24px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 999px 999px 999px 4px;
  background: var(--gold);
  border: 2px solid var(--ink);
  box-shadow: inset -5px -2px 0 rgba(217, 93, 57, 0.65);
}

.status-cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(8px, 3vw, 18px);
}

.stats {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(8px, 3vw, 18px);
  font-size: clamp(0.78rem, 2.8vw, 0.96rem);
  white-space: nowrap;
}

.stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  color: rgba(23, 51, 41, 0.72);
}

.stats strong {
  min-width: 2ch;
  color: var(--ink);
  font-size: 1.18em;
}

.audio-toggle {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(23, 51, 41, 0.22);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.62);
  cursor: pointer;
}

.audio-toggle:hover {
  background: rgba(255, 250, 240, 0.95);
}

.audio-toggle:focus-visible {
  outline: 3px solid rgba(36, 115, 106, 0.5);
  outline-offset: 3px;
}

.speaker-icon {
  position: relative;
  width: 19px;
  height: 18px;
}

.speaker-icon::before {
  position: absolute;
  left: 0;
  top: 5px;
  width: 7px;
  height: 8px;
  content: "";
  background: currentColor;
  border-radius: 2px;
}

.speaker-icon::after {
  position: absolute;
  left: 7px;
  top: 2px;
  width: 10px;
  height: 14px;
  content: "";
  border: 3px solid currentColor;
  border-left: 0;
  border-radius: 0 999px 999px 0;
}

.audio-toggle.is-muted .speaker-icon::after {
  left: 8px;
  top: 8px;
  width: 15px;
  height: 3px;
  border: 0;
  border-radius: 999px;
  background: var(--coral);
  transform: rotate(-38deg);
  transform-origin: center;
}

.stage {
  position: relative;
  width: min(100%, calc((100vh - 92px) * 9 / 16));
  align-self: center;
  justify-self: center;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 2px solid rgba(23, 51, 41, 0.28);
  border-radius: 8px;
  background: #9dd7eb;
  box-shadow: 0 22px 56px var(--shadow);
}

@supports (height: 100dvh) {
  .stage {
    width: min(100%, calc((100dvh - 92px) * 9 / 16));
  }
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.menu-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(calc(100% - 48px), 290px);
  transform: translate(-50%, -50%);
  padding: 22px;
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(33, 45, 39, 0.2);
  backdrop-filter: blur(8px);
}

.menu-panel.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -46%);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.menu-panel h1 {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.15rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.menu-score {
  min-height: 1.4em;
  margin: 0;
  color: rgba(23, 51, 41, 0.72);
  font-weight: 700;
}

.primary-button {
  min-width: 134px;
  min-height: 46px;
  padding: 0 22px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: #fffaf0;
  background: var(--coral);
  box-shadow: 0 5px 0 #85381f;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #85381f;
}

.primary-button:focus-visible {
  outline: 3px solid rgba(36, 115, 106, 0.5);
  outline-offset: 3px;
}

@media (max-width: 420px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .top-bar {
    min-height: 48px;
    padding: 7px 8px;
  }

  .status-cluster,
  .stats {
    gap: 7px;
  }

  .audio-toggle {
    width: 34px;
    height: 34px;
  }

  .menu-panel {
    width: min(calc(100% - 30px), 268px);
    padding: 18px;
  }
}
