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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f0f4f8;
  color: #333;
  min-height: 100vh;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #4a90d9, #357abd);
  color: white;
  border-radius: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.logo {
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: -0.5px;
}

.header-right {
  display: flex;
  gap: 16px;
  font-size: 16px;
  font-weight: 600;
}

main {
  flex: 1;
}

.view {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: flex;
}

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

h1 {
  font-size: 36px;
  color: #2c3e50;
  text-align: center;
}

h2 {
  font-size: 28px;
  color: #2c3e50;
  text-align: center;
  width: 100%;
}

h3 {
  font-size: 20px;
  color: #555;
  text-align: center;
  width: 100%;
  margin-top: 8px;
}

.subtitle {
  font-size: 18px;
  color: #888;
  text-align: center;
}

.hero {
  text-align: center;
  padding: 24px 0;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  text-decoration: none;
  width: 100%;
}

.btn:active {
  transform: scale(0.97);
}

.btn-lg {
  padding: 20px 32px;
  font-size: 22px;
  border-radius: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, #4a90d9, #357abd);
  color: white;
  box-shadow: 0 4px 12px rgba(74, 144, 217, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(74, 144, 217, 0.4);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: linear-gradient(135deg, #f5a623, #e0961a);
  color: white;
  box-shadow: 0 4px 12px rgba(245, 166, 35, 0.3);
}

.btn-success {
  background: linear-gradient(135deg, #7ed321, #6bbd1b);
  color: white;
  box-shadow: 0 4px 12px rgba(126, 211, 33, 0.3);
}

.btn-info {
  background: linear-gradient(135deg, #50e3c2, #3dc9ab);
  color: white;
  box-shadow: 0 4px 12px rgba(80, 227, 194, 0.3);
}

.btn-text {
  background: none;
  color: #4a90d9;
  font-weight: 600;
  padding: 8px;
  width: auto;
}

.btn-text:hover {
  text-decoration: underline;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.topic-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 20px 12px;
  background: white;
  border: 3px solid #e0e6ed;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  line-height: 1.3;
}

.topic-card:hover {
  border-color: #4a90d9;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 144, 217, 0.15);
}

.topic-card.selected {
  border-color: #4a90d9;
  background: #eaf2fb;
  box-shadow: 0 4px 12px rgba(74, 144, 217, 0.2);
}

.difficulty-selector, .quiz-count-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
}

.diff-btn, .count-btn {
  padding: 8px 20px;
  border: 2px solid #d0d7e2;
  border-radius: 24px;
  background: white;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.diff-btn.active, .count-btn.active {
  background: #4a90d9;
  color: white;
  border-color: #4a90d9;
}

.problem-display {
  font-size: 48px;
  font-weight: 800;
  color: #2c3e50;
  text-align: center;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  width: 100%;
  word-break: break-all;
}

.answer-area {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.answer-area input {
  flex: 1;
  padding: 16px;
  font-size: 24px;
  font-weight: 700;
  border: 3px solid #d0d7e2;
  border-radius: 12px;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

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

.answer-area input:focus {
  border-color: #4a90d9;
}

.answer-area .btn {
  flex-shrink: 0;
  width: auto;
  padding: 16px 24px;
  font-size: 18px;
}

#practice-feedback, #quiz-feedback {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  width: 100%;
}

.feedback-correct {
  background: #e8f8d4;
  color: #4a7d15;
}

.feedback-incorrect {
  background: #fce4e4;
  color: #b00020;
}

.steps-box {
  background: #f8faff;
  border: 2px solid #d0e0f5;
  border-radius: 12px;
  padding: 16px 20px;
  width: 100%;
  line-height: 1.8;
  font-size: 16px;
}

.steps-box p {
  margin: 4px 0;
  padding-left: 12px;
  border-left: 3px solid #4a90d9;
}

.practice-header, .practice-actions {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-weight: 600;
  font-size: 16px;
  color: #666;
}

.practice-actions {
  gap: 12px;
}

.practice-actions .btn {
  width: auto;
  flex: 1;
}

.quiz-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  font-weight: 600;
}

.quiz-timer {
  font-size: 22px;
  font-weight: 800;
  color: #e74c3c;
  white-space: nowrap;
}

.quiz-progress-bar {
  height: 10px;
  background: #e0e6ed;
  border-radius: 5px;
  overflow: hidden;
}

#quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #7ed321, #4a90d9);
  border-radius: 5px;
  transition: width 0.3s ease;
  width: 0%;
}

.quiz-score {
  font-size: 16px;
  white-space: nowrap;
}

.quiz-question-num {
  font-size: 18px;
  font-weight: 700;
  color: #666;
}

.results-stars {
  font-size: 64px;
  text-align: center;
}

.results-score {
  font-size: 48px;
  font-weight: 800;
  color: #2c3e50;
}

.results-pct {
  font-size: 28px;
  font-weight: 700;
  color: #4a90d9;
}

.results-details {
  text-align: center;
  font-size: 18px;
  line-height: 1.8;
}

.results-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.progress-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 20px 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  font-size: 14px;
  color: #888;
  font-weight: 600;
}

.stat-value {
  display: block;
  font-size: 32px;
  font-weight: 800;
  color: #2c3e50;
  margin-bottom: 4px;
}

.topic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: white;
  border-radius: 12px;
  width: 100%;
  font-weight: 600;
}

.topic-row .topic-name {
  width: 100px;
  flex-shrink: 0;
}

.topic-row .topic-bar-bg {
  flex: 1;
  height: 20px;
  background: #e0e6ed;
  border-radius: 10px;
  overflow: hidden;
}

.topic-row .topic-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #7ed321, #4a90d9);
  border-radius: 10px;
  transition: width 0.5s ease;
}

.topic-row .topic-pct {
  width: 50px;
  text-align: right;
}

.quiz-history-item {
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}

@media (max-width: 500px) {
  .topic-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .problem-display {
    font-size: 36px;
    padding: 16px;
  }
  .progress-summary {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .stat-value {
    font-size: 24px;
  }
}
