:root {
  --bg-top: #73d4ff;
  --bg-mid: #bfe9ff;
  --bg-bottom: #fff2bf;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --text-main: #173e62;
  --text-soft: #476a87;
  --ink-deep: #144466;
  --sunny: #ffd85b;
  --orange: #ff9f43;
  --coral: #ff7b6b;
  --mint: #66d6a4;
  --blue: #5baeff;
  --line: rgba(91, 174, 255, 0.2);
  --line-strong: rgba(91, 174, 255, 0.34);
  --shadow: 0 22px 55px rgba(46, 124, 176, 0.18);
  --shadow-soft: 0 12px 32px rgba(70, 152, 202, 0.12);
  --radius-lg: 32px;
  --radius-md: 22px;
}

* {
  box-sizing: border-box;
}

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

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

html {
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
  font-family: "Nunito", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.92), transparent 16%),
    radial-gradient(circle at 82% 10%, rgba(255, 215, 91, 0.5), transparent 18%),
    radial-gradient(circle at 50% 72%, rgba(255, 169, 86, 0.14), transparent 24%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 42%, var(--bg-bottom) 100%);
  -webkit-tap-highlight-color: transparent;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background-image:
    url("./assets/kenney/backgrounds/background_clouds.svg"),
    url("./assets/kenney/backgrounds/background_color_hills.svg");
  background-position: center top, center bottom;
  background-repeat: no-repeat, no-repeat;
  background-size: cover, cover;
  opacity: 0.24;
}

body::after {
  background-image:
    radial-gradient(circle at 12% 22%, rgba(255, 255, 255, 0.72) 0 12px, transparent 13px),
    radial-gradient(circle at 78% 19%, rgba(255, 255, 255, 0.55) 0 10px, transparent 11px),
    radial-gradient(circle at 86% 62%, rgba(255, 223, 105, 0.3) 0 14px, transparent 15px),
    radial-gradient(circle at 24% 76%, rgba(112, 224, 184, 0.22) 0 16px, transparent 17px);
  opacity: 0.9;
}

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 24px 18px 40px;
  position: relative;
  z-index: 1;
}

body.game-active {
  overflow: hidden;
}

body.game-active .hero,
body.game-active .menu-screen {
  display: none;
}

body.game-active .app-shell {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.hero {
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
  padding: 28px 24px 116px;
  border-radius: 36px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.56)),
    url("./assets/kenney/backgrounds/background_clouds.svg") center top / cover no-repeat,
    url("./assets/kenney/backgrounds/background_color_hills.svg") center bottom / cover no-repeat;
  box-shadow: var(--shadow);
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.hero::before {
  width: 122px;
  height: 122px;
  top: 20px;
  right: 20px;
  background: radial-gradient(circle at 35% 35%, #fff7bf 0 18%, #ffd859 42%, #ffb648 100%);
  box-shadow:
    0 0 0 12px rgba(255, 216, 91, 0.18),
    0 28px 40px rgba(255, 173, 64, 0.24);
}

.hero::after {
  width: 160px;
  height: 160px;
  bottom: -72px;
  left: -24px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0));
}

.eyebrow,
.card-kicker,
.label,
.result-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  padding: 7px 12px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 800;
}

.eyebrow,
.label {
  color: var(--blue);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px rgba(91, 174, 255, 0.16);
}

h1,
h2,
h3,
.play-button,
.ghost-button {
  font-family: "Baloo 2", sans-serif;
}

h1,
h2 {
  margin: 0;
  line-height: 0.94;
}

h1 {
  max-width: 10ch;
  font-size: clamp(3.1rem, 11vw, 5.8rem);
  color: var(--ink-deep);
  text-shadow: 0 6px 24px rgba(255, 255, 255, 0.42);
}

.lede {
  max-width: 48ch;
  margin-top: 14px;
  color: #40657f;
  font-size: 1.08rem;
  line-height: 1.55;
}

.menu-screen {
  display: grid;
  gap: 18px;
  align-items: stretch;
}

.game-card,
.canvas-shell,
.hud,
.score-strip {
  backdrop-filter: blur(18px) saturate(1.08);
}

.game-card {
  --card-start: #ffe36a;
  --card-end: #ff9b6a;
  --card-chip: #ff8d57;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-soft);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.game-card::before,
.game-card::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.game-card::before {
  inset: 0 0 auto;
  height: 110px;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.9), transparent 28%),
    linear-gradient(135deg, var(--card-start), var(--card-end));
  opacity: 0.9;
}

.game-card::after {
  top: 76px;
  right: -18px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 55%),
    rgba(255, 255, 255, 0.22);
}

.game-card:nth-child(6n + 1) {
  --card-start: #ffe36a;
  --card-end: #ff9d6d;
  --card-chip: #ff8e57;
}

.game-card:nth-child(6n + 2) {
  --card-start: #79e3ff;
  --card-end: #71b6ff;
  --card-chip: #3a88ff;
}

.game-card:nth-child(6n + 3) {
  --card-start: #96f0a6;
  --card-end: #5fd4c7;
  --card-chip: #22b69a;
}

.game-card:nth-child(6n + 4) {
  --card-start: #ffd27d;
  --card-end: #ff7f7a;
  --card-chip: #ff6262;
}

.game-card:nth-child(6n + 5) {
  --card-start: #c7b7ff;
  --card-end: #7cb0ff;
  --card-chip: #6a7cff;
}

.game-card:nth-child(6n + 6) {
  --card-start: #ffe08d;
  --card-end: #8fd7ff;
  --card-chip: #42a2ff;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 26px 60px rgba(63, 140, 196, 0.22);
}

.card-head {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  z-index: 1;
}

.game-card .card-kicker {
  margin-top: 2px;
  color: #fffdf8;
  background: rgba(20, 68, 102, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.game-card h2 {
  position: relative;
  z-index: 1;
  font-size: clamp(1.9rem, 5vw, 2.35rem);
  color: var(--ink-deep);
}

.game-card p {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--text-soft);
  line-height: 1.55;
}

.game-card > p {
  flex: 1;
  padding-top: 2px;
}

.game-card .card-meta {
  margin-top: auto;
  font-size: 0.97rem;
  font-weight: 800;
  color: color-mix(in srgb, var(--card-chip) 62%, #8a4300 38%);
}

.play-button,
.ghost-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  border-radius: 999px;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
  touch-action: manipulation;
}

.play-button {
  width: 100%;
  padding: 15px 18px;
  color: #6a3e0a;
  font-weight: 800;
  background:
    linear-gradient(180deg, #ffe67e 0%, #ffc85d 44%, #ff9f43 100%);
  border: 1px solid rgba(255, 255, 255, 0.84);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 16px 34px rgba(255, 159, 67, 0.3);
}

.game-card .play-button[data-game] {
  margin-top: auto;
}

.ghost-button {
  padding: 11px 16px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink-deep);
  border: 1px solid rgba(91, 174, 255, 0.18);
  box-shadow: 0 8px 18px rgba(89, 171, 220, 0.12);
}

.ghost-button.accent {
  background: linear-gradient(180deg, rgba(153, 244, 187, 0.92), rgba(92, 220, 165, 0.9));
  border-color: rgba(62, 181, 124, 0.26);
  color: #11614c;
}

.play-button:hover,
.ghost-button:hover {
  transform: translateY(-2px);
}

.play-button:active,
.ghost-button:active {
  transform: translateY(1px) scale(0.99);
}

.game-screen {
  display: grid;
  gap: 14px;
}

body.game-active .game-screen {
  flex: 1;
  height: 100%;
  min-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
}

.hidden {
  display: none;
}

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.hud-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-self: end;
}

.hud-actions .ghost-button {
  white-space: nowrap;
}

.hud-copy h2 {
  font-size: clamp(1.6rem, 6vw, 2.5rem);
  color: var(--ink-deep);
}

.hud-tip {
  margin: 8px 0 0;
  color: var(--text-soft);
  line-height: 1.45;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  background: var(--panel);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.score-pill {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(245, 252, 255, 0.74));
  border-radius: 18px;
  padding: 12px 14px;
  min-width: 0;
  box-shadow: inset 0 0 0 1px rgba(91, 174, 255, 0.12);
}

.score-pill strong {
  display: block;
  margin-top: 8px;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.45rem;
  color: var(--ink-deep);
}

.canvas-shell {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.78), transparent 16%),
    radial-gradient(circle at 78% 16%, rgba(255, 216, 91, 0.42), transparent 18%),
    linear-gradient(180deg, #85d8ff 0%, #d4f0ff 58%, #fff0ba 100%);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.three-stage,
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.three-stage {
  z-index: 1;
}

.three-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  min-height: 0;
  z-index: 2;
}

.result-overlay,
.motion-overlay,
.startup-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.result-overlay {
  z-index: 4;
  background: rgba(68, 168, 228, 0.22);
}

.motion-overlay {
  z-index: 3;
  background: rgba(68, 168, 228, 0.16);
}

.startup-overlay {
  position: fixed;
  z-index: 10;
  background: rgba(54, 150, 213, 0.26);
}

.result-card,
.motion-card,
.startup-card {
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(243, 251, 255, 0.87));
  box-shadow: var(--shadow);
  text-align: center;
}

.result-card {
  width: min(100%, 340px);
  border-radius: 28px;
  padding: 24px 20px;
  color: var(--ink-deep);
}

.motion-card {
  width: min(100%, 320px);
  border-radius: 26px;
  padding: 22px 18px;
}

.startup-card {
  width: min(100%, 360px);
  border-radius: 28px;
  padding: 24px 20px;
}

.startup-card h2 {
  font-size: clamp(1.9rem, 8vw, 2.6rem);
  margin-bottom: 12px;
  color: var(--ink-deep);
}

.startup-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.result-kicker {
  margin: 0 auto 10px;
  color: #ff7b6b;
  background: rgba(255, 123, 107, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 123, 107, 0.12);
}

.result-card h3,
.motion-card h3 {
  margin: 0;
  color: var(--ink-deep);
  line-height: 0.98;
}

.result-card h3 {
  font-size: clamp(2rem, 8vw, 2.8rem);
  color: #123f63;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.motion-card h3 {
  margin-bottom: 10px;
  font-size: clamp(1.5rem, 6vw, 2rem);
}

.result-score {
  margin: 14px 0 8px;
  font-family: "Baloo 2", sans-serif;
  font-size: 2.2rem;
  color: #c96f19;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.result-note {
  margin: 0;
  color: #355a76;
  font-weight: 700;
  line-height: 1.45;
}

.motion-button {
  margin-top: 16px;
}

.startup-overlay.hidden,
#game-canvas.hidden,
.three-stage.hidden,
.motion-overlay.hidden,
.result-overlay.hidden {
  display: none;
}

@media (min-width: 760px) {
  .app-shell {
    padding: 32px 24px 48px;
  }

  .menu-screen {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-card {
    min-height: 330px;
  }

  #game-canvas {
    min-height: 620px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px 12px calc(28px + env(safe-area-inset-bottom));
  }

  .hero {
    padding: 22px 18px 102px;
    border-radius: 28px;
  }

  .hero::before {
    width: 88px;
    height: 88px;
    top: 16px;
    right: 14px;
    box-shadow:
      0 0 0 8px rgba(255, 216, 91, 0.16),
      0 22px 28px rgba(255, 173, 64, 0.18);
  }

  .game-card {
    padding: 18px;
    border-radius: 24px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
    border-radius: 20px;
  }

  .hud-copy {
    grid-column: 1 / -1;
    order: -1;
  }

  .hud-tip {
    font-size: 0.96rem;
  }

  .score-strip {
    gap: 10px;
    border-radius: 20px;
    padding: 10px;
  }

  .score-pill {
    padding: 10px 12px;
  }

  .canvas-shell {
    border-radius: 24px;
  }

  #game-canvas {
    min-height: 0;
  }
}

@media (max-width: 430px), (max-height: 740px) {
  body.game-active .app-shell {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: 10px;
  }

  body.game-active .game-screen {
    gap: 8px;
  }

  body.game-active .hud {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 16px;
  }

  body.game-active .hud-actions {
    gap: 8px;
  }

  body.game-active .hud-copy {
    grid-column: auto;
    order: 0;
    min-width: 0;
  }

  body.game-active .hud-copy h2 {
    font-size: clamp(1.2rem, 7vw, 1.6rem);
    line-height: 0.98;
  }

  body.game-active .hud-tip {
    display: none;
  }

  body.game-active .eyebrow,
  body.game-active .card-kicker,
  body.game-active .label,
  body.game-active .result-kicker {
    font-size: 0.62rem;
    letter-spacing: 0.13em;
    padding: 6px 10px;
  }

  body.game-active .ghost-button {
    padding: 8px 12px;
    font-size: 0.95rem;
  }

  body.game-active .score-strip {
    gap: 8px;
    padding: 8px;
    border-radius: 16px;
  }

  body.game-active .score-pill {
    padding: 8px 10px;
    border-radius: 14px;
  }

  body.game-active .score-pill strong {
    margin-top: 4px;
    font-size: 1rem;
  }

  body.game-active .canvas-shell {
    border-radius: 20px;
  }

  body.game-active .result-overlay {
    padding: 14px;
  }

  body.game-active .result-card {
    border-radius: 22px;
    padding: 18px 16px;
  }

  body.game-active .result-score {
    font-size: 1.8rem;
  }
}
