:root {
  --bg: #fdf6ee;
  --paper: #fffdf8;
  --ink: #2d2016;
  --muted: #8a7060;
  --accent: #e8632a;
  --accent2: #4a9eca;
  --accent3: #6abf69;
  --border: #e8d8c4;
  --shadow: rgba(60,30,10,0.10);
}

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

body {
  background: var(--bg);
  background-image: radial-gradient(circle at 20% 50%, #fde8d0 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, #d0e8fd 0%, transparent 40%);
  font-family: 'Nunito', 'PingFang SC', sans-serif;
  color: var(--ink);
  min-height: 100vh;
}

/* ── SETUP ── */
#setup {
  max-width: 680px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.logo { text-align: center; margin-bottom: 40px; }
.logo h1 {
  font-family: 'Ma Shan Zheng', serif;
  font-size: 2.6rem;
  color: var(--accent);
  letter-spacing: 4px;
  line-height: 1.2;
}
.logo p { color: var(--muted); margin-top: 8px; font-size: 0.95rem; }

.card {
  background: var(--paper);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px var(--shadow);
}

.card-title {
  font-family: 'ZCOOL XiaoWei', serif;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

input[type="text"], textarea, select {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent2); }
textarea { resize: vertical; min-height: 80px; }

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

.style-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 4px;
}
.style-opt {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.85rem;
  background: var(--bg);
}
.style-opt:hover { border-color: var(--accent2); }
.style-opt.active { border-color: var(--accent); background: #fff3ee; color: var(--accent); font-weight: 700; }
.style-opt .icon { font-size: 1.6rem; display: block; margin-bottom: 4px; }

.btn-main {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 1.1rem;
  font-family: 'ZCOOL XiaoWei', serif;
  letter-spacing: 3px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(232,99,42,0.35);
  margin-top: 8px;
}
.btn-main:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(232,99,42,0.4); }
.btn-main:disabled { background: #ccc; box-shadow: none; transform: none; cursor: not-allowed; }

.error-box {
  background: #fff5f5;
  border: 1.5px solid #fed7d7;
  border-radius: 12px;
  padding: 16px 20px;
  color: #c53030;
  font-size: 0.9rem;
  margin-top: 12px;
  display: none;
}

/* ── PROGRESS ── */
#progress {
  max-width: 680px;
  margin: 0 auto;
  padding: 80px 24px;
  text-align: center;
}
.progress-title {
  font-family: 'Ma Shan Zheng', serif;
  font-size: 1.8rem;
  color: var(--accent);
  margin-bottom: 32px;
}
.steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto 40px;
  text-align: left;
}
.step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--paper);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
  transition: all 0.3s;
}
.step.active { border-color: var(--accent2); background: #f0f8ff; }
.step.done { border-color: var(--accent3); background: #f0fff4; }
.step.error { border-color: #e53e3e; background: #fff5f5; }
.step-icon { font-size: 1.4rem; width: 28px; text-align: center; flex-shrink: 0; }
.spinner { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint-text { color: var(--muted); font-size: 0.9rem; }

/* ── BOOK VIEW ── */
#book-view { padding: 40px 20px 80px; }

.book-header { text-align: center; margin-bottom: 48px; }
.book-header h2 {
  font-family: 'Ma Shan Zheng', serif;
  font-size: 2.2rem;
  color: var(--accent);
}
.book-header p { color: var(--muted); margin-top: 8px; }

.pages-container { max-width: 960px; margin: 0 auto; }

/* Cover */
.cover-page {
  background: linear-gradient(135deg, #fff3ee 0%, #e8f4fd 100%);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 60px 40px;
  text-align: center;
  margin-bottom: 48px;
  box-shadow: 0 8px 40px var(--shadow);
  position: relative;
  overflow: hidden;
}
.cover-page::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, #fde8d0 0%, transparent 70%);
  pointer-events: none;
}
.cover-img {
  width: 260px;
  height: 260px;
  object-fit: cover;
  border-radius: 50%;
  border: 6px solid white;
  box-shadow: 0 8px 32px var(--shadow);
  margin-bottom: 28px;
}
.cover-title {
  font-family: 'Ma Shan Zheng', serif;
  font-size: 2.4rem;
  color: var(--accent);
  line-height: 1.3;
  margin-bottom: 12px;
}
.cover-subtitle { color: var(--muted); font-size: 1rem; }

/* Spread pages */
.spread {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 48px;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 8px 40px var(--shadow);
  border: 2px solid var(--border);
}
@media (max-width: 640px) {
  .spread { grid-template-columns: 1fr; }
}

.page-left {
  background: var(--paper);
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1.5px solid var(--border);
  position: relative;
}
.page-right {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  padding: 24px;
}
.page-right img {
  width: 100%;
  height: 320px;
  object-fit: cover;
  border-radius: 12px;
}

.page-num {
  position: absolute;
  bottom: 16px;
  font-size: 0.75rem;
  color: var(--border);
}
.page-left .page-num { right: 16px; }

.page-chapter {
  font-size: 0.78rem;
  color: var(--accent2);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.page-text {
  font-family: 'ZCOOL XiaoWei', serif;
  font-size: 1.15rem;
  line-height: 2;
  color: var(--ink);
}

.img-placeholder {
  width: 100%;
  height: 320px;
  background: linear-gradient(135deg, #f0f4f8, #e8eef4);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 10px;
}
.img-placeholder .spin-icon { font-size: 2rem; animation: spin 2s linear infinite; }

.img-error {
  width: 100%;
  height: 320px;
  background: #fff5f5;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #e53e3e;
  gap: 8px;
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
}

/* ── QUIZ SECTION ── */
.quiz-section {
  max-width: 960px;
  margin: 0 auto;
  padding-top: 20px;
}

.quiz-category {
  background: var(--paper);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px var(--shadow);
}
.quiz-category-title {
  font-family: 'ZCOOL XiaoWei', serif;
  font-size: 1.2rem;
  color: var(--accent);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--border);
}

.quiz-item {
  margin-bottom: 20px;
  padding-left: 16px;
  border-left: 3px solid var(--accent2);
}
.quiz-item:last-child { margin-bottom: 0; }

.quiz-question {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
  line-height: 1.6;
}
.quiz-hints {
  list-style: none;
  padding: 0;
}
.quiz-hints li {
  font-size: 0.88rem;
  color: var(--muted);
  padding: 4px 0 4px 20px;
  position: relative;
  line-height: 1.5;
}
.quiz-hints li::before {
  content: '\2192';
  position: absolute;
  left: 0;
  color: var(--accent3);
}

/* ── ACTIONS ── */
.actions {
  text-align: center;
  margin-top: 48px;
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-sec {
  padding: 14px 28px;
  background: var(--paper);
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  color: var(--ink);
}
.btn-sec:hover { border-color: var(--accent2); color: var(--accent2); }

/* ── PRINT ── */
@media print {
  #setup, #progress, .actions, .hint-text { display: none !important; }
  body { background: white; }
  .spread { break-inside: avoid; page-break-inside: avoid; }
  .cover-page { break-after: page; }
  .quiz-category { break-inside: avoid; }
}
