:root {
  color-scheme: light;
  --paper: #f7faf7;
  --desk: #d5e3dc;
  --ink: #182420;
  --pencil: #3e5148;
  --margin: #c4453c;
  --mark: #8f2d28;
  --cloth: #243833;
  --cloth-ink: #e7efe9;
  --cloth-dim: #c5d5cc;
  --line: #c5d6cc;
  --font-title: "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
  --font-body: "Kaiti SC", "STKaiti", "KaiTi", "楷体", serif;
  --font-ui: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --measure: 34em;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--desk);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
}

:focus-visible {
  outline: 2px solid var(--margin);
  outline-offset: 2px;
}

::selection { background: #f0c8c4; }

.skip {
  position: absolute;
  left: 1rem;
  top: 0;
  transform: translateY(-120%);
  background: var(--paper);
  color: var(--ink);
  padding: 0.4rem 0.6rem;
  z-index: 3;
}

.skip:focus { transform: none; }

.app {
  display: grid;
  grid-template-columns: 18.5rem minmax(0, 1fr);
  align-items: start;
}

.index {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cloth);
  color: var(--cloth-ink);
}

.index-head {
  padding: 1.4rem 1.15rem 0.7rem;
}

.index-head h1 {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: 0;
}

.index-head p {
  margin: 0.25rem 0 0;
  color: var(--cloth-dim);
  font-size: 0.92rem;
}

.index-tools {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.35rem 1.15rem 0.8rem;
}

.index-tools input {
  flex: 1;
  min-width: 0;
  background: transparent;
  color: var(--cloth-ink);
  border: 0;
  border-bottom: 1px solid rgb(231 239 233 / 35%);
  border-radius: 0;
  font: inherit;
  font-size: 1rem;
  padding: 0.4rem 0;
}

.index-tools input::placeholder { color: var(--cloth-dim); }

.index-tools button {
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  background: transparent;
  color: var(--cloth-ink);
  border: 1px solid rgb(231 239 233 / 40%);
  border-radius: 0;
  padding: 0.38rem 0.55rem;
}

.toc {
  overflow: auto;
  flex: 1;
  padding-bottom: 1.5rem;
}

.toc a {
  display: block;
  padding: 0.62rem 1.15rem;
  color: inherit;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.toc a:hover { background: rgb(255 255 255 / 5%); }

.toc a[aria-current="page"] {
  border-left-color: var(--margin);
  background: rgb(255 255 255 / 7%);
}

.toc-title {
  font-family: var(--font-title);
  font-size: 1.02rem;
  line-height: 1.45;
}

.empty-index {
  margin: 0.6rem 1.15rem;
  color: var(--cloth-dim);
}

.reader { padding: 1.25rem 1.25rem 3rem; }

.toolbar {
  width: min(44rem, 100%);
  margin: 0 auto 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
  align-items: center;
  color: var(--pencil);
  min-height: 2rem;
}

.toolbar a,
.toolbar button {
  font: inherit;
  font-size: 0.98rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  padding: 0.15rem 0;
  text-decoration: none;
  cursor: pointer;
}

.toolbar a[aria-current="page"] { border-bottom-color: var(--margin); }

.toolbar .grow { flex: 1; }

.solid {
  font: inherit;
  font-size: 0.95rem;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: 0;
  padding: 0.38rem 0.75rem;
  cursor: pointer;
}

.solid:disabled {
  opacity: 0.35;
  cursor: default;
}

.status { color: var(--pencil); }

.sheet {
  width: min(44rem, 100%);
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 0 0 1px rgb(24 36 32 / 10%);
  padding: 2.8rem 2.2rem 2rem;
  font-family: var(--font-body);
  font-size: 1.1875rem;
  line-height: 2;
}

.doc-title,
.title-input {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 1.65rem;
  line-height: 1.45;
  text-align: center;
  margin: 0 auto 0.35em;
  max-width: var(--measure);
}

.title-input {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 0;
}

.lead-notes { margin: 0 auto 0.35em; max-width: var(--measure); }

.column {
  max-width: var(--measure);
  margin: 0.35em auto 0;
  border-left: 1.5px solid var(--margin);
  padding-left: 1.05rem;
  overflow-wrap: break-word;
}

.prose,
.verse,
.note,
.salute,
.remark,
.break,
.block-text {
  margin: 0;
  font: inherit;
  line-height: 2;
}

.prose {
  text-indent: 2em;
  text-align: justify;
  text-justify: inter-ideograph;
  text-justify: inter-character;
}

.verse {
  text-indent: 0;
  text-align: center;
}

.note {
  text-indent: 0;
  text-align: center;
  color: var(--pencil);
}

.salute {
  text-indent: 0;
  text-align: left;
}

.remark {
  text-indent: 0;
  text-align: left;
  color: var(--mark);
}

.break { height: 2em; }

.colophon {
  max-width: var(--measure);
  margin: 1.4em auto 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.4;
  color: #5c7068;
}

.edit-hint {
  max-width: var(--measure);
  margin: 1.1rem auto 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--pencil);
}

.block {
  margin: 0 0 0.15rem;
}

.block-tools {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--pencil);
  opacity: 0.55;
}

.block:focus-within .block-tools,
.block:hover .block-tools { opacity: 1; }

.block-tools select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.block-tools button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.block-text {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  resize: none;
  overflow: hidden;
  padding: 0;
  background: transparent;
  color: inherit;
  field-sizing: content;
}

textarea.prose {
  text-align: left;
  text-indent: 2em;
}

textarea.verse,
textarea.note {
  text-indent: 0;
  text-align: center;
}

textarea.salute { text-indent: 0; text-align: left; }

textarea.remark {
  text-indent: 0;
  text-align: left;
  color: var(--mark);
}

.block-text::placeholder { color: #8aa094; }

.break-row {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 2;
  color: var(--pencil);
}

.add-row {
  margin-top: 0.4rem;
}

.add-row button,
.write,
.danger {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  background: transparent;
  color: var(--pencil);
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 0.1rem 0;
  cursor: pointer;
}

.sheet-empty {
  margin: 2rem 0;
  text-align: center;
  font-family: var(--font-ui);
  color: var(--pencil);
}

.write { color: var(--ink); border-bottom-color: var(--line); }
.danger { color: var(--mark); }

@media (hover: none) {
  .block-tools { opacity: 1; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .index {
    position: relative;
    height: auto;
    max-height: none;
  }
  .toc { max-height: 16rem; flex: none; }
  .sheet { padding: 1.8rem 1.05rem 1.4rem; }
  .reader { padding: 0.9rem 0.7rem 2rem; }
}

@media print {
  .index, .toolbar, .skip, .block-tools, .add-row, .edit-hint, .danger { display: none !important; }
  .app { display: block; }
  body, .reader { background: white; padding: 0; }
  .sheet { box-shadow: none; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
