*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-gradient: linear-gradient(135deg, #fef3c7 0%, #e0f2fe 50%, #fce7f3 100%);
  --app-bg: rgba(255, 255, 255, 0.92);
  --primary: #f97316;
  --primary-dark: #ea580c;
  --accent-blue: #60a5fa;
  --accent-pink: #fb7185;
  --accent-yellow: #fcd34d;
  --accent-green: #34d399;
  --text-muted: #6b7280;
}

body {
  background: var(--bg-gradient);
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
}

.app {
  background: var(--app-bg);
  padding: 2.5rem 2rem;
  border-radius: 28px;
  box-shadow: 0 20px 45px rgba(14, 23, 38, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.7);
  width: min(92%, 640px);
  min-height: 90vh;
  display: flex;
  flex-direction: column;
  position: relative;
  backdrop-filter: blur(6px);
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.25rem;
  color: #0f172a;
  letter-spacing: 0.01em;
  text-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.title-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-toggle {
  border: 3px solid transparent;
  background: linear-gradient(135deg, #fde68a, #fca5a5);
  color: #7c2d12;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  line-height: 1;
  padding: 0;
  box-shadow: 0 8px 18px rgba(244, 114, 182, 0.25);
}

.settings-toggle:hover {
  transform: rotate(12deg) scale(1.05);
  box-shadow: 0 10px 22px rgba(249, 168, 212, 0.35);
}

.settings-toggle:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

.settings-toggle-icon {
  font-size: 1.4rem;
  display: block;
  transform: translateY(-1px);
}

.settings-panel {
  position: absolute;
  top: 2rem;
  right: 2rem;
  background: #fff9f2;
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(244, 114, 182, 0.2);
  border: 3px solid var(--accent-yellow);
  padding: 1.4rem;
  width: min(260px, 85vw);
  z-index: 10;
  text-align: left;
}

.card {
  background: linear-gradient(145deg, #fff7ed, #fffbeb);
  border: 4px solid var(--accent-yellow);
  border-radius: 24px;
  padding: 3rem 1.75rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: clamp(3.2rem, 8vw, 5.5rem);
  font-weight: 700;
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  box-shadow: 0 18px 40px rgba(251, 113, 133, 0.2);
}

.problem {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.2;
  font-family: "Fira Mono", "Roboto Mono", "SFMono-Regular", "Menlo", "Consolas", monospace;
  letter-spacing: 0.02em;
  color: #0f172a;
  text-shadow: 0 6px 12px rgba(15, 23, 42, 0.15);
}

.problem.finished {
  align-items: center;
  text-align: center;
  font-family: inherit;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.3;
  gap: 0.75rem;
}

.problem.finished .done-message {
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.problem.finished .results {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: clamp(1.15rem, 3vw, 1.4rem);
}

.problem.finished .result-line strong {
  color: var(--primary-dark);
}


.equation-row {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  width: 100%;
}

.operand {
  min-width: 4ch;
  text-align: right;
  display: inline-flex;
  justify-content: flex-end;
}

.operator {
  width: 2ch;
  text-align: center;
  display: inline-flex;
  justify-content: center;
}

.problem hr {
  border: none;
  border-top: 6px solid var(--accent-pink);
  width: 100%;
  margin-top: 0.6rem;
  border-radius: 999px;
}

.answer-row {
  margin-top: 1.4rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  align-items: center;
}

.answer-row input {
  width: clamp(140px, 30vw, 200px);
  font-size: 2rem;
  text-align: center;
  border: 3px solid var(--accent-blue);
  border-radius: 16px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  box-shadow: 0 10px 24px rgba(96, 165, 250, 0.35);
}

.answer-row input:focus-visible {
  outline: 3px solid var(--accent-pink);
  outline-offset: 3px;
}

button {
  font-size: 1.1rem;
  padding: 0.75rem 2.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), #f472b6);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 15px 28px rgba(249, 115, 22, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 32px rgba(244, 114, 182, 0.3);
  filter: brightness(1.03);
}

button:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

.status {
  margin-top: 1.2rem;
  font-size: 1.4rem;
  font-weight: 700;
  min-height: 1.8rem;
  color: #1f2937;
}

.status.correct {
  color: var(--accent-green);
}

.status.wrong {
  color: var(--accent-pink);
}

.summary {
  margin-top: 1rem;
  font-size: 1.05rem;
  text-align: left;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 18px rgba(148, 163, 184, 0.25);
}

.summary strong {
  color: var(--primary-dark);
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}

.controls label span {
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: #1f2937;
}

.controls input {
  font-size: 1rem;
  padding: 0.4rem 0.5rem;
  border: 2px solid var(--accent-blue);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 12px rgba(96, 165, 250, 0.2);
}

.controls input:focus-visible {
  outline: 3px solid var(--accent-pink);
  outline-offset: 2px;
}

.ops {
  grid-column: span 2;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 0.8rem;
  box-shadow: 0 6px 14px rgba(148, 163, 184, 0.2);
}

.ops label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  color: #1f2937;
}

.main-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  margin-top: 2rem;
  gap: 1.5rem;
  width: 100%;
  overflow: hidden;
}

#startBtn {
  align-self: center;
  font-size: 1.2rem;
  padding: 0.85rem 3rem;
  letter-spacing: 0.02em;
}

.hidden {
  display: none !important;
}

@media (max-width: 500px) {
  .card {
    font-size: clamp(2.6rem, 12vw, 3.4rem);
  }

  .operand {
    min-width: 3ch;
  }

  .answer-row input {
    width: clamp(120px, 60vw, 160px);
    font-size: 1.8rem;
  }

  .settings-toggle {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
  }
}
