:root {
  --bg: #120807;
  --ink: #2b1813;
  --paper: #f5ead2;
  --paper-deep: #e8d4a8;
  --panel: rgba(31, 15, 12, 0.78);
  --panel-strong: rgba(21, 10, 9, 0.9);
  --line: rgba(222, 187, 116, 0.3);
  --line-strong: rgba(222, 187, 116, 0.54);
  --text: #f6ead8;
  --muted: rgba(246, 234, 216, 0.66);
  --gold: #debb74;
  --red: #b34235;
  --teal: #55d4c2;
  --green: #7dcc89;
  --shadow: rgba(0, 0, 0, 0.36);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
  padding-bottom: calc(20px + var(--safe-bottom));
  background:
    radial-gradient(ellipse at 22% 4%, rgba(179, 66, 53, 0.26), transparent 42%),
    linear-gradient(145deg, rgba(85, 212, 194, 0.08), transparent 28%),
    linear-gradient(180deg, #1b0908, var(--bg) 58%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto minmax(96px, 1fr);
  align-items: center;
  gap: 14px;
  padding: calc(16px + var(--safe-top)) 24px 14px;
  background: rgba(18, 8, 7, 0.86);
  border-bottom: 1px solid rgba(222, 187, 116, 0.16);
  backdrop-filter: blur(14px);
}

.brand-link {
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-decoration: none;
}

.brand-link:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.source-note a:focus-visible {
  outline: 3px solid rgba(85, 212, 194, 0.46);
  outline-offset: 3px;
}

.top-title {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
}

.top-title span,
.kicker,
.rail-head p,
.daily-card span,
.completion-card span {
  margin: 0;
  color: var(--teal);
  font-size: 11px;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.22em;
}

.top-title strong {
  font-family: "Noto Serif SC", serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.ghost-button,
.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.ghost-button {
  justify-self: end;
  padding: 0 14px;
  color: var(--gold);
  background: rgba(246, 234, 216, 0.07);
  border-color: rgba(222, 187, 116, 0.22);
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: rgba(222, 187, 116, 0.1);
}

.ghost-button.full {
  justify-self: stretch;
  width: 100%;
  margin-top: 18px;
}

.scribe-layout {
  width: min(1420px, 100%);
  min-height: calc(100dvh - 78px);
  margin: 0 auto;
  padding: 22px 24px 12px;
  display: grid;
  grid-template-columns: minmax(210px, 0.68fr) minmax(420px, 1.5fr) minmax(300px, 0.88fr);
  gap: 18px;
  align-items: stretch;
}

.chapter-rail,
.practice-panel,
.meaning-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 26px 68px var(--shadow);
}

.chapter-rail {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(222, 187, 116, 0.16);
}

.rail-head span {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chapter-list {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.chapter-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  padding: 10px 11px;
  border: 1px solid rgba(222, 187, 116, 0.16);
  border-radius: 6px;
  color: var(--muted);
  text-align: left;
  background: rgba(18, 8, 7, 0.34);
}

.chapter-button span {
  color: rgba(222, 187, 116, 0.76);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chapter-button strong {
  color: inherit;
  font-family: "Noto Serif SC", serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}

.chapter-button.is-active {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(179, 66, 53, 0.22);
}

.chapter-button.is-done strong::after {
  content: "已抄";
  display: inline-flex;
  margin-left: 8px;
  color: var(--green);
  font-family:
    "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 11px;
  font-weight: 600;
}

.practice-panel,
.meaning-panel {
  padding: 20px;
}

.session-head,
.meaning-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

h1,
h2 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
  text-wrap: balance;
}

h1 {
  margin-top: 8px;
  font-size: clamp(30px, 3.4vw, 48px);
  line-height: 1.16;
  letter-spacing: 0.04em;
}

h2 {
  margin-top: 8px;
  font-size: 28px;
  letter-spacing: 0.08em;
}

.chapter-badge,
#ai-source {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  white-space: nowrap;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--gold);
  border: 1px solid rgba(222, 187, 116, 0.3);
  background: rgba(18, 8, 7, 0.35);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.sutra-page {
  position: relative;
  margin-top: 20px;
  min-height: 210px;
  padding: 28px 28px 22px 118px;
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(113, 62, 32, 0.2), transparent 16%),
    repeating-linear-gradient(90deg, rgba(92, 52, 30, 0.12) 0 1px, transparent 1px 46px),
    linear-gradient(180deg, var(--paper), var(--paper-deep));
  box-shadow:
    inset 0 0 0 1px rgba(105, 62, 31, 0.16),
    inset 28px 0 36px rgba(126, 72, 31, 0.13),
    0 18px 46px rgba(0, 0, 0, 0.22);
  max-height: min(56vh, 560px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(92, 52, 30, 0.34) transparent;
}

.sutra-page::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(92, 52, 30, 0.16);
  border-radius: 5px;
  pointer-events: none;
}

.page-ornament {
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 22px;
  width: 62px;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(92, 52, 30, 0.24);
}

.page-ornament span {
  display: block;
  width: 28px;
  height: 78%;
  border-radius: 999px;
  background: rgba(179, 66, 53, 0.78);
  box-shadow:
    16px 0 0 rgba(179, 66, 53, 0.42),
    -16px 0 0 rgba(179, 66, 53, 0.28);
}

.page-ornament span:nth-child(2),
.page-ornament span:nth-child(3) {
  display: none;
}

.sutra-text {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(21px, 2.4vw, 29px);
  line-height: 2;
  letter-spacing: 0;
  text-wrap: pretty;
  white-space: pre-line;
}

.sutra-source {
  position: relative;
  z-index: 1;
  margin: 18px 0 0;
  color: rgba(43, 24, 19, 0.58);
  font-size: 13px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

.writing-board {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.board-head span {
  color: var(--muted);
  letter-spacing: 0.08em;
}

.board-head strong {
  color: var(--gold);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.copy-lines {
  display: grid;
  gap: 10px;
}

.copy-line {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(74px, auto);
  gap: 8px 12px;
  padding: 14px;
  border: 1px solid rgba(222, 187, 116, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(246, 234, 216, 0.07), rgba(18, 8, 7, 0.2)),
    rgba(18, 8, 7, 0.34);
}

.copy-line::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 8px 0 0 8px;
  background: rgba(222, 187, 116, 0.22);
}

.copy-line[data-state="right"]::before {
  background: #5d8fff;
}

.copy-line[data-state="wrong"]::before {
  background: #ff685c;
}

.copy-line[data-state="complete"]::before {
  background: var(--green);
}

.line-source {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.line-source span {
  color: rgba(222, 187, 116, 0.64);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.line-source p {
  margin: 0;
  color: rgba(246, 234, 216, 0.9);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 18px;
  line-height: 1.7;
  text-wrap: pretty;
}

.copy-input {
  width: 100%;
  border: 1px solid rgba(222, 187, 116, 0.26);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  background:
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(222, 187, 116, 0.12) 32px 33px),
    rgba(18, 8, 7, 0.42);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 18px;
  line-height: 1.45;
  letter-spacing: 0;
  outline: none;
}

.copy-line[data-state="right"] .copy-input {
  color: #8fb0ff;
  border-color: rgba(93, 143, 255, 0.46);
}

.copy-line[data-state="wrong"] .copy-input {
  color: #ff897f;
  border-color: rgba(255, 104, 92, 0.54);
}

.copy-line[data-state="complete"] .copy-input {
  color: #a9e7b3;
  border-color: rgba(125, 204, 137, 0.48);
}

.copy-input:focus {
  border-color: rgba(85, 212, 194, 0.62);
  box-shadow: 0 0 0 3px rgba(85, 212, 194, 0.09);
}

.line-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  background: rgba(246, 234, 216, 0.06);
  border: 1px solid rgba(246, 234, 216, 0.12);
  font-size: 12px;
  white-space: nowrap;
}

.copy-line[data-state="right"] .line-status {
  color: #a8beff;
}

.copy-line[data-state="wrong"] .line-status {
  color: #ffa097;
}

.copy-line[data-state="complete"] .line-status {
  color: #b9ebc1;
}

.progress-card {
  margin-top: 16px;
}

.progress-top,
.metrics,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.progress-top span {
  color: var(--gold);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.progress-top strong {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  text-wrap: pretty;
}

.progress-track {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(246, 234, 216, 0.13);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.metrics {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

#complete-status.is-complete {
  color: var(--green);
}

.action-row {
  margin-top: 18px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button {
  padding: 0 18px;
}

.primary-button {
  color: #fff7ed;
  background: var(--red);
  border-color: rgba(255, 214, 190, 0.22);
  box-shadow: 0 12px 24px rgba(91, 21, 16, 0.28);
}

.primary-button:hover {
  background: #963128;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.secondary-button {
  color: var(--text);
  background: rgba(246, 234, 216, 0.07);
  border-color: rgba(246, 234, 216, 0.18);
}

.secondary-button:hover {
  border-color: rgba(246, 234, 216, 0.36);
}

.dedication-band {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(222, 187, 116, 0.18);
}

.dedication-fields {
  display: grid;
  grid-template-columns: minmax(150px, 0.48fr) minmax(0, 1fr);
  gap: 12px;
}

.dedication-fields label {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.dedication-fields input,
.dedication-fields textarea {
  width: 100%;
  border: 1px solid rgba(222, 187, 116, 0.24);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  background: rgba(18, 8, 7, 0.42);
  outline: none;
  letter-spacing: 0;
}

.dedication-fields textarea {
  min-height: 94px;
  resize: vertical;
  line-height: 1.8;
}

.dedication-fields input::placeholder {
  color: rgba(246, 234, 216, 0.36);
}

.dedication-fields input:focus,
.dedication-fields textarea:focus {
  border-color: rgba(85, 212, 194, 0.58);
  box-shadow: 0 0 0 3px rgba(85, 212, 194, 0.09);
}

.dedication-action {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.dedication-submit {
  min-width: 188px;
}

.ritual-note {
  min-height: 28px;
  margin: 12px 0 0;
  color: rgba(222, 187, 116, 0.9);
  font-size: 14px;
  line-height: 1.75;
  text-wrap: pretty;
}

.meaning-panel {
  display: flex;
  flex-direction: column;
}

.plain-meaning {
  min-height: 198px;
  margin: 20px 0 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.95;
  text-wrap: pretty;
}

.daily-card,
.completion-card {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(222, 187, 116, 0.18);
}

.daily-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
  text-wrap: pretty;
}

.completion-card {
  margin-top: auto;
}

.completion-card strong {
  display: block;
  margin-top: 8px;
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.source-note {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 0 24px;
  color: rgba(246, 234, 216, 0.44);
  font-size: 12px;
  line-height: 1.75;
}

.source-note a {
  color: rgba(222, 187, 116, 0.78);
}

.keepsake-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #1b0d0b;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}

.keepsake-dialog::backdrop {
  background: rgba(8, 3, 3, 0.8);
  backdrop-filter: blur(6px);
}

.keepsake-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(222, 187, 116, 0.18);
}

.keepsake-head p {
  margin: 0;
  color: var(--teal);
  font-size: 11px;
  line-height: 1.25;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.keepsake-head h2 {
  margin-top: 7px;
  font-size: 25px;
}

.dialog-close {
  display: inline-grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--gold);
  border: 1px solid rgba(222, 187, 116, 0.22);
  border-radius: 6px;
  background: rgba(246, 234, 216, 0.06);
  font-size: 25px;
  line-height: 1;
}

.keepsake-stage {
  max-height: calc(100dvh - 230px);
  padding: 18px;
  overflow: auto;
  text-align: center;
  background: #100706;
}

.keepsake-stage img {
  display: block;
  width: min(100%, 560px);
  height: auto;
  margin: 0 auto;
  border: 1px solid rgba(222, 187, 116, 0.28);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.42);
}

.keepsake-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid rgba(222, 187, 116, 0.18);
}

.keepsake-note {
  min-height: 24px;
  margin: 0;
  padding: 0 20px 14px;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 1180px) {
  .scribe-layout {
    grid-template-columns: minmax(190px, 0.62fr) minmax(0, 1.38fr);
  }

  .meaning-panel {
    grid-column: 1 / -1;
  }

  .plain-meaning {
    min-height: auto;
  }
}

@media (min-width: 821px) {
  .scribe-layout {
    height: calc(100dvh - 98px);
    min-height: 640px;
  }

  .chapter-rail,
  .practice-panel,
  .meaning-panel {
    max-height: 100%;
    min-height: 0;
  }

  .practice-panel,
  .meaning-panel {
    overflow: auto;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: relative;
    grid-template-columns: 1fr auto;
    padding-inline: 18px;
  }

  .top-title {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-items: start;
  }

  .ghost-button {
    padding-inline: 12px;
  }

  .scribe-layout {
    min-height: auto;
    padding: 16px 16px 10px;
    grid-template-columns: 1fr;
  }

  .chapter-rail {
    display: block;
  }

  .chapter-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(138px, 42vw);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .chapter-button {
    min-height: 72px;
  }

  .practice-panel,
  .meaning-panel {
    padding: 16px;
  }

  .session-head,
  .meaning-head {
    align-items: flex-start;
  }

  .sutra-page {
    min-height: 188px;
    max-height: 52vh;
    padding: 24px 20px 20px 78px;
  }

  .page-ornament {
    left: 14px;
    width: 44px;
  }

  .page-ornament span {
    width: 18px;
  }

  .sutra-text {
    line-height: 1.9;
  }

  .source-note {
    padding-inline: 16px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 10px;
  }

  .brand-link {
    font-size: 12px;
  }

  .top-title strong {
    font-size: 18px;
  }

  .session-head,
  .meaning-head,
  .progress-top,
  .metrics {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 34px;
  }

  h2 {
    font-size: 25px;
  }

  .chapter-badge,
  #ai-source {
    min-height: 32px;
  }

  .sutra-page {
    max-height: 48vh;
    padding: 22px 16px 18px;
  }

  .sutra-page::after,
  .page-ornament {
    display: none;
  }

  .sutra-text {
    font-size: 22px;
  }

  .copy-line {
    grid-template-columns: 1fr;
  }

  .line-status {
    justify-self: start;
    min-height: 32px;
  }

  .dedication-fields {
    grid-template-columns: 1fr;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .action-row .secondary-button,
  .dedication-submit {
    width: 100%;
  }

  .dedication-action {
    display: block;
  }

  .keepsake-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .keepsake-head {
    padding: 14px;
  }

  .keepsake-stage {
    max-height: calc(100dvh - 238px);
    padding: 10px;
  }

  .keepsake-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 12px 14px;
  }

  .keepsake-actions button {
    width: 100%;
    padding-inline: 10px;
  }

  .keepsake-note {
    padding-inline: 14px;
  }
}
