:root {
  --red: #c0392b;
  --red-light: #e74c3c;
  --gold: #d4a017;
  --gold-light: #f1c40f;
  --cream: #fdf6ec;
  --white: #ffffff;
  --text: #2c1810;
  --text-light: #6b5344;
  --border: #e8d5c4;
  --success: #27ae60;
  --error: #e74c3c;
  --shadow: 0 4px 20px rgba(44, 24, 16, 0.08);
  --radius: 16px;
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(135deg, #fdf6ec 0%, #fce4d6 50%, #f5e6d3 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--red) 0%, #a93226 100%);
  color: white;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 44px;
  height: 44px;
  background: var(--gold);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--red);
}

.logo h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

.logo p {
  font-size: 0.8rem;
  opacity: 0.9;
}

.progress-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 0.4rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Navigation */
.nav {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  flex: 1;
  min-width: fit-content;
  padding: 0.6rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--cream);
}

.nav-btn.active {
  background: var(--red);
  color: white;
}

/* Main */
.main {
  flex: 1;
  padding: 1.25rem;
}

.section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

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

.section-header {
  margin-bottom: 1.25rem;
}

.section-header h2 {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.section-header p {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Welcome */
.welcome-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.welcome-decoration {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.welcome-card h2 {
  font-size: 1.75rem;
  margin-bottom: 1rem;
  font-family: 'Noto Sans SC', sans-serif;
}

.welcome-text {
  color: var(--text-light);
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

.gift-note {
  background: linear-gradient(135deg, #fff9e6 0%, #ffeaa7 100%);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border: 2px solid var(--gold-light);
}

.gift-note p {
  font-size: 1rem;
}

.gift-sub {
  font-size: 0.9rem !important;
  color: var(--text-light);
  margin-top: 0.25rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.feature-item {
  background: var(--cream);
  border-radius: 12px;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.feature-item span {
  font-size: 1.5rem;
}

.feature-item strong {
  font-size: 0.85rem;
}

.feature-item small {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--red);
  color: white;
}

.btn-primary:hover {
  background: var(--red-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--gold);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--gold-light);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--red);
  color: var(--red);
}

.btn-outline.learned {
  border-color: var(--success);
  color: var(--success);
  background: #f0fff4;
}

.btn-audio {
  background: linear-gradient(135deg, #3498db, #2980b9);
  color: white;
}

.btn-audio:hover {
  transform: scale(1.02);
}

.btn-audio.playing {
  animation: pulse 0.8s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.btn-large {
  width: 100%;
  padding: 1rem;
  font-size: 1.05rem;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

/* Search */
.search-bar {
  margin-bottom: 1rem;
}

.search-bar input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--white);
  transition: border-color 0.2s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--red);
}

/* Vocabulary grid */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}

.vocab-card {
  background: var(--white);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  position: relative;
}

.vocab-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.vocab-card.learned {
  border-color: var(--success);
  background: #f0fff4;
}

.vocab-card .hanzi {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 0.25rem;
}

.vocab-card .pinyin {
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.vocab-card .vietnamese {
  font-size: 0.8rem;
  color: var(--text-light);
  line-height: 1.3;
}

.vocab-card .learn-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.vocab-card .learn-btn.learned {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

/* Pinyin chart */
.pinyin-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.pinyin-tab {
  flex: 1;
  min-width: fit-content;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.pinyin-tab:hover {
  border-color: var(--gold);
  background: var(--cream);
}

.pinyin-tab.active {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.pinyin-panel {
  display: none;
}

.pinyin-panel.active {
  display: block;
}

.pinyin-group-block {
  margin-top: 1.1rem;
}

.pinyin-group-block:first-child {
  margin-top: 0;
}

.pinyin-group-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-light);
  margin: 0 0 0.2rem;
  padding-left: 0.25rem;
}

.pinyin-group-subtitle {
  font-size: 0.8rem;
  color: var(--text-light);
  margin: 0 0 0.6rem;
  padding-left: 0.25rem;
  opacity: 0.9;
}

.pinyin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.65rem;
}

.pinyin-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.pinyin-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.pinyin-card.playing {
  border-color: var(--red);
  background: linear-gradient(135deg, #fff5f5 0%, #ffeaa7 100%);
  animation: pulse-audio 0.8s ease infinite alternate;
}

.pinyin-display {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--red);
  line-height: 1.2;
}

.pinyin-example {
  font-size: 0.95rem;
  color: var(--gold);
  font-weight: 700;
  margin-top: 0.15rem;
}

.pinyin-hanzi {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 1.1rem;
  color: var(--text);
  margin-top: 0.2rem;
}

.pinyin-tip {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 0.35rem;
  line-height: 1.3;
}

.pinyin-tone-mark {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  margin-top: 0.15rem;
}

.pinyin-audio-error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #fadbd8;
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 600;
}

.pinyin-attribution {
  margin-top: 1.25rem;
  font-size: 0.72rem;
  color: var(--text-light);
  text-align: center;
}

.pinyin-attribution a {
  color: var(--red);
}

@keyframes pulse-audio {
  from {
    box-shadow: 0 4px 20px rgba(192, 57, 43, 0.15);
  }
  to {
    box-shadow: 0 4px 24px rgba(192, 57, 43, 0.35);
  }
}

/* Sentence learning */
.sentence-mode-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.sentence-mode-btn {
  flex: 1;
  min-width: fit-content;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
}

.sentence-mode-btn:hover {
  border-color: var(--gold);
  background: var(--cream);
}

.sentence-mode-btn.active {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.sentence-view {
  display: none;
}

.sentence-view.active {
  display: block;
}

.sentence-course-controls {
  background: var(--white);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.9rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.sentence-course-controls label {
  font-weight: 700;
  color: var(--text-light);
  font-size: 0.9rem;
  white-space: nowrap;
}

.sentence-course-controls select {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--white);
}

.sentence-course-controls select:focus {
  outline: none;
  border-color: var(--red);
}

.sentence-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.6rem 1.4rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.sentence-progress {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1.2rem;
}

.sentence-hanzi {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 2.6rem;
  line-height: 1.35;
  color: var(--red);
  margin-bottom: 0.35rem;
}

.sentence-hanzi-small {
  font-size: 2.2rem;
}

.sentence-pinyin {
  font-size: 1.1rem;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 0.8rem;
}

.sentence-pinyin-small {
  margin-bottom: 0.65rem;
}

.sentence-translation {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  color: var(--text-light);
}

.sentence-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  margin-bottom: 1.1rem;
}

.sentence-nav {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
}

.sentence-random-label {
  color: var(--text-light);
  font-size: 0.95rem;
}

/* Pronunciation */
.pronounce-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.pronounce-progress {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.pronounce-hanzi {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 4.5rem;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.pronounce-pinyin {
  font-size: 1.5rem;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.pronounce-vietnamese {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.pronounce-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.pronounce-tip {
  background: var(--cream);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.pronounce-nav {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.pronounce-nav .btn {
  min-width: 120px;
}

/* Quiz */
.quiz-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.quiz-score {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.quiz-hanzi {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 0.25rem;
}

.quiz-pinyin {
  font-size: 1.2rem;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 1rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.quiz-option {
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--red);
  background: var(--cream);
}

.quiz-option.correct {
  border-color: var(--success);
  background: #d5f5e3;
  color: var(--success);
}

.quiz-option.wrong {
  border-color: var(--error);
  background: #fadbd8;
  color: var(--error);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-feedback {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  font-weight: 600;
}

.quiz-feedback.correct {
  background: #d5f5e3;
  color: var(--success);
}

.quiz-feedback.wrong {
  background: #fadbd8;
  color: var(--error);
}

.quiz-result {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.quiz-result h3 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.quiz-result p {
  margin-bottom: 0.5rem;
  color: var(--text-light);
}

.hidden {
  display: none !important;
}

.surprise-hidden {
  display: none !important;
}

.surprise-revealed {
  animation: surpriseIn 0.8s ease forwards;
}

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

/* Fireworks & celebration */
.fireworks-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
}

.celebration-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 8, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}

.celebration-card {
  background: var(--white);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  border: 3px solid var(--gold-light);
}

.celebration-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.celebration-card h2 {
  font-size: 1.6rem;
  color: var(--red);
  margin-bottom: 0.75rem;
  font-family: 'Noto Sans SC', sans-serif;
}

.celebration-main {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.celebration-rest {
  color: var(--text-light);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.celebration-encourage {
  color: var(--red);
  font-weight: 700;
  margin-bottom: 1rem;
}

.celebration-surprise {
  background: linear-gradient(135deg, #fff9e6 0%, #ffeaa7 100%);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.25rem;
  border: 2px solid var(--gold-light);
}

.celebration-surprise p {
  font-size: 0.95rem;
}

/* Test panel (developer only) */
.test-panel {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: #1a1a2e;
  color: #fff;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  font-size: 0.78rem;
  z-index: 10000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-width: 220px;
}

.test-panel p {
  margin: 0.4rem 0 0.6rem;
  opacity: 0.9;
}

.test-btn {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 8px;
  background: #e74c3c;
  color: white;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.test-btn:nth-child(4) {
  background: #3498db;
}

.test-btn:nth-child(5) {
  background: #27ae60;
}

.test-btn:last-child {
  background: #636e72;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.25rem;
  color: var(--text-light);
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 480px) {
  .sentence-course-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .sentence-hanzi {
    font-size: 2rem;
  }

  .sentence-actions,
  .sentence-nav {
    flex-direction: column;
  }

  .sentence-actions .btn,
  .sentence-nav .btn {
    width: 100%;
  }

  .pronounce-hanzi {
    font-size: 3.5rem;
  }

  .quiz-hanzi {
    font-size: 2.8rem;
  }

  .nav-btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.5rem;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }
}
