* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 10px;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  animation: slideIn 0.5s ease-out;
}

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

.header {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  padding: 30px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.header p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.main-content {
  padding: 30px;
}

/* Desktop Controls */
.controls-grid {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr;
  gap: 20px;
  margin-bottom: 30px;
}

.control-group {
  display: flex;
  flex-direction: column;
}

.control-group label {
  font-weight: 600;
  margin-bottom: 8px;
  color: #374151;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="number"] {
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  font-size: 16px;
  background: white;
  transition: all 0.3s ease;
  font-weight: 500;
}

select:focus, input[type="number"]:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  transform: translateY(-1px);
}

/* Mobile Controls - Hidden by default */
.mobile-controls {
  display: none;
}

.controls-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.controls-row:last-child {
  grid-template-columns: 1fr 1fr;
}

.timer-display {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  padding: 20px;
  border-radius: 15px;
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 8px 25px rgba(239, 68, 68, 0.3);
  transition: all 0.3s ease;
}

.timer-warning {
  animation: pulse 1s infinite;
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.progress-container {
  background: #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  height: 20px;
  margin-bottom: 20px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #059669);
  transition: width 0.5s ease;
  border-radius: 10px;
  width: 0%;
  position: absolute;
  left: 0;
  top: 0;
}

.progress-text {
  position: relative;
  z-index: 1;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.question-section {
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  border-radius: 20px;
  padding: 30px;
  margin: 15px auto 15px;
  text-align: center;
  border: 3px solid #e2e8f0;
}

.question-text {
  font-size: 2.2rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 15px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.answer-input {
  width: 300px;
  max-width: 100%;
  padding: 15px 20px;
  font-size: 1.5rem;
  text-align: center;
  border: 3px solid #cbd5e1;
  border-radius: 15px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.answer-input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2);
  transform: scale(1.05);
}

.desktop-tips {
  margin-top: 15px;
  font-size: 0.9rem;
  color: #64748b;
  line-height: 1.4;
}

.mobile-tips {
  display: none;
  margin-top: 10px;
  padding: 10px;
  background: #e0f2fe;
  border-radius: 8px;
  font-size: 0.8rem;
}

kbd {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.8rem;
  font-family: monospace;
}

/* Enhanced mobile keypad */
.mobile-keypad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 320px;
  margin: 15px auto 15px;
  background: rgba(255, 255, 255, 0.98);
  padding: 18px;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.keypad-btn {
  padding: 16px 10px;
  border: 2px solid rgba(226, 232, 240, 0.8);
  border-radius: 14px;
  background: linear-gradient(135deg, #ffffff, #f8fafc);
  font-size: 1.2rem;
  font-weight: 700;
  color: #1e293b;
  cursor: pointer;
  transition: none;
  will-change: transform;
  transform: translateZ(0); /* Force hardware acceleration */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.keypad-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, rgba(79, 70, 229, 0.1) 0%, transparent 70%);
  opacity: 0;
  transition: none;
}

.keypad-btn:active::before {
  opacity: 1;
}

.keypad-btn:hover {
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  transform: translateY(-1px) translateZ(0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-color: rgba(79, 70, 229, 0.3);
}

.keypad-btn:active {
  transform: translateY(0) scale(0.96) translateZ(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.keypad-btn.pressed {
  transform: scale(0.94) translateZ(0);
  background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.keypad-btn.operator {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  border-color: rgba(79, 70, 229, 0.8);
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.3);
}

.keypad-btn.operator:hover {
  background: linear-gradient(135deg, #4338ca, #6d28d9);
  box-shadow: 0 5px 15px rgba(79, 70, 229, 0.4);
}

.keypad-btn.delete {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  border-color: rgba(239, 68, 68, 0.8);
  box-shadow: 0 3px 10px rgba(239, 68, 68, 0.3);
}

.keypad-btn.delete:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
}

.keypad-btn.zero {
  grid-column: span 2;
}

.keypad-btn.enter {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border-color: rgba(16, 185, 129, 0.8);
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
  font-size: 1.1rem;
}

.keypad-btn.enter:hover {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 5px 15px rgba(16, 185, 129, 0.4);
}

.buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

.btn {
  padding: 10px 25px;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  box-shadow: 0 8px 25px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background: linear-gradient(135deg, #06b6d4, #0891b2);
  color: white;
  box-shadow: 0 8px 25px rgba(6, 182, 212, 0.3);
}

.btn-skip {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.3);
  font-size: 1rem;
  padding: 12px 20px;
}

.btn-stop {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 8px 25px rgba(239, 68, 68, 0.3);
  font-size: 1.1rem;
  padding: 15px 25px;
  width: 100%;
  margin-bottom: 20px;
}

.btn-stop:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(239, 68, 68, 0.4);
}

.stop-button-container {
  margin-bottom: 20px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
}

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

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.hint-section {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  border-left: 5px solid #f59e0b;
  display: none;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 200px; }
}

.hint-text {
  font-size: 1rem;
  color: #92400e;
  font-weight: 500;
  margin: 0;
}

.feedback {
  position: fixed !important;
  top: 20px !important;
  right: 20px !important;
  z-index: 999999 !important;
  font-size: 1rem;
  font-weight: 600;
  padding: 15px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  background: white;
  border: 2px solid #ccc;
  transition: all 0.3s ease;
  display: none;
  min-width: 200px;
  max-width: 300px;
  text-align: center;
  animation: slideInRight 0.3s ease-out;
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}

@keyframes slideInRight {
  from { 
    opacity: 0; 
    transform: translateX(100%); 
  }
  to { 
    opacity: 1; 
    transform: translateX(0); 
  }
}

@keyframes slideOutRight {
  from { 
    opacity: 1; 
    transform: translateX(0); 
  }
  to { 
    opacity: 0; 
    transform: translateX(100%); 
  }
}

.feedback.correct {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0) !important;
  color: #065f46 !important;
  border: 2px solid #10b981 !important;
  display: block !important;
}

.feedback.wrong {
  background: linear-gradient(135deg, #fee2e2, #fecaca) !important;
  color: #991b1b !important;
  border: 2px solid #ef4444 !important;
  display: block !important;
}

.feedback.hidden {
  animation: slideOutRight 0.3s ease-in forwards !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
  background: linear-gradient(135deg, #fdfdfd, #ffffff);
  border-radius: 20px;
  padding: 10px;
  margin: 15px auto 15px;
  border: 3px solid #e2e8f0;
}

.stat-card {
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  padding: 18px 15px;
  border-radius: 15px;
  text-align: center;
  border: 2px solid #e2e8f0;
  transition: all 0.3s ease;
  min-height: 85px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.history-section {
  background: #f8fafc;
  border-radius: 15px;
  padding: 25px;
  margin-top: 30px;
}

.history-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 20px;
  text-align: center;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.history-table th {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  padding: 15px 10px;
  font-weight: 600;
  text-align: center;
}

.history-table td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 500;
}

.history-table tr:nth-child(even) {
  background: #f8fafc;
}

.result-correct {
  color: #059669;
  font-weight: 700;
}

.result-wrong {
  color: #dc2626;
  font-weight: 700;
}

.game-over {
  text-align: center;
  padding: 40px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: 20px;
}

.game-over h2 {
  font-size: 2rem;
  color: #92400e;
  margin-bottom: 20px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  body {
    padding: 5px;
  }
  
  .container {
    border-radius: 15px;
  }
  
  .header {
    padding: 15px;
  }
  
  .header h1 {
    font-size: 1.5rem;
  }
  
  .header p {
    font-size: 0.9rem;
  }
  
  .main-content {
    padding: 15px;
  }
  
  /* Hide desktop controls, show mobile controls */
  .controls-grid {
    display: none;
  }
  
  .mobile-controls {
    display: block;
    margin-bottom: 15px;
  }
  
  .mobile-controls .control-group label {
    font-size: 0.75rem;
    margin-bottom: 5px;
  }
  
  .mobile-controls select,
  .mobile-controls input[type="number"] {
    padding: 10px 12px;
    font-size: 14px;
    border-radius: 10px;
  }
  
  /* Show mobile keypad */
  .mobile-keypad {
    display: grid !important;
    max-width: 100%;
    padding: 15px;
  }
  
  .keypad-btn {
    padding: 15px 8px;
    font-size: 1.1rem;
    min-height: 50px;
    border-radius: 12px;
  }
  
  /* Hide desktop tips, show mobile tips */
  .desktop-tips {
    display: none;
  }
  
  .mobile-tips {
    display: block;
  }
  
  .question-section {
    padding: 15px 15px;
  }
  
  .question-text {
    font-size: 1.5rem;
  }
  
  .answer-input {
    width: 100%;
    font-size: 1.2rem;
    padding: 12px 15px;
  }
  
  .answer-input[readonly] {
    cursor: pointer;
  }
  
  .buttons-grid {
    grid-template-columns: 1fr;
  }
  
  .stop-button-container {
    margin-bottom: 15px;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 15px;
  }
  
  .stat-card {
    padding: 10px;
    min-height: 65px;
  }
  
  .stat-value {
    font-size: 1.1rem;
  }
  
  .stat-label {
    font-size: 0.7rem;
  }
  
  .timer-display {
    padding: 12px;
    font-size: 1.2rem;
    margin-bottom: 15px;
  }
  
  .progress-container {
    height: 18px;
    margin-bottom: 15px;
  }
  
  .progress-text {
    font-size: 0.7rem;
  }

  .feedback {
    top: 10px !important;
    right: 10px !important;
    min-width: 180px;
    max-width: 280px;
    padding: 12px 16px;
    font-size: 0.9rem;
    border-radius: 10px;
  }
  
  .history-section {
    padding: 15px;
    margin-top: 20px;
  }

  .history-section div[style*="overflow"] {
    max-height: 250px !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .history-title {
    font-size: 1.2rem;
    margin-bottom: 15px;
  }
  
  .history-table {
    font-size: 0.7rem;
    min-width: 100%;
    white-space: nowrap;
  }
  
  .history-table th {
    font-size: 0.7rem;
  }

  .history-table th,
  .history-table td {
    padding: 6px 3px;
    white-space: nowrap;
  }
  
  .game-over {
    padding: 25px 15px;
  }
  
  .game-over h2 {
    font-size: 1.5rem;
  }
  
  .game-over p {
    font-size: 0.95rem;
    margin-bottom: 8px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .keypad-btn {
    padding: 12px 6px;
    font-size: 1rem;
    min-height: 45px;
  }
}
