
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --ink: #202747;
  --muted: #68718b;
  --line: #e4e8f5;
  --surface: #ffffff;
  --background: #f5f7ff;
  --green: #15965c;
  --red: #dc3545;
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 5% 5%, #e7eaff 0, transparent 35%),
    radial-gradient(ellipse at 95% 20%, #fff0e2 0, transparent 25%),
    var(--background);
  line-height: 1.6;
}

button, input, select {
  font: inherit;
}

button, select, input[type="file"] {
  cursor: pointer;
}

button:focus-visible, a:focus-visible,
input:focus-visible, select:focus-visible {
  outline: 3px solid #a5b4fc;
  outline-offset: 3px;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 20px max(5%, calc((100% - 1150px) / 2));
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 800;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border-radius: 14px;
  background: #eeedff;
  font-size: 1.5rem;
}

.brand strong {
  color: var(--primary);
}

.header-label, .eyebrow {
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 1.2px;
}

.header-label {
  background: #eeedff;
  padding: 8px 13px;
  border-radius: 30px;
}

.container {
  width: min(100% - 32px, 1000px);
  margin: 0 auto;
}

.hero {
  padding: 48px 12px 28px;
  text-align: center;
}

.hero h1 {
  margin: 10px 0;
  font-size: clamp(2.1rem, 6vw, 3.8rem);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -1.5px;
}

.hero h1 span {
  color: var(--primary);
}

.hero p {
  max-width: 600px;
  margin: 12px auto;
  color: var(--muted);
  font-size: 1.05rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 10px 35px rgba(46, 57, 111, 0.055);
}

.settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.setting label {
  font-size: 0.84rem;
  font-weight: 800;
}

.setting select, .setting input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fafbff;
  border: 1px solid #dfe4f3;
  border-radius: 11px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 22px 0;
}

.stat-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 12px;
  padding: 17px 20px;
  border: 1px solid transparent;
  border-radius: 17px;
}

.stat-icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  font-size: 1.5rem;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.7px;
}

.stat-card strong {
  font-size: 1.65rem;
  line-height: 1.2;
}

.purple { background: #eeedff; border-color: #dfdcff; }
.blue { background: #e8f4ff; border-color: #d6eaff; }
.orange { background: #fff1e4; border-color: #ffe3cb; }
.timer-danger { background: #ffe7e9; border-color: #ffc6cb; animation: pulse 0.8s infinite alternate; }

.game-panel {
  padding: clamp(18px, 4vw, 36px);
  min-height: 300px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
  font-weight: 800;
}

.progress-track {
  width: 100%;
  height: 10px;
  margin: 12px 0 28px;
  background: #e8eafa;
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #a78bfa);
  border-radius: inherit;
  transition: width 0.35s ease;
}

.welcome-screen, .result-screen {
  text-align: center;
  padding: 12px 0;
}

.welcome-emoji, .result-emoji {
  font-size: 4.3rem;
  animation: float 2s ease-in-out infinite;
}

.welcome-screen h2, .result-screen h2 {
  margin: 8px 0;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.welcome-screen p, .result-screen > p {
  max-width: 550px;
  margin: 10px auto 22px;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 17px;
  border: 0;
  border-radius: 11px;
  font-weight: 900;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  color: white;
  background: var(--primary);
  box-shadow: 0 5px 12px #4f46e52b;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  color: #343b73;
  background: #e9eaff;
}

.btn-outline {
  color: var(--muted);
  background: white;
  border: 1px solid #dce1ef;
}

.btn-large {
  min-height: 54px;
  padding: 14px 26px;
  font-size: 1.05rem;
}

.question-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.operation-badge, .difficulty-badge {
  display: inline-flex;
  padding: 5px 11px;
  border-radius: 30px;
  background: #eeedff;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 900;
}

.difficulty-badge {
  color: #8b5700;
  background: #fff1cf;
}

.question-title {
  margin: 18px 0 3px;
  font-size: clamp(1.8rem, 5vw, 2.7rem);
  line-height: 1.25;
  font-weight: 900;
}

.instruction {
  color: var(--muted);
  margin-top: 8px;
}

.answers-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 24px 0;
}

.answer-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 100px;
  padding: 18px;
  border: 2px solid transparent;
  border-radius: 17px;
  color: #24284a;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(36, 40, 74, 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.answer-card:hover:not(:disabled) {
  transform: translateY(-4px) scale(1.015);
  box-shadow: 0 9px 18px #303b691c;
}

.answer-card:disabled {
  cursor: default;
}

.answer-card:nth-child(4n + 1) { background: #e7efff; border-color: #cddcff; }
.answer-card:nth-child(4n + 2) { background: #ffeddc; border-color: #ffdcc0; }
.answer-card:nth-child(4n + 3) { background: #e2f8ed; border-color: #c4efd8; }
.answer-card:nth-child(4n + 4) { background: #f5e7ff; border-color: #e8d0ff; }

.answer-card.correct {
  background: #c8f7db;
  border-color: var(--green);
  color: #087344;
  animation: pop 0.35s ease;
}

.answer-card.wrong {
  background: #ffe0e3;
  border-color: var(--red);
  color: #b42333;
  animation: shake 0.3s ease;
}

.feedback {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 16px;
  margin: 16px 0;
  border-radius: 15px;
  background: #e6f9ed;
  border: 1px solid #c9efd7;
  animation: slideUp 0.3s ease;
}

.feedback.is-wrong {
  background: #fff0e5;
  border-color: #ffddc5;
}

.feedback-emoji {
  font-size: 2.5rem;
}

.feedback strong {
  font-size: 1.1rem;
}

.feedback p {
  margin: 3px 0 0;
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.result-score {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 250px;
  margin: 20px auto;
  padding: 20px;
  background: #eeedff;
  border-radius: 18px;
}

.result-score span {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 900;
}

.result-score strong {
  font-size: 3rem;
  line-height: 1.2;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 20px 0;
}

.result-grid div {
  display: flex;
  flex-direction: column;
  padding: 15px 8px;
  background: #f7f8ff;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.result-grid strong {
  font-size: 1.5rem;
}

.result-grid span {
  color: var(--muted);
  font-size: 0.82rem;
}

.teacher-section {
  margin-top: 25px;
}

.teacher-section > div:first-child {
  margin-bottom: 12px;
}

.teacher-section h2 {
  margin: 5px 0;
}

.teacher-section p {
  color: var(--muted);
}

.teacher-panel {
  padding-top: 22px;
  margin-top: 22px;
  border-top: 1px solid var(--line);
}

.teacher-note {
  font-size: 0.9rem;
}

.teacher-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.teacher-preview {
  margin-top: 15px;
  padding: 18px;
  background: #f2f3ff;
  border-radius: 14px;
}

.question-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.question-item p {
  margin: 0;
  overflow-wrap: anywhere;
}

.question-item small {
  color: var(--muted);
}

.question-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.question-item-actions .btn {
  padding: 7px 10px;
  min-height: 36px;
  font-size: 0.83rem;
}

.import-label {
  cursor: pointer;
}

.learning-section {
  padding: 45px 0;
  text-align: center;
}

.learning-section > h2 {
  font-size: 1.8rem;
  margin-bottom: 22px;
}

.benefits-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.benefit-card {
  padding: 23px 17px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 17px;
}

.benefit-card > span {
  font-size: 2.3rem;
}

.benefit-card h3 {
  margin: 10px 0 4px;
}

.benefit-card p {
  color: var(--muted);
  font-size: 0.92rem;
}

.about-section {
  margin-bottom: 35px;
}

.about-section h2 {
  margin-top: 0;
}

.about-section p {
  color: var(--muted);
}

.site-footer {
  padding: 25px 16px;
  text-align: center;
  background: white;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
}

.site-footer a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.confetti {
  position: fixed;
  top: -20px;
  z-index: 9999;
  pointer-events: none;
  animation: fall 1.5s ease-in forwards;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}

@keyframes pop {
  50% { transform: scale(1.06); }
}

@keyframes pulse {
  to { transform: scale(1.025); }
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

@media (max-width: 760px) {
  .settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card {
    padding: 12px;
    column-gap: 7px;
  }

  .stat-icon {
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
  }

  .stat-card strong {
    font-size: 1.35rem;
  }

  .stat-label {
    font-size: 0.61rem;
  }

  .benefits-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .site-header {
    padding: 13px 16px;
  }

  .brand {
    font-size: 1rem;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
  }

  .header-label {
    font-size: 0.58rem;
    padding: 6px 8px;
  }

  .hero {
    padding-top: 35px;
  }

  .panel {
    padding: 17px;
  }

  .stats-grid {
    gap: 7px;
  }

  .answers-grid {
    gap: 9px;
  }

  .answer-card {
    min-height: 82px;
    padding: 12px;
  }

  .teacher-fields {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .question-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-actions .btn {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
