:root {
  --red: #b3261e;
  --red-dark: #8a1c16;
  --gold: #d4a017;
  --ink: #222;
  --bg: #faf7f2;
  --card-bg: #fff;
  --border: #e4ddd0;
  --green: #2e7d32;
  --muted: #6b6459;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

a { color: var(--red); text-decoration: none; }

/* ---------- Gate ---------- */
#gate-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, var(--red), var(--red-dark));
  display: flex; align-items: center; justify-content: center;
  z-index: 999; padding: 1rem;
}
.gate-box {
  background: var(--card-bg); padding: 2.5rem 2rem; border-radius: 16px;
  text-align: center; max-width: 360px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.gate-box h1 { font-size: 1.3rem; margin: 0 0 .5rem; color: var(--red); }
.gate-box p { color: var(--muted); margin: .25rem 0 1rem; }
.gate-box input {
  width: 100%; padding: .7rem; font-size: 1rem; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: .75rem;
}
.gate-box button {
  width: 100%; padding: .7rem; font-size: 1rem; background: var(--red); color: #fff;
  border: none; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.gate-box button:hover { background: var(--red-dark); }
.gate-error { color: var(--red); font-size: .9rem; }
.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.file-protocol-warning {
  background: #fff3cd; color: #7a5c00; padding: .75rem 1rem; text-align: center;
  font-size: .9rem; border-bottom: 1px solid #e0c060;
}

/* ---------- Header/Nav ---------- */
.site-header {
  background: var(--red); color: #fff; padding: .75rem 1.25rem;
}
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
#theme-switcher {
  padding: .4rem .6rem; border-radius: 6px; border: none; font-size: .95rem;
}
.mode-nav { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.mode-nav a {
  color: #fff; background: rgba(255,255,255,.15); padding: .4rem .8rem;
  border-radius: 999px; font-size: .9rem;
}
.mode-nav a.active { background: #fff; color: var(--red); font-weight: 600; }

main { max-width: 900px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

/* ---------- Home dashboard ---------- */
.hero { text-align: center; margin-bottom: 2rem; }
.hero h1 { color: var(--red); margin-bottom: .25rem; }
.hero p { color: var(--muted); }

.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem;
}
.theme-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.25rem; box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.theme-card h2 { margin: 0 0 .15rem; font-size: 1.1rem; }
.theme-card .zh { font-size: 1.4rem; }
.theme-card .stats { color: var(--muted); font-size: .85rem; margin: .5rem 0 .75rem; }
.progress-bar { background: var(--border); border-radius: 999px; height: 8px; overflow: hidden; margin-bottom: .75rem; }
.progress-bar-fill { background: var(--green); height: 100%; }
.theme-card .links { display: flex; gap: .5rem; flex-wrap: wrap; }
.theme-card .links a {
  background: var(--red); color: #fff; padding: .35rem .7rem; border-radius: 8px; font-size: .85rem;
}
.theme-card .links a:hover { background: var(--red-dark); }

/* ---------- Weekly plan ---------- */
.plan-table { display: grid; gap: .4rem; }
.plan-row {
  display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; flex-wrap: wrap;
}
.plan-row.today { border-color: var(--red); background: #fff5f4; }
.plan-day { font-weight: 700; width: 5.5rem; flex-shrink: 0; }
.plan-today-badge { background: var(--red); color: #fff; font-size: .7rem; padding: .1rem .5rem; border-radius: 999px; }
.plan-detail { color: var(--muted); font-size: .9rem; flex: 1; }
.plan-detail a { font-weight: 600; }

/* ---------- Cards / generic panels ---------- */
.panel {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.5rem; margin-bottom: 1.5rem;
}
.panel h2 { margin-top: 0; color: var(--red); }

.ap-tips {
  background: #fff8e6; border: 1px solid #ecd48a; border-radius: 10px;
  padding: .6rem 1rem; margin-bottom: 1rem;
}
.ap-tips summary { cursor: pointer; font-weight: 600; color: #7a5c00; }
.ap-tips ul { margin: .6rem 0 .2rem; padding-left: 1.2rem; color: #5c4600; font-size: .9rem; }
.ap-tips li { margin-bottom: .35rem; }

.btn {
  background: var(--red); color: #fff; border: none; padding: .6rem 1.1rem;
  border-radius: 8px; cursor: pointer; font-size: .95rem; font-weight: 600;
}
.btn:hover { background: var(--red-dark); }
.btn.secondary { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn.secondary:hover { background: #fdece9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Flashcards ---------- */
.flash-progress { text-align: center; color: var(--muted); margin-bottom: .75rem; }
.flashcard-wrap { display: flex; justify-content: center; margin: 1.5rem 0; perspective: 1000px; }
.flashcard {
  width: 100%; max-width: 420px; height: 260px; position: relative; cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.08);
  border: 1px solid var(--border); background: var(--card-bg);
}
.flashcard-face.back { transform: rotateY(180deg); }
.flashcard-face .big { font-size: 2.4rem; margin-bottom: .5rem; }
.flashcard-face .pinyin { color: var(--gold); font-size: 1.2rem; margin-bottom: .25rem; }
.flashcard-face .example { color: var(--muted); font-size: .9rem; margin-top: .75rem; }
.flash-actions { display: flex; justify-content: center; gap: 1rem; }
.flash-actions .btn.know { background: var(--green); }
.flash-actions .btn.know:hover { background: #1f5c24; }

/* ---------- Quiz ---------- */
.quiz-mode-select { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.quiz-mode-select button.active { background: var(--red-dark); }
.quiz-question { font-size: 1.6rem; text-align: center; margin: 1rem 0; }
.quiz-choices { display: grid; gap: .6rem; }
.quiz-choice-row { display: flex; align-items: center; gap: .5rem; }
.quiz-choice-row .quiz-choice { flex: 1; }
.quiz-choice {
  padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; cursor: pointer; text-align: left; font-size: 1rem;
}
.quiz-choice:hover { border-color: var(--red); }
.quiz-choice.correct { background: #e6f4ea; border-color: var(--green); }
.quiz-choice.incorrect { background: #fdecea; border-color: var(--red); }
.quiz-choice.selected { border-color: var(--red); border-width: 2px; }
.quiz-input { width: 100%; padding: .7rem; font-size: 1.1rem; border-radius: 8px; border: 1px solid var(--border); }
.quiz-feedback { margin-top: .75rem; font-weight: 600; }
.quiz-feedback.correct { color: var(--green); }
.quiz-feedback.incorrect { color: var(--red); }
.quiz-summary { text-align: center; }
.quiz-summary .score { font-size: 2.5rem; color: var(--red); font-weight: 700; }

/* ---------- Writing ---------- */
.prompt-list { display: grid; gap: .75rem; }
.prompt-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 1rem; background: #fff; cursor: pointer;
}
.prompt-item:hover { border-color: var(--red); }
.prompt-item .type-tag {
  display: inline-block; background: var(--gold); color: #3a2b00; font-size: .75rem;
  padding: .15rem .5rem; border-radius: 999px; margin-bottom: .4rem;
}
.timer { font-size: 1.3rem; font-weight: 700; color: var(--red); text-align: center; margin: .5rem 0; }
textarea#writing-area {
  width: 100%; min-height: 260px; padding: 1rem; font-size: 1.05rem; border-radius: 10px;
  border: 1px solid var(--border); font-family: inherit; resize: vertical;
}
.word-count { color: var(--muted); font-size: .85rem; text-align: right; }
.sample-response { background: #f4f8f4; border-left: 4px solid var(--green); padding: 1rem; margin-top: 1rem; border-radius: 6px; }

/* ---------- Speaking ---------- */
.speak-turn { border-left: 4px solid var(--gold); padding: .75rem 1rem; margin-bottom: 1rem; background: #fffdf5; border-radius: 6px; }
.speak-turn .zh { font-size: 1.3rem; }
.speak-turn .pinyin { color: var(--gold); }
.speak-turn .en { color: var(--muted); font-size: .9rem; }
.speak-your-turn { border-left-color: var(--red); background: #fff5f4; }
.tts-btn { background: none; border: 1px solid var(--border); border-radius: 999px; padding: .3rem .7rem; cursor: pointer; margin-left: .5rem; }
.tts-btn:hover { border-color: var(--red); }
.prep-timer, .speak-timer { font-size: 2rem; font-weight: 700; text-align: center; color: var(--red); margin: 1rem 0; }
.no-voice-warning { background: #fff3cd; color: #7a5c00; padding: .6rem 1rem; border-radius: 8px; font-size: .9rem; }

footer.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem 1rem; }

@media (max-width: 480px) {
  .flashcard { height: 220px; }
  .quiz-question { font-size: 1.3rem; }
}
