:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --bg-gradient: linear-gradient(135deg, #f3e8ff 0%, #e0e7ff 100%);
  --card-bg: #ffffff;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 20px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  font-family: 'Comic Sans MS', 'Bubblegum Sans', 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
}

#app-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  max-height: 900px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

@media (min-width: 481px) {
  #app-container {
    border-radius: 32px;
    height: 92vh;
    border: 8px solid #ffffff;
  }
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
  display: flex;
}

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

/* Common Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.profile-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f3f4f6;
  padding: 6px 14px;
  border-radius: 50px;
  cursor: pointer;
  border: 2px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  transition: all 0.2s;
}

.profile-pill:hover {
  background: #e5e7eb;
  transform: scale(1.02);
}

.icon-btn {
  background: #f3f4f6;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: #e5e7eb;
  transform: scale(1.05);
}

/* Typography */
h1 { font-size: 1.8rem; color: var(--primary); text-align: center; margin-bottom: 6px; }
h2 { font-size: 1.4rem; color: var(--text-main); margin-bottom: 12px; }
p.subtitle { text-align: center; color: var(--text-muted); font-size: 0.95rem; margin-bottom: 20px; }

/* Buttons */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: #f3f4f6;
  color: var(--text-main);
  box-shadow: none;
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: #e5e7eb;
  box-shadow: none;
}

.btn-danger {
  background: var(--danger);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: #dc2626;
}

/* Profiles Screen */
.profiles-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.profile-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.profile-card.active-profile {
  border-color: var(--primary);
  background: #eef2ff;
}

.profile-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.profile-avatar {
  font-size: 2.2rem;
  background: #f3f4f6;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.profile-actions {
  display: flex;
  gap: 8px;
}

.profile-actions button {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.profile-actions button:hover {
  background: rgba(0,0,0,0.05);
}

/* Modal */
.modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  width: 100%;
  max-width: 400px;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.open .modal-content {
  transform: scale(1);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.avatar-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.avatar-option {
  font-size: 1.8rem;
  background: #f3f4f6;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.avatar-option.selected {
  border-color: var(--primary);
  background: #eef2ff;
  transform: scale(1.05);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-buttons button {
  flex: 1;
}

/* Home Screen */
.target-grid-section {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  border: 2px solid var(--border);
  margin-bottom: 20px;
}

.target-numbers {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.target-btn {
  aspect-ratio: 1;
  background: #f3f4f6;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.target-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary-dark);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.mode-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.mode-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.mode-info h3 {
  font-size: 1.2rem;
  color: var(--text-main);
  margin-bottom: 4px;
}

.mode-info p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.mode-icon {
  font-size: 2.5rem;
}

.history-summary-card {
  background: #f8fafc;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  transition: all 0.2s;
}

.history-summary-card:hover {
  background: #f1f5f9;
  border-color: var(--primary);
  color: var(--primary);
}

/* Arena Screen */
.arena-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.arena-progress {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  background: #eef2ff;
  padding: 6px 14px;
  border-radius: 50px;
}

.arena-score {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.arena-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 10px;
}

.question-display {
  font-size: 4rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: 2px;
}

.answer-display {
  background: #f8fafc;
  border: 3px solid var(--border);
  border-radius: 16px;
  width: 180px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
  transition: all 0.2s;
}

.answer-display.correct {
  background: #d1fae5;
  border-color: var(--success);
  color: #065f46;
}

.answer-display.incorrect {
  background: #fee2e2;
  border-color: var(--danger);
  color: #991b1b;
}

.feedback-hint {
  background: #dcfce7;
  color: #166534;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  margin-top: 10px;
  font-size: 1.1rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.hidden {
  display: none !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.shake {
  animation: shake 0.4s ease-in-out;
}

/* Custom Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-bottom: 10px;
}

.numpad-btn {
  background: white;
  border: 2px solid var(--border);
  border-radius: 16px;
  height: 64px;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.02);
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.numpad-btn:hover {
  background: #f8fafc;
  border-color: var(--primary);
}

.numpad-btn:active {
  transform: scale(0.95);
  background: #eef2ff;
}

.numpad-btn.action-c {
  color: var(--danger);
}

.numpad-btn.action-del {
  color: var(--accent);
}

/* Results Screen */
.result-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.result-score-big {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary);
  margin: 10px 0;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.order-toggle-container {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  background: #f3f4f6;
  padding: 4px;
  border-radius: 14px;
  border: 2px solid var(--border);
}

.order-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.order-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.stat-box {
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}

.stat-box .label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-box .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
}

.review-section {
  margin-bottom: 20px;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 8px;
}

.review-item {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

/* History Screen */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.history-item {
  background: white;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-info .date {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-info .mode {
  font-weight: 700;
  color: var(--text-main);
  font-size: 1.05rem;
}

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