:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #ec4899;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-light: #f8fafc;
  --text-dim: #94a3b8;
  --success: #22c55e;
  --danger: #ef4444;
  --font-main: "Outfit", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
}

body {
  background-color: var(--bg-dark);
  color: var(--text-light);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden; /* Prevent scrolling on mobile */
}

.app-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  background-color: var(--bg-dark);
  position: relative;
  display: flex;
  flex-direction: column;
}

@media (min-width: 481px) {
  .app-container {
    height: 800px;
    border-radius: 24px;
    background-color: var(--bg-card);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
  }
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  background-color: inherit; /* Inherit from container */
  overflow-y: auto;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
  z-index: 10;
}

.screen.hidden {
  display: none; /* Fully hide to prevent focus issues */
}

/* Typography */
h1.logo {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(to right, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2rem;
  margin-top: 2rem;
  text-align: center;
}

h2 {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
}

/* Settings */
.settings-group {
  width: 100%;
  margin-bottom: 1.5rem;
}

.settings-group label {
  display: block;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toggle-group {
  display: flex;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.toggle-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.toggle-btn.active {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Buttons */
.primary-btn,
.secondary-btn,
.danger-btn {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  border: none;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: transform 0.1s;
}

.primary-btn:active,
.secondary-btn:active,
.danger-btn:active {
  transform: scale(0.98);
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
  margin-top: auto; /* Push to bottom if flex container */
}

.secondary-btn {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-light);
}

.danger-btn {
  background-color: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  margin-top: auto;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
}

/* Game Screen */
.game-controls {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 1rem;
}

.game-header {
  width: 100%;
  margin-bottom: 2rem;
}

.progress-container {
  width: 100%;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: var(--success);
  width: 0%;
  transition: width 0.3s ease;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-dim);
}

.equation-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.equation {
  font-size: 3.5rem;
  font-weight: 800;
  text-align: center;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.input-area {
  width: 100%;
  margin-top: auto;
  padding-bottom: 2rem;
}

/* MC Options */
.mc-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.mc-btn {
  background-color: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.1);
  color: white;
  padding: 20px;
  border-radius: 16px;
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.mc-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.mc-btn.correct {
  background-color: var(--success);
  border-color: var(--success);
}

.mc-btn.wrong {
  background-color: var(--danger);
  border-color: var(--danger);
  opacity: 0.5;
}

/* Numpad / Input */
.numpad-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.answer-display {
  background-color: rgba(0, 0, 0, 0.3);
  padding: 1rem;
  border-radius: 12px;
  text-align: center;
  font-size: 2rem;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
}

.answer-display.correct {
  border-color: var(--success);
  color: var(--success);
}

.answer-display.wrong {
  border-color: var(--danger);
  color: var(--danger);
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.num-btn {
  background-color: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 15px;
  border-radius: 12px;
  font-size: 1.5rem;
  cursor: pointer;
}

.num-btn:active {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Results */
.score-card {
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 24px;
  padding: 2rem;
  width: 100%;
  margin-bottom: 2rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.stat-item .label {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.stat-item .value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}

/* History */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 1rem;
}

.history-list {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding-bottom: 1rem;
}

.history-item {
  background-color: rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.history-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.history-mode {
  font-size: 0.9rem;
  font-weight: 600;
}

.history-score {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--success);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  margin-top: 2rem;
}

/* Modal */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(5px);
  opacity: 1;
  transition: opacity 0.3s;
}

.modal.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background-color: var(--bg-card);
  padding: 2rem;
  border-radius: 24px;
  width: 80%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
