:root {
  --primary: #c41e3a;
  --primary-dark: #9a1830;
  --primary-light: #e8354f;
  --gold: #d4a017;
  --gold-light: #f0c040;
  --bg: #f0f0f0;
  --bg-card: #ffffff;
  --text: #111111;
  --text-muted: #444444;
  --border: #dddddd;
  --success: #2ecc71;
  --error: #e74c3c;
  --warning: #f39c12;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.logo-text strong {
  font-size: 1.05rem;
  font-weight: 800;
}

.logo-text small {
  font-size: .72rem;
  font-weight: 500;
  opacity: .75;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.nav-links {
  display: flex;
  gap: 8px;
  list-style: none;
}

.nav-links a {
  color: rgba(255,255,255,.85);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  transition: all .2s;
}

.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
}

.header-actions { display: flex; gap: 10px; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover { background: var(--gold-light); color: var(--text); }

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-white {
  background: rgba(255,255,255,.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
}
.btn-white:hover { background: rgba(255,255,255,.3); }

.btn-sm { padding: 6px 14px; font-size: .85rem; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #8b1528 50%, var(--primary-dark) 100%);
  color: #fff;
  padding: 80px 0 100px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(212,160,23,.15) 0%, transparent 70%);
  border-radius: 50%;
}

.hero-content { position: relative; text-align: center; max-width: 700px; margin: 0 auto; }

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  margin-bottom: 16px;
  line-height: 1.2;
}

.hero p {
  font-size: 1.15rem;
  opacity: .9;
  margin-bottom: 32px;
}

.hero-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

.hero-badge {
  display: inline-block;
  background: rgba(212,160,23,.25);
  border: 1px solid var(--gold);
  color: var(--gold-light);
  padding: 4px 16px;
  border-radius: 20px;
  font-size: .85rem;
  margin-bottom: 20px;
}

/* Sections */
.section { padding: 60px 0; }
.section-title {
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 12px;
  color: var(--text);
}
.section-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 40px;
  font-size: 1.05rem;
}

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: all .3s;
  border: 1px solid var(--border);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-icon {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: linear-gradient(135deg, #fff5f5, #fff);
}

.card-body { padding: 20px; }
.card-body h3 { font-size: 1.1rem; margin-bottom: 8px; color: #111; }
.card-body p { color: #333; font-size: .9rem; margin-bottom: 16px; }

/* Game cards */
.game-card {
  cursor: pointer;
  text-align: center;
}

.game-card .card-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-size: 2.5rem;
}

.game-card .stars {
  color: var(--gold);
  font-size: .85rem;
  margin-top: 8px;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .75rem;
  background: #ececec;
  color: #333;
  margin: 2px;
}

.tag-level { background: #e8f5e9; color: #2e7d32; }
.tag-type { background: #fff3e0; color: #e65100; }

/* Search bar */
.search-bar {
  display: flex;
  gap: 10px;
  max-width: 600px;
  margin: 0 auto 40px;
}

.search-bar input {
  flex: 1;
  padding: 12px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .2s;
}

.search-bar input:focus { border-color: var(--primary); }

/* Library layout */
.library-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 30px;
  padding: 30px 0 60px;
}

.sidebar {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  height: fit-content;
  position: sticky;
  top: 84px;
}

.sidebar h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  color: #111;
  font-weight: 700;
}

.cat-list { list-style: none; }
.cat-list li { margin-bottom: 4px; }

.cat-list a, .cat-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .9rem;
  font-family: inherit;
  color: #222;
  font-weight: 500;
  text-align: left;
  transition: all .2s;
}

.cat-list a:hover, .cat-list a.active,
.cat-list button:hover, .cat-list button.active {
  background: #f5e6e9;
  color: #7a1020;
  font-weight: 600;
}

.cat-sub { padding-left: 20px; }

.material-list { display: flex; flex-direction: column; gap: 16px; }

.material-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  gap: 16px;
  align-items: flex-start;
  transition: all .2s;
}

.material-item:hover { border-color: var(--primary-light); }

.material-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.material-info { flex: 1; }
.material-info h4 { margin-bottom: 4px; font-size: 1.05rem; color: #111; font-weight: 700; }
.material-info p { color: #333; font-size: .9rem; line-height: 1.5; }
.material-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all .3s;
}

.modal-overlay.show { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 700px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform .3s;
}

.modal-overlay.show .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.2rem; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: #f0f0f0; }

/* Auth form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: .9rem; font-weight: 500; }
.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); }

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.auth-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Game UI */
.game-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 30px 20px 60px;
}

.game-header {
  text-align: center;
  margin-bottom: 30px;
}

.game-header h1 { font-size: 1.6rem; margin-bottom: 8px; }

.game-stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 24px;
}

.stat-item { text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); }

.game-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 40px 30px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.game-char {
  font-size: 4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}

.game-pinyin { font-size: 1.5rem; color: var(--text-muted); margin-bottom: 24px; }

.tone-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.tone-btn {
  width: 80px;
  height: 80px;
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 1.8rem;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.tone-btn:hover { border-color: var(--primary); background: #fff5f5; }
.tone-btn.correct { border-color: var(--success); background: #e8f5e9; }
.tone-btn.wrong { border-color: var(--error); background: #fce4ec; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin-bottom: 20px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: 4px;
  transition: width .3s;
}

.game-feedback {
  font-size: 1.2rem;
  margin-top: 16px;
  min-height: 30px;
}

.game-feedback.correct { color: var(--success); }
.game-feedback.wrong { color: var(--error); }

/* Puzzle game */
.puzzle-area {
  display: flex;
  gap: 40px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

.puzzle-column h4 { margin-bottom: 12px; color: var(--text-muted); }

.puzzle-items { display: flex; flex-direction: column; gap: 8px; }

.puzzle-item {
  padding: 12px 24px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  font-size: 1.2rem;
  background: var(--bg);
  transition: all .2s;
  user-select: none;
}

.puzzle-item:hover { border-color: var(--primary); }
.puzzle-item.selected { border-color: var(--primary); background: #fff5f5; }
.puzzle-item.matched { border-color: var(--success); background: #e8f5e9; opacity: .6; }
.puzzle-item.dragging { opacity: .5; transform: scale(1.05); }

.puzzle-slots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.puzzle-slot {
  min-width: 72px;
  padding: 12px 16px;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700;
}

.drop-zone.matched { border-color: var(--success); background: #e8f5e9; }

.stage-badge {
  display: inline-block;
  padding: 6px 14px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.syl-mark { padding: 2px 6px; border-radius: 4px; margin: 0 2px; }
.syl-ok { background: #e8f5e9; color: #2e7d32; }
.syl-err { background: #fce4ec; color: #c41e3a; text-decoration: line-through; }

.drop-zone {
  min-height: 60px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  margin: 20px 0;
  font-size: 1.3rem;
  gap: 8px;
}

.drop-zone.active { border-color: var(--primary); background: #fff5f5; }

/* Dictation */
.dictation-input {
  width: 100%;
  max-width: 400px;
  padding: 16px;
  font-size: 1.5rem;
  text-align: center;
  border: 3px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  outline: none;
  letter-spacing: 2px;
}

.dictation-input:focus { border-color: var(--primary); }
.dictation-input.correct { border-color: var(--success); }
.dictation-input.wrong { border-color: var(--error); }

/* Timer */
.timer-display {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.timer-display.warning { color: var(--warning); }
.timer-display.danger { color: var(--error); animation: pulse 1s infinite; }

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

/* Footer */
.site-footer {
  background: #2c2c2c;
  color: rgba(255,255,255,.7);
  padding: 40px 0 20px;
  margin-top: 60px;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 30px;
  margin-bottom: 30px;
}

.footer-grid h4 { color: #fff; margin-bottom: 12px; }
.footer-grid a { color: rgba(255,255,255,.6); display: block; margin-bottom: 6px; font-size: .9rem; }
.footer-grid a:hover { color: var(--gold); }

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .85rem;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease;
  max-width: 360px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--primary); }

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

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .library-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .hero { padding: 50px 0 70px; }
  .material-item { flex-direction: column; }
  .material-actions { width: 100%; justify-content: flex-end; }
  .game-char { font-size: 3rem; }
  .tone-btn { width: 64px; height: 64px; font-size: 1.4rem; }
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    box-shadow: 0 -2px 12px rgba(0,0,0,.1);
    z-index: 100;
    justify-content: space-around;
    padding: 8px 0;
  }
  .mobile-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: .7rem;
    color: var(--text-muted);
    padding: 4px 12px;
  }
  .mobile-nav a.active { color: var(--primary); }
  .mobile-nav .nav-icon { font-size: 1.3rem; }
  body { padding-bottom: 60px; }
}

@media (min-width: 769px) {
  .mobile-nav { display: none; }
}

/* Preview content */
.preview-content { line-height: 1.8; }
.preview-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.preview-content th, .preview-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.preview-content th { background: #f9f9f9; }

.fav-btn { background: none; border: none; cursor: pointer; font-size: 1.3rem; transition: transform .2s; }
.fav-btn:hover { transform: scale(1.2); }
.fav-btn.active { color: var(--gold); }

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: #333;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  transition: all .2s;
}

.filter-btn.active, .filter-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 40px;
}

.level-card {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all .2s;
  border: 2px solid transparent;
}

.level-card:hover, .level-card.active {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.level-card .level-icon { font-size: 2rem; margin-bottom: 8px; }
.level-card h4 { font-size: .95rem; }

@media (max-width: 600px) {
  .level-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Payment & Support */
.payment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.payment-price {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
}

.payment-features {
  list-style: none;
  padding: 0;
  margin: 0;
}

.payment-features li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}

.payment-features li::before {
  content: '✓ ';
  color: var(--primary);
  font-weight: 700;
}

.qr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.qr-box { text-align: center; }

.qr-label {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: .9rem;
}

.qr-placeholder {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .85rem;
  padding: 16px;
}

.qr-image {
  max-width: 100%;
  width: 160px;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.payment-notice {
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.payment-notice-pending {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.payment-notice-rejected {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.contact-list { display: flex; flex-direction: column; gap: 16px; }

.contact-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.contact-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .9rem;
}

.contact-value {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
}

@media (max-width: 768px) {
  .payment-grid, .qr-grid { grid-template-columns: 1fr; }
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.module-card {
  padding: 16px;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid #e0e0e0;
}

.module-card h4 {
  font-size: .95rem;
  margin: 8px 0 4px;
  color: #111;
  font-weight: 700;
}

.module-card p {
  font-size: .88rem;
  color: #333;
  line-height: 1.55;
  margin: 0;
}

.library-hero h2 {
  color: #111;
  font-weight: 800;
}

.library-intro {
  color: #333;
  margin-bottom: 16px;
  font-size: .95rem;
}

.library-note {
  margin-top: 16px;
  font-size: .9rem;
  color: #444;
}

.module-icon {
  font-size: 1.5rem;
}

.practice-report p {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 600px) {
  .module-grid { grid-template-columns: 1fr; }
}
