:root {
  --bg1: #11162f;
  --bg2: #21104a;
  --panel: rgba(10, 17, 40, 0.72);
  --panel2: rgba(255,255,255,0.12);
  --text: #fff7df;
  --muted: rgba(255,247,223,0.74);
  --accent: #7efcff;
  --pink: #ff5fd2;
  --green: #73ff92;
  --yellow: #ffd166;
  --danger: #ff5c7a;
  --shadow: 0 16px 40px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 30% 20%, #3d2c83 0%, var(--bg1) 42%, #090d1d 100%);
  font-family: ui-rounded, "Nunito", "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  touch-action: none;
  user-select: none;
}

.game-app {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
}

.asset-loader {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255,255,255,.95), rgba(255,255,255,0) 18%),
    radial-gradient(circle at 78% 22%, rgba(255,209,102,.42), rgba(255,209,102,0) 24%),
    linear-gradient(135deg, #071023 0%, #133d58 46%, #21104a 100%);
  backdrop-filter: blur(10px);
}

.game-app.is-loading .asset-loader {
  display: flex;
}

.loader-card {
  width: min(520px, 100%);
  border: 1px solid rgba(255,255,255,.62);
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 26px 80px rgba(8,37,26,.28);
  padding: clamp(20px, 5vw, 34px);
  text-align: center;
}

.brand-loader {
  position: relative;
  overflow: hidden;
  border-color: rgba(255,255,255,.74);
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(241,253,247,.92));
}

.brand-loader::before {
  content: "";
  position: absolute;
  inset: -45% -18% auto;
  height: 140px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.78), transparent);
  transform: rotate(-8deg) translateX(-55%);
  animation: loaderSweep 2.2s ease-in-out infinite;
  pointer-events: none;
}

.loader-eyebrow {
  margin: 0 0 12px;
  color: #0e6b40;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .12em;
  line-height: 1.2;
  text-transform: uppercase;
}

.loader-brand {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow: visible;
  color: #0f2438;
  white-space: nowrap;
  line-height: 1.08;
  font-size: clamp(28px, 10vw, 58px);
  font-weight: 950;
}

.loader-brand span {
  flex: 0 0 auto;
  display: inline-block;
  background: linear-gradient(135deg, #102033 0%, #0f766e 52%, #ffbf3d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  transform: translateX(-28px) translateY(8px) rotate(-5deg);
  animation: brandLetterIn .68s cubic-bezier(.18,.86,.25,1.18) forwards;
  animation-delay: calc(var(--i) * .075s);
}

.loader-card p {
  margin: 12px 0 0;
  color: #557086;
  line-height: 1.55;
}

.loader-bar {
  height: 10px;
  margin-top: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: #dceee7;
}

.loader-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f8a4c, #27c6a1, #ffbf3d);
  transition: width .25s ease;
}

@keyframes brandLetterIn {
  0% { opacity: 0; transform: translateX(-28px) translateY(8px) rotate(-5deg); }
  68% { opacity: 1; transform: translateX(3px) translateY(0) rotate(1deg); }
  100% { opacity: 1; transform: translateX(0) translateY(0) rotate(0); }
}

@keyframes loaderSweep {
  0%, 18% { transform: rotate(-8deg) translateX(-62%); }
  62%, 100% { transform: rotate(-8deg) translateX(62%); }
}

#gameWrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  pointer-events: none;
  z-index: 3;
}

.pill {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  border-radius: 18px;
  padding: 10px 12px;
}

.scoreBox {
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, auto));
  gap: 8px 12px;
  font-weight: 900;
  font-size: clamp(13px, 2vw, 18px);
  line-height: 1.1;
  text-shadow: 0 2px 0 rgba(0,0,0,.18);
}
.scoreBox span { color: var(--accent); }
.scoreBox .wide { grid-column: 1 / -1; color: var(--yellow); }

.lessonBox {
  text-align: center;
  justify-self: center;
  max-width: min(560px, 58vw);
  padding: 10px 14px;
  font-weight: 850;
  font-size: clamp(13px, 2vw, 18px);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lessonBox small {
  display: block;
  color: var(--muted);
  font-size: .78em;
  font-weight: 750;
  margin-top: 2px;
}

.rightHud {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  pointer-events: auto;
}

.tinyBtn {
  border: 0;
  color: var(--text);
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  min-width: 42px;
  min-height: 42px;
  border-radius: 14px;
  font-weight: 950;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,.16);
}
.tinyBtn:active { transform: translateY(2px) scale(.98); }
.hidden { display: none !important; }

.controls {
  position: absolute;
  z-index: 4;
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
  pointer-events: none;
}

.lanePad, .shapePad, .boostPad {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(10px);
  border-radius: 22px;
  padding: 8px;
  box-shadow: var(--shadow);
}

.lanePad {
  display: grid;
  grid-template-rows: repeat(3, 46px);
  gap: 7px;
  width: 62px;
}

.shapePad {
  display: grid;
  grid-template-columns: repeat(6, minmax(48px, 1fr));
  gap: 8px;
  justify-self: center;
  width: min(620px, 100%);
}

.boostPad { width: 84px; }

.controlBtn, .shapeBtn, .boostBtn {
  border: 0;
  border-radius: 16px;
  background: rgba(255,255,255,.13);
  color: var(--text);
  min-height: 46px;
  cursor: pointer;
  font-weight: 950;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10), 0 8px 20px rgba(0,0,0,.12);
  -webkit-tap-highlight-color: transparent;
}
.controlBtn { font-size: 20px; }
.shapeBtn {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 5px 4px 4px;
}
.shapeIcon {
  width: 32px;
  height: 32px;
  display: block;
}
.shapeBtn b {
  font-size: 10px;
  letter-spacing: .02em;
  line-height: 1;
  color: rgba(255,247,223,.83);
}
.shapeBtn.active {
  outline: 3px solid rgba(126,252,255,.75);
  background: rgba(126,252,255,.22);
  box-shadow: 0 0 22px rgba(126,252,255,.28), inset 0 0 0 1px rgba(255,255,255,.2);
}
.controlBtn:active, .shapeBtn:active, .boostBtn:active { transform: translateY(2px) scale(.98); }

.boostBtn {
  width: 100%;
  min-height: 160px;
  background: linear-gradient(180deg, rgba(255,209,102,.28), rgba(255,95,210,.18));
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1.05;
  padding: 10px;
}
.boostBtn.disabled {
  opacity: .55;
  filter: grayscale(.3);
}

.overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2.4vw, 22px);
  background: radial-gradient(circle at 45% 35%, rgba(126,252,255,.12), rgba(3,7,22,.76) 55%, rgba(3,7,22,.92));
  backdrop-filter: blur(8px);
}
.overlay.show { display: flex; }

.card {
  width: min(760px, 94vw);
  max-height: calc(100dvh - clamp(16px, 4vw, 44px));
  overflow: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, rgba(23,33,73,.92), rgba(17,14,52,.92));
  border: 1px solid rgba(255,255,255,.18);
  border-radius: clamp(16px, 4vw, 30px);
  padding: clamp(12px, min(4vw, 3dvh), 34px);
  box-shadow: 0 30px 90px rgba(0,0,0,.45);
  text-align: center;
  -webkit-overflow-scrolling: touch;
}
.card h1 {
  margin: 0 0 clamp(4px, 1dvh, 8px);
  font-size: clamp(26px, min(8vw, 9dvh), 66px);
  line-height: .92;
  letter-spacing: -.06em;
  text-shadow: 0 6px 0 rgba(0,0,0,.18);
}
.card h1 span { color: var(--accent); }
.card p {
  margin: clamp(6px, 1.4dvh, 10px) auto;
  max-width: 650px;
  font-size: clamp(13px, min(2.4vw, 2.7dvh), 20px);
  color: var(--muted);
  line-height: 1.4;
  font-weight: 720;
}

.menuLine {
  max-width: 54ch;
}

.difficultyPicker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 1.5vw, 10px);
  width: min(520px, 100%);
  margin: clamp(10px, 2dvh, 18px) auto;
}

.difficultyBtn,
.secondaryBtn {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255,255,255,.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 10px 20px rgba(0,0,0,.18);
  cursor: pointer;
  font: inherit;
  font-weight: 950;
}

.difficultyBtn {
  min-height: clamp(42px, 9dvh, 56px);
  padding: 8px;
}

.difficultyBtn.active {
  color: #15122b;
  background: linear-gradient(135deg, var(--accent), var(--yellow));
  box-shadow: 0 0 24px rgba(126,252,255,.25), 0 12px 24px rgba(0,0,0,.2);
}

.menuActions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(520px, 100%);
  margin-inline: auto;
  gap: clamp(8px, 1.8dvh, 12px);
  margin-top: clamp(8px, 2dvh, 16px);
}

.secondaryBtn {
  min-height: clamp(44px, 8dvh, 56px);
  padding: 12px 22px;
}

.menuActions .bigBtn,
.menuActions .secondaryBtn {
  width: 100%;
  min-width: 0;
}

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

.gameOverActions .bigBtn,
.gameOverActions .secondaryBtn {
  width: 100%;
  min-width: 0;
}

.instructionsCard {
  width: min(860px, 96vw);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.instructionScroll {
  min-height: 0;
  max-height: min(62dvh, 560px);
  overflow: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.instructionGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 1.6vw, 12px);
  text-align: left;
}

.instructionGrid article {
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  align-items: start;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  padding: clamp(10px, 2vw, 14px);
  background: rgba(255,255,255,.09);
}

.instructionGrid strong {
  display: block;
  color: var(--yellow);
  font-size: clamp(14px, 2vw, 17px);
}

.instructionGrid p {
  grid-column: 2;
  margin: 4px 0 0;
  font-size: clamp(12px, min(2vw, 2.4dvh), 15px);
  line-height: 1.36;
}

.instructionIcon {
  grid-row: span 2;
  width: clamp(42px, 9vw, 56px);
  height: clamp(42px, 9vw, 56px);
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(126,252,255,.14);
  border: 1px solid rgba(126,252,255,.34);
  color: var(--accent);
  font-size: clamp(15px, 4vw, 22px);
  font-weight: 1000;
  box-shadow: 0 0 18px rgba(126,252,255,.22);
}

.shapeIconText { color: var(--yellow); }
.gemIcon { color: var(--yellow); }
.hazardIcon {
  color: var(--danger);
  background: rgba(255,92,122,.12);
  border-color: rgba(255,92,122,.38);
  box-shadow: 0 0 18px rgba(255,92,122,.2);
}
.shieldIcon {
  color: var(--green);
  background: rgba(115,255,146,.12);
  border-color: rgba(115,255,146,.38);
  box-shadow: 0 0 18px rgba(115,255,146,.22);
}

.iconFrame {
  overflow: visible;
}

.instructionSvg {
  width: 84%;
  height: 84%;
  overflow: visible;
}

.hazardSvg {
  filter: drop-shadow(0 0 8px rgba(255,92,122,.7));
}

.hazardSvg path {
  fill: #ff5c7a;
  stroke: rgba(255,255,255,.8);
  stroke-width: 2;
  stroke-linejoin: round;
}

.hazardSvg circle {
  fill: #2b1030;
}

.shieldSvg {
  filter: drop-shadow(0 0 8px rgba(115,255,146,.72));
}

.shieldBody {
  fill: #73ff92;
  stroke: rgba(255,255,255,.92);
  stroke-width: 3.5;
  stroke-linejoin: round;
}

.shieldSplit {
  fill: none;
  stroke: rgba(15,55,45,.45);
  stroke-width: 2;
  stroke-linecap: round;
}

.shieldCheck {
  fill: none;
  stroke: rgba(255,255,255,.82);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.closeInstructionBtn {
  justify-self: center;
  margin-top: clamp(10px, 2dvh, 16px);
}
.how {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
  text-align: left;
}
.how div {
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 12px;
  min-height: 92px;
  font-weight: 800;
  color: rgba(255,247,223,.9);
}
.how strong {
  display: block;
  color: var(--yellow);
  margin-bottom: 6px;
  font-size: 1.08em;
}

.bigBtn {
  border: 0;
  border-radius: 22px;
  padding: 15px 26px;
  min-width: min(320px, 82vw);
  background: linear-gradient(135deg, var(--yellow), var(--pink));
  color: #17112c;
  font-weight: 1000;
  letter-spacing: -.02em;
  font-size: clamp(18px, 3vw, 24px);
  cursor: pointer;
  box-shadow: 0 18px 34px rgba(0,0,0,.28), inset 0 -3px 0 rgba(0,0,0,.16);
}
.bigBtn:active { transform: translateY(3px); }

.miniStats {
  margin-top: 14px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.miniStats span {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 850;
  color: rgba(255,247,223,.9);
}

@media (max-width: 740px) {
  .hud { grid-template-columns: 1fr auto; }
  .lessonBox {
    grid-column: 1 / -1;
    order: 3;
    max-width: 100%;
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
  }
  .scoreBox { grid-template-columns: repeat(2, minmax(60px, auto)); padding: 8px 10px; }
  .controls { grid-template-columns: 54px 1fr 62px; gap: 8px; }
  .lanePad { width: 54px; grid-template-rows: repeat(3, 42px); gap: 6px; padding: 6px; border-radius: 18px; }
  .shapePad { grid-template-columns: repeat(3, minmax(42px, 1fr)); gap: 6px; padding: 6px; border-radius: 18px; }
  .boostPad { width: 62px; padding: 6px; border-radius: 18px; }
  .boostBtn { min-height: 134px; font-size: 12px; padding: 6px; border-radius: 14px; }
  .shapeIcon { width: 25px; height: 25px; }
  .shapeBtn b { display: none; }
  .how { grid-template-columns: 1fr; }
  .how div { min-height: auto; }
  .difficultyPicker { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .difficultyBtn { min-height: 38px; padding: 6px 4px; font-size: 13px; }
  .menuActions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .menuActions .bigBtn, .menuActions .secondaryBtn { min-width: 0; width: 100%; }
  .gameOverActions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
  .gameOverActions .bigBtn, .gameOverActions .secondaryBtn { min-width: 0; width: 100%; }
  .instructionGrid { grid-template-columns: 1fr; }
  .instructionScroll { max-height: min(60dvh, 520px); }
}

@media (max-height: 590px) {
  .lessonBox { display: none; }
  .controls { bottom: 6px; }
  .shapePad { grid-template-columns: repeat(6, minmax(36px, 1fr)); }
  .shapeBtn { min-height: 38px; }
  .shapeIcon { width: 24px; height: 24px; }
  .lanePad { grid-template-rows: repeat(3, 38px); }
  .boostBtn { min-height: 122px; }
  .card { padding: 18px; }
  .card p { font-size: 14px; }
  .how { margin: 12px 0; }
  .difficultyPicker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 8px auto;
  }
  .difficultyBtn { min-height: 36px; padding: 6px; }
  .menuActions { margin-top: 8px; }
  .gameOverActions { margin-top: 8px; }
  .bigBtn, .secondaryBtn {
    min-height: 40px;
    padding: 9px 16px;
    font-size: 16px;
  }
  .instructionScroll { max-height: 54dvh; }
  .instructionGrid { gap: 7px; }
  .instructionGrid article { padding: 8px; }
  .instructionIcon { width: 38px; height: 38px; border-radius: 12px; }
}

@media (max-width: 360px), (max-height: 430px) {
  .card h1 { font-size: clamp(22px, min(7vw, 8dvh), 38px); }
  .card p { font-size: 12px; line-height: 1.3; }
  .difficultyBtn { min-height: 34px; }
  .menuActions .bigBtn, .menuActions .secondaryBtn {
    min-height: 36px;
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 14px;
  }
  .gameOverActions .bigBtn, .gameOverActions .secondaryBtn {
    min-height: 36px;
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 14px;
  }
  .instructionGrid p { font-size: 12px; }
}
