:root {
  --bg-deep: #07151c;
  --bg-mid: #0f2a38;
  --ink: #e8f4ef;
  --muted: #8fb3a8;
  --accent: #f0b429;
  --theme-accent: #7ee0b8;
  --theme-fog: #0b1f2a;
  --panel: rgba(8, 22, 30, 0.9);
  --wall: #0a1620;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Outfit", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 55% at 15% 0%, color-mix(in srgb, var(--theme-accent) 28%, transparent), transparent 55%),
    radial-gradient(ellipse 60% 45% at 95% 90%, rgba(58, 169, 255, 0.16), transparent 50%),
    radial-gradient(circle at 50% 120%, rgba(240, 180, 41, 0.08), transparent 40%),
    linear-gradient(165deg, var(--bg-deep), var(--bg-mid) 50%, #0a2030);
  min-height: 100%;
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

#app {
  width: min(980px, 96vw);
  padding: 1.1rem 0 1.75rem;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.85rem 1.25rem;
  margin-bottom: 0.85rem;
  padding: 0 0.2rem;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.home-link {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  width: fit-content;
  transition: color 0.15s ease;
}

.home-link:hover {
  color: var(--theme-accent, #7ee0b8);
}

.lang-corner {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 50;
}

html[dir="rtl"] .lang-corner {
  right: auto;
  left: 0.85rem;
}

.flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(126, 224, 184, 0.25);
  background: rgba(8, 24, 32, 0.88);
  backdrop-filter: blur(8px);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.flag-img,
.flag-option img {
  display: block;
  width: 28px;
  height: 20px;
  object-fit: cover;
  border-radius: 3px;
}

.flag-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}

.flag-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 11.5rem;
  max-height: min(70vh, 22rem);
  overflow: auto;
  padding: 0.35rem;
  border-radius: 12px;
  background: rgba(8, 22, 30, 0.96);
  border: 1px solid rgba(126, 224, 184, 0.22);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

html[dir="rtl"] .flag-menu {
  right: auto;
  left: 0;
}

.flag-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.55rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-family: "Outfit", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: start;
}

.flag-option:hover,
.flag-option.is-active {
  background: rgba(126, 224, 184, 0.14);
}

.brand {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(1.55rem, 4vw, 2.05rem);
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, #f0b429 10%, var(--theme-accent) 70%, #5ec8ff);
  background-size: 180% 100%;
  animation: brandShift 8s ease-in-out infinite alternate;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

html[dir="rtl"] .hud-right {
  align-items: flex-start;
}

html[dir="rtl"] .stats {
  justify-content: flex-start;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 4.2rem;
  padding: 0.4rem 0.65rem;
  background: rgba(8, 24, 32, 0.55);
  border: 1px solid rgba(126, 224, 184, 0.12);
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  white-space: nowrap;
}

.progress-wrap {
  margin-bottom: 0.75rem;
  padding: 0 0.2rem;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(8, 24, 32, 0.65);
  border: 1px solid rgba(126, 224, 184, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f0b429, var(--theme-accent));
  box-shadow: 0 0 12px color-mix(in srgb, var(--theme-accent) 50%, transparent);
  transition: width 0.25s ease;
}

.stage {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--theme-accent) 22%, transparent),
    0 0 40px color-mix(in srgb, var(--theme-accent) 10%, transparent),
    0 28px 56px rgba(0, 0, 0, 0.5);
  animation: stageIn 0.5s ease both;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  background: var(--wall);
  vertical-align: middle;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--theme-accent) 12%, transparent), transparent 45%),
    linear-gradient(180deg, rgba(8, 24, 32, 0.5), rgba(8, 24, 32, 0.86));
  backdrop-filter: blur(3px);
  transition: opacity 0.28s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  text-align: center;
  max-width: min(28rem, 94vw);
  max-height: min(92vh, 920px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 1.85rem 1.6rem 1.5rem;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--theme-accent) 28%, transparent);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  animation: panelPop 0.35s ease both;
  width: 100%;
  box-sizing: border-box;
}

.panel #fb-root {
  width: 100%;
  max-width: 100%;
}

.panel h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.8rem;
  margin-bottom: 0.65rem;
  letter-spacing: -0.02em;
}

.panel p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.panel .hint {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

#start-btn {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: #0b1f2a;
  background: linear-gradient(135deg, #f0b429, var(--theme-accent));
  border: none;
  border-radius: 9px;
  padding: 0.75rem 1.7rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

#start-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

#start-btn:active {
  transform: translateY(0);
}

@keyframes brandShift {
  from { background-position: 0% 50%; }
  to { background-position: 100% 50%; }
}

@keyframes stageIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes panelPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 640px) {
  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-right {
    width: 100%;
    align-items: stretch;
  }

  .lang-picker {
    justify-content: space-between;
  }

  .stats {
    width: 100%;
    justify-content: flex-start;
  }

  .stat {
    flex: 1;
    min-width: 0;
  }

  .stat-value {
    font-size: 0.85rem;
  }
}
