:root {
  --bg: #f6f4ee;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #20313d;
  --muted: #60707b;
  --line: rgba(32, 49, 61, 0.16);
  --shadow: 0 18px 45px rgba(32, 49, 61, 0.13);
  --shadow-soft: 0 10px 26px rgba(32, 49, 61, 0.1);
  --primary: #e94f64;
  --primary-contrast: #ffffff;
  --accent: #1e9b8f;
  --accent-contrast: #ffffff;
  --warning: #f2b84b;
  --gold: #f0b429;
  --danger: #c74343;
  --success: #178a5b;
  --radius: 8px;
  --button-radius: 10px;
  --stage-tint: #ffe8ed;
  --stage-deep: #e94f64;
  --stage-soft: #fff7e0;
  --stage-ink: #142632;
  --gift-main: #e94f64;
  --gift-dark: #b83452;
  --gift-light: #ff7f93;
  --gift-ribbon: #f2b84b;
  --gift-ribbon-dark: #c98218;
  --focus: #1b6dd8;
  --font: "Segoe UI", Tahoma, Arial, sans-serif;
}

.theme-world-1 { --stage-tint: #ffe6f0; --stage-deep: #d93f73; --stage-soft: #fff7db; --gift-main: #e85c8f; --gift-dark: #b92f66; --gift-light: #ff86b3; }
.theme-world-2 { --stage-tint: #e5f4df; --stage-deep: #2f7d54; --stage-soft: #f7f0d3; --gift-main: #35a765; --gift-dark: #1f6c43; --gift-light: #67ca87; }
.theme-world-3 { --stage-tint: #e1f4fb; --stage-deep: #197da3; --stage-soft: #e9ffe9; --gift-main: #24a4c7; --gift-dark: #126d8f; --gift-light: #6bd2ea; }
.theme-world-4 { --stage-tint: #ebe7ff; --stage-deep: #6652c7; --stage-soft: #f6f1ff; --gift-main: #735fd4; --gift-dark: #4b3ca0; --gift-light: #9c8af0; }
.theme-world-5 { --stage-tint: #fff0d8; --stage-deep: #9b5b2e; --stage-soft: #eef6ff; --gift-main: #b66d36; --gift-dark: #7d421f; --gift-light: #d8985b; }
.theme-world-6 { --stage-tint: #ffedcf; --stage-deep: #b76a29; --stage-soft: #e6f7ef; --gift-main: #c8792d; --gift-dark: #8b4c19; --gift-light: #eba35b; }
.theme-world-7 { --stage-tint: #e8eff5; --stage-deep: #3f6680; --stage-soft: #fff0d5; --gift-main: #527993; --gift-dark: #2e526b; --gift-light: #86a8bb; }
.theme-world-8 { --stage-tint: #ffe4e0; --stage-deep: #b34232; --stage-soft: #edf6de; --gift-main: #c84d3d; --gift-dark: #893025; --gift-light: #ef806b; }
.theme-world-9 { --stage-tint: #e7ebff; --stage-deep: #394b99; --stage-soft: #fff9d5; --gift-main: #4b5fbb; --gift-dark: #2d3d80; --gift-light: #788ae3; }
.theme-world-10 { --stage-tint: #fce8d6; --stage-deep: #9b3f6b; --stage-soft: #e2f4f2; --gift-main: #9b3f6b; --gift-dark: #69284d; --gift-light: #c96d98; --gift-ribbon: #f0b429; --gift-ribbon-dark: #b87516; }

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app {
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.52) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.52) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.72), rgba(255,255,255,0.08) 46%, rgba(255,255,255,0.26)),
    var(--stage-tint);
  background-size: 34px 34px, 34px 34px, auto, auto;
  transition: background-color 220ms ease;
}

.ambient-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background:
    repeating-linear-gradient(135deg, transparent 0 22px, rgba(255,255,255,0.35) 23px 24px),
    linear-gradient(180deg, rgba(255,255,255,0.65), rgba(255,255,255,0.12));
}

.ambient-layer::before,
.ambient-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ambient-layer::before {
  opacity: 0.34;
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.7) 0 3px, transparent 4px),
    radial-gradient(circle at 82% 18%, rgba(255,255,255,0.62) 0 4px, transparent 5px),
    radial-gradient(circle at 76% 78%, rgba(255,255,255,0.54) 0 5px, transparent 6px);
}

.ambient-layer::after {
  inset: 10% 3% auto 3%;
  min-height: 74vh;
  color: color-mix(in srgb, var(--stage-deep) 55%, transparent);
  font-size: 1.35rem;
  line-height: 8.2rem;
  letter-spacing: 2.8rem;
  opacity: 0.12;
  white-space: pre-wrap;
  overflow: hidden;
  animation: driftWorld 22s linear infinite;
}

.effects-off .ambient-layer::before,
.effects-off .ambient-layer::after {
  display: none;
}

.theme-world-1 .ambient-layer::after { content: "🍬 ✦ 🍭 ✧ 🍬 ✦ 🍭 ✧ 🍬"; }
.theme-world-2 .ambient-layer::after { content: "🍃 ✦ 🍂 ✧ 🍃 ✦ 🍂 ✧ 🍃"; }
.theme-world-3 .ambient-layer::after { content: "○ ◌ ○ ◌ ○ ◌ ○ ◌ ○ ◌"; }
.theme-world-4 .ambient-layer::after { content: "✦ · ✧ · ✦ · ✧ · ✦ ·"; }
.theme-world-5 .ambient-layer::after { content: "⚑ ✦ ⚐ ✧ ⚑ ✦ ⚐ ✧ ⚑"; }
.theme-world-6 .ambient-layer::after { content: "· ∙ · ∙ · ∙ · ∙ · ∙ ·"; }
.theme-world-7 .ambient-layer::after { content: "▣ · ▢ · ▣ · ▢ · ▣ ·"; }
.theme-world-8 .ambient-layer::after { content: "✶ · ✦ · ✶ · ✦ · ✶ ·"; }
.theme-world-9 .ambient-layer::after { content: "✦ ✧ ★ ✦ ✧ ★ ✦ ✧ ★"; }
.theme-world-10 .ambient-layer::after { content: "★ ✦ ✧ ★ ✦ ✧ ★ ✦ ✧"; color: rgba(176, 116, 16, 0.55); opacity: 0.16; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 12px 0 10px;
}

.brand-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
  font-weight: 800;
  white-space: nowrap;
}

.brand-mini-mark {
  font-size: 1.2rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-control {
  position: relative;
}

.language-button {
  display: inline-flex;
  align-items: center;
  min-width: 132px;
  justify-content: center;
  white-space: nowrap;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  min-width: 92px;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.sound-toggle.is-on {
  color: #ffffff;
  background: var(--success);
  border-color: transparent;
}

.language-menu {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 80;
  display: grid;
  gap: 6px;
  min-width: 190px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--button-radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.language-menu button {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  color: var(--text);
  background: transparent;
  font-weight: 850;
  text-align: start;
  cursor: pointer;
}

.language-menu button:hover,
.language-menu button:focus-visible {
  background: var(--stage-soft);
}

.icon-button,
.utility-button,
.action-button,
.danger-button,
.toggle-button,
.option-button,
.world-card,
.stage-node,
.segmented-control button {
  border: 0;
  border-radius: var(--button-radius);
  cursor: pointer;
}

.icon-button,
.utility-button {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  font-weight: 800;
}

.utility-button {
  min-width: 78px;
}

.is-soft {
  background: rgba(255, 255, 255, 0.7);
}

.app[data-screen="home"] .is-hidden-on-home {
  visibility: hidden;
}

.main {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 14px 0 38px;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
  animation: screenIn 220ms ease both;
}

.home-screen {
  min-height: calc(100vh - 90px);
  display: none;
  place-items: center;
}

.home-screen.is-active {
  display: grid;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 390px);
  align-items: center;
  gap: 56px;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

.logo-stack {
  display: grid;
  justify-items: start;
  gap: 14px;
}

html[dir="rtl"] .logo-stack {
  justify-items: end;
}

.kicker {
  margin: 0;
  color: var(--stage-deep);
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

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

h1 {
  max-width: 720px;
  font-size: 5.2rem;
  letter-spacing: 0;
}

h2 {
  font-size: 2.8rem;
}

h3 {
  font-size: 1.05rem;
}

.subtitle {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 1.16rem;
  line-height: 1.7;
}

.home-actions,
.completion-actions {
  display: grid;
  gap: 12px;
}

.home-actions {
  align-self: center;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
}

.action-button,
.danger-button,
.toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  padding: 15px 18px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  font-weight: 850;
  text-align: center;
  line-height: 1.2;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.action-button span:last-child,
.danger-button span:last-child,
.toggle-button span:last-child {
  min-width: 0;
}

.action-button:hover,
.icon-button:hover,
.utility-button:hover,
.world-card:hover,
.stage-node:hover,
.segmented-control button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.action-button:disabled,
.danger-button:disabled,
.toggle-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: var(--shadow-soft);
}

.action-button:disabled:hover,
.danger-button:disabled:hover,
.toggle-button:disabled:hover {
  transform: none;
  box-shadow: var(--shadow-soft);
}

.primary-action {
  color: var(--primary-contrast);
  background: var(--stage-deep);
  border-color: transparent;
  box-shadow: 0 14px 30px color-mix(in srgb, var(--stage-deep) 30%, transparent);
}

.home-main-action,
.continue-action {
  grid-column: 1 / -1;
}

.home-main-action {
  min-height: 72px;
  font-size: 1.18rem;
}

.continue-action {
  min-height: 62px;
  color: var(--stage-deep);
  border-color: color-mix(in srgb, var(--stage-deep) 40%, var(--line));
}

.secondary-action {
  min-height: 54px;
  padding: 12px 10px;
  color: #304550;
  background: rgba(255, 255, 255, 0.76);
  font-size: 0.94rem;
}

.danger-button {
  color: #ffffff;
  background: var(--danger);
  border-color: transparent;
}

.screen-heading,
.stage-topline {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin: 10px 0 22px;
}

.screen-heading > div,
.stage-meta {
  min-width: 0;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 16px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #314650;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
  font-size: 0.86rem;
  font-weight: 850;
}

.world-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.world-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(2.8em, auto) auto auto;
  gap: 9px;
  min-height: 164px;
  padding: 15px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  text-align: start;
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.world-card.is-selected {
  border-color: var(--stage-deep);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--stage-deep) 22%, transparent), var(--shadow);
}

.world-card.is-active-level {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.8)),
    var(--stage-soft);
}

.world-card.is-complete {
  border-color: color-mix(in srgb, var(--success) 44%, var(--line));
}

.world-card.is-locked {
  color: #5f6970;
  background: rgba(248, 250, 251, 0.72);
}

.world-card.is-final {
  border-color: var(--gold);
}

.world-card.is-final.is-selected,
.world-card.is-final.is-active-level {
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.28), var(--shadow);
}

.world-card:disabled,
.stage-node:disabled {
  cursor: not-allowed;
  opacity: 1;
  transform: none;
}

.world-emoji {
  font-size: 2.15rem;
  line-height: 1;
}

.world-name {
  min-width: 0;
  font-weight: 900;
  line-height: 1.18;
}

.world-description,
.world-stats,
.stage-stat {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.world-description,
.world-name,
.world-stats,
.stage-stat {
  overflow-wrap: anywhere;
  hyphens: auto;
}

.world-status-badge {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: calc(100% - 20px);
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--stage-ink);
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1.1;
}

.world-card.is-complete .world-status-badge {
  color: #ffffff;
  background: var(--success);
  border-color: transparent;
}

.world-card.is-locked .world-status-badge {
  color: #ffffff;
  background: #6c747a;
  border-color: transparent;
}

.world-card.is-active-level .world-status-badge {
  color: #ffffff;
  background: var(--stage-deep);
  border-color: transparent;
}

.world-meter {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(32, 49, 61, 0.12);
}

.world-meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--stage-deep);
}

.stage-road {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.82)),
    var(--stage-soft);
  box-shadow: var(--shadow);
}

.stage-road-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.stage-road-title {
  display: grid;
  gap: 4px;
}

.stage-path {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 12px;
}

.stage-path::before {
  content: "";
  position: absolute;
  inset-inline: 4%;
  top: 50%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(23, 138, 91, 0.28), rgba(240, 180, 41, 0.36), rgba(155, 63, 107, 0.24));
  transform: translateY(-50%);
  pointer-events: none;
}

.stage-node {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  place-items: center;
  min-height: 98px;
  padding: 10px 8px;
  color: var(--text);
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  font-weight: 900;
  text-align: center;
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background-color 160ms ease;
  z-index: 1;
}

.stage-node.is-complete {
  color: #ffffff;
  background: var(--success);
  border-color: transparent;
}

.stage-node.is-active-level {
  color: #ffffff;
  background: var(--stage-deep);
  border-color: transparent;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--stage-deep) 24%, transparent), var(--shadow);
}

.stage-node.is-locked {
  color: #5d676e;
  background: rgba(239, 243, 245, 0.9);
  box-shadow: none;
}

.stage-node.is-challenge {
  border-color: var(--warning);
  box-shadow: 0 0 0 3px rgba(242, 184, 75, 0.22), var(--shadow-soft);
}

.stage-node.is-final {
  min-height: 110px;
  border-width: 2px;
  border-color: var(--gold);
  background:
    linear-gradient(145deg, rgba(255,255,255,0.96), rgba(255,247,215,0.94));
}

.stage-node.is-final::before {
  content: "★";
  position: absolute;
  inset-block-start: 6px;
  inset-inline-end: 8px;
  color: var(--gold);
  font-size: 0.9rem;
  line-height: 1;
}

.stage-node.is-final.is-active-level,
.stage-node.is-final.is-complete {
  background:
    linear-gradient(145deg, #9b3f6b, #5f4fa8);
  color: #ffffff;
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(240, 180, 41, 0.28), var(--shadow);
}

.stage-emoji {
  display: block;
  font-size: 1.45rem;
  line-height: 1;
}

.stage-node.is-final .stage-emoji {
  font-size: 1.72rem;
}

.stage-number {
  display: block;
  font-size: 1.2rem;
  line-height: 1;
}

.stage-stars {
  display: block;
  min-height: 17px;
  color: var(--gold);
  font-size: 0.75rem;
  letter-spacing: 0;
}

.stage-node.is-complete .stage-stars,
.stage-node.is-active-level .stage-stars,
.stage-node.is-final.is-complete .stage-stars {
  color: #fff0a3;
}

.stage-shell {
  max-width: 860px;
  margin: 0 auto;
}

.stage-meta {
  min-width: 0;
}

.score-counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 124px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  font-weight: 900;
}

.progress-wrap {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 800;
}

.progress-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(32, 49, 61, 0.14);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--stage-deep);
  transition: width 260ms ease;
}

.playfield {
  display: grid;
  justify-items: center;
  gap: 20px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.94), rgba(255,255,255,0.84)),
    var(--stage-soft);
  box-shadow: var(--shadow);
}

.equation {
  width: 100%;
  min-height: 104px;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255,255,255,0.78);
  border: 1px solid color-mix(in srgb, var(--stage-deep) 24%, var(--line));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
  font-size: 4.2rem;
  font-weight: 950;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 14px;
  width: 100%;
}

.option-button {
  min-height: 82px;
  padding: 12px;
  color: var(--text);
  background: #ffffff;
  border: 2px solid transparent;
  box-shadow: var(--shadow-soft);
  font-size: 2.15rem;
  font-weight: 950;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.option-button:hover {
  transform: translateY(-2px);
  border-color: var(--stage-deep);
}

.option-button.is-wrong {
  color: #ffffff;
  background: var(--danger);
  box-shadow: 0 10px 22px rgba(199, 67, 67, 0.2);
  animation: optionShake 320ms ease;
}

.option-button.is-correct {
  color: #ffffff;
  background: var(--success);
  box-shadow: 0 10px 22px rgba(23, 138, 91, 0.2);
}

.option-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 50px;
  max-width: 680px;
  margin: 0;
  color: var(--text);
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.6;
  text-align: center;
}

.gift-logo,
.gift-box {
  position: relative;
  width: 178px;
  height: 164px;
  filter: drop-shadow(0 20px 14px rgba(32, 49, 61, 0.18));
}

.gift-logo {
  width: 196px;
  height: 178px;
  animation: floatGift 2.8s ease-in-out infinite;
}

.gift-box:not(.is-open):not(.is-shaking) {
  animation: idleGift 3.6s ease-in-out infinite;
}

.gift-box::after,
.gift-logo::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 76%;
  height: 18px;
  border-radius: 50%;
  background: rgba(32, 49, 61, 0.12);
  transform: translateX(-50%);
}

.gift-lid,
.gift-body,
.gift-ribbon,
.gift-bow {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.gift-lid {
  z-index: 4;
  top: 36px;
  width: 88%;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.34), rgba(255,255,255,0.04) 45%, rgba(0,0,0,0.08)),
    linear-gradient(90deg, var(--gift-light), var(--gift-main) 42%, var(--gift-dark));
  border: 3px solid color-mix(in srgb, var(--gift-dark) 64%, #ffffff);
  box-shadow:
    inset 0 3px 0 rgba(255,255,255,0.24),
    0 8px 0 rgba(32, 49, 61, 0.08);
  transition: transform 420ms cubic-bezier(.2,.9,.25,1.2);
}

.gift-lid::before,
.gift-lid::after {
  content: "";
  position: absolute;
  inset-block: -3px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.gift-lid::before {
  width: 28px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.36), transparent 38%, rgba(0,0,0,0.08)),
    var(--gift-ribbon);
}

.gift-lid::after {
  inset-block-start: 7px;
  width: 72%;
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
}

.gift-body {
  z-index: 2;
  bottom: 0;
  width: 80%;
  height: 104px;
  border-radius: 14px 14px 12px 12px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.26), transparent 30%),
    linear-gradient(90deg, var(--gift-light), var(--gift-main) 48%, var(--gift-dark));
  border: 4px solid color-mix(in srgb, var(--gift-dark) 70%, #ffffff);
  box-shadow:
    inset 0 4px 0 rgba(255,255,255,0.16),
    inset 0 -14px 0 rgba(32, 49, 61, 0.08);
}

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

.gift-body::before {
  z-index: 3;
  left: 0;
  right: 0;
  top: 36px;
  height: 26px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.32), transparent 42%, rgba(0,0,0,0.06)),
    var(--gift-ribbon);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.05);
}

.gift-body::after {
  z-index: 4;
  top: 14px;
  left: 16%;
  width: 18%;
  height: 66%;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  transform: skewX(-12deg);
}

.gift-ribbon {
  z-index: 3;
  bottom: 0;
  width: 30px;
  height: 118px;
  border-radius: 8px 8px 0 0;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.42), transparent 35%, rgba(0,0,0,0.08)),
    var(--gift-ribbon);
  box-shadow: inset -5px 0 0 rgba(0,0,0,0.06);
}

.gift-bow {
  z-index: 5;
  top: 5px;
  width: 94px;
  height: 56px;
  background:
    radial-gradient(circle at 50% 57%, var(--gift-ribbon-dark) 0 12px, transparent 13px);
  transition: transform 420ms cubic-bezier(.2,.9,.25,1.2);
}

.gift-bow::before,
.gift-bow::after {
  content: "";
  position: absolute;
  top: 7px;
  width: 44px;
  height: 36px;
  border-radius: 50% 50% 10px 50%;
  background:
    linear-gradient(145deg, rgba(255,255,255,0.36), transparent 42%),
    var(--gift-ribbon);
  border: 3px solid rgba(32, 49, 61, 0.1);
  box-shadow: inset -4px -5px 0 rgba(0,0,0,0.05);
}

.gift-bow::before {
  left: 0;
  transform: rotate(-18deg);
}

.gift-bow::after {
  right: 0;
  transform: scaleX(-1) rotate(-18deg);
}

.gift-value {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 46px;
  min-width: 64px;
  transform: translate(-50%, 22px) scale(0.72);
  color: var(--gift-dark);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  box-shadow: var(--shadow-soft);
  font-size: 3.1rem;
  font-weight: 1000;
  line-height: 1;
  opacity: 0;
  transition: transform 320ms ease, opacity 220ms ease;
}

.gift-box.is-open .gift-lid {
  transform: translate(-50%, -58px) rotate(-12deg);
}

.gift-box.is-open .gift-bow {
  transform: translate(-50%, -58px) rotate(-12deg);
}

.gift-box.is-open .gift-body {
  box-shadow: inset 0 -10px 0 rgba(32, 49, 61, 0.05), 0 0 0 6px color-mix(in srgb, var(--stage-deep) 12%, transparent);
}

.gift-box.is-open .gift-value {
  transform: translate(-50%, -18px) scale(1);
  opacity: 1;
}

.gift-box.is-shaking {
  animation: shakeBox 360ms ease;
}

.stars-burst {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.star-particle {
  position: absolute;
  color: var(--gold);
  font-size: 1.35rem;
  animation: starFly 900ms ease-out forwards;
}

.star-particle:nth-child(3n) {
  color: var(--stage-deep);
}

.star-particle:nth-child(4n) {
  color: var(--success);
}

.star-particle:nth-child(5n) {
  color: #ffffff;
}

.complete-screen {
  min-height: calc(100vh - 110px);
}

.complete-screen.is-active {
  display: grid;
  place-items: center;
}

.complete-panel {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 15px;
  width: min(560px, 100%);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,0.26) 0 10px, transparent 10px 22px),
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.88)),
    var(--stage-soft);
  box-shadow: var(--shadow);
  text-align: center;
  overflow: hidden;
}

.complete-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 8px;
  background: linear-gradient(90deg, var(--stage-deep), var(--gold), var(--success));
}

.complete-panel::after {
  content: "★ ✦ ★";
  position: absolute;
  inset-block-start: 16px;
  inset-inline-end: 18px;
  color: var(--gold);
  font-size: 1.05rem;
  font-weight: 900;
  opacity: 0.82;
}

.perfect-gift {
  display: none;
  width: 132px;
  height: 122px;
  margin-bottom: -4px;
  --gift-main: #f0b429;
  --gift-dark: #a66a10;
  --gift-light: #ffd86a;
  --gift-ribbon: #ffffff;
  --gift-ribbon-dark: #e7c45a;
  animation: none;
}

.complete-panel.is-perfect {
  border-color: rgba(240, 180, 41, 0.7);
  box-shadow: 0 0 0 4px rgba(240, 180, 41, 0.18), var(--shadow);
}

.complete-panel.is-perfect .perfect-gift {
  display: block;
}

.complete-panel.is-perfect .perfect-gift .gift-lid,
.complete-panel.is-perfect .perfect-gift .gift-bow {
  transform: translate(-50%, -38px) rotate(-8deg);
}

.complete-panel.is-perfect .perfect-gift .gift-value {
  transform: translate(-50%, -8px) scale(1);
  opacity: 1;
  color: #9c650f;
}

.result-map-button {
  width: fit-content;
  margin: -2px 0 16px;
  color: #ffffff;
  background: linear-gradient(135deg, #b87814, var(--gold));
  border-color: transparent;
}

.global-score-card {
  display: grid;
  gap: 10px;
  width: min(560px, 100%);
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
}

.global-score-card.is-perfect {
  border-color: rgba(240, 180, 41, 0.72);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,248,218,0.92)),
    #fff9dd;
  box-shadow: 0 0 0 4px rgba(240, 180, 41, 0.18), var(--shadow-soft);
}

.global-score-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-weight: 950;
}

.global-score-head strong,
.score-counter strong,
.result-score-card strong {
  color: var(--stage-deep);
  font-size: 1.18rem;
}

.global-score-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(32, 49, 61, 0.14);
}

.global-score-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--stage-deep), var(--success));
  transition: width 420ms ease;
}

.global-score-track.is-perfect .global-score-fill {
  background: linear-gradient(90deg, #c48116, var(--gold), #ffe38a);
}

.global-score-points {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 850;
}

.result-screen.is-active {
  display: grid;
  place-items: center;
}

.result-panel {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: min(820px, 100%);
  padding: 30px;
  border: 1px solid rgba(240, 180, 41, 0.55);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(135deg, rgba(240,180,41,0.08) 0 12px, transparent 12px 24px),
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.9)),
    var(--stage-soft);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-panel.is-regular {
  border-color: var(--line);
}

.result-panel.is-perfect {
  border-color: rgba(240, 180, 41, 0.75);
  box-shadow: 0 0 0 5px rgba(240, 180, 41, 0.18), var(--shadow);
}

.result-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.result-medal {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff3b0, var(--gold));
  box-shadow: var(--shadow-soft);
  font-size: 2.6rem;
}

.result-gift {
  width: 128px;
  height: 118px;
  --gift-main: #f0b429;
  --gift-dark: #a66a10;
  --gift-light: #ffd86a;
  --gift-ribbon: #ffffff;
  --gift-ribbon-dark: #e7c45a;
  animation: none;
}

.result-score-card {
  display: grid;
  gap: 10px;
  width: min(620px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  font-weight: 950;
}

.result-score-card.is-perfect {
  border-color: rgba(240, 180, 41, 0.72);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,249,224,0.94)),
    #fff9dd;
}

.result-score-card strong {
  font-size: clamp(2.6rem, 9vw, 4.8rem);
  line-height: 1;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(720px, 100%);
}

.site-notice {
  position: relative;
  z-index: 2;
  width: min(920px, calc(100% - 110px));
  margin: 0 auto;
  padding: 0 0 24px;
  color: #40545f;
  font-size: 0.88rem;
  line-height: 1.6;
  text-align: center;
}

.site-notice a {
  color: var(--stage-deep);
  font-weight: 900;
}

.portfolio-fab {
  position: fixed;
  z-index: 50;
  inset-inline-end: 18px;
  inset-block-end: 22px;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--stage-deep);
  box-shadow: var(--shadow);
  text-decoration: none;
  font-size: 1.35rem;
}

.portfolio-fab:hover,
.portfolio-fab:focus-visible {
  transform: translateY(-2px);
}

.celebration-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--stage-deep);
  font-size: 2.4rem;
  animation: popIn 380ms ease both;
}

.completion-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 10px 18px;
  border-radius: var(--button-radius);
  color: #ffffff;
  background: var(--stage-deep);
  box-shadow: var(--shadow-soft);
  font-size: 1.5rem;
  font-weight: 950;
  direction: ltr;
}

.completion-stars {
  min-height: 44px;
  color: var(--gold);
  font-size: 2rem;
  letter-spacing: 0;
}

.settings-grid,
.how-list {
  display: grid;
  gap: 12px;
  max-width: 780px;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
}

.settings-row.is-column {
  grid-template-columns: 1fr;
}

.settings-row p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.toggle-button.is-on {
  color: #ffffff;
  background: var(--success);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segmented-control button {
  min-height: 48px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-weight: 850;
}

.segmented-control button.is-active {
  color: #ffffff;
  background: var(--stage-deep);
  border-color: transparent;
}

.how-list {
  margin: 0;
  padding: 0 1.4rem;
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.7;
}

.how-list li {
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 30, 38, 0.44);
}

.modal.is-hidden {
  display: none;
}

.modal-card {
  width: min(460px, 100%);
  padding: 24px;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.language-card {
  display: grid;
  gap: 18px;
  width: min(620px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.9)),
    var(--stage-soft);
  box-shadow: var(--shadow);
  text-align: center;
}

.language-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.language-choice {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
  min-height: 132px;
  padding: 18px 12px;
  border: 1px solid var(--line);
  border-radius: var(--button-radius);
  color: var(--text);
  background: #ffffff;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

.language-choice:hover,
.language-choice:focus-visible {
  transform: translateY(-2px);
  border-color: var(--stage-deep);
  box-shadow: var(--shadow);
}

.language-choice span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--stage-deep);
  font-size: 1.35rem;
  font-weight: 950;
}

.language-choice strong {
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.is-hidden {
  display: none !important;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floatGift {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-10px) rotate(1deg); }
}

@keyframes idleGift {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes shakeBox {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px) rotate(-2deg); }
  40% { transform: translateX(8px) rotate(2deg); }
  60% { transform: translateX(-5px) rotate(-1deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

@keyframes optionShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

@keyframes starFly {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(0.8) rotate(0deg);
  }
  to {
    opacity: 0;
    transform: translate(var(--x), var(--y)) scale(1.35) rotate(120deg);
  }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes driftWorld {
  from { transform: translateY(0); }
  to { transform: translateY(-24px); }
}

@media (max-width: 980px) {
  h1 {
    font-size: 4.2rem;
  }

  h2 {
    font-size: 2.45rem;
  }

  .world-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-path {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .equation {
    font-size: 3.55rem;
  }
}

@media (max-width: 760px) {
  .app-header {
    width: min(100% - 20px, 1120px);
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .brand-mini {
    justify-content: start;
    padding: 9px 10px;
  }

  .main {
    width: min(100% - 20px, 1120px);
    padding-top: 8px;
  }

  .home-hero {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 28px;
  }

  .logo-stack,
  html[dir="rtl"] .logo-stack {
    justify-items: center;
    text-align: center;
  }

  .gift-logo {
    width: 154px;
    height: 142px;
  }

  .home-actions {
    width: 100%;
    max-width: 480px;
    justify-self: center;
  }

  .screen-heading,
  .stage-topline {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }

  .world-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .world-card {
    min-height: 132px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    align-items: center;
  }

  .world-emoji {
    grid-row: 1 / span 2;
  }

  .world-description,
  .world-meter,
  .world-stats {
    grid-column: 1 / -1;
  }

  .stage-road {
    padding: 12px;
  }

  .stage-road-header {
    align-items: start;
    flex-direction: column;
  }

  .stage-path {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-path::before {
    display: none;
  }

  .stage-node {
    min-height: 92px;
  }

  .progress-wrap {
    grid-template-columns: 1fr;
  }

  .options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .playfield {
    padding: 22px;
  }

  .equation {
    font-size: 3rem;
  }

  .option-button {
    min-height: 78px;
    font-size: 1.95rem;
  }

  .settings-row {
    grid-template-columns: 1fr;
  }

  .segmented-control {
    grid-template-columns: 1fr;
  }

  .language-choice-grid {
    grid-template-columns: 1fr;
  }

  .language-choice {
    min-height: 92px;
    grid-template-columns: 54px minmax(0, 1fr);
    justify-items: start;
    align-content: center;
    text-align: start;
  }

  .modal-actions {
    flex-direction: column;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }

  .result-panel {
    padding: 22px;
  }

  .result-hero {
    flex-direction: column;
    gap: 8px;
  }

  h1 {
    font-size: 3.25rem;
  }

  h2 {
    font-size: 2.1rem;
  }

  .subtitle {
    font-size: 1.05rem;
  }
}

@media (max-width: 430px) {
  .app-header {
    width: min(100% - 16px, 1120px);
  }

  .main {
    width: min(100% - 16px, 1120px);
  }

  .utility-button {
    min-width: 58px;
    padding: 0 8px;
  }

  .language-button {
    min-width: 116px;
    max-width: 142px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sound-toggle {
    min-width: 54px;
  }

  .sound-toggle #sound-label {
    display: none;
  }

  .language-menu {
    position: fixed;
    inset-block-start: 62px;
    inset-inline: 8px;
    min-width: 0;
  }

  .language-card {
    padding: 22px 16px;
  }

  .site-notice {
    width: min(100% - 86px, 920px);
    padding-bottom: 18px;
    font-size: 0.78rem;
  }

  .portfolio-fab {
    width: 48px;
    height: 48px;
    inset-inline-end: 12px;
    inset-block-end: 16px;
  }

  .brand-mini span:last-child {
    display: none;
  }

  .stage-topline {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
  }

  .score-counter {
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .playfield {
    gap: 14px;
    padding: 16px;
  }

  .equation {
    min-height: 80px;
    padding: 12px;
    font-size: 2.45rem;
  }

  .home-actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .home-main-action {
    min-height: 68px;
  }

  .secondary-action {
    min-height: 52px;
  }

  .gift-box {
    width: 142px;
    height: 132px;
  }

  .gift-lid {
    top: 30px;
    height: 32px;
  }

  .gift-body {
    height: 82px;
  }

  .gift-ribbon {
    height: 94px;
  }

  .gift-value {
    bottom: 38px;
    font-size: 2.55rem;
  }

  .option-button {
    min-height: 74px;
    font-size: 1.78rem;
  }

  .complete-panel {
    padding: 28px 18px;
  }

  .completion-actions {
    width: 100%;
  }

  h1 {
    font-size: 2.72rem;
  }

  h2 {
    font-size: 1.86rem;
  }
}

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