/* Gilroy → system font fallback */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #F5F5F7;
  --white: #FFFFFF;
  --accent: #7B4FE0;
  --accent-light: #EDE6FA;
  --text: #1A1A1A;
  --text-muted: #888;
  --correct: #34C759;
  --wrong: #FF3B30;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 16px;
  --radius-sm: 10px;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  user-select: none;
}

/* ── SCREENS ─────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: var(--tg-viewport-stable-height, 100vh);
  width: 100%;
  background: var(--bg);
}
.screen.active { display: flex; }

/* ── HOME ─────────────────────────────────────────── */
.home-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 40px;
  gap: 0;
  min-height: 100%;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
}

.logo-frac {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 64px;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 8px;
}

.title {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 36px;
  color: var(--text);
  letter-spacing: -0.5px;
}

.subtitle {
  font-family: 'Gilroy', sans-serif;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 4px;
}

.section-label {
  font-family: 'Gilroy', sans-serif;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  align-self: flex-start;
  margin-bottom: 10px;
  margin-top: 24px;
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-group.wrap {
  flex-wrap: wrap;
}

.toggle-btn {
  flex: 1;
  min-width: 80px;
  padding: 12px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-muted);
  font-family: 'Gilroy', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: var(--shadow);
}

.toggle-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.btn-start {
  width: 100%;
  padding: 18px;
  margin-top: 36px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 22px;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(123,79,224,0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  -webkit-appearance: none;
}

.btn-start:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(123,79,224,0.25);
}

/* ── GAME ─────────────────────────────────────────── */
.game-header {
  padding: 16px 20px 12px;
  background: var(--white);
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
  flex-shrink: 0;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.progress-info span {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

#score-display {
  color: var(--accent);
}

.progress-bar-wrap {
  height: 4px;
  background: #E8E8EC;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 10%;
}

.timer-bar-wrap {
  height: 3px;
  background: #E8E8EC;
  border-radius: 99px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  width: 100%;
  transition: width 0.1s linear, background-color 0.5s ease;
}

.timer-bar.urgent {
  background: var(--wrong);
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 32px;
  gap: 32px;
}

/* ── PROBLEM ──────────────────────────────────────── */
.problem-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  animation: slideInQuestion 0.28s ease both;
}

.op-symbol {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 36px;
  color: var(--text-muted);
  line-height: 1;
  margin: 0 4px;
}

.fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.frac-num, .frac-den {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 42px;
  line-height: 1.1;
  color: var(--text);
}

.frac-line {
  width: 100%;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  margin: 4px 0;
  min-width: 48px;
}

.problem-label {
  font-family: 'Gilroy', sans-serif;
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
  font-weight: 600;
  width: 100%;
}

/* ── CHOICES ──────────────────────────────────────── */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.choice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease;
  animation: fadeInUp 0.2s ease both;
}

.choice-btn:nth-child(2) { animation-delay: 0.03s; }
.choice-btn:nth-child(3) { animation-delay: 0.06s; }
.choice-btn:nth-child(4) { animation-delay: 0.09s; }

.choice-btn:active {
  transform: scale(0.97);
}

.choice-btn.correct {
  border-color: var(--correct);
  background: #F0FFF4;
  animation: correctPulse 0.4s ease forwards;
}

.choice-btn.wrong {
  border-color: var(--wrong);
  background: #FFF5F5;
  animation: wrongShake 0.4s ease forwards;
}

.choice-btn.reveal {
  border-color: var(--correct);
  background: #F0FFF4;
}

.choice-btn .fraction .frac-num,
.choice-btn .fraction .frac-den {
  font-size: 28px;
}

.choice-btn .fraction .frac-line {
  min-width: 32px;
}

.choice-btn .whole-num {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 32px;
  color: var(--text);
}

/* ── RESULTS ──────────────────────────────────────── */
.results-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 48px;
  min-height: 100%;
  gap: 8px;
}

.result-emoji {
  font-size: 64px;
  margin-bottom: 16px;
  line-height: 1;
  animation: pop 0.35s ease;
}

.result-score {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 80px;
  color: var(--accent);
  line-height: 1;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.result-label {
  font-family: 'Gilroy', sans-serif;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.record-display {
  font-family: 'Gilroy', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 24px;
}

.record-display.new-record {
  color: var(--accent);
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: 0.2s;
}

.result-stats {
  display: flex;
  gap: 32px;
  margin-bottom: 40px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-val {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 40px;
  color: var(--text);
  line-height: 1;
}

.stat-name {
  font-family: 'Gilroy', sans-serif;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-home {
  width: 100%;
  padding: 14px;
  margin-top: 12px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font-family: 'Gilroy', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-home:active {
  background: var(--accent-light);
}

/* ── FEEDBACK OVERLAY ─────────────────────────────── */
.feedback-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  border-radius: 0;
  z-index: 10;
}

.feedback-overlay.show-correct {
  background: rgba(52, 199, 89, 0.12);
  opacity: 1;
}

.feedback-overlay.show-wrong {
  background: rgba(255, 59, 48, 0.12);
  opacity: 1;
}

/* ── HINT TRIGGER BUTTON ──────────────────────────── */
.hint-trigger-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.btn-hint-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 2px solid #E0D4F7;
  border-radius: 99px;
  background: var(--white);
  color: var(--accent);
  cursor: pointer;
  font-family: 'Gilroy', sans-serif;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(123,79,224,0.1);
  transition: all 0.18s ease;
}

.btn-hint-trigger:active {
  transform: scale(0.95);
}

.btn-hint-trigger.used {
  opacity: 0.4;
  pointer-events: none;
}

.bulb-icon {
  font-size: 18px;
  animation: bulgePulse 2s ease infinite;
  display: inline-block;
}

@keyframes bulgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ── HINT OVERLAY ─────────────────────────────────── */
.hint-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.hint-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.hint-overlay.active .hint-card {
  transform: translateY(0);
}

.hint-card {
  background: var(--white);
  border-radius: 24px 24px 0 0;
  padding: 24px 24px 32px;
  width: 100%;
  max-width: 520px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

/* ── Hint card header ─────────────────────────────── */
.hint-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.hint-title {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 20px;
  color: var(--text);
}

.btn-skip {
  font-family: 'Gilroy', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
}

/* ── Animation stage ──────────────────────────────── */
.anim-stage {
  min-height: 200px;
  max-height: 52vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0 16px;
  margin-bottom: 16px;
}

/* Problem row — big fractions */
.av-prob-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.av-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 38px;
  line-height: 1.1;
}

.av-slot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 28px;
  justify-content: center;
}

.av-val {
  display: inline-block;
  position: relative;
}

.av-fline {
  width: calc(100% + 8px);
  min-width: 34px;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  margin: 3px 0;
}

.av-fline-green {
  background: var(--correct);
}

.av-op-sym {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 32px;
  color: var(--text-muted);
  transition: color 0.3s;
}

.av-op-sym.op-switched {
  color: var(--accent);
  animation: opPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Strike-through animation */
.av-strikeline {
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 3px;
  background: var(--wrong);
  border-radius: 2px;
  transform: translateY(-50%) scaleX(0);
  transform-origin: left center;
  animation: strikeGrow 0.65s linear forwards;
}

@keyframes strikeGrow {
  0%   { transform: translateY(-50%) scaleX(0); }
  100% { transform: translateY(-50%) scaleX(1); }
}

@keyframes hlNum {
  from { color: inherit; }
  to   { color: var(--accent); }
}

@keyframes hlDen {
  from { color: inherit; }
  to   { color: #FF9500; }
}

@keyframes dimVal {
  to { opacity: 0.3; }
}

/* Replacement arrow + new value */
.av-rarrow {
  font-size: 16px;
  color: var(--text-muted);
  opacity: 0;
  animation: gentleFade 0.5s ease 0.05s both;
  margin: 0 2px;
}

.av-new-val {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 0.9em;
  color: var(--correct);
  opacity: 0;
  animation: gentleSlideIn 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.1s both;
}

/* Highlight classes */
.av-val.hl-n {
  color: var(--accent);
  transition: color 0.5s ease;
}

.av-val.hl-d {
  color: #FF9500;
  transition: color 0.5s ease;
}

/* Calc rows */
.av-calc-row {
  font-family: 'Gilroy', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  animation: gentleRise 0.55s cubic-bezier(0.4, 0, 0.2, 1) both;
  line-height: 1.5;
}

.av-calc-row strong {
  font-size: 17px;
}

.av-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #aaa;
  margin-left: 6px;
}

.hl-n {
  color: var(--accent);
  font-weight: 700;
}

.hl-d {
  color: #FF9500;
  font-weight: 700;
}

/* Result row (intermediate, with possible strike) */
.av-res-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  animation: gentleRise 0.6s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.av-res-row .av-frac {
  font-size: 32px;
}

/* Final big green result */
.av-final-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 0 8px;
  animation: gentleRise 0.7s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.av-frac-final {
  font-size: 52px;
  color: var(--correct);
}

.av-frac-final .av-val {
  color: var(--correct);
}

.av-whole-result {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 52px;
  color: var(--correct);
}

.av-eq-sym {
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 28px;
  color: var(--text-muted);
}

/* Divide flip animation */
.av-flip-wrap {
  display: inline-flex;
}

.av-flip-wrap.flipping .av-frac {
  animation: fracFlip 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fracFlip {
  0%   { transform: scaleX(1); }
  45%  { transform: scaleX(0.04); }
  55%  { transform: scaleX(0.04); }
  100% { transform: scaleX(1); }
}

@keyframes opPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* Gentle rise — for calc rows and result rows */
@keyframes gentleRise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gentle fade — for arrow */
@keyframes gentleFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Gentle slide in from left — for new values */
@keyframes gentleSlideIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

.btn-hint-ok {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: 'Delta Gothic One', sans-serif;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(123,79,224,0.3);
  transition: transform 0.12s ease, opacity 0.25s ease;
  -webkit-appearance: none;
  opacity: 0;
  pointer-events: none;
}

.btn-hint-ok.visible {
  opacity: 1;
  pointer-events: all;
  animation: fadeInUp 0.3s ease both;
}

.btn-hint-ok:active {
  transform: scale(0.97);
}

/* ── ANIMATIONS ───────────────────────────────────── */
@keyframes slideInQuestion {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes correctPulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.07); }
  70%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-7px); }
  35%       { transform: translateX(7px); }
  55%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

@keyframes pop {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes popIn {
  0%   { transform: scale(0.7); opacity: 0; }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
