:root {
  --night: #061523;
  --deep: #09283a;
  --cream: #fff8d8;
  --gold: #ffd85c;
  --mint: #7fffd1;
  --coral: #ff8d78;
  --glass: rgba(5, 27, 38, .72);
  color-scheme: dark;
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #020a12;
  color: var(--cream);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--night);
  isolation: isolate;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}

.screen.is-active { display: block; }

.start-screen {
  background: #071827 url("assets/start-forest.webp") center/cover no-repeat;
}

.shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(2, 12, 21, .76) 0%, rgba(2, 12, 21, .08) 29%, rgba(2, 12, 21, .05) 58%, rgba(2, 12, 21, .84) 100%),
    radial-gradient(circle at 50% 42%, transparent 20%, rgba(1, 10, 18, .36) 100%);
}

.brandbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 18px 0;
}

.kasaloma-logo {
  width: clamp(112px, 29vw, 148px);
  height: auto;
  object-fit: contain;
}

.quick-controls { display: flex; gap: 8px; }

.icon-button, .hud-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 50%;
  color: white;
  background: rgba(4, 21, 32, .56);
  backdrop-filter: blur(9px);
  cursor: pointer;
}

.icon-button[aria-pressed="false"] { opacity: .68; }

.title-lockup {
  position: absolute;
  z-index: 2;
  top: clamp(112px, 17dvh, 180px);
  left: 24px;
  right: 24px;
  text-align: center;
  text-shadow: 0 3px 18px rgba(0,0,0,.8);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .19em;
}

h1 {
  max-width: 610px;
  margin: 0 auto;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.45rem, 10vw, 5.2rem);
  line-height: .88;
  letter-spacing: -.045em;
}

h1 span {
  display: block;
  margin-bottom: .06em;
  color: var(--mint);
  font-size: .55em;
  font-style: italic;
  letter-spacing: -.02em;
}

.intro {
  max-width: 360px;
  margin: 16px auto 0;
  color: rgba(255, 248, 216, .88);
  font-size: clamp(.95rem, 3.4vw, 1.14rem);
  line-height: 1.35;
}

.start-actions {
  position: absolute;
  z-index: 2;
  left: 20px;
  right: 20px;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 14px));
  display: grid;
  justify-items: center;
  gap: 9px;
}

.play-button {
  min-width: min(82vw, 350px);
  min-height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 999px;
  background: linear-gradient(135deg, #59f0c3, #27bfa8 55%, #179b98);
  color: #042b31;
  font-weight: 1000;
  font-size: 1.08rem;
  letter-spacing: .12em;
  box-shadow: 0 9px 30px rgba(38, 222, 177, .34), inset 0 1px rgba(255,255,255,.66);
  cursor: pointer;
}

.play-button:active { transform: translateY(2px) scale(.99); }

.play-triangle {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid #07353b;
}

.tiny-note {
  margin: 0;
  color: rgba(255,255,255,.72);
  font-size: .76rem;
  letter-spacing: .08em;
}

.panel-screen {
  background: #061a28;
}

.panel-backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(3,18,29,.58), rgba(3,18,29,.84)),
    url("assets/start-forest.webp") center/cover no-repeat;
  filter: saturate(.75);
}

.panel-header {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  text-align: center;
}

.panel-header .eyebrow { margin: 0 0 2px; font-size: .62rem; }

.panel-header h2 {
  margin: 0;
  font: 700 clamp(1.45rem, 6vw, 2.1rem)/1 Georgia, serif;
}

.help-button { font-weight: 900; }

.tutorial-track {
  position: absolute;
  z-index: 2;
  inset: max(92px, calc(env(safe-area-inset-top) + 80px)) 20px 150px;
  display: grid;
  place-items: center;
}

.tutorial-card {
  display: none;
  width: min(100%, 420px);
  padding: clamp(22px, 5dvh, 38px) 24px 28px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 32px;
  background: linear-gradient(160deg, rgba(12,62,65,.93), rgba(4,30,43,.96));
  box-shadow: 0 25px 60px rgba(0,0,0,.34);
  text-align: center;
}

.tutorial-card.is-current { display: block; }
.tutorial-card strong { display: block; margin-top: 20px; font: 700 1.55rem/1.1 Georgia, serif; }
.tutorial-card p { margin: 8px 0 0; color: rgba(255,255,255,.74); font-size: .95rem; line-height: 1.45; }

.tutorial-picture {
  position: relative;
  width: min(76vw, 280px);
  height: clamp(150px, 25dvh, 210px);
  margin: 0 auto;
  border-radius: 24px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, rgba(88,198,160,.2), rgba(3,22,34,.54));
}

.demo-firefly, .demo-flower, .match-mark {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 900;
}

.demo-firefly {
  left: 22%;
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  color: #15343a;
  box-shadow: 0 0 24px currentColor;
}

.demo-firefly::before, .demo-firefly::after {
  content: "";
  position: absolute;
  top: 5px;
  width: 22px;
  height: 13px;
  border-radius: 50%;
  background: rgba(235,255,255,.73);
}

.demo-firefly::before { left: -16px; transform: rotate(-28deg); }
.demo-firefly::after { right: -16px; transform: rotate(28deg); }
.demo-firefly.yellow { left: 50%; background: var(--gold); box-shadow: 0 0 28px rgba(255,216,92,.8); }
.demo-firefly.mint { background: var(--mint); box-shadow: 0 0 28px rgba(127,255,209,.75); }
.demo-firefly.coral { background: var(--coral); box-shadow: 0 0 28px rgba(255,141,120,.75); }

.tap-ripple {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 82px;
  height: 82px;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.75);
  border-radius: 50%;
  animation: tap 1.6s infinite;
}

@keyframes tap { from { opacity: .8; transform: translate(-50%, -50%) scale(.58); } to { opacity: 0; transform: translate(-50%, -50%) scale(1.25); } }

.demo-flower {
  right: 10%;
  top: 50%;
  width: 58px;
  height: 58px;
  transform: translateY(-50%);
  border: 8px dotted currentColor;
  background: rgba(255,255,255,.9);
  color: #15343a;
}

.demo-flower.mint { box-shadow: 0 0 25px rgba(127,255,209,.55); }
.demo-flower.coral { box-shadow: 0 0 25px rgba(255,141,120,.55); }

.demo-trail {
  position: absolute;
  left: 29%;
  right: 29%;
  top: 50%;
  height: 8px;
  margin-top: -4px;
  border-radius: 10px;
  background: var(--mint);
  box-shadow: 0 0 15px rgba(127,255,209,.8);
  transform: rotate(-7deg);
}

.match-mark {
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,.12);
  color: var(--mint);
  font-size: 1.5rem;
}

.tutorial-footer {
  position: absolute;
  z-index: 3;
  left: 20px;
  right: 20px;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px));
  display: grid;
  justify-items: center;
  gap: 9px;
}

.step-dots { display: flex; gap: 7px; }
.step-dots span { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.28); }
.step-dots span.active { width: 24px; border-radius: 10px; background: var(--gold); }

.text-button {
  min-height: 34px;
  padding: 4px 16px;
  border: 0;
  color: rgba(255,255,255,.68);
  background: transparent;
  cursor: pointer;
}

.text-button.light { color: rgba(255,255,255,.82); text-decoration: underline; text-underline-offset: 4px; }

.chapter-progress {
  position: relative;
  z-index: 2;
  width: min(calc(100% - 40px), 430px);
  margin: 12px auto 0;
  color: rgba(255,255,255,.78);
  font-size: .82rem;
  text-align: center;
}

.chapter-switcher {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px 0;
}

.chapter-chip {
  flex: 1 1 0;
  max-width: 132px;
  min-height: 42px;
  padding: 0 8px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  color: rgba(255,255,255,.72);
  background: rgba(3,25,36,.58);
  font-size: clamp(.64rem, 2.7vw, .76rem);
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.chapter-chip span { margin-right: 4px; color: var(--gold); font-size: 1rem; }
.chapter-chip.active { border-color: rgba(127,255,209,.7); color: #062f36; background: var(--mint); }
.chapter-chip.active span { color: #064047; }
.chapter-chip.locked { opacity: .58; }

.chapter-progress > div {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(255,255,255,.14);
}

.chapter-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--mint), var(--gold)); transition: width .35s ease; }

.level-path {
  position: relative;
  z-index: 2;
  width: min(calc(100% - 42px), 430px);
  height: min(62dvh, 540px);
  margin: 16px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 7px 48px;
}

.level-path::before {
  content: "";
  position: absolute;
  inset: 11% 25% 12%;
  border: 3px dashed rgba(255,216,92,.28);
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}

.level-node {
  position: relative;
  align-self: center;
  justify-self: center;
  width: 92px;
  border: 0;
  color: white;
  background: transparent;
  cursor: pointer;
}

.level-node:nth-child(2), .level-node:nth-child(3), .level-node:nth-child(6) { transform: translateY(16px); }
.level-node:nth-child(3) { grid-column: 2; }
.level-node:nth-child(4) { grid-column: 1; grid-row: 2; }
.level-node:nth-child(5) { grid-column: 1; grid-row: 3; }
.level-node:nth-child(6) { grid-column: 2; grid-row: 3; }

.level-node span {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 7px;
  border: 2px solid rgba(255,255,255,.74);
  border-radius: 50%;
  background: linear-gradient(145deg, #2c987f, #0c4e54);
  box-shadow: 0 8px 24px rgba(0,0,0,.28), 0 0 20px rgba(127,255,209,.2);
  font-size: 1.25rem;
  font-weight: 900;
}

.level-node.complete span { border-color: var(--gold); background: linear-gradient(145deg, #ffe47d, #df9d28); color: #4c3307; box-shadow: 0 0 25px rgba(255,216,92,.42); }
.level-node:disabled { opacity: .38; cursor: default; }
.level-node:disabled span { background: rgba(7,34,44,.8); }
.level-node small { display: block; min-height: 30px; color: rgba(255,255,255,.86); font-size: .7rem; line-height: 1.25; }

.map-note {
  position: absolute;
  z-index: 2;
  left: 24px;
  right: 24px;
  bottom: max(15px, calc(env(safe-area-inset-bottom) + 9px));
  margin: 0;
  color: rgba(255,255,255,.62);
  font-size: .76rem;
  text-align: center;
}

.play-screen { background: #061c26; }

.play-backdrop {
  position: absolute;
  inset: 0;
  background: url("assets/start-forest.webp") center/cover no-repeat;
  filter: saturate(.76) brightness(.51) blur(1px);
  transform: scale(1.02);
}

.puddle-active .play-backdrop { background-image: url("assets/puddle-patch.webp"); background-position: center; }
.puddle-active .panel-backdrop {
  background:
    linear-gradient(180deg, rgba(3,18,29,.58), rgba(3,18,29,.84)),
    url("assets/puddle-patch.webp") center/cover no-repeat;
}

.puddle-active .play-backdrop { filter: saturate(.88) brightness(.54) blur(1px); }

.breeze-active .play-backdrop { background-image: url("assets/breezy-grove.webp"); background-position: center; filter: saturate(.82) brightness(.52) blur(1px); }
.breeze-active .panel-backdrop {
  background:
    linear-gradient(180deg, rgba(3,18,29,.58), rgba(3,18,29,.84)),
    url("assets/breezy-grove.webp") center/cover no-repeat;
}

.play-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2,14,24,.7), rgba(4,33,39,.18) 30%, rgba(1,16,24,.78));
}

.game-hud {
  position: absolute;
  z-index: 3;
  top: max(10px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  height: 54px;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 9px;
}

.hud-button { font-size: 1.25rem; }

.level-copy { min-width: 0; }
.level-copy span { display: block; color: var(--gold); font-size: .62rem; font-weight: 900; letter-spacing: .13em; }
.level-copy strong { display: block; margin-top: 2px; font-size: 1rem; }

.flower-count {
  min-width: 78px;
  padding: 10px 13px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: var(--glass);
  text-align: center;
  font-weight: 900;
  backdrop-filter: blur(8px);
}

.instruction {
  position: absolute;
  z-index: 3;
  top: max(76px, calc(env(safe-area-inset-top) + 68px));
  left: 50%;
  width: min(88%, 430px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(3, 22, 31, .76);
  color: rgba(255,255,255,.9);
  text-align: center;
  font-size: .78rem;
  line-height: 1.3;
  backdrop-filter: blur(8px);
}

#gameCanvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.restart-button {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  min-height: 46px;
  transform: translateX(-50%);
  padding: 0 20px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 999px;
  color: white;
  background: rgba(3, 22, 31, .74);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.celebration {
  position: absolute;
  z-index: 9;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(1, 10, 17, .7);
  backdrop-filter: blur(7px);
}

.celebration[hidden] { display: none; }

.celebration-card {
  width: min(100%, 390px);
  padding: 28px 24px 24px;
  border: 1px solid rgba(255,255,255,.27);
  border-radius: 32px;
  background: linear-gradient(160deg, rgba(15,65,65,.96), rgba(5,29,40,.98));
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
  text-align: center;
}

.bloom-mark { color: var(--gold); font-size: 4.2rem; filter: drop-shadow(0 0 18px rgba(255,216,92,.62)); }
.celebration-card h2 { margin: 7px 0; font: 700 2rem/1 Georgia, serif; }
.celebration-card p:not(.eyebrow) { margin: 10px auto 22px; color: rgba(255,255,255,.78); line-height: 1.45; }
.play-button.compact { min-width: 220px; min-height: 54px; font-size: .88rem; }
.result-actions { display: grid; justify-items: center; gap: 8px; }

button:focus-visible { outline: 3px solid white; outline-offset: 3px; }

.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}

@media (min-width: 761px) {
  body { background: radial-gradient(circle, #143f48, #020a12 67%); }
  .game-shell { box-shadow: 0 0 80px rgba(0,0,0,.7); }
}

@media (max-height: 680px) {
  .title-lockup { top: 92px; }
  h1 { font-size: clamp(2.1rem, 9vw, 3.5rem); }
  .intro { margin-top: 10px; }
  .play-button { min-height: 54px; }
  .tutorial-track { top: 78px; bottom: 128px; }
  .tutorial-card { padding: 15px 20px 18px; }
  .tutorial-picture { height: 130px; }
  .tutorial-card strong { margin-top: 12px; font-size: 1.3rem; }
  .level-path { height: 55dvh; margin-top: 8px; }
  .level-node span { width: 54px; height: 54px; }
}
