/* Lessons (Spec 8). Tokens and shared components come from ui.css/stories.css. */

/* --------------------------------------------------------------- new lesson */
.lesson-create { padding: 12px 16px 20px; }
.lesson-create-top {
  flex: none;
  height: 48px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
}
.lesson-create-head { min-width: 0; text-align: center; }
.lesson-create-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-create-step { margin-top: 2px; font-size: 12px; color: var(--muted); }
.lesson-create-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0 16px;
  -webkit-overflow-scrolling: touch;
}
.lesson-create-footer { flex: none; padding-top: 10px; }
.lesson-create-footer .btn-primary { width: 100%; }

.lesson-folder-btn {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  margin-bottom: 12px;
  border: 1.5px solid var(--line2);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--line);
  color: var(--ink);
  text-align: left;
}
.lesson-folder-btn:active { transform: scale(.99); filter: brightness(.98); }
.lesson-folder-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lesson-folder-kicker { font-size: 12px; color: var(--muted); }
.lesson-folder-name {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-folder-chevron { width: 20px; height: 20px; color: var(--muted); flex: none; }
.lesson-folder-chevron svg { width: 20px; height: 20px; display: block; }
.lesson-lock-open { width: 100%; margin-top: 8px; }

.lesson-problems { margin-bottom: 10px; }
.lesson-problems-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 800;
}
.lesson-problem {
  margin: 0 0 4px;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #FFF9EA;
  font-size: 13px;
  line-height: 1.4;
  color: #7A5A16;
}
.lesson-problem.blocking {
  border-color: #E7B9B2;
  background: var(--red-tint);
  color: var(--red-edge);
  font-weight: 700;
}
.lesson-problem.ok { background: var(--l3t); color: var(--l3k); border-color: var(--l3s); }

.lesson-preview-chips { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.lesson-chip {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--line);
}
.lesson-chip.locked { border-color: var(--red); box-shadow: 0 2px 0 var(--red-edge); }
.lesson-chip-head { display: flex; align-items: baseline; gap: 8px; }
.lesson-chip-char {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 28px;
  line-height: 1;
  color: var(--l0k);
}
.lesson-chip-pinyin { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }
.lesson-chip-uses { font: 800 13px/1 var(--ui-font); color: var(--muted); }
.lesson-chip-word { margin-top: 2px; font-size: 14px; font-weight: 700; }
.lesson-chip-reason { margin-top: 2px; font-size: 12px; color: var(--muted); }
.lesson-chip-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.lesson-chip-actions .story-link { min-height: 28px; font-size: 13px; }

.lesson-preview-story {
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--line);
}
.lesson-preview-story .reader-title { margin-bottom: 10px; }
.lesson-preview-story .reader-body { font-size: 26px; }
.lesson-new {
  outline: 1.5px solid var(--red);
  outline-offset: 1px;
  border-radius: 3px;
}
.lesson-preview-actions { display: flex; gap: 10px; margin-top: 12px; }
.lesson-preview-actions button { flex: 1; font-size: 13px; }

/* ------------------------------------------------------------------ sheets */
.lesson-folder-sheet,
.lesson-lock-sheet,
.lesson-pacing-sheet { max-height: 88dvh; display: flex; flex-direction: column; }
.lesson-folder-list,
.lesson-lock-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.lesson-new-folder { display: flex; gap: 8px; flex: none; }
.lesson-new-folder input { margin-top: 0; flex: 1; min-height: 44px; }
.lesson-new-folder button { flex: none; }
.lesson-lock-row {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}
.lesson-lock-row.selected { border-color: var(--red); background: #FFFAF0; }
.lesson-lock-char {
  width: 44px;
  flex: none;
  text-align: center;
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 24px;
  line-height: 1.1;
}
.lesson-lock-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lesson-lock-word { font-size: 14px; font-weight: 700; }
.lesson-lock-reason { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------- lesson deck block */
.lesson-block {
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--line);
}
.lesson-block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lesson-block-kicker { font: 800 15px/1.2 var(--ui-font); }
.lesson-block-count { font-size: 12px; color: var(--muted); }
.lesson-block-chars { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 10px; }
.lesson-block-char {
  min-width: 30px;
  padding: 2px 5px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 20px;
  line-height: 1.15;
  text-align: center;
  color: var(--l0k);
}
.lesson-block-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  margin-top: 8px;
}
.lesson-story-row {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 8px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--ink);
  text-align: left;
}
.lesson-story-label { font-size: 12px; font-weight: 800; color: var(--muted); }
.lesson-story-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-story-row .story-browse-chevron { transform: none; color: var(--muted); }

/* --------------------------------------------------------------- reader */
.reader-practice {
  width: 100%;
  height: 48px;
  margin-top: 12px;
}

/* ------------------------------------------------------------ next characters */
.next-tabs { width: 100%; margin-bottom: 8px; }
.next-tabs button { flex: 1; }
.next-box { display: flex; flex-direction: column; gap: 6px; }
.next-meta { font-size: 11px; color: var(--muted); line-height: 1.4; margin-bottom: 4px; }
.next-row {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.next-rank {
  width: 26px;
  flex: none;
  text-align: right;
  font: 800 12px/1.4 var(--ui-font);
  color: var(--muted);
}
.next-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.next-head { display: flex; align-items: baseline; gap: 8px; }
.next-chars {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 20px;
  line-height: 1.1;
}
.next-word {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.next-score { font: 800 12px/1.2 var(--ui-font); color: var(--red); }
.next-reason { font-size: 12px; font-weight: 700; line-height: 1.35; }
.next-signals { font-size: 10.5px; color: var(--muted); }
.gap-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}
.gap-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px 2px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
}
.gap-tile.rare { border-style: dashed; opacity: .72; }
.gap-tile strong {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 22px;
  line-height: 1.1;
}
.gap-tile small { font-size: 9px; color: var(--muted); }

@media (max-width: 380px) {
  .lesson-create { padding-left: 14px; padding-right: 14px; }
  .gap-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .lesson-preview-story { padding: 12px; }
  .lesson-preview-story .reader-body { font-size: 24px; }
}
.lesson-preview-meta {
  margin: -2px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------------------------------------------- Spec 12: settings/preview */
.lesson-folder-block { margin-bottom: 12px; }
.lesson-folder-block .lesson-folder-btn { margin-bottom: 6px; }
.lesson-folder-icon {
  width: 20px; height: 20px; flex: none; color: var(--ink);
  display: grid; place-items: center;
}
.lesson-folder-icon svg { width: 20px; height: 20px; display: block; }
.lesson-folder-block .story-hint { display: block; padding: 0 2px; }

.lesson-include-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1.5px solid var(--line2);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--line);
  color: var(--ink);
  text-align: left;
}
.lesson-include-card:active { transform: scale(.995); filter: brightness(.98); }
.lesson-include-icon {
  width: 22px; height: 22px; flex: none; color: var(--ink);
  display: grid; place-items: center;
}
.lesson-include-icon svg { width: 22px; height: 22px; display: block; }
.lesson-include-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lesson-include-text strong { font-size: 15px; font-weight: 800; }
.lesson-include-text small { font-size: 13px; color: var(--muted); }
.lesson-include-action {
  flex: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: underline;
}
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.lesson-create-step {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-checks-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
}
.lesson-checks-bar.ok { background: #E3EFD5; color: #2F6410; }
.lesson-checks-bar.warn { background: #FFF3D6; color: #7A5A16; }
.lesson-preview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.lesson-preview-heading { font-size: 14px; font-weight: 700; color: var(--muted); }
.lesson-preview-head .story-hint { font-size: 12px; }

.lesson-preview-chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.lesson-chip {
  min-width: 0;
  padding: 6px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 1.5px solid var(--line2);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--line);
  color: var(--ink);
}
.lesson-chip.locked { border-color: var(--red); box-shadow: 0 2px 0 var(--red-edge); }
.lesson-chip-char {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 30px;
  line-height: 1.1;
  background: #FAEEDA;
  border-radius: 6px;
  box-shadow: inset 0 -3px 0 #EF9F27;
  padding: 0 4px;
}
.lesson-chip-pinyin { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.lesson-chip-word {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 15px;
  font-weight: 400;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lesson-chip-uses { font: 800 11px/1.2 var(--ui-font); color: var(--muted); }
.lesson-chip.skip {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}
.lesson-chip.skip .lesson-chip-char {
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}

.lesson-skipped-note {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 14px;
  background: #FAEEDA;
  color: #633806;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}
.lesson-skipped-note strong { font-weight: 800; }

.lesson-preview-story .story-char.focus {
  background: #FAEEDA;
  border-radius: 5px;
  box-shadow: inset 0 -3px 0 #EF9F27;
  padding: 0 1px;
  outline: none;
}
.lesson-preview-story .reader-body { font-size: 24px; line-height: 1.75; }
.lesson-preview-story .reader-title {
  font-size: 22px;
  text-align: center;
  margin-bottom: 4px;
}

@media (min-width: 420px) {
  .lesson-preview-chips { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* ------------------------------------- Spec 12 follow-up: Must include sheet */
.lesson-lock-sheet {
  max-height: 92dvh;
  padding: 10px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lesson-lock-grab {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: var(--line2);
  align-self: center;
  flex: none;
}
.lesson-lock-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex: none;
}
.lesson-lock-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
#lessonLockSheetCount { font-size: 14px; font-weight: 800; }
.lesson-lock-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: none;
}
.lesson-lock-chip {
  height: 36px;
  border-radius: 18px;
  background: var(--ink);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 12px;
  font-size: 15px;
  font-weight: 700;
}
.lesson-lock-chip strong {
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 20px;
  font-weight: 400;
}
.lesson-lock-chip button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.lesson-lock-chip button svg { width: 14px; height: 14px; }
.lesson-lock-search {
  height: 48px;
  border-radius: 14px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 0 14px;
  flex: none;
}
.lesson-lock-search > svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.lesson-lock-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
}
.lesson-lock-search input::-webkit-search-cancel-button { display: none; }
.lesson-lock-search button {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.lesson-lock-search button svg { width: 18px; height: 18px; }
.lesson-lock-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -2px;
  padding: 0 2px;
}
.lesson-lock-heading {
  padding: 2px 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.lesson-lock-row {
  display: grid;
  grid-template-columns: 22px 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 7px 0;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
}
.lesson-lock-result { grid-template-columns: 44px minmax(0, 1fr) auto; }
.lesson-lock-rank {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-align: right;
}
.lesson-lock-tile {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--red);
  display: grid;
  place-items: center;
  font-family: "LXGW WenKai", "KaiTi", "STKaiti", serif;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
  background:
    repeating-linear-gradient(to bottom, rgba(178, 58, 47, 0.35) 0 3px, transparent 3px 7px) center / 1.5px 100% no-repeat,
    repeating-linear-gradient(to right, rgba(178, 58, 47, 0.35) 0 3px, transparent 3px 7px) center / 100% 1.5px no-repeat,
    var(--paper);
}
.lesson-lock-tile.off {
  border-color: var(--line2);
  background: #F5EDDD;
  color: var(--muted);
}
.lesson-lock-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lesson-lock-pinyin { font-size: 12px; color: var(--muted); }
.lesson-lock-why {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-lock-why.off { font-weight: 600; color: var(--muted); }
.lesson-lock-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line2);
  background: var(--paper);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.lesson-lock-toggle.on { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.lesson-lock-toggle svg { width: 20px; height: 20px; }
.lesson-lock-pill {
  height: 44px;
  border-radius: 22px;
  border: 1.5px solid var(--line2);
  background: var(--paper);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.lesson-lock-pill.on { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.lesson-lock-pill svg { width: 16px; height: 16px; }

/* ---------------------------------------- Spec 12 follow-up: Next characters */
.lesson-next-sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  padding: 12px 16px 20px;
  overflow: hidden;
}
.lesson-next-sheet[hidden] { display: none; }
.lesson-next-top {
  flex: none;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 48px;
}
.lesson-next-head-text { min-width: 0; }
.lesson-next-head-text h1 { margin: 0; font-size: 22px; text-align: left; }
.lesson-next-head-text .settings-note { margin: 0; font-size: 12px; }
.lesson-next-tabs { flex: none; margin: 10px 0; }
.lesson-next-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.lesson-known-note {
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 14px;
  background: #F3EEE4;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.lesson-known-note strong { color: var(--ink); font-weight: 800; }

/* ------------------------------------- shared preview header (Spec 12.1) */
.story-create-top,
.lesson-create-top { height: auto; min-height: 48px; padding: 3px 0; }
.story-create-subtitle,
.lesson-create-subtitle {
  margin-top: 1px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-info-btn { flex: none; }
.preview-info-btn[hidden] { visibility: hidden; }
.character-grid-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 7px;
  background: var(--character-grid-outside-bg);
  color: var(--muted);
  border: 1px solid var(--character-grid-outside-line);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
}
.character-grid-card.unused { border-style: dashed; opacity: .78; }
.character-grid-card.unused .character-grid-count { font-size: 9px; }


/* -------------------------------------------- shared Choose characters (D2/D3) */
.choose-overlay { padding: 0; align-items: stretch; }
.choose-page {
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  max-height: none;
  margin: 0 auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.choose-top {
  flex: none;
  min-height: 48px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.choose-top h1 { margin: 0; text-align: left; font-size: 20px; }
.choose-count { font: 800 13px/1.2 var(--ui-font); color: var(--muted); white-space: nowrap; }
.choose-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0 12px;
  -webkit-overflow-scrolling: touch;
}
.choose-tray { margin-bottom: 6px; }
.choose-note { margin: 8px 0 10px; }
.choose-search { width: 100%; margin: 6px 0 10px; }
.choose-list .story-add-btn { min-width: 44px; width: 44px; padding: 0; font-size: 20px; }
.choose-list .story-add-btn.added { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.choose-done { flex: none; width: 100%; margin-top: 8px; }
