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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: #1a1a1a;
  background: #f8f9fa;
  padding-bottom: 4rem;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-links a {
  margin-right: 1.5rem;
  text-decoration: none;
  color: #555;
  font-weight: 500;
}
.nav-links a.active { color: #d63384; border-bottom: 2px solid #d63384; }
.nav-links a:hover { color: #d63384; }

.settings-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.settings-btn:hover { background: #f0f0f0; }

main {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

h1 { margin-bottom: 0.5rem; font-size: 1.8rem; }
.subtitle { color: #666; margin-bottom: 2rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.summary-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.summary-card h3 a { text-decoration: none; color: #d63384; }
.summary-card p { color: #666; font-size: 0.95rem; }

.setup-hint {
  background: #fff3cd;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  font-size: 0.95rem;
}
.setup-hint a { color: #d63384; }

.category {
  background: #fff;
  border-radius: 10px;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
}

.category summary {
  padding: 0.8rem 1.2rem;
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.category summary::-webkit-details-marker { display: none; }
.category summary::before { content: "▸ "; color: #d63384; }
.category[open] summary::before { content: "▾ "; }

.count { color: #999; font-weight: 400; font-size: 0.9rem; }

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  padding: 0.5rem 1.2rem;
  border-bottom: 2px solid #eee;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.03em;
}

tbody tr { border-bottom: 1px solid #f0f0f0; }
tbody tr:last-child { border-bottom: none; }

td { padding: 0.6rem 1.2rem; vertical-align: middle; }

.col-cantonese { font-size: 1.3rem; }
.col-jyutping { font-family: "SF Mono", "Fira Code", monospace; color: #666; font-size: 0.95rem; }
.col-english { color: #444; }

.play-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 0.3rem;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.play-btn:hover { opacity: 1; background: #f8f0f4; }
.play-btn.playing { opacity: 1; color: #d63384; }

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.modal-content h3 { margin-bottom: 1rem; }
.modal-content label {
  display: block;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  color: #555;
}
.modal-content input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95rem;
}
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.modal-actions button {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
.modal-actions button:first-child { background: #d63384; color: #fff; border-color: #d63384; }
.modal-actions button:first-child:hover { background: #c22b76; }

#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 300;
}
#toast.show { opacity: 1; }

@media (max-width: 600px) {
  main { padding: 0 1rem; }
  .col-jyutping { font-size: 0.8rem; }
  .col-cantonese { font-size: 1.1rem; }
  td { padding: 0.5rem 0.6rem; }
}

/* ===== Training Page ===== */
.hidden { display: none !important; }

.train-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.stat {
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.95rem;
}
.stat.new { background: #e3f2fd; color: #1565c0; }
.stat.due { background: #fff3e0; color: #e65100; }
.stat.learned { background: #e8f5e9; color: #2e7d32; }

.train-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.train-option {
  background: #fff;
  border-radius: 10px;
  padding: 1.2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.train-option h3 { margin-bottom: 0.5rem; font-size: 1rem; }
.train-option label { display: block; margin-bottom: 0.3rem; cursor: pointer; font-size: 0.95rem; }
.train-option select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95rem;
}
.number-input {
  width: 80px;
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95rem;
}

.cat-filter-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.cat-filter-actions button {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.cat-section { margin-bottom: 0.5rem; }
.cat-section strong { font-size: 0.9rem; color: #d63384; }

.primary-btn {
  background: #d63384;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 2rem;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}
.primary-btn:hover { background: #c22b76; }

.secondary-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.train-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
#progress-text { font-weight: 600; color: #666; }

#flashcard {
  background: #fff;
  border-radius: 16px;
  padding: 3rem 2rem;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
}

.q-cantonese, .a-cantonese { font-size: 2.5rem; margin-bottom: 0.5rem; }
.q-jyutping, .a-jyutping { font-family: monospace; color: #666; font-size: 1.1rem; margin-bottom: 1rem; }
.q-english, .a-english { font-size: 1.4rem; color: #444; margin-bottom: 1rem; }
.q-listening { font-size: 1.5rem; color: #888; margin-bottom: 1rem; }

.play-btn-lg {
  background: none;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 1.3rem;
  cursor: pointer;
  margin-bottom: 1rem;
}
.play-btn-lg:hover { background: #f8f0f4; }

#card-answer { margin-top: 1.5rem; width: 100%; }
#answer-content { margin-bottom: 1.5rem; }

#rating-buttons { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }
.rate-btn {
  padding: 0.6rem 1.5rem;
  border: 2px solid;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  transition: transform 0.1s;
}
.rate-btn:hover { transform: scale(1.05); }
.rate-again { border-color: #e53935; color: #e53935; }
.rate-again:hover { background: #ffebee; }
.rate-hard { border-color: #fb8c00; color: #fb8c00; }
.rate-hard:hover { background: #fff3e0; }
.rate-good { border-color: #43a047; color: #43a047; }
.rate-good:hover { background: #e8f5e9; }
.rate-easy { border-color: #1e88e5; color: #1e88e5; }
.rate-easy:hover { background: #e3f2fd; }

.key-hint {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.7rem;
  background: #eee;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  color: #888;
  font-weight: 400;
}

#session-summary {
  text-align: center;
  padding: 3rem 0;
}
#session-summary h2 { margin-bottom: 1rem; }
#summary-stats { margin-bottom: 2rem; font-size: 1.1rem; }
#summary-stats p { margin-bottom: 0.5rem; }

@media (max-width: 600px) {
  #flashcard { padding: 2rem 1rem; min-height: 250px; }
  .q-cantonese, .a-cantonese { font-size: 2rem; }
  .rate-btn { padding: 0.5rem 1rem; font-size: 0.9rem; }
}
