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

:root {
  --red: #FF165D;
  --blue: #0060CA;
  --green: #2DB871;
  --primary: #E8653A;
  --primary-dark: #D14E25;
  --primary-light: #FFF3EE;
  --bg: #f7f5f2;
  --card-bg: #fff;
  --text: #2c2420;
  --text2: #8a7e76;
  --border: #e8e2dc;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---- Header ---- */
.header {
  text-align: center;
  padding: 2rem 1rem 1.2rem;
  background: linear-gradient(135deg, #E8653A 0%, #F4A236 100%);
  color: #fff;
}
.header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.4;
}
.subtitle {
  margin-top: .5rem;
  font-size: .85rem;
  opacity: .85;
}

/* ---- Chapter List ---- */
.chapter-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto;
}
.chapter-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  cursor: pointer;
  transition: box-shadow .2s, transform .15s;
}
.chapter-card:hover {
  box-shadow: 0 4px 12px rgba(232,101,58,.1);
  transform: translateY(-2px);
}
.chapter-card .ch-num {
  display: inline-block;
  background: linear-gradient(135deg, #E8653A, #F4A236);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  margin-bottom: .4rem;
}
.chapter-card .ch-title {
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.4;
}
.chapter-card .ch-meta {
  font-size: .8rem;
  color: var(--text2);
  margin-top: .3rem;
}

/* ---- Detail View ---- */
.detail-header {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.detail-header h2 {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Audio Player ---- */
.audio-player {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: .6rem 1rem;
  position: sticky;
  top: 52px;
  z-index: 9;
}
.audio-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.btn-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #E8653A, #F4A236);
  color: #fff;
  font-size: .9rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.audio-time {
  font-size: .75rem;
  color: var(--text2);
  min-width: 32px;
  text-align: center;
}
.audio-progress {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.audio-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

/* ---- Story Section ---- */
.story-section {
  padding: 1.2rem 1rem;
  max-width: 700px;
  margin: 0 auto;
}
.story-section h3 {
  font-size: 1.15rem;
  margin-bottom: .8rem;
  color: var(--text);
}
.story-content {
  font-size: 1rem;
  line-height: 2;
  color: #333;
}
.story-content p {
  margin-bottom: .8rem;
}
.story-content strong {
  color: var(--red);
  font-weight: 600;
}
.story-content em {
  color: var(--blue);
  font-style: italic;
}
.story-content code {
  color: var(--green);
  background: #e8f5e9;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: inherit;
  font-size: .95em;
}

.legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: .6rem 0;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text2);
  flex-wrap: wrap;
}
.legend-red strong { color: var(--red); }
.legend-blue em { color: var(--blue); }
.legend-green code {
  color: var(--green);
  background: #e8f5e9;
  padding: 0 4px;
  border-radius: 2px;
  font-family: inherit;
}

/* ---- Vocabulary Section ---- */
.vocab-section {
  padding: 0 1rem 1.2rem;
  max-width: 700px;
  margin: 0 auto;
}

.vocab-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.vocab-toggle:hover {
  background: var(--primary-light);
}
.vocab-toggle span:first-child {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.toggle-arrow {
  font-size: .7rem;
  color: var(--text2);
  transition: transform .2s;
}
.vocab-toggle.open .toggle-arrow {
  transform: rotate(90deg);
}

.vocab-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
}
.vocab-panel.open {
  max-height: 3000px;
  padding-top: .8rem;
}

.badge {
  background: #f0ebe6;
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 400;
}
.vocab-filter {
  display: flex;
  gap: .4rem;
  margin-bottom: .8rem;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: #fff;
  font-size: .8rem;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.vocab-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.vocab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.vocab-table th {
  background: #f5f0eb;
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.vocab-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
}
.vocab-table tr.hidden-row { display: none; }

.cat-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: .75rem;
  font-weight: 500;
}
.cat-red { background: #fce4ec; color: var(--red); }
.cat-blue { background: #e3f2fd; color: var(--blue); }
.cat-green { background: #e8f5e9; color: var(--green); }

/* ---- Print Button (in legend) ---- */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--card-bg);
  font-size: .75rem;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
}
.btn-print:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ---- Mobile tweaks ---- */
@media (max-width: 600px) {
  .header h1 { font-size: 1.15rem; }
  .chapter-list {
    grid-template-columns: 1fr;
    padding: .6rem;
    gap: 8px;
  }
  .story-content { font-size: .95rem; line-height: 1.9; }
  .legend { flex-wrap: wrap; gap: .5rem; }
  .detail-header h2 { font-size: .9rem; }
  .vocab-table { font-size: .8rem; min-width: 360px; }
}
