:root {
  --primary: #3eb5a8;
  --primary-dark: #2f9a7a;
  --primary-light: #e8f8f6;
  --secondary: #5db5f2;
  --secondary-dark: #3d8fe8;
  --highlight: rgba(62, 181, 168, 0.22);
  --highlight-preview: rgba(62, 181, 168, 0.14);
  --ink: #2b2b2f;
  --muted: #8a8a90;
  --line: #d8ece9;
  --bg: #f7f8fb;
  --gold: #ffd65a;
  --gold-dark: #c99a12;
  --sky-top: #5fe3d6;
  --sky-mid: #3eb5a8;
  --sky-deep: #268f73;
  /* WebP backgrounds — see assets/bg/manifest.txt (no SVG) */
  --bg-start-image: url("assets/bg/start_bg.webp");
  --bg-levels-image: url("assets/bg/levels_bg.webp");
  --bg-game-image: url("assets/bg/game_bg.webp");
  --bg-result-image: url("assets/bg/result_bg.webp");
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.95) 0 9%, transparent 10%),
    radial-gradient(circle at 82% 92%, rgba(93, 181, 242, 0.45) 0 22%, transparent 23%),
    radial-gradient(circle at 8% 88%, rgba(62, 181, 168, 0.4) 0 18%, transparent 19%),
    linear-gradient(155deg, #a8e3d9 0%, #c8eee8 42%, #e4f7f3 100%);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.phone-frame {
  position: relative;
  width: min(100vw, 430px);
  height: min(100vh, 932px);
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-mid) 0%, var(--sky-deep) 100%);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.45),
    0 28px 60px rgba(20, 70, 90, 0.38);
}

h1,
h2,
p {
  margin: 0;
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}

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

.screen.is-active.screen-enter {
  animation: screen-enter 0.38s ease-out;
}

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.screen-start,
.screen-result {
  padding: 0;
  overflow: hidden;
}

/* App bar */
.app-bar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  height: 56px;
  padding: 0 12px;
  background: linear-gradient(180deg, #55d4c8 0%, var(--primary) 100%);
  color: #ffffff;
}

.app-bar-title {
  font-size: 19px;
  font-weight: 700;
  text-align: center;
}

.app-bar-side {
  display: block;
}

.app-bar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
}

.chevron {
  width: 10px;
  height: 10px;
  border-left: 2.5px solid #ffffff;
  border-bottom: 2.5px solid #ffffff;
  transform: rotate(45deg);
}

/* Shared game buttons */
.btn-game {
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.42),
    0 5px 0 var(--primary-dark),
    0 8px 16px rgba(47, 154, 122, 0.28);
}

.btn-game:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 2px 0 var(--primary-dark),
    0 4px 10px rgba(47, 154, 122, 0.22);
}

.btn-primary {
  color: #ffffff;
  background: linear-gradient(180deg, #55d4c8 0%, var(--primary) 100%);
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  color: var(--primary-dark);
  background: linear-gradient(180deg, #ffffff 0%, var(--primary-light) 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    0 4px 0 #b8ddd8,
    0 6px 12px rgba(47, 154, 122, 0.14);
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 0 #b8ddd8;
}

/* Scene backgrounds — WebP image + CSS gradient fallback until art is ready */
.start-scene,
.result-scene,
.levels-scene {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  background-color: var(--sky-deep);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center top;
}

.start-scene {
  background-image:
    var(--bg-start-image),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-deep) 100%);
}

.levels-scene {
  background-image:
    var(--bg-levels-image),
    linear-gradient(180deg, #6ec4ff 0%, var(--sky-mid) 40%, var(--sky-deep) 100%);
}

.result-scene {
  background-image:
    var(--bg-result-image),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-deep) 100%);
}

.start-scene::before,
.levels-scene::before,
.start-scene::after,
.levels-scene::after {
  display: none;
}

.result-scene::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 38%,
    rgba(255, 255, 255, 0.28) 0%,
    rgba(180, 235, 228, 0.18) 40%,
    transparent 72%
  );
}

.result-scene.is-lose::before {
  background: radial-gradient(
    ellipse at 50% 38%,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 210, 220, 0.16) 40%,
    transparent 72%
  );
}

.start-scene,
.result-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 22px 36px;
}

.levels-scene {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 14px 24px;
}

.result-back {
  position: absolute;
  top: 16px;
  left: 14px;
  z-index: 2;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffe566 0%, #f5c832 100%);
  box-shadow: 0 5px 0 #c99a12, 0 8px 16px rgba(0, 0, 0, 0.18);
}

.result-back:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c99a12, 0 4px 10px rgba(0, 0, 0, 0.16);
}

.result-back-arrow {
  display: block;
  width: 14px;
  height: 14px;
  margin: 0 auto;
  border-left: 4px solid #ffffff;
  border-bottom: 4px solid #ffffff;
  transform: rotate(45deg) translate(2px, -2px);
}

.start-body,
.result-body {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 24px;
}

.start-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 320px;
  padding: 0;
  background: none;
  box-shadow: none;
  border-radius: 0;
  text-align: center;
}

.result-scene .result-back {
  z-index: 3;
}

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

.result-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 300px;
  padding: 20px 18px 18px;
  border-radius: 22px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.72) 0%,
    rgba(220, 248, 244, 0.78) 100%
  );
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 10px 28px rgba(47, 154, 122, 0.16);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-align: center;
}

.result-scene.is-lose .result-card {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 232, 238, 0.78) 100%
  );
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 10px 28px rgba(239, 98, 123, 0.14);
}

.result-card .btn-result-main {
  width: 100%;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.start-logo {
  width: 124px;
  height: 124px;
  margin: 0 auto 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(244, 251, 251, 0.92) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.9),
    0 8px 0 rgba(37, 143, 120, 0.35),
    0 14px 28px rgba(0, 0, 0, 0.2);
  animation: logo-float 3s ease-in-out infinite;
}

#startButton {
  animation: btn-idle 2.2s ease-in-out infinite;
}

#startButton:active {
  animation: none;
}

.start-logo span {
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink);
  font-size: 23px;
  font-weight: 800;
  box-shadow: 0 4px 0 #cce8e4;
}

.start-logo .marked {
  color: #ffffff;
  background: var(--secondary);
  box-shadow: 0 4px 0 var(--secondary-dark);
}

.start-logo span:nth-child(2),
.start-logo span:nth-child(4),
.start-logo span:nth-child(8) {
  background: var(--gold);
}

.start-heading,
.result-heading {
  font-size: 28px;
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0 2px 0 rgba(20, 80, 70, 0.45),
    0 4px 14px rgba(0, 0, 0, 0.22);
}

.start-hook {
  max-width: 260px;
  margin: 0 auto 14px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}

.start-card .btn-game {
  width: 100%;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.start-card .btn-primary {
  margin-top: 4px;
}

.start-card .btn-secondary {
  margin-top: 10px;
}

.start-settings {
  position: absolute;
  top: 16px;
  right: 14px;
  z-index: 2;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #e8f8f6 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    0 3px 0 #258f78;
}

.start-settings:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 0 #258f78;
}

.start-settings-icon {
  display: block;
  width: 16px;
  height: 16px;
  margin: 0 auto;
  border: 3px solid var(--primary-dark);
  border-radius: 50%;
  position: relative;
}

.start-settings-icon::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 7px;
  left: 50%;
  top: -5px;
  transform: translateX(-50%);
  background: var(--primary-dark);
  border-radius: 2px;
}

.start-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 10px auto 20px;
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #6ec4ff 0%, var(--secondary-dark) 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 4px 0 #2a6bb8;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

.start-progress-label {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.start-progress-value {
  font-variant-numeric: tabular-nums;
}

.start-progress-value::before {
  content: "* ";
  color: var(--gold);
}

.result-title {
  margin: 2px 0 8px;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #c99a12;
  line-height: 1.1;
}

.result-title.is-fail {
  font-size: 28px;
  letter-spacing: 0.02em;
  color: #e25570;
}

.result-meta {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--muted);
}

.result-share {
  margin: 0 0 6px;
  padding: 0;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--primary-dark);
  white-space: pre-line;
}

.result-share[hidden],
.btn-result-share[hidden] {
  display: none;
}

.btn-result-share {
  margin: 0 0 8px;
}

.btn-result-main {
  min-height: 58px;
  font-size: 22px;
  letter-spacing: 0.04em;
  animation: result-btn-pop 0.45s ease-out;
}

@keyframes result-btn-pop {
  0% {
    transform: scale(0.92);
    opacity: 0.6;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Buttons */
.btn {
  width: 100%;
  min-height: 52px;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.btn + .btn {
  margin-top: 10px;
}

.btn-plain {
  min-height: 44px;
  color: var(--primary-dark);
  background: transparent;
  font-weight: 700;
}

.btn-plain:active {
  opacity: 0.6;
}

/* Level select */
.screen-levels {
  padding: 0;
  overflow: hidden;
  background: var(--sky-deep);
}

.levels-back {
  position: absolute;
  top: 16px;
  left: 14px;
  z-index: 2;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffe566 0%, #f5c832 100%);
  box-shadow: 0 5px 0 #c99a12, 0 8px 16px rgba(0, 0, 0, 0.18);
}

.levels-back:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c99a12, 0 4px 10px rgba(0, 0, 0, 0.16);
}

.levels-back-arrow {
  display: block;
  width: 14px;
  height: 14px;
  margin: 0 auto;
  border-left: 4px solid #ffffff;
  border-bottom: 4px solid #ffffff;
  transform: rotate(45deg) translate(2px, -2px);
}

.levels-title {
  position: relative;
  z-index: 1;
  margin: 6px 0 8px;
  color: #ffffff;
  font-size: clamp(22px, 6.5vw, 30px);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  -webkit-text-stroke: 2px #173848;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #173848;
}

.levels-total {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 168px;
  margin-bottom: 14px;
  padding: 7px 16px 7px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #6ec4ff 0%, #3d8fe8 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), 0 4px 0 #2a6bb8;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
}

.levels-total-label {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.levels-total-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.levels-total-value::before {
  content: "*";
  color: #ffd84f;
  font-size: 16px;
  text-shadow: 0 1px 0 #b8860b;
}

.level-grid {
  position: relative;
  z-index: 1;
  width: min(100%, 370px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px 8px;
  margin: 0;
}

.level-card {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  aspect-ratio: 0.82;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #8ed8ff 0%, #5db5f2 48%, #3f96db 100%);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.5),
    0 6px 0 #1a4a72,
    0 10px 16px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.level-card:active:not(.is-locked) {
  transform: translateY(4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    0 2px 0 #1f4f7a,
    0 4px 10px rgba(0, 0, 0, 0.16);
}

.level-card.is-locked {
  pointer-events: none;
  background: linear-gradient(180deg, rgba(238, 250, 250, 0.92) 0%, rgba(178, 225, 225, 0.92) 100%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.72),
    0 5px 0 rgba(80, 138, 138, 0.72),
    0 9px 14px rgba(0, 0, 0, 0.12);
  filter: saturate(0.82);
}

.level-card.is-locked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, transparent 0 46%, rgba(255, 255, 255, 0.28) 47% 53%, transparent 54% 100%);
  pointer-events: none;
}

.level-card-face {
  display: grid;
  place-items: start center;
  padding-top: 10px;
  color: #ffffff;
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(16, 58, 98, 0.4);
}

.level-card.is-locked .level-card-face {
  color: #3e8f94;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 8px rgba(255, 255, 255, 0.35);
}

.level-card-stars {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 3px;
  min-height: 20px;
  padding: 4px 4px 6px;
  background: linear-gradient(180deg, #243a54 0%, #152536 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.level-card.is-locked .level-card-stars {
  background: linear-gradient(180deg, rgba(72, 142, 146, 0.48) 0%, rgba(56, 112, 118, 0.62) 100%);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

.level-card-stars .star {
  font-size: 10px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.15);
}

.level-card.is-locked .level-card-stars .star {
  color: rgba(255, 255, 255, 0.34);
}

.level-card-stars .star.is-on {
  color: #ffd84f;
  text-shadow: 0 1px 0 #b8860b;
  font-weight: 900;
}

.levels-dots {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.levels-dot {
  width: 11px;
  height: 11px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  cursor: pointer;
}

.levels-dot.is-active {
  background: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.65);
}

.result-stars {
  margin-bottom: 12px;
  filter: drop-shadow(0 2px 4px rgba(47, 154, 122, 0.2));
}

.result-stars .star {
  font-size: 38px;
}

.result-stars .star.star-pop {
  animation: star-pop 0.55s cubic-bezier(0.34, 1.45, 0.64, 1) backwards;
}

.result-scene.is-win .result-card {
  animation: win-card-pop 0.65s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.result-scene.is-win .result-title {
  animation: win-badge-pop 0.7s ease-out 0.1s backwards;
}

.result-scene.is-win {
  animation: win-sky-flash 0.8s ease-out;
}

.result-scene.is-lose .result-card {
  animation: lose-card-in 0.5s ease-out;
}

.result-scene.is-lose .result-title {
  animation: lose-badge-shake 0.65s ease-out;
}

.result-scene.is-lose .btn-result-main {
  animation: retry-pulse 1.8s ease-in-out infinite;
}

.result-stars[hidden] {
  display: none;
}

.result-stars .level-card-stars {
  justify-content: center;
  min-height: auto;
  padding: 0;
  background: transparent;
  box-shadow: none;
  gap: 10px;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 10px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-burst 1.6s ease-out forwards;
}

.word-chip.is-found-pop {
  animation: chip-pop 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.game-scene.is-word-pop {
  animation: micro-shake 0.32s ease-out;
}

.game-message.is-pop {
  animation: message-pop 0.38s ease-out;
}

.level-card:not(.is-locked) {
  animation: level-breathe 3.2s ease-in-out infinite;
}

.level-card:nth-child(5n + 2) {
  animation-delay: 0.4s;
}

.level-card:nth-child(5n + 3) {
  animation-delay: 0.8s;
}

.level-card:nth-child(5n + 4) {
  animation-delay: 1.2s;
}

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

@keyframes btn-idle {
  0%,
  100% {
    transform: translateY(0);
    box-shadow:
      inset 0 3px 0 rgba(255, 255, 255, 0.42),
      0 5px 0 var(--primary-dark),
      0 8px 16px rgba(47, 154, 122, 0.28);
  }
  50% {
    transform: translateY(-3px);
    box-shadow:
      inset 0 3px 0 rgba(255, 255, 255, 0.42),
      0 8px 0 var(--primary-dark),
      0 12px 20px rgba(47, 154, 122, 0.32);
  }
}

@keyframes star-pop {
  0% {
    transform: scale(0) rotate(-30deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.2) rotate(8deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes win-card-pop {
  0% {
    transform: scale(0.7) translateY(24px);
    opacity: 0;
  }
  65% {
    transform: scale(1.04) translateY(-4px);
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes win-badge-pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  60% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes win-sky-flash {
  0% {
    filter: brightness(1);
  }
  30% {
    filter: brightness(1.12);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes confetti-burst {
  0% {
    opacity: 0;
    transform: translateY(0) rotate(0deg) scale(0.5);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(120px) rotate(540deg) scale(1);
  }
}

@keyframes lose-card-in {
  0% {
    transform: translateY(16px);
    opacity: 0.5;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes lose-badge-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20%,
  60% {
    transform: translateX(-4px);
  }
  40%,
  80% {
    transform: translateX(4px);
  }
}

@keyframes retry-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      inset 0 3px 0 rgba(255, 255, 255, 0.42),
      0 5px 0 var(--primary-dark),
      0 8px 16px rgba(47, 154, 122, 0.28);
  }
  50% {
    transform: scale(1.03);
    box-shadow:
      inset 0 3px 0 rgba(255, 255, 255, 0.42),
      0 6px 0 var(--primary-dark),
      0 12px 22px rgba(47, 154, 122, 0.38);
  }
}

@keyframes tile-found-pop {
  0% {
    transform: scale(0.55);
    opacity: 0.4;
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes chip-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes message-pop {
  0% {
    transform: scale(0.92);
    opacity: 0.4;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes level-breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes result-stars-pop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Game scene */
.screen-game {
  padding: 0;
  overflow: hidden;
  background: var(--sky-deep);
}

.game-scene {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background-color: #e3f7f3;
  background-image:
    var(--bg-game-image),
    linear-gradient(165deg, #c9ece6 0%, #e3f7f3 45%, #f2fbfb 100%);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.game-scene::before,
.game-scene::after {
  display: none;
}

.grid-wrap,
.word-tray,
.game-message {
  position: relative;
  z-index: 1;
}

.game-hud {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #55d4c8 0%, var(--primary) 100%);
  box-shadow: 0 4px 0 rgba(37, 143, 120, 0.45);
}

.hud-center {
  display: grid;
  gap: 1px;
  justify-items: center;
}

.hud-level {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
}

.hud-timer {
  font-size: 28px;
  font-weight: 900;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(37, 143, 120, 0.35);
}

.hud-timer.is-warning {
  color: #ffe566;
  animation: timer-pulse 0.8s ease-in-out infinite;
}

.hud-progress {
  font-size: 13px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.92);
  font-variant-numeric: tabular-nums;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #e8f8f6 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    0 3px 0 #258f78;
}

.hud-btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 0 #258f78;
}

.hud-icon {
  display: block;
}

.hud-icon-back {
  width: 10px;
  height: 10px;
  border-left: 3px solid var(--primary-dark);
  border-bottom: 3px solid var(--primary-dark);
  transform: rotate(45deg);
}

.hud-icon-restart {
  width: 14px;
  height: 14px;
  border: 3px solid var(--primary-dark);
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}

.hud-icon-pause {
  width: 12px;
  height: 14px;
  background:
    linear-gradient(to right, var(--primary-dark) 0 35%, transparent 35% 65%, var(--primary-dark) 65% 100%);
}

.hud-icon-bulb {
  position: relative;
  width: 14px;
  height: 16px;
}

.hud-icon-bulb::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 11px;
  height: 11px;
  border: 3px solid var(--primary-dark);
  border-radius: 50%;
  transform: translateX(-50%);
  box-sizing: border-box;
}

.hud-icon-bulb::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 9px;
  height: 5px;
  border-radius: 0 0 4px 4px;
  background: var(--primary-dark);
  transform: translateX(-50%);
}

.hud-btn-hint {
  position: relative;
}

.hud-btn-hint .hint-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--gold);
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 0 var(--gold-dark);
}

.game-message {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 28px;
  margin: 0;
  padding: 6px 16px;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--primary-dark);
}

.game-message-text:empty + .game-message-say[hidden] {
  display: none;
}

.game-message:has(.game-message-text:empty) {
  min-height: 8px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.game-message-say {
  flex: 0 0 auto;
  min-height: 26px;
  padding: 2px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #e8f8f6 100%);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 2px 0 #258f78;
}

.game-message-say:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #258f78;
}

.game-message-say[hidden] {
  display: none;
}

@keyframes timer-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

/* Grid */
.grid-wrap {
  flex: 0 1 auto;
  min-height: 0;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 6px 12px 2px;
  overflow: hidden;
}

.letter-grid {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow:
    0 8px 22px rgba(47, 154, 122, 0.14),
    0 0 0 1px rgba(255, 255, 255, 0.85);
  touch-action: none;
}

.letter-grid[data-size="9"] {
  width: min(100%, 382px);
  padding: 6px;
}

.letter-grid[data-size="10"] {
  width: min(100%, 392px);
  padding: 5px;
}

.letter-grid[data-size="11"] {
  width: min(100%, 400px);
  padding: 4px;
}

.letter-grid[data-size="12"] {
  width: min(100%, 408px);
  padding: 4px;
}

.letter-grid[data-size="7"] .tile {
  font-size: clamp(18px, 5vw, 23px);
}

.letter-grid[data-size="8"] .tile {
  font-size: clamp(17px, 4.6vw, 21px);
}

.letter-grid[data-size="9"] .tile {
  font-size: clamp(17px, 4.8vw, 22px);
}

.letter-grid[data-size="10"] .tile {
  font-size: clamp(15px, 4.2vw, 20px);
}

.letter-grid[data-size="11"] .tile {
  font-size: clamp(14px, 3.8vw, 18px);
}

.letter-grid[data-size="12"] .tile {
  font-size: clamp(13px, 3.5vw, 17px);
}

.letter-grid[data-size="7"] .tile::before,
.letter-grid[data-size="8"] .tile::before,
.letter-grid[data-size="9"] .tile::before,
.letter-grid[data-size="10"] .tile::before,
.letter-grid[data-size="11"] .tile::before,
.letter-grid[data-size="12"] .tile::before {
  inset: 7%;
}

.tile {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: transparent;
  color: #4a5668;
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 600;
  border: none;
  padding: 0;
  cursor: pointer;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 32%;
  z-index: -1;
  opacity: 0;
  transform: scale(0.82);
  transition:
    transform 0.14s ease-out,
    opacity 0.14s ease-out,
    box-shadow 0.14s ease-out;
}

.tile.is-selected::before {
  opacity: 1;
  transform: scale(1);
  background: linear-gradient(180deg, rgba(93, 181, 242, 0.35) 0%, rgba(62, 181, 168, 0.28) 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    0 2px 0 rgba(47, 154, 122, 0.2);
}

.tile.is-selected {
  color: var(--primary-dark);
  font-weight: 700;
}

.tile.is-found {
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

.tile.is-found::before {
  opacity: 1;
  transform: scale(1);
}

.tile.is-found.tone-0::before {
  background: linear-gradient(180deg, #ff7070 0%, #e82e3a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    0 3px 0 #b81828;
}

.tile.is-found.tone-1::before {
  background: linear-gradient(180deg, #6ef07a 0%, #22c03a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    0 3px 0 #168a28;
}

.tile.is-found.tone-2::before {
  background: linear-gradient(180deg, #ffe84a 0%, #f0c800 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    0 3px 0 #c99a00;
  color: #6a4f00;
  text-shadow: none;
}

.tile.is-found.tone-3::before {
  background: linear-gradient(180deg, #5ec8ff 0%, #1a9af0 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    0 3px 0 #1870c4;
}

.tile.is-found.tone-4::before {
  background: linear-gradient(180deg, #ffaa55 0%, #f07018 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    0 3px 0 #c85810;
}

.tile.is-found.tone-5::before {
  background: linear-gradient(180deg, #c89cff 0%, #9b4ef0 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    0 3px 0 #6a28c0;
}

.tile.is-found-pop::before {
  animation: tile-found-pop 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.tile.is-hint::before {
  opacity: 1;
  transform: scale(1);
  background: rgba(93, 181, 242, 0.28);
  box-shadow:
    inset 0 0 0 2px #ffffff,
    0 0 0 3px var(--secondary);
  animation: hint-pulse 0.8s ease-in-out 2;
}

.tile.is-hint {
  color: var(--secondary-dark);
  font-weight: 800;
}

.word-tray {
  flex: 0 0 auto;
  width: min(100%, 400px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--tray-cols, 3), minmax(0, 1fr));
  gap: 5px 6px;
  padding: 4px 12px 10px;
  overflow: hidden;
}

.word-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 6px;
  border-radius: 10px;
  background: linear-gradient(180deg, #55d4c8 0%, var(--primary) 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--primary-dark);
  color: #ffffff;
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.15;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  white-space: nowrap;
}

.word-tray[data-word-count="9"] .word-chip,
.word-tray[data-word-count="10"] .word-chip {
  font-size: clamp(11px, 3.1vw, 14px);
  min-height: 28px;
  padding: 4px 5px;
}

.word-tray[data-word-count="6"] .word-chip {
  font-size: clamp(12px, 3.5vw, 15px);
}

.word-chip.is-found {
  text-decoration: line-through;
  opacity: 0.88;
}

.word-chip.is-found.tone-0 {
  background: linear-gradient(180deg, #ff8a8a 0%, #e82e3a 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #b81828;
  color: #ffffff;
}

.word-chip.is-found.tone-1 {
  background: linear-gradient(180deg, #7ef48a 0%, #22c03a 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #168a28;
  color: #ffffff;
}

.word-chip.is-found.tone-2 {
  background: linear-gradient(180deg, #fff06a 0%, #f0c800 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 3px 0 #c99a00;
  color: #6a4f00;
}

.word-chip.is-found.tone-3 {
  background: linear-gradient(180deg, #72d0ff 0%, #1a9af0 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #1870c4;
  color: #ffffff;
}

.word-chip.is-found.tone-4 {
  background: linear-gradient(180deg, #ffbc70 0%, #f07018 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #c85810;
  color: #ffffff;
}

.word-chip.is-found.tone-5 {
  background: linear-gradient(180deg, #d4aeff 0%, #9b4ef0 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #6a28c0;
  color: #ffffff;
}

.word-chip.is-hint {
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--primary);
  animation: hint-pulse 0.8s ease-in-out 2;
}

.hud-btn-hint:disabled,
.hud-btn-hint.is-empty {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint-count {
  display: inline-grid;
  place-items: center;
}

.tile:focus {
  outline: none;
}

@keyframes hint-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

/* Modals */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 30, 40, 0.4);
}

.modal[hidden] {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 300px;
  padding: 24px 20px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 16% 10%, rgba(255, 255, 255, 0.96) 0 12%, transparent 13%),
    linear-gradient(180deg, #ffffff 0%, #f4fbfb 100%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.9),
    0 8px 0 #258f78,
    0 16px 28px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.modal-box h2 {
  font-size: 24px;
  font-weight: 900;
  color: var(--ink);
}

.modal-box p {
  margin: 10px 0 18px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--muted);
  font-weight: 600;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(62, 181, 168, 0.1);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-align: left;
}

.setting-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  max-width: min(92vw, 320px);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(23, 56, 72, 0.92);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.phone-frame.is-big-letters .tile {
  font-size: clamp(22px, 6vw, 28px);
  font-weight: 700;
}

.phone-frame.is-big-letters .letter-grid[data-size="8"] .tile {
  font-size: clamp(20px, 5.4vw, 26px);
}

.phone-frame.is-big-letters .letter-grid[data-size="9"] .tile {
  font-size: clamp(21px, 5.8vw, 28px);
}

.phone-frame.is-big-letters .letter-grid[data-size="10"] .tile {
  font-size: clamp(19px, 5.2vw, 26px);
}

.phone-frame.is-big-letters .letter-grid[data-size="11"] .tile {
  font-size: clamp(17px, 4.8vw, 24px);
}

.phone-frame.is-big-letters .letter-grid[data-size="12"] .tile {
  font-size: clamp(16px, 4.4vw, 22px);
}

.phone-frame.is-big-letters .word-chip {
  font-size: 15px;
  padding: 8px 12px;
}

/* Visual QA — iPhone 14 / 15 class viewports */
@media (max-width: 390px) and (max-height: 844px) {
  .phone-frame {
    width: 100vw;
    height: 100dvh;
    max-height: 844px;
  }

  .game-hud {
    min-height: 64px;
    padding: 8px 10px;
  }

  .hud-timer {
    font-size: 24px;
  }

  .grid-wrap {
    padding: 4px 8px 2px;
  }

  .letter-grid[data-size="11"],
  .letter-grid[data-size="12"] {
    width: min(100%, 366px);
    padding: 3px;
  }

  .letter-grid[data-size="12"] .tile {
    font-size: clamp(12px, 3.2vw, 15px);
  }

  .word-tray {
    padding: 4px 10px 8px;
    gap: 4px 5px;
  }

  .word-tray[data-word-count="9"] .word-chip,
  .word-tray[data-word-count="10"] .word-chip {
    font-size: clamp(11px, 3vw, 13px);
  }
}

@media (min-width: 391px) and (max-width: 430px) and (min-height: 845px) {
  .phone-frame {
    width: min(100vw, 430px);
    height: min(100dvh, 932px);
  }

  .letter-grid[data-size="12"] {
    width: min(100%, 398px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
