/* ===== Colors (all in one place) ===== */
:root {
  --bg: #f4f6f8;
  --cyan: #29c1f0;        /* SCIENCE + "math" + logo blue */
  --indigo: #3b4fd6;      /* "physics" */
  --indigo-soft: #5566dd; /* "always learn" + "Mini Games" */
  --violet: #6c46f0;      /* "Download App" */
  --pink: #ff2e9a;        /* the "|" before EN */
  --ink: #2a2f3a;         /* "EN" text */
  --team1: #ff4b4c;       /* team 1 (red) */
  --team2: #29c1f0;       /* team 2 (blue) */
}

/* ===== REMOVE MOBILE TAP HIGHLIGHT GLOBALLY ===== */
*,
*::before,
*::after,
button,
a,
input,
div,
span,
canvas,
rive-canvas {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  touch-action: manipulation;   /* lets two simultaneous touches register as taps, not a pinch/zoom gesture */
  -webkit-tap-highlight-color: transparent !important;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
  -webkit-touch-callout: none;
  outline: none !important;
}

*:focus,
*:focus-visible,
*:active {
  -webkit-tap-highlight-color: transparent !important;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
  outline: none !important;
}

body {
  font-family: "Inter", sans-serif;
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===== Full-page animation =====
   BEHIND (z-index 1): SCIENCE, math, physics, always learn
   ANIMATION (z-index 2)
   ON TOP (z-index 3): logo, Download App, Mini Games, EN */
.rive-bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 2;
  display: block;
}

/* ===== Top bar (responsive) ===== */
.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(18px, 3vw, 34px) clamp(22px, 4vw, 48px);
}

.logo {
  /* Uses cqw/vw scaling so it shrinks smoothly on narrow screens */
  height: clamp(20px, 3.5vw, 32px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
}

.download-app {
  font-size: clamp(15px, 1.4vw, 20px);
  font-weight: 700;
  color: var(--violet);
  text-decoration: none;
  white-space: nowrap;
}

.download-app:hover {
  opacity: 0.8;
}

/* ===== Hero (center area) ===== */
.hero {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  min-height: calc(100vh - 200px);
}

/* Middle content. Main size dials: .science font-size + .stage max-width */
.stage {
  position: relative;
  width: 100%;
  max-width: 1350px;
  aspect-ratio: 1000 / 560;
}

/* Big word - BEHIND the animation */
.science {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  /* Uses min() so it scales smoothly down on small screens while obeying the clamp max */
  font-size: clamp(32px, 15vw, 400px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--cyan);
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}

/* Main hero center character illustration (Mr. Square) */
.hero-character,
.hero-center-avatar,
.hero-img {
  width: clamp(280px, 38vw, 540px);
  height: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

/* ===== Labels ===== */

/* math + physics - BEHIND the animation (z-index 1) */
.labels-left {
  position: absolute;
  top: 16%;
  left: 16%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}

.label-math {
  font-size: clamp(16px, 2.5vw, 48px);
  font-weight: 700;
  color: var(--cyan);
}

.label-physics {
  font-size: clamp(16px, 2.5vw, 48px);
  font-weight: 700;
  color: var(--indigo);
}

.label-always {
  position: absolute;
  top: 3%;
  right: 27%;
  z-index: 1;
  font-size: clamp(12px, 1.8vw, 32px);
  font-weight: 500;
  color: var(--indigo-soft);
}

.label-mini {
  position: absolute;
  bottom: 11%;
  right: 8%;
  z-index: 3;
  font-size: clamp(16px, 2.2vw, 44px);
  font-weight: 600;
  color: var(--indigo-soft);
  text-decoration: none;
  cursor: pointer;

  /* Smooth return animation */
  display: inline-block;
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.15s ease;
  will-change: transform;
}

.label-mini:hover {
  opacity: 0.85;
}

/* Push down slightly when pressed/tapped */
.label-mini:active {
  transform: translateY(3px) scale(0.96);
  opacity: 0.7;
}

/* ===== Language selector (bottom-left) ===== */
.langbar {
  position: absolute;
  bottom: clamp(20px, 3vw, 34px);
  left: clamp(22px, 4vw, 48px);
  z-index: 3;
}

/* row holding: | CURRENT [options ->] */
.lang-switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-switch .bar {
  color: var(--pink);
  font-weight: 700;
  font-size: clamp(16px, 1.6vw, 22px);
}

/* shared look for every language word (current + options) */
.lang-current,
.lang-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(16px, 1.6vw, 22px);
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink);
  transition: opacity 0.15s ease;
  line-height: 1.2;
  white-space: nowrap;
}

/* the always-visible current language */
.lang-current {
  font-weight: 700;
}

.lang-current:hover {
  opacity: 0.75;
}

/* the two OTHER languages: in a ROW to the RIGHT, hidden until open */
.lang-options {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;

  /* closed state */
  opacity: 0;
  visibility: hidden;
  transform: translateX(-8px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

/* open state (added by JS) */
.lang-switch.open .lang-options {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.lang-btn {
  opacity: 0.55;
}

.lang-btn:hover {
  opacity: 1;
}

/* ===== Short screens ===== */
@media (max-height: 640px) {
  .hero { min-height: calc(100vh - 140px); }
}

/* =====================================================
   MINI GAMES PAGE
===================================================== */

/* logo wrapped in a link back home */
.logo-home {
  display: inline-flex;
  align-items: center;
  max-width: 40vw; /* Prevents logo from crushing center titles on narrow header bars */
}

/* title centered in the top bar, no matter the side widths */
.mini-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(18px, 1.8vw, 26px);
  font-weight: 700;
  color: var(--indigo-soft);
  white-space: nowrap;
}

/* pink "Download App" (this page only) */
.download-app--pink {
  color: var(--pink);
}

/* main column: box + play, stacked + centered */
.mini-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vh, 34px);
  min-height: calc(100vh - 170px);
  padding: 20px;
}

/* ===== ONE container: avatar (back) + toggle (front) ===== */
.game-box {
  position: relative;
  width: clamp(340px, 50vw, 640px);
  aspect-ratio: 1 / 1;
}

.game-box .avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

.game-box .difficulty {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}

/* ===== Difficulty toggle ===== */
.difficulty {
  display: inline-flex;
  align-items: center;
  background: #e9edf2;
  border-radius: 999px;
  padding: 5px;
}

.diff-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: clamp(14px, 1.3vw, 17px);
  letter-spacing: 0.04em;
  color: #9aa3ad;
  padding: 10px 22px;
  border-radius: 999px;
  transition: background 0.18s ease, color 0.18s ease;
}

.diff-btn:hover {
  color: #6b7480;
}

.diff-btn.active {
  background: var(--cyan);
  color: #fff;
}

/* ===== Play button ===== */
.play-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(16px, 1.6vw, 22px);
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--cyan);
  padding: 16px clamp(48px, 8vw, 90px);
  border-radius: 999px;
  transition: transform 0.12s ease;
}

.play-btn:active {
  transform: translateY(1px);
}

/* =====================================================
   GAME PAGE (two-team battle)
===================================================== */

/* Fill the space under the header and CENTER everything (both axes). */
.game-wrap {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;              /* vertical centering */
  justify-content: center;           /* horizontal centering */
  gap: clamp(16px, 2.5vw, 48px);
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  min-height: calc(100vh - 150px);   /* space below the top bar */
  padding: clamp(8px, 1.5vh, 20px) clamp(12px, 2vw, 32px);
  box-sizing: border-box;
}

/* ----- team calculator panel ----- */
.team-panel {
  container-type: inline-size;
  background: #fdfdfe;
  border: 3px solid #edf0f3;
  border-radius: 36px;
  padding: clamp(14px, 1.6vw, 28px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.4vw, 18px);
  width: auto;
  max-width: 460px;
  min-width: 280px;
  flex: 1 1 340px;                   /* Expands flexibly to widen calculators */
  box-sizing: border-box;
}

/* team header — pill outline */
.team-head {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: clamp(8px, 1vw, 14px);
  border-radius: 999px;
  border: 3px solid #edf0f3;
  font-size: clamp(13px, 1.3vw, 20px);
}

.team1 .team-head { color: var(--team1); }
.team2 .team-head { color: var(--team2); }

/* equation row: "12+32=" [box] */
.equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: clamp(18px, 8cqw, 42px);
  font-weight: 800;
  color: #4a5260;
  margin: 2px 0;
}

/* answer box: SQUARE by default, STRETCHES for long answers */
.eq-box {
  height: clamp(42px, 4vw, 58px);
  min-width: clamp(42px, 4vw, 58px);
  width: auto;
  padding: 0 10px;
  border-radius: 14px;
  border: 3px solid var(--cyan);
  background: #eaf7fd;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #3a4250;
  box-sizing: border-box;
}

.team1 .eq-box { border-color: var(--team1); background: #ffecec; }
.team2 .eq-box { border-color: var(--team2); background: #eaf7fd; }

/* typed-number display — pill, gray fill, WITH stroke */
.display {
  height: clamp(42px, 4vw, 60px);
  border-radius: 999px;
  background: #eef1f4;
  border: 3px solid #e2e7ec;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 1.8vw, 30px);
  font-weight: 700;
  color: #9aa3ad;
  box-sizing: border-box;
}

/* numpad */
.pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 0.8vw, 12px);
}

/* Flatter pill keys */
.key {
  --key-h: clamp(40px, 3.8vw, 58px);
  height: var(--key-h);
  padding: 0;
  border: 3px solid #eef1f4;
  background: #fff;
  border-radius: 999px;
  font-size: clamp(15px, 1.5vw, 24px);
  font-weight: 700;
  color: #3a4250;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease;
  box-sizing: border-box;
}

.key:hover { background: #f5f7f9; }
.key:active { transform: translateY(1px); }

/* backspace — soft gray fill */
.key.back {
  background: #eef1f4;
  border-color: #e2e7ec;
  color: #8b94a0;
  padding: 0;
}

.key.back:hover { background: #e6eaee; }

.key.back img {
  width: clamp(20px, 2vw, 32px);
  height: clamp(20px, 2vw, 32px);
  object-fit: contain;
  display: block;
  pointer-events: none;
}

/* minus — solid blue pill */
.key.op {
  background: var(--cyan);
  color: #fff;
  border-color: #1eb4e6;
}

/* CHECK button */
.check-btn {
  border: none;
  border-radius: 999px;
  padding: clamp(10px, 1.2vw, 18px);
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: clamp(13px, 1.2vw, 19px);
  color: #aeb6c0;
  background: #e9edf2;
  cursor: default;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
  box-sizing: border-box;
}

.check-btn.ready {
  color: #fff;
  background: var(--cyan);
  cursor: pointer;
}

.check-btn.ready:active { transform: translateY(1px); }

/* ----- center column ----- */
.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 1.4vh, 22px);
  flex: 0 1 auto;
}

.center.has-result { gap: clamp(8px, 1.2vh, 16px); }

/* timer pill */
.timer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 3px solid #edf0f3;
  border-radius: 999px;
  padding: clamp(6px, 0.8vw, 11px) clamp(16px, 1.5vw, 24px);
  box-sizing: border-box;
}

.clock { width: clamp(24px, 2vw, 34px); height: clamp(24px, 2vw, 34px); display: block; }
.timer-text {
  font-weight: 600;
  color: var(--team1);
  font-size: clamp(18px, 1.8vw, 26px);
}

.center-teams {
  display: flex;
  gap: clamp(16px, 3vw, 60px);
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

.team-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

/* LARGE DISPLAY SIZES */
.stars {
  width: clamp(160px, 18vw, 380px);
  height: auto;
  aspect-ratio: 370 / 132;
  display: block;
  margin-bottom: -10px;
  object-fit: contain;
}

.score { font-weight: 900; font-size: clamp(32px, 4vw, 76px); line-height: 1; }
.score-1 { color: var(--team1); }
.score-2 { color: var(--team2); }

/* LARGE DISPLAY SIZES */
.game-avatar {
  width: clamp(160px, 16vw, 360px);
  height: auto;
  aspect-ratio: 300 / 330;
  display: block;
  margin-top: -6px;
  object-fit: contain;
}

/* ----- countdown overlay ----- */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.countdown.hide { display: none; }

.countdown-text {
  color: #fff;
  font-weight: 900;
  font-size: clamp(90px, 18vw, 230px);
  line-height: 1;
  text-align: center;
}

.countdown-text.go {
  font-size: clamp(48px, 10vw, 150px);
}

.countdown-text.pop {
  animation: countPop 0.85s ease both;
}

@keyframes countPop {
  0%   { transform: scale(0.6); opacity: 0; }
  40%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ----- result section ----- */
.game-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  animation: resultIn 0.35s ease both;
}

.game-result[hidden] { display: none; }

@keyframes resultIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-title {
  font-size: clamp(18px, 2.5vw, 44px);
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.02em;
  text-align: center;
}

.result-title.win-1 { color: var(--team1); }
.result-title.win-2 { color: var(--team2); }

.restart-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: #fff;
  background: var(--cyan);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.restart-btn:hover { filter: brightness(1.05); }
.restart-btn:active { transform: scale(0.94); }

/* =====================================================
   MID-RANGE DISPLAY FIX (1001px to 1350px)
===================================================== */
@media screen and (max-width: 1350px) and (min-width: 1001px) {
  .game-wrap {
    padding: 10px 16px;
    gap: 16px;
  }

  .center-teams {
    gap: 18px;
  }

  .stars {
    width: clamp(130px, 14vw, 240px);
  }

  .game-avatar {
    width: clamp(130px, 13vw, 220px);
  }

  .team-panel {
    padding: 14px;
    border-radius: 28px;
    min-width: 250px;
  }
}

/* =====================================================
   RESPONSIVE ADJUSTMENTS (<= 1000px)
===================================================== */
@media (max-width: 1000px) {
  
  .logo {
    /* Lower minimum size (12px) and scaling rate (2.2vw) for small screens */
    height: clamp(12px, 2.2vw, 20px);
  }

  /* Enlarge Mr. Square Hero Character on small/mobile screens */
  .hero-character,
  .hero-center-avatar,
  .hero-center,
  .hero-img,
  .hero-character canvas,
  .hero-character svg,
  .hero-character rive-canvas {
    width: 100% !important;
    max-width: none !important;
  }

  /* 2. Задаем большой размер целевому блоку сцены */
  .stage, 
  .hero-character {
    width: clamp(450px, 95vw, 750px) !important;
    max-width: 98vw !important;
    height: auto !important;
    margin: 0 auto !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  /* Centered stage alignment */
  .hero {
    padding: 10px;
    min-height: calc(100vh - 160px);
  }

  .stage {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Scaled background text framing */
  .science {
    font-size: clamp(40px, 18vw, 180px);
  }

  /* ===== Main Game Wrapper ===== */
  .game-wrap {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;         /* Keeps both rows grouped nicely near center */
    align-items: flex-start;
    min-height: calc(100vh - 80px);
    max-height: 100vh;
    overflow-y: auto;
    padding: 8px 4px;
    gap: 0;
  }

  /* Middle Section Wrapper (Timer + Both Team Avatars) */
  .center {
    order: -1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0;
    gap: 2px;
  }

  /* Force Team Avatars to sit SIDE-BY-SIDE across the top */
  .center-teams {
    display: flex !important;
    flex-direction: row !important;
    width: 100%;
    max-width: 100%;
    justify-content: space-around;
    align-items: flex-end;
  }

  /* Each team's visual stack (stars + score + avatar) */
  .team-visual {
    flex: 1 1 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  /* ===== Stars, Scores, & Avatars ===== */
  .stars {
    width: clamp(90px, 25vw, 160px);
    height: auto;
    aspect-ratio: 370 / 132;
    margin-bottom: -4px;
  }

  .game-avatar {
    width: clamp(115px, 30vw, 190px);
    height: auto;
    aspect-ratio: 300 / 330;
    margin-top: -2px;
    margin-bottom: 0;
  }

  .score {
    font-size: clamp(24px, 5.5vw, 38px);
    text-align: center;
    line-height: 1;
  }

  .timer {
    padding: 4px 14px;
    margin: 0 auto;
  }

  .clock {
    width: 20px;
    height: 20px;
  }

  .timer-text {
    font-size: 16px;
  }

  /* ===== Side-by-Side 2-Column Calculators ===== */
  .team-panel {
    flex: 0 0 48%;
    width: 48%;
    min-width: 0;
    max-width: 48%;
    border-radius: 18px;
    padding: 6px;
    gap: 6px;
    margin: 6px auto 0 auto;       /* Positive top margin gives exact Breathing Room */
  }

  .team-head {
    padding: 4px;
    font-size: 11px;
    border-width: 2px;
  }

  .equation {
    font-size: clamp(14px, 3.2cqw, 18px);
    margin: 0;
    justify-content: center;
  }

  .eq-box {
    height: 30px;
    min-width: 30px;
    padding: 0 6px;
    border-radius: 8px;
    border-width: 2px;
  }

  .display {
    height: 30px;
    font-size: 15px;
    border-width: 2px;
  }

  .pad {
    gap: 3px;
  }

  .key {
    --key-h: 32px;
    font-size: 13px;
    border-width: 2px;
  }

  .key.back img {
    width: 16px;
    height: 16px;
  }

  .check-btn {
    padding: 8px;
    font-size: 11px;
  }
}