:root {
  --cream: #fbf9df;
  --orange: #ff5a00;
  --orange-deep: #d94d00;
  --green: #06421d;
  --leaf: #0b7b3c;
  --grape: #a8d76f;
  --ink: #10180f;
  --white: #ffffff;
  --shadow: rgba(6, 66, 29, 0.18);
  --phone-browser-clearance: 64px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--green);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 90, 0, 0.14), transparent 24rem),
    radial-gradient(circle at 86% 76%, rgba(168, 215, 111, 0.18), transparent 22rem),
    var(--cream);
  font-family: "Lazydog", "Comic Sans MS", "Trebuchet MS", sans-serif;
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
}

button,
.home-button {
  min-width: 144px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  color: var(--white);
  background: var(--orange);
  box-shadow: none;
  font: inherit;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

button:hover,
.home-button:hover {
  background: var(--orange-deep);
  transform: translateY(2px);
  box-shadow: none;
}

button:active,
.home-button:active {
  transform: translateY(2px);
  box-shadow: none;
}

.game-shell {
  width: min(100% - 24px, 1120px);
  height: 100vh;
  min-height: 100svh;
  height: 100svh;
  min-height: 100dvh;
  height: 100dvh;
  margin: 0 auto;
  padding: 16px 0 max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  overflow: hidden;
}

.game-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px;
  border: 4px solid var(--green);
  background: rgba(251, 249, 223, 0.96);
  box-shadow: 0 8px 0 var(--shadow);
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 0;
  border: 4px solid var(--green);
  background: var(--white);
  box-shadow: 0 8px 0 var(--shadow);
}

.game-scoreboard {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
}

.scoreboard span {
  min-width: 112px;
  padding: 12px 16px;
  font-size: 16px;
  text-align: center;
  text-transform: uppercase;
}

.scoreboard span + span {
  border-left: 4px solid var(--green);
}

.scoreboard strong {
  display: block;
  margin-top: 2px;
  color: var(--orange);
  font-size: 26px;
  line-height: 1;
}

.stage-wrap {
  position: relative;
  align-self: center;
  width: min(100%, calc((100vh - 136px) * 1.7778));
  width: min(100%, calc((100svh - 136px) * 1.7778));
  width: min(100%, calc((100dvh - 136px) * 1.7778));
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 136px);
  max-height: calc(100svh - 136px);
  max-height: calc(100dvh - 136px);
  min-height: 0;
  border: 6px solid var(--green);
  background: var(--cream);
  box-shadow: 0 16px 0 var(--shadow);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  background: var(--cream);
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
  background: rgba(251, 249, 223, 0.88);
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
}

.overlay.is-visible {
  display: grid;
}

.overlay-grape {
  width: 112px;
  height: 96px;
  object-fit: contain;
  border: 0;
  border-radius: 0;
  background: transparent;
}

h1 {
  margin: 0;
  color: var(--orange);
  font-size: clamp(48px, 10vw, 104px);
  line-height: 0.86;
  text-transform: uppercase;
  text-shadow: 4px 4px 0 var(--green);
}

.overlay-copy {
  max-width: 360px;
  margin: 8px 0 16px;
  color: var(--green);
  font: 700 18px/1.35 "Trebuchet MS", Arial, sans-serif;
}

.game-actions {
  min-height: 56px;
}

.game-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-actions p {
  max-width: 340px;
  margin: 0;
  color: var(--green);
  font: 900 13px/1.35 "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0.03em;
  text-align: center;
  text-transform: uppercase;
}

.volume-control {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 4px solid var(--green);
  background: var(--white);
  box-shadow: none;
  color: var(--green);
  font: 900 14px/1 "Trebuchet MS", Arial, sans-serif;
  text-transform: uppercase;
}

.volume-control input {
  width: 116px;
  accent-color: var(--orange);
  cursor: pointer;
}

.volume-control strong {
  min-width: 42px;
  color: var(--orange);
  font-size: 16px;
  text-align: right;
}

.audio-player {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  pointer-events: none;
  overflow: hidden;
}

.is-embed {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: transparent;
}

.is-embed .game-shell {
  position: relative;
  width: 100%;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: block;
}

.is-embed .scoreboard {
  border-width: 3px;
  box-shadow: 0 5px 0 var(--shadow);
}

.is-embed .scoreboard span {
  min-width: 82px;
  padding: 8px 10px;
  font-size: 12px;
}

.is-embed .scoreboard strong {
  font-size: 20px;
}

.is-embed .stage-wrap {
  width: 100%;
  margin: 0;
  height: 100vh;
  height: 100dvh;
  aspect-ratio: auto;
  max-height: none;
  min-height: 320px;
  border-width: 4px;
  box-shadow: none;
}

.is-embed #gameCanvas {
  min-height: 0;
  height: 100%;
}

.is-embed .overlay {
  background: rgba(251, 249, 223, 0.36);
}

.is-embed:not(.is-result) .overlay-grape,
.is-embed:not(.is-result) .overlay h1,
.is-embed:not(.is-result) .overlay-copy {
  display: none;
}

.is-embed .game-actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  justify-content: flex-end;
  pointer-events: none;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.is-embed #restartButton,
.is-embed #songTarget {
  display: none;
}

.is-embed .volume-control {
  min-height: 38px;
  padding: 6px 10px;
  border-width: 3px;
  box-shadow: 0 5px 0 var(--shadow);
  pointer-events: auto;
}

.is-embed .volume-control input {
  width: 92px;
}

.is-embed.is-preview .overlay,
.is-embed.is-preview .game-actions {
  display: none;
}

.is-embed.is-preview .game-shell {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.is-embed.is-preview .stage-wrap {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    width: min(100% - 20px, 1120px);
    padding: 8px 0 max(68px, calc(env(safe-area-inset-bottom) + var(--phone-browser-clearance)));
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .game-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    border-width: 3px;
    box-shadow: 0 5px 0 var(--shadow);
  }

  .game-scoreboard {
    top: 6px;
    right: 6px;
    transform: scale(0.86);
    transform-origin: top right;
  }

  .scoreboard {
    width: auto;
    border-width: 3px;
    box-shadow: 0 5px 0 var(--shadow);
  }

  .scoreboard span {
    min-width: 54px;
    padding: 5px 7px;
    font-size: 10px;
  }

  .scoreboard span + span {
    border-left-width: 3px;
  }

  .scoreboard strong {
    font-size: 18px;
  }

  h1 {
    font-size: clamp(34px, 15vw, 58px);
    line-height: 0.92;
    text-shadow: 3px 3px 0 var(--green);
  }

  .overlay {
    gap: 4px;
    padding: 14px;
  }

  .overlay-grape {
    width: 84px;
    height: 72px;
  }

  .overlay-copy {
    max-width: 270px;
    margin: 6px 0 10px;
    font-size: 14px;
  }

  .game-actions button {
    width: 100%;
    height: 44px;
    min-height: 44px;
    font-size: 18px;
  }

  .game-nav-actions {
    width: 100%;
    gap: 8px;
  }

  .game-nav-actions button,
  .game-nav-actions .home-button {
    flex: 1;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    font-size: 18px;
  }

  .game-actions p {
    max-width: none;
    font-size: 10px;
    line-height: 1.12;
  }

  .volume-control {
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 6px 8px;
    border-width: 3px;
    font-size: 12px;
  }

  .volume-control input {
    flex: 1;
    width: auto;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .stage-wrap {
    width: min(100%, calc((100vh - 214px) * 0.8));
    width: min(100%, calc((100svh - 214px) * 0.8));
    width: min(100%, calc((100dvh - 214px) * 0.8));
    aspect-ratio: 4 / 5;
    max-height: calc(100vh - 214px);
    max-height: calc(100svh - 214px);
    max-height: calc(100dvh - 214px);
    min-height: min(390px, calc(100vh - 214px));
    min-height: min(390px, calc(100svh - 214px));
    min-height: min(390px, calc(100dvh - 214px));
    border-width: 4px;
    box-shadow: 0 10px 0 var(--shadow);
  }
}
