:root {
  color-scheme: light;
  --ink: #182238;
  --muted: #5b6576;
  --paper: rgba(255, 251, 240, 0.94);
  --paper-solid: #fffaf0;
  --line: rgba(24, 34, 56, 0.16);
  --blue: #0d6b91;
  --teal: #17a6a0;
  --amber: #f0a23a;
  --red: #c93232;
  --green: #168a4f;
  --shadow: 0 18px 48px rgba(7, 16, 30, 0.34);
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #14243d;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
label.ghost-action {
  -webkit-tap-highlight-color: transparent;
}

.scene-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.scene-shade {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(rgba(9, 18, 35, 0.02), rgba(9, 18, 35, 0.18)),
    radial-gradient(circle at center 18%, rgba(255, 250, 240, 0.24), transparent 36%);
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 54px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 8px;
  color: #fffaf0;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.top-actions {
  display: flex;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 250, 240, 0.85);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(122, 24, 40, 0.8);
  font-weight: 900;
}

.brand h1,
.brand p,
.hero-copy h2,
.hero-copy p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.08;
}

.eyebrow,
.mode-label,
.toolbar-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.eyebrow {
  color: rgba(255, 250, 240, 0.78);
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 250, 240, 0.34);
  border-radius: 8px;
  color: #fffaf0;
  background: rgba(9, 18, 35, 0.36);
  backdrop-filter: blur(10px);
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
}

.icon-button.is-blank {
  visibility: hidden;
  pointer-events: none;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: 6px;
}

.home,
.editor-view,
.overview-view,
.learned-view,
.practice-view,
.feedback-view,
.summary-view,
.complete-gate {
  animation: rise 180ms ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.quick-actions,
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.three-actions {
  grid-template-columns: 1fr 1fr 0.78fr;
}

.primary-action,
.ghost-action {
  min-height: 42px;
  border-radius: 8px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  font-weight: 900;
  cursor: pointer;
}

.primary-action {
  color: #fffaf0;
  background: linear-gradient(135deg, #a92e31, #d46c25 55%, #e0a333);
  box-shadow: 0 12px 28px rgba(89, 23, 22, 0.32);
}

.ghost-action {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(255, 250, 240, 0.64);
}

.ghost-action input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.wide {
  width: 100%;
}

.toolbar,
.overview-card,
.practice-card,
.custom-form,
.feedback-block,
.summary-view,
.complete-gate,
.recite-form {
  background: rgba(255, 251, 240, 0.76);
  border: 1px solid rgba(255, 250, 240, 0.72);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar {
  margin-top: 10px;
  padding: 8px;
  display: grid;
  gap: 8px;
  box-shadow: 0 12px 32px rgba(7, 16, 30, 0.22);
}

.compact-toolbar {
  backdrop-filter: blur(8px);
}

.segmented {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-top: 5px;
  scrollbar-width: none;
}

.segmented::-webkit-scrollbar {
  display: none;
}

.segmented button {
  flex: 0 0 auto;
  min-width: 42px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.is-active {
  color: #fffaf0;
  border-color: rgba(18, 83, 110, 0.4);
  background: #126f84;
}

.section-heading {
  margin: 12px 2px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #fffaf0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.36);
}

.editor-view .section-heading,
.summary-view .section-heading {
  color: var(--ink);
  text-shadow: none;
}

.section-heading h3 {
  margin: 0;
  font-size: 18px;
}

.section-heading span {
  font-size: 12px;
  font-weight: 800;
}

.lesson-list {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
}

.lesson-card {
  border: 1px solid rgba(255, 250, 240, 0.72);
  border-radius: 8px;
  background: rgba(255, 251, 240, 0.72);
  box-shadow: 0 12px 30px rgba(7, 16, 30, 0.28);
  padding: 12px;
  display: grid;
  gap: 8px;
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.lesson-card:active {
  transform: translateY(1px);
}

.lesson-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lesson-card h4 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.lesson-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  color: #253047;
  background: rgba(23, 166, 160, 0.14);
  font-size: 12px;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.mini-action {
  min-height: 34px;
  border: 1px solid rgba(24, 34, 56, 0.15);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.lesson-open-hint {
  margin: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.small-icon {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--red);
  background: rgba(255, 255, 255, 0.68);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.empty-state {
  padding: 24px 16px;
  color: var(--muted);
  text-align: center;
  background: var(--paper);
  border-radius: 8px;
}

.editor-view,
.overview-view,
.learned-view,
.practice-view,
.feedback-view,
.summary-view,
.complete-gate {
  margin-top: 14px;
}

.panel-title {
  padding: 10px 4px 12px;
  color: #fffaf0;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.panel-title .mode-label {
  color: #ffe0a4;
}

.panel-title h2 {
  margin: 5px 0 0;
  font-size: 30px;
  line-height: 1.08;
}

.custom-form,
.recite-form {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.custom-form label,
.recite-form label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meta-fields[hidden] {
  display: none;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  padding: 12px;
  outline: 0;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 166, 160, 0.18);
}

.preview-box {
  border: 1px dashed rgba(24, 34, 56, 0.28);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.38);
}

.segment-preview,
.summary-list {
  margin: 0;
  padding-left: 22px;
}

.segment-preview {
  max-height: 180px;
  overflow: auto;
  line-height: 1.65;
}

.practice-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: #fffaf0;
  font-size: 13px;
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.42);
}

.practice-card {
  min-height: 300px;
  padding: 18px;
  display: grid;
  align-content: center;
  gap: 16px;
}

.overview-card {
  padding: 16px;
  display: grid;
  gap: 10px;
  backdrop-filter: blur(7px);
}

.overview-card h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.12;
}

.overview-author {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.overview-segments {
  margin: 6px 0 4px;
  padding-left: 26px;
  display: grid;
  gap: 9px;
  max-height: min(54vh, 520px);
  overflow: auto;
  line-height: 1.55;
  font-size: 17px;
  font-weight: 800;
}

.overview-segments li {
  padding: 8px 8px 8px 2px;
  border-bottom: 1px solid rgba(24, 34, 56, 0.1);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.error-badge {
  align-self: start;
  white-space: nowrap;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fffaf0;
  background: var(--red);
  font-size: 12px;
}

.support-block {
  border-top: 1px solid rgba(24, 34, 56, 0.14);
  padding-top: 10px;
}

.support-block h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.support-block p,
.support-block ul {
  margin: 0;
  color: #2b3548;
  line-height: 1.6;
  font-size: 14px;
  font-weight: 700;
}

.support-block ul {
  padding-left: 20px;
  display: grid;
  gap: 5px;
}

.overview-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.overview-actions .wide {
  grid-column: 1 / -1;
}

.danger-action {
  color: #8b2525;
}

.practice-card h2 {
  margin: 0;
  font-size: 20px;
}

.study-segment {
  min-height: 128px;
  display: grid;
  place-items: center;
  padding: 18px 10px;
  border-block: 1px solid rgba(24, 34, 56, 0.12);
  font-size: clamp(25px, 8vw, 38px);
  font-weight: 900;
  line-height: 1.42;
  text-align: center;
}

.practice-hint {
  min-height: 40px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.progress-rail {
  height: 9px;
  margin: 12px 0;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.38);
}

.progress-rail span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #17a6a0, #e0a333);
  transition: width 180ms ease;
}

.complete-gate,
.summary-view {
  padding: 22px 16px;
  text-align: center;
}

.gate-symbol {
  width: 62px;
  height: 62px;
  margin: 0 auto 12px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fffaf0;
  background: var(--green);
  font-size: 36px;
  font-weight: 900;
}

.complete-gate h2,
.summary-view h2 {
  margin: 0 0 14px;
  font-size: 30px;
}

.recite-form {
  margin-top: 18px;
}

.recite-form textarea {
  min-height: 160px;
  font-size: 21px;
  font-weight: 800;
}

.diff-hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.feedback-view {
  display: grid;
  gap: 12px;
}

.wrong-mark {
  width: 78px;
  height: 78px;
  margin: 0 auto;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fffaf0;
  background: var(--red);
  box-shadow: 0 14px 34px rgba(105, 18, 18, 0.36);
  font-size: 38px;
  font-weight: 1000;
}

.feedback-block {
  padding: 14px;
}

.correct-segment,
.wrong-answer {
  margin-top: 7px;
  font-size: 24px;
  line-height: 1.45;
  font-weight: 900;
}

.wrong-answer {
  color: var(--red);
}

.char-diff-list {
  display: grid;
  gap: 6px;
}

.diff-chip {
  padding: 9px 11px;
  border-radius: 8px;
  color: #681b1b;
  background: rgba(255, 236, 226, 0.95);
  font-weight: 800;
}

.summary-count {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 800;
}

.summary-list {
  display: grid;
  gap: 8px;
  padding-left: 0;
  list-style: none;
  text-align: left;
}

.summary-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  line-height: 1.45;
  font-weight: 800;
}

.summary-list span {
  min-width: 52px;
  text-align: right;
  color: var(--red);
  font-weight: 1000;
}

.summary-list .perfect {
  color: var(--green);
  font-size: 18px;
}

.summary-view .primary-action {
  margin-top: 14px;
}

@media (min-width: 700px) {
  .app-shell {
    padding-top: 22px;
  }

  .lesson-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 360px) {
  .quick-actions,
  .button-row,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .three-actions,
  .card-actions,
  .overview-actions {
    grid-template-columns: 1fr;
  }

  .study-segment {
    font-size: 24px;
  }
}

/* Calm lavender refresh */
:root {
  --ink: #352d4f;
  --muted: #746a8e;
  --paper: rgba(255, 255, 255, 0.9);
  --paper-solid: #ffffff;
  --line: rgba(91, 76, 139, 0.18);
  --blue: #7062b8;
  --teal: #7f77c9;
  --amber: #d4a247;
  --red: #b84a5f;
  --green: #5b9871;
  --shadow: 0 14px 34px rgba(83, 65, 130, 0.16);
}

body {
  background: #efe9ff;
}

.forest-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(180deg, #fbf8ff 0%, #efe7ff 45%, #f7f2ff 100%),
    linear-gradient(135deg, rgba(213, 203, 255, 0.36), rgba(255, 255, 255, 0.48));
}

.forest-scene::before,
.forest-scene::after {
  display: none;
}

.moon,
.tree,
.leaf,
.acorn,
.forest-friend {
  display: none !important;
}

.moon {
  position: absolute;
  top: 40px;
  left: calc(50% - 54px);
  width: 108px;
  height: 108px;
  border-radius: 999px;
  background: #fff6bb;
  box-shadow: 0 0 46px rgba(255, 244, 166, 0.9);
}

.tree {
  position: absolute;
  bottom: 4%;
  width: 95px;
  height: 78%;
  background: linear-gradient(90deg, #6c4a2e, #8b6744);
  border-radius: 48px 48px 0 0;
}

.tree::before,
.tree::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(57, 112, 70, 0.92);
}

.tree::before {
  width: 260px;
  height: 260px;
  top: -70px;
  left: -90px;
}

.tree::after {
  width: 210px;
  height: 210px;
  top: 76px;
  left: -54px;
  background: rgba(72, 135, 77, 0.86);
}

.tree-left {
  left: -32px;
  transform: rotate(2deg);
}

.tree-right {
  right: -44px;
  width: 78px;
  opacity: 0.88;
  transform: rotate(-2deg);
}

.leaf,
.acorn {
  position: absolute;
  z-index: 0;
  opacity: 0.84;
}

.leaf {
  width: 72px;
  height: 34px;
  border-radius: 100% 0 100% 0;
  background: #7eb36a;
  box-shadow: inset 16px 0 0 rgba(255, 245, 170, 0.16);
}

.leaf-a {
  top: 21%;
  right: 15%;
  transform: rotate(-24deg);
}

.leaf-b {
  top: 62%;
  left: 12%;
  transform: rotate(34deg) scale(0.78);
}

.acorn {
  width: 42px;
  height: 52px;
  border-radius: 48% 48% 54% 54%;
  background: #9f6a3c;
  box-shadow: inset 0 13px 0 #6b452b;
}

.acorn::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 12px;
  left: 12px;
  top: -8px;
  border-radius: 50%;
  background: #654126;
}

.acorn-a {
  top: 17%;
  left: 18%;
  transform: rotate(-15deg);
}

.acorn-b {
  right: 12%;
  bottom: 18%;
  transform: rotate(18deg) scale(0.85);
}

.forest-friend {
  position: absolute;
  left: calc(50% - 52px);
  bottom: 8%;
  width: 104px;
  height: 126px;
  border-radius: 50% 50% 42% 42%;
  background: #6d776b;
  box-shadow: inset 0 -24px 0 rgba(255, 244, 213, 0.52), 0 16px 40px rgba(28, 54, 33, 0.22);
  opacity: 0.68;
}

.forest-friend::before,
.forest-friend::after {
  content: "";
  position: absolute;
  top: -18px;
  width: 30px;
  height: 48px;
  border-radius: 50% 50% 20% 20%;
  background: #6d776b;
}

.forest-friend::before {
  left: 14px;
  transform: rotate(-20deg);
}

.forest-friend::after {
  right: 14px;
  transform: rotate(20deg);
}

.forest-friend span,
.forest-friend span::before,
.forest-friend span::after {
  position: absolute;
  content: "";
  display: block;
}

.forest-friend span {
  top: 44px;
  left: 32px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #1f2c22;
  box-shadow: 31px 0 0 #1f2c22;
}

.forest-friend span::before {
  top: 22px;
  left: 9px;
  width: 24px;
  height: 10px;
  border-radius: 0 0 999px 999px;
  border-bottom: 3px solid #334237;
}

.app-shell {
  width: min(100%, 500px);
}

.topbar {
  color: #3a3158;
  grid-template-columns: 38px 1fr auto;
  text-shadow: none;
}

.eyebrow {
  color: #746a8e;
}

.top-actions {
  gap: 0;
  width: 38px;
  height: 38px;
}

.brand-mark {
  background: #7869ba;
}

.icon-button {
  width: 38px;
  height: 38px;
  color: #fff;
  background: #7465ad;
}

#homeButton {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: auto;
  left: calc(100% - 48px);
  left: calc(100dvw - 48px);
  z-index: 30;
}

@media (min-width: 540px) {
  #homeButton {
    left: auto;
    right: calc((100vw - 500px) / 2 + 10px);
  }
}

.primary-action {
  background: linear-gradient(135deg, #7665bd, #d5a84c);
  box-shadow: 0 10px 22px rgba(92, 76, 145, 0.2);
}

.ghost-action {
  background: rgba(255, 255, 255, 0.82);
}

.toolbar,
.overview-card,
.practice-card,
.custom-form,
.feedback-block,
.summary-view,
.complete-gate,
.recite-form,
.lesson-card {
  background: rgba(255, 255, 255, 0.88);
  border-color: rgba(255, 255, 255, 0.92);
}

.toolbar {
  margin-top: 8px;
  padding: 7px;
  gap: 4px;
}

.toolbar-label {
  font-size: 11px;
}

.book-segmented {
  padding-top: 4px;
}

.book-segmented button {
  min-width: auto;
  min-height: 27px;
  padding: 4px 8px;
  font-size: 11px;
}

.section-heading,
.practice-meta {
  color: #4a4168;
  text-shadow: none;
}

.lesson-list {
  gap: 7px;
}

.lesson-card {
  padding: 8px;
  gap: 5px;
}

.lesson-main {
  gap: 8px;
}

.lesson-card h4 {
  font-size: 16px;
}

.lesson-card p {
  margin-top: 2px;
  font-size: 11px;
}

.pill-row {
  gap: 4px;
}

.pill {
  min-height: 20px;
  padding: 3px 7px;
  font-size: 11px;
  background: rgba(120, 105, 186, 0.12);
}

.card-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 5px;
}

.mini-action {
  min-height: 28px;
  padding: 4px 3px;
  font-size: 11px;
}

.overview-card {
  padding: 12px;
}

.overview-card h2 {
  font-size: 14px;
  line-height: 1.35;
}

.overview-author {
  min-height: 14px;
  font-size: 12px;
}

.overview-segments {
  max-height: min(64vh, 620px);
  gap: 5px;
  font-size: 16px;
}

.overview-segments li {
  padding: 6px 6px 6px 0;
}

.char-diff-list {
  display: none;
}

.correct-segment,
.wrong-answer {
  font-size: 21px;
}

@media (max-width: 360px) {
  .card-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .mini-action {
    min-height: 28px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
