:root {
  --bg: #F7FAFB;
  --card: #FFFFFF;
  --text: #1F2937;
  --muted: #657280;
  --primary: #2353EB;
  --success: #16434A;
  --error: #DC2526;
  --accent: #F6350B;
  --neutral: #F1F037;
  --radius: 24px;
  --shadow: 0 12px 32px rgba(35, 83, 235, 0.08);
  --button-shadow: 0 4px 16px rgba(35, 83, 235, 0.24);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Lexend', 'Noto Sans', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;
  font-variant-numeric: tabular-nums;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

/* Header - Mobile First */
.app-header {
  width: 100%;
  max-width: 480px;
  padding: 8px 16px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  height: 50px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.top-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lang-btn {
  padding: 12px 16px;
  border: none;
  background: var(--neutral);
  color: var(--text);
  border-radius: 16px;
  font-weight: 600;
  font-size: 14px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: all 0.2s ease;
}

.lang-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.stats {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}

.hearts {
  display: flex;
  align-items: center;
}

.hearts svg {
  width: 24px;
  height: 24px;
  fill: var(--error);
  margin-right: 4px;
  filter: drop-shadow(0 2px 4px rgba(220, 37, 38, 0.2));
}

/* Main Card - Mobile Optimized */
.card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 12px;
  margin: 2px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  border: 1px solid rgba(35, 83, 235, 0.08);
  overflow: hidden;
}

/* Controls - Aligned for Better Layout */
.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.control-row {
  display: flex;
  gap: 12px;
  align-items: end;
  justify-content: flex-start;
  flex-wrap: nowrap;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  min-width: 120px;
}

.control-row:first-child .session-label {
  flex: 0 0 auto;
  width: 120px;
}

.control-row:first-child .range-label {
  flex: 1;
  margin-left: 8px;
}

.control-row:last-child .ops-label {
  flex: 1;
}

.control-row:last-child .primary {
  align-self: end;
  margin-left: auto;
}

.controls select {
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid rgba(35, 83, 235, 0.12);
  background: #fff;
  font-size: 14px;
  min-height: 48px;
  min-width: 80px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.controls select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(35, 83, 235, 0.08);
}

/* Buttons - Large Touch Targets */
.primary, .secondary {
  padding: 16px 24px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  min-height: 56px;
  min-width: 120px;
  touch-action: manipulation;
  transition: all 0.2s ease;
  letter-spacing: -0.01em;
}

.primary {
  background: #22c55e;
  color: white;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.24);
  padding: 16px 40px;
  font-size: 18px;
  min-height: 56px;
}

.primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.32);
}

.secondary {
  background: rgba(35, 83, 235, 0.08);
  color: var(--primary);
  border: 2px solid rgba(35, 83, 235, 0.12);
}

.secondary:active {
  background: rgba(35, 83, 235, 0.12);
  transform: translateY(1px);
}

/* Problem Area - Centered and Large */
.problem-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  overflow: hidden;
}

.progress {
  width: 100%;
  background: rgba(35, 83, 235, 0.08);
  border-radius: 12px;
  height: 12px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.4s ease;
  border-radius: 12px;
}

.problem {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 8px 0;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.answer {
  font-size: 24px;
  text-align: center;
  width: 120px;
  padding: 10px;
  border: 3px solid rgba(35, 83, 235, 0.12);
  border-radius: 16px;
  background: white;
  min-height: 48px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: all 0.2s ease;
  pointer-events: none;
  caret-color: transparent;
  user-select: none;
}

.answer:focus {
  outline: none;
}

/* Keypad - Large Touch Targets */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  justify-content: center;
  width: 100%;
  max-width: 280px;
  margin: 8px 0;
}

.keypad button {
  height: 56px;
  font-size: 24px;
  font-weight: 600;
  border-radius: 20px;
  border: none;
  background: var(--primary);
  color: white;
  box-shadow: var(--button-shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.keypad button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 12px rgba(35, 83, 235, 0.4);
}

.keypad .wide {
  grid-column: span 2;
}

.keypad .backspace {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 16px rgba(246, 53, 11, 0.24);
  height: 48px;
  font-size: 20px;
}

.keypad .backspace:active {
  box-shadow: 0 2px 12px rgba(246, 53, 11, 0.4);
}

/* Feedback */
.feedback {
  min-height: 24px;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px 0;
}

.feedback.ok {
  color: var(--success);
}

.feedback.no {
  color: var(--error);
}

/* Results */
.results.hidden {
  display: none;
}

.results {
  text-align: center;
}

.results h2 {
  margin: 0 0 16px;
  font-size: 24px;
}

.results .stars {
  margin: 16px 0;
}

.results .stars svg {
  width: 36px;
  height: 36px;
  fill: var(--accent);
  margin: 0 6px;
  filter: drop-shadow(0 2px 8px rgba(246, 53, 11, 0.3));
}

.badges {
  margin: 16px 0;
}

.badges svg {
  width: 32px;
  height: 32px;
  fill: var(--success);
  margin: 0 8px;
  filter: drop-shadow(0 2px 6px rgba(22, 67, 74, 0.3));
}

.cta-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 20px 0;
  flex-wrap: wrap;
}

.session-stats {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(35, 83, 235, 0.12);
}

.session-stats p {
  margin: 4px 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

/* Footer */
.app-footer {
  width: 100%;
  max-width: 480px;
  padding: 8px;
  text-align: center;
  flex-shrink: 0;
}

.app-footer small {
  color: var(--muted);
  font-size: 11px;
}

/* Accessibility & Motion */
@media (prefers-reduced-motion: reduce) {
  .progress span,
  .primary,
  .keypad button {
    transition: none;
  }
}

/* Larger screens - tablets and up */
@media (min-width: 768px) {
  .app-header {
    max-width: 600px;
  }
  
  .card {
    max-width: 600px;
    padding: 24px;
  }
  
  .app-header h1 {
    font-size: 32px;
  }
  
  .problem {
    font-size: 64px;
  }
  
  .control-row {
    flex-wrap: nowrap;
  }
  
  .keypad {
    max-width: 320px;
  }
  
  .keypad button {
    height: 64px;
    font-size: 28px;
  }
}

/* Very small screens - extra mobile optimization */
@media (max-width: 360px) {
  .card {
    margin: 4px 8px;
    padding: 12px;
  }
  
  .problem {
    font-size: 36px;
  }
  
  .answer {
    font-size: 28px;
    width: 120px;
  }
  
  .keypad {
    max-width: 240px;
  }
  
  .keypad button {
    height: 50px;
    font-size: 20px;
  }
  
  .controls label {
    font-size: 13px;
    min-width: 100px;
  }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 600px) {
  .problem {
    font-size: 36px;
    margin: 8px 0;
  }
  
  .card {
    gap: 8px;
  }
  
  .problem-area {
    gap: 8px;
  }
}