:root {
  --bg: #53bc8f;
  --btn: #3c8c64;
  --btn-hover: #317553;
  --shop: #4664b4;
  --shop-hover: #385196;
  --exit: #963232;
  --exit-hover: #7c2727;
  --gold: #ffd700;
  --red: #c83232;
  --white: #ffffff;
  --black: #111111;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Segoe UI', Arial, sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  margin: 0;
  font-weight: 800;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.subtitle {
  font-size: 1.05rem;
  opacity: 0.92;
  margin-top: -8px;
}

.coins-banner {
  font-size: clamp(1.4rem, 3.5vw, 2.1rem);
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  width: 100%;
}

.topic-card {
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  transition: 0.15s ease;
}

.topic-card:hover { background: rgba(255, 255, 255, 0.24); }
.topic-card.selected {
  background: var(--btn);
  border-color: var(--gold);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.topic-title { font-weight: 800; font-size: 1.05rem; margin-bottom: 4px; }
.topic-desc { font-size: 0.86rem; opacity: 0.9; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: var(--btn);
  color: var(--white);
  border: none;
  border-radius: 18px;
  padding: 16px 28px;
  font-size: clamp(1.1rem, 2.5vw, 1.4rem);
  font-weight: 700;
  cursor: pointer;
  min-width: 220px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(2px); }
.btn-shop { background: var(--shop); }
.btn-shop:hover { background: var(--shop-hover); }
.btn-exit { background: var(--exit); }
.btn-exit:hover { background: var(--exit-hover); }
.btn-small { min-width: auto; padding: 10px 18px; font-size: 1rem; border-radius: 12px; }

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(1.15rem, 2.8vw, 1.6rem);
  font-weight: 800;
  background: rgba(0, 0, 0, 0.14);
  padding: 10px 18px;
  border-radius: 16px;
}

.hud-coins { color: var(--gold); }
.hud-timer.danger {
  color: #ffdddd;
  background: var(--red);
  padding: 2px 12px;
  border-radius: 10px;
}

.question-box {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 22px;
  padding: 20px 24px;
  width: 100%;
  min-height: 145px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.question-hint {
  font-size: 0.98rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.16);
  padding: 4px 12px;
  border-radius: 999px;
}

.math-expr {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: clamp(2.1rem, 5.5vw, 3.5rem);
  font-weight: 800;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}
.frac .num { border-bottom: 4px solid currentColor; padding: 0 8px 4px; }
.frac .den { padding: 4px 8px 0; }

.answer-area { 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  gap: 12px; 
  min-height: 90px;
}
.shake { animation: shakeAnim 0.35s ease; }

@keyframes shakeAnim {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-12px); }
  50% { transform: translateX(12px); }
  75% { transform: translateX(-8px); }
}

/* ==================== НОВЫЕ СТИЛИ ДЛЯ ВВОДА ==================== */
.slot {
  background: var(--white);
  color: var(--black);
  min-width: 70px;
  height: 60px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 1.9rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  transition: all 0.15s ease;
}

.slot.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(255, 215, 0, 0.35);
}

.single-slot { min-width: 200px; height: 74px; font-size: 2.3rem; }
.whole-slot { min-width: 70px; height: 74px; font-size: 2.1rem; }

.frac-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.frac-line {
  width: 100%;
  min-width: 70px;
  height: 4px;
  background: var(--white);
  border-radius: 2px;
}

.mixed-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
/* ============================================================= */

.feedback { min-height: 30px; font-size: 1.2rem; font-weight: 800; }

.numpad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.num-btn {
  background: rgba(255, 255, 255, 0.92);
  color: var(--black);
  border: none;
  border-radius: 12px;
  padding: 13px 0;
  font-size: 1.35rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

.num-btn:active { transform: translateY(2px); }
.num-btn.action-del { background: #f5c6c6; color: #801b1b; }
.num-btn.action-next { background: #dce7ff; color: #1f3c88; font-size: 0.95rem; }
.num-btn.action-ok { background: var(--gold); color: #2b2100; grid-column: span 2; }

.shop-list { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 600px; }
.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--btn);
  padding: 16px 20px;
  border-radius: 16px;
  gap: 12px;
  text-align: left;
}
.shop-item-title { font-size: 1.15rem; font-weight: 800; }
.shop-item-sub { font-size: 0.9rem; opacity: 0.9; }
.diff-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.16);
  color: var(--white);
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.diff-btn.selected {
  background: var(--btn);
  border-color: var(--gold);
}

.mixed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.grade-box {
  background: rgba(0, 0, 0, 0.28);
  border: 3px solid var(--gold);
  border-radius: 18px;
  padding: 14px 22px;
  font-size: 1.25rem;
  font-weight: 800;
}

.frac-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.frac-line {
  width: 100%;
  min-width: 70px;
  height: 4px;
  background: var(--white);
  border-radius: 2px;
}

.slot {
  background: var(--white);
  color: var(--black);
  min-width: 70px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 1.9rem;
  font-weight: 800;
  border: 3px solid transparent;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.slot.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(255, 215, 0, 0.35);
}

.slot {
  background: var(--white);
  color: var(--black);
  min-width: 80px;
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 1.1rem;  /* Уменьшенный шрифт для подписей */
  font-weight: 700;
  border: 3px solid transparent;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
  padding: 0 10px;
  transition: all 0.15s ease;
}

.site-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 14px;
  font-size: 0.9rem;
  opacity: 0.92;
}

.footer-link {
  background: rgba(0, 0, 0, 0.18);
  color: var(--white);
  border: none;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.footer-link:hover {
  background: rgba(0, 0, 0, 0.3);
}

.donate-link {
  background: rgba(255, 215, 0, 0.22);
  color: var(--gold);
  border: 1px solid rgba(255, 215, 0, 0.5);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: #2f7d5b;
  border: 3px solid var(--gold);
  border-radius: 20px;
  padding: 22px 24px;
  max-width: 460px;
  width: 100%;
  text-align: left;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.modal-card h2 {
  margin: 0 0 10px;
  font-size: 1.4rem;
}

.modal-card p {
  margin: 8px 0;
  font-size: 0.96rem;
  line-height: 1.45;
}
