:root {
  --bg: #f5f0e6;
  --paper: #fffef8;
  --line: #d4cfc4;
  --ink: #1a3a5c;
  --ink-light: #4a6a8c;
  --accent: #c45c26;
  --accent-hover: #a34a1e;
  --success: #2d7a4f;
  --error: #b83232;
  --shadow: rgba(26, 58, 92, 0.12);
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 31px,
      var(--line) 31px,
      var(--line) 32px
    );
  background-size: 100% 32px;
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

header {
  margin-bottom: 32px;
  padding-top: 16px;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

header h1 {
  font-size: 1.75rem;
  color: var(--ink);
  text-align: center;
  flex: 1;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  text-decoration: none;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: all 0.2s;
  background: var(--paper);
}

.btn-icon:hover {
  background: var(--accent);
  color: white;
}

.btn-icon-placeholder {
  visibility: hidden;
  pointer-events: none;
}

.container-wide {
  max-width: 1100px;
}
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.lesson-card {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.lesson-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--shadow);
}

.lesson-card h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.lesson-card p {
  font-size: 0.85rem;
  color: var(--ink-light);
}

.lesson-card .count {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.mode-tab {
  padding: 8px 18px;
  border: 2px solid var(--line);
  background: var(--paper);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
  color: var(--ink);
}

.mode-tab.active,
.mode-tab:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--line);
  color: var(--ink);
}

.btn-secondary:hover {
  background: #c4bfb4;
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #962626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.back-btn {
  margin-bottom: 16px;
}

/* Flashcard */
.flashcard-area {
  text-align: center;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.flashcard {
  width: 100%;
  max-width: 500px;
  min-height: 200px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  cursor: pointer;
  transition: transform 0.3s;
  position: relative;
  box-shadow: 0 4px 20px var(--shadow);
}

.flashcard:hover {
  transform: scale(1.02);
}

.flashcard .meaning-front {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--success);
  line-height: 1.4;
  padding: 0 8px;
}

.flashcard .phonetic {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--ink-light);
  font-style: italic;
  margin-top: 8px;
}

.flashcard .chinese {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--ink);
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', sans-serif;
}

.flashcard .pinyin {
  font-size: 1.3rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.flashcard .meaning {
  font-size: 1.2rem;
  color: var(--success);
  margin-top: 8px;
}

.flashcard .hint {
  position: absolute;
  bottom: 12px;
  font-size: 0.75rem;
  color: var(--ink-light);
}

.flashcard-controls {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  align-items: center;
}

.progress-text {
  font-size: 0.9rem;
  color: var(--ink-light);
  margin-top: 12px;
}

.score-bar {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.score-bar span {
  padding: 4px 12px;
  border-radius: 12px;
  background: var(--line);
}

/* Quiz */
.quiz-question {
  text-align: center;
  margin-bottom: 24px;
}

.quiz-question .label {
  font-size: 0.85rem;
  color: var(--ink-light);
  margin-bottom: 8px;
}

.quiz-question .text {
  font-size: 1.6rem;
  font-weight: 600;
  font-style: italic;
}

.quiz-options {
  display: grid;
  gap: 10px;
  max-width: 500px;
  margin: 0 auto;
}

.quiz-option {
  padding: 14px 20px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  transition: all 0.2s;
  color: var(--ink);
  font-family: var(--font);
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--accent);
}

.quiz-option.correct {
  border-color: var(--success);
  background: #e8f5ee;
}

.quiz-option.wrong {
  border-color: var(--error);
  background: #fdeaea;
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-question .text.chinese {
  font-size: 2rem;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', sans-serif;
  font-style: normal;
}

.quiz-question .pinyin {
  font-size: 1.1rem;
  color: var(--accent);
  margin-top: 4px;
}

.quiz-question .phonetic-quiz {
  font-size: 0.95rem;
  color: var(--ink-light);
  font-style: italic;
  margin-top: 2px;
}

/* Speak button */
.btn-speak {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
}

.btn-speak:hover {
  background: var(--accent-hover);
  transform: scale(1.08);
}

.btn-speak-sm {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  margin-top: 0;
}

/* Vocab table */
.scroll-hint {
  display: none;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-light);
  margin-bottom: 8px;
}

.vocab-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 0 -16px;
  padding: 0 16px 8px;
  touch-action: pan-x pan-y;
}

.vocab-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.vocab-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--line);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.vocab-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.vocab-table .col-phonetic {
  font-style: italic;
  font-weight: 600;
  color: var(--ink);
  min-width: 140px;
  white-space: nowrap;
}

.vocab-table .col-meaning {
  color: var(--success);
  min-width: 130px;
  max-width: 220px;
  white-space: normal;
  line-height: 1.4;
}

.vocab-table .col-chinese {
  font-size: 1.15rem;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', sans-serif;
  font-weight: 600;
  white-space: nowrap;
  min-width: 100px;
}

.vocab-table .col-pinyin {
  color: var(--accent);
  white-space: nowrap;
  min-width: 120px;
}

.vocab-table .col-speak {
  text-align: center;
  width: 48px;
  position: sticky;
  left: 0;
  background: var(--paper);
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.04);
  z-index: 1;
}

.vocab-table thead th:first-child {
  position: sticky;
  left: 0;
  background: var(--line);
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.04);
  z-index: 2;
  width: 48px;
}

.vocab-table thead th:last-child {
  position: static;
  box-shadow: none;
}

#mode-list {
  overflow: visible;
}

/* Admin */
.admin-login {
  max-width: 400px;
  margin: 60px auto;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.lesson-section {
  margin-bottom: 32px;
}

.lesson-section h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.item-row-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-light);
  margin-bottom: 4px;
  padding: 0 2px;
}

.item-row-header span:last-child {
  width: 36px;
}

.item-row input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--paper);
}

.lesson-header-edit {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.lesson-header-edit input {
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: var(--font);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 24px;
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.hidden { display: none !important; }

@media (max-width: 700px) {
  .scroll-hint {
    display: block;
  }

  .vocab-table-wrap {
    margin: 0 -24px;
    padding: 0 24px 8px;
  }

  .mode-tabs {
    flex-wrap: nowrap;
  }

  .mode-tab {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.82rem;
    text-align: center;
  }

  .item-row,
  .item-row-header {
    grid-template-columns: 1fr;
  }

  .item-row-header {
    display: none;
  }

  .lesson-header-edit {
    grid-template-columns: 1fr;
  }

  .flashcard .meaning-front {
    font-size: 1.3rem;
  }

  .flashcard .chinese {
    font-size: 1.8rem;
  }

  header h1 {
    font-size: 1.4rem;
  }

  .vocab-table {
    font-size: 0.8rem;
  }
}
