:root {
  --ink: #1a3d5c;
  --ink-soft: #4a6d8c;
  --danger: #e63946;
  --ok: #2fae4a;
  --gold: #f5b400;
  --frame-w: min(100vw, calc(100dvh * 9 / 16));
  --frame-h: min(100dvh, calc(100vw * 16 / 9));
  --font-en: "Nunito", system-ui, sans-serif;
  --font-km: "Kantumruy Pro", "Nunito", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a2540;
  font-family: var(--font-en);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.app-shell {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 15%, #1e6fa8 0%, transparent 50%), #0a2540;
}

.phone {
  position: relative;
  width: var(--frame-w);
  height: var(--frame-h);
  overflow: hidden;
  /* border-radius: clamp(14px, 2.2vw, 30px); */
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.12),
    0 24px 80px rgba(0, 0, 0, 0.55);
  background: #5ec8ff;
}

.phone--km {
  font-family: var(--font-km);
}

.phone--en {
  font-family: var(--font-en);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(10px, 2.8vh, 24px) clamp(12px, 3.5vw, 24px);
  overflow: hidden;
}

.screen[hidden] {
  display: none !important;
}

.screen__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  z-index: 0;
}

.screen > *:not(.screen__bg) {
  position: relative;
  z-index: 1;
}

/* Image buttons — chrome only, text baked in asset */
.img-btn {
  position: relative;
  display: block;
  border: 0;
  padding: 0;
  background: transparent !important;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  width: min(82%, 360px);
  transition: transform 0.1s ease;
}

.img-btn:active:not(:disabled) {
  transform: scale(0.96) translateY(2px);
}

.img-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.img-btn__img {
  width: 100%;
  height: auto;
  max-height: clamp(64px, 12vh, 96px);
  object-fit: contain;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 6px 12px rgba(0, 60, 100, 0.25));
  background: transparent;
}


.img-btn--hint {
  width: min(52%, 220px);
}

.hint-badge {
  position: absolute;
  top: 8%;
  right: 6%;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #ff5a5a;
  color: #fff;
  font-weight: 900;
  font-size: clamp(14px, 3.8vw, 18px);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.icon-btn {
  width: clamp(48px, 12vw, 60px);
  height: clamp(48px, 12vw, 60px);
  border: 0;
  padding: 0;
  background: transparent !important;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0, 60, 100, 0.2));
}

/* HOME */
.home-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.home-hero {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 0;
  padding: 0.25rem 0 1rem;
  overflow: hidden;
}

.home-logo {
  width: min(92%, 340px);
  max-height: min(42vh, 300px);
  height: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 1;
  filter: drop-shadow(0 8px 20px rgba(0, 60, 120, 0.3));
  animation: logo-float 3s ease-in-out infinite;
}

@keyframes logo-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.home-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: 0.5rem;
}

.text-btn {
  border: 0;
  background: rgba(8, 40, 70, 0.55);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: clamp(16px, 4.2vw, 20px);
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
}

.text-btn:active {
  transform: scale(0.96);
}

/* PLAY — 70–90% game area */
.play-hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.play-hud__spacer {
  width: clamp(48px, 12vw, 60px);
}

.play-hud__panel {
  position: relative;
  display: flex;
  justify-content: space-around;
  align-items: center;
  min-height: clamp(54px, 8.5vh, 76px);
  padding: 0.35rem 0.75rem;
  background: rgba(8, 32, 58, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 6px 18px rgba(0, 20, 50, 0.25);
}

.play-hud__panel-bg {
  display: none;
}

.play-hud__row {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  min-width: 4.5rem;
}

.play-hud__label {
  font-size: clamp(11px, 2.8vw, 14px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.72);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.play-hud__value {
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.play-hud__row.is-urgent .play-hud__value {
  color: #ff6b6b;
  animation: pulse 0.55s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.1);
  }
}

.play-prompt {
  margin: 0.35rem auto 0.25rem;
  text-align: center;
  font-size: clamp(14px, 3.6vw, 18px);
  font-weight: 800;
  color: #fff;
  background: rgba(8, 32, 58, 0.6);
  padding: 0.28rem 0.9rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  width: fit-content;
  max-width: 92%;
}

.play-level {
  margin: 0.1rem auto 0.2rem;
  text-align: center;
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(8, 40, 70, 0.35);
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  width: fit-content;
  max-width: 92%;
}

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: clamp(6px, 1.6vw, 12px);
  align-content: center;
  justify-content: center;
  min-height: 0;
  padding: 0.2rem 0;
  width: 100%;
  max-width: 100%;
}

.board--ok {
  animation: board-pop 0.3s ease;
}

.board--bad {
  animation: shake 0.22s linear;
}

@keyframes board-pop {
  50% {
    transform: scale(1.02);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(7px);
  }
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  background: rgba(8, 35, 60, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 22%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    0 4px 14px rgba(0, 30, 60, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.1s ease;
  overflow: hidden;
}

.cell:active:not(:disabled) {
  transform: scale(0.94);
}

.cell__object {
  position: absolute;
  inset: 2%;
  width: 96%;
  height: 96%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0, 30, 60, 0.25));
}

.cell--hint {
  border-color: #ffd24a;
  box-shadow: 0 0 16px rgba(255, 210, 74, 0.85);
  animation: hint-glow 0.8s ease-in-out infinite;
}

@keyframes hint-glow {
  50% {
    box-shadow: 0 0 22px rgba(255, 210, 74, 1);
  }
}

.play-footer {
  display: grid;
  place-items: center;
  padding-top: 0.25rem;
  flex-shrink: 0;
}

.img-btn--hint {
  width: min(52%, 220px);
}

/* RESULT — one primary action */
.screen--result {
  justify-content: flex-start;
  gap: 0.75rem;
  padding-top: clamp(10px, 2.5vh, 20px);
}

.screen--result::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(6, 28, 52, 0.5);
  z-index: 0;
  pointer-events: none;
}

.result-celebrate {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  opacity: 0;
  animation: confetti-burst 1.1s ease-out forwards;
}

.confetti--rect {
  width: clamp(7px, 1.8vw, 11px);
  height: clamp(12px, 3vw, 18px);
  border-radius: 2px;
}

.confetti--circle {
  width: clamp(8px, 2vw, 12px);
  height: clamp(8px, 2vw, 12px);
  border-radius: 50%;
}

.confetti--star {
  width: clamp(10px, 2.4vw, 14px);
  height: clamp(10px, 2.4vw, 14px);
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}

@keyframes confetti-burst {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.5);
  }
}

.result-card.is-celebrate {
  animation: result-card-pop 0.55s cubic-bezier(0.2, 1.35, 0.4, 1) both;
}

@keyframes result-card-pop {
  0% {
    transform: scale(0.92);
  }
  55% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

.result-title.is-win-pop {
  animation: result-title-pop 0.65s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes result-title-pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  60% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.result-top__spacer {
  width: clamp(48px, 12vw, 60px);
}

.result-card {
  position: relative;
  width: min(88%, 360px);
  margin: auto 0 0;
  background: rgba(10, 36, 64, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 28px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 18px 44px rgba(0, 15, 40, 0.4);
  overflow: hidden;
}

.result-card__bg {
  display: none;
}

.result-card__body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 1.5rem 1.1rem 1.35rem;
  text-align: center;
}

.result-kicker {
  margin: 0;
  font-size: clamp(13px, 3.4vw, 16px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.result-title {
  margin: 0;
  font-size: clamp(34px, 9vw, 48px);
  font-weight: 900;
  line-height: 1.05;
  color: #fff;
}

.result-title.is-clear {
  color: #5dff7a;
  text-shadow: 0 3px 0 rgba(20, 120, 40, 0.45);
}

.result-title.is-fail {
  color: #ff6b6b;
  text-shadow: 0 3px 0 rgba(140, 20, 30, 0.4);
}

.result-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.15rem;
  padding: 0.55rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  min-width: 70%;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 4.5rem;
}

.result-stat__label {
  font-weight: 800;
  font-size: clamp(11px, 2.8vw, 13px);
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
}

.result-stat__value {
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 900;
  color: #fff;
  line-height: 1;
}

.result-stat__divider {
  width: 2px;
  height: 2.2rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.result-score,
.result-score__label,
.result-score__value {
  display: none;
}

.result-best {
  margin: 0.2rem 0 0;
  font-size: clamp(14px, 3.5vw, 17px);
  font-weight: 800;
  color: #ffd24a;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  max-width: 18ch;
  line-height: 1.3;
  min-height: 1.3em;
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  margin-top: auto;
  padding-bottom: 0.6rem;
}

.cta-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  letter-spacing: 0.02em;
  transition: transform 0.1s ease;
  appearance: none;
  -webkit-appearance: none;
}

.cta-btn:active {
  transform: scale(0.97) translateY(2px);
}

.cta-btn--primary {
  width: min(78%, 300px);
  min-height: clamp(56px, 9vh, 72px);
  border-radius: 999px;
  color: #fff;
  font-size: clamp(22px, 5.5vw, 30px);
  background: linear-gradient(180deg, #ffd24a 0%, #ff9a1a 55%, #f07800 100%);
  box-shadow:
    0 6px 0 #c45e00,
    0 12px 24px rgba(0, 30, 60, 0.3);
  text-shadow: 0 2px 0 rgba(160, 70, 0, 0.35);
}

.cta-btn--text {
  width: auto;
  min-height: auto;
  padding: 0.35rem 0.8rem;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(15px, 3.8vw, 18px);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  box-shadow: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.stars {
  display: flex;
  gap: 0.45rem;
  justify-content: center;
  margin: 0.15rem 0;
}

.stars__item {
  width: clamp(42px, 11vw, 58px);
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.stars__item--on {
  animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes pop {
  from {
    transform: scale(0.3) rotate(-20deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

.why-flash {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  pointer-events: none;
  background: rgba(8, 40, 70, 0.88);
  color: #fff;
  font-weight: 900;
  font-size: clamp(16px, 4.5vw, 22px);
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 2px solid #ffd24a;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* Beat .screen > * { z-index: 1 } so flash sits above the board */
.screen > .why-flash {
  z-index: 20;
}

.why-flash--pop {
  animation: why-pop 0.9s ease both;
}

@keyframes why-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.7) translateY(8px);
  }
  20% {
    opacity: 1;
    transform: translateX(-50%) scale(1.05) translateY(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* LEVEL MAP */
.screen--map {
  gap: 0.5rem;
}

.map-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.4rem;
}

.map-top__spacer {
  width: clamp(48px, 12vw, 60px);
}

.map-title {
  margin: 0;
  text-align: center;
  font-size: clamp(20px, 5.5vw, 28px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.map-world {
  margin: 0;
  text-align: center;
  font-size: clamp(13px, 3.5vw, 16px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(8, 32, 58, 0.55);
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  width: fit-content;
  align-self: center;
}

.map-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(8px, 2vw, 12px);
  align-content: start;
  overflow: auto;
  padding: 0.4rem 0.1rem 0.8rem;
  min-height: 0;
}

.map-node {
  aspect-ratio: 1;
  border: 0;
  border-radius: 22%;
  background: rgba(12, 45, 80, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  cursor: pointer;
  padding: 0.2rem;
  box-shadow: 0 4px 12px rgba(0, 20, 50, 0.25);
}

.map-node:active:not(:disabled) {
  transform: scale(0.94);
}

.map-node--locked,
.map-node:disabled {
  opacity: 0.45;
  cursor: default;
  filter: grayscale(0.4);
}

.map-node__id {
  font-size: clamp(16px, 4.5vw, 22px);
  font-weight: 900;
  line-height: 1;
}

.map-node__stars {
  font-size: clamp(9px, 2.4vw, 11px);
  letter-spacing: -0.05em;
  color: #ffd24a;
}
