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

body {
  font-family: 'Segoe UI', 'Comic Sans MS', 'Chalkboard SE', sans-serif;
  background: var(--gradient-bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  transition: background 0.5s;
}

#app {
  width: 100%;
  max-width: 440px;
  position: relative;
}

.screen {
  display: none;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: block;
}

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

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Welcome Screen */
.welcome-box {
  background: white;
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.welcome-box h1 {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 8px;
  transition: color 0.5s;
}

.subtitle {
  color: #666;
  font-size: 18px;
  margin-bottom: 32px;
}

.input-group {
  margin-bottom: 24px;
}

.input-group label {
  display: block;
  font-size: 16px;
  color: #555;
  margin-bottom: 8px;
  font-weight: 600;
}

#player-name {
  width: 100%;
  padding: 14px 20px;
  border: 3px solid var(--primary-border);
  border-radius: 14px;
  font-size: 20px;
  text-align: center;
  outline: none;
  transition: border-color 0.3s;
  font-family: inherit;
}

#player-name:focus {
  border-color: var(--primary);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  padding: 14px 48px;
  border-radius: 50px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.3s;
  font-family: inherit;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow-color);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Game Screen */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  background: white;
  padding: 12px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.level-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--secondary);
  background: var(--secondary-bg);
  padding: 4px 14px;
  border-radius: 20px;
  transition: color 0.5s, background 0.5s;
}

.lives {
  font-size: 24px;
  letter-spacing: 3px;
}

.score-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  transition: color 0.5s;
}

/* Progress Bar */
.progress-bar-container {
  background: var(--secondary-bg);
  border-radius: 10px;
  height: 10px;
  margin-bottom: 20px;
  overflow: hidden;
  transition: background 0.5s;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--secondary), var(--secondary-light));
  border-radius: 10px;
  transition: width 0.4s ease;
  width: 0%;
}

/* Question */
.question-area {
  display: flex;
  justify-content: center;
  margin-bottom: 28px;
}

.question-card {
  background: white;
  padding: 36px 40px;
  border-radius: 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 42px;
  font-weight: 800;
  color: #2d3436;
}

.question-card .operator {
  color: var(--primary);
  transition: color 0.5s;
}

.question-card .equals {
  color: #b2bec3;
}

.question-card .question-mark {
  color: var(--primary);
  animation: bounce 0.8s infinite;
  transition: color 0.5s;
}

/* Answer Form */
#answer-form {
  display: flex;
  gap: 10px;
}

#answer-input {
  flex: 1;
  padding: 16px 20px;
  border: 3px solid #dfe6e9;
  border-radius: 16px;
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  -moz-appearance: textfield;
}

#answer-input::-webkit-outer-spin-button,
#answer-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#answer-input:focus {
  border-color: var(--primary);
}

#submit-btn {
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--secondary), var(--secondary-light));
  color: white;
  border: none;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

#submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow-secondary);
}

#submit-btn:active {
  transform: translateY(0);
}

/* Result Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.result-box {
  background: white;
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  animation: popIn 0.3s ease;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: 320px;
  width: 90%;
}

.result-icon {
  font-size: 64px;
  margin-bottom: 12px;
}

.result-text {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  color: #2d3436;
}

.levelup-sub {
  font-size: 18px;
  color: #666;
  margin-bottom: 20px;
}

/* Level Up */
.levelup-box {
  border-top: 6px solid var(--secondary);
  transition: border-color 0.5s;
}

/* Tamat Screen */
.tamat-box {
  position: relative;
  overflow: hidden;
}

.tamat-icon {
  font-size: 80px;
  margin-bottom: 8px;
  animation: bounce 1s infinite;
}

.tamat-message {
  font-size: 16px;
  color: #555;
  margin-bottom: 4px;
  line-height: 1.5;
}

.tamat-hebat {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 20px;
  animation: bounce 1.2s infinite;
  transition: color 0.5s;
}

.tamat-box h1 {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 8px;
  transition: color 0.5s;
}

/* Game Over Screen */
.gameover-box {
  background: white;
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.gameover-box h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 8px;
  transition: color 0.5s;
}

.player-info {
  font-size: 18px;
  color: #666;
  margin-bottom: 20px;
}

.final-score {
  margin: 24px 0;
}

.score-label {
  display: block;
  font-size: 16px;
  color: #999;
  margin-bottom: 4px;
}

.score-value {
  font-size: 56px;
  font-weight: 800;
  color: var(--primary);
  transition: color 0.5s;
}

.high-score {
  font-size: 16px;
  color: #666;
  margin-bottom: 16px;
  padding: 10px 20px;
  background: var(--primary-bg);
  border-radius: 12px;
  display: inline-block;
  transition: background 0.5s;
}

.leaderboard {
  text-align: left;
  margin-bottom: 24px;
}

.leaderboard-title {
  font-size: 14px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  text-align: center;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 15px;
  color: #555;
  margin-bottom: 4px;
  background: #fafafa;
}

.leaderboard-list li:nth-child(1) {
  background: linear-gradient(135deg, #fff9e6, #fff3cc);
  color: #b8860b;
  font-weight: 700;
}

.leaderboard-list li:nth-child(2) {
  background: linear-gradient(135deg, #f0f0f0, #e8e8e8);
  color: #666;
  font-weight: 600;
}

.leaderboard-list li:nth-child(3) {
  background: linear-gradient(135deg, #fef0e6, #fde8d8);
  color: #8b4513;
  font-weight: 600;
}

.leaderboard-rank {
  font-weight: 700;
  margin-right: 10px;
  min-width: 20px;
}

.leaderboard-name {
  flex: 1;
  text-align: left;
}

.leaderboard-score {
  font-weight: 700;
}
