:root {
  --paper: #faf8f5;
  --white: #ffffff;
  --navy: #1e3a5f;
  --navy-2: #152a45;
  --brown: #8b5a2b;
  --sky: #e0f2fe;
  --sky-text: #0284c7;
  --line: rgba(139, 90, 43, 0.22);
  --shadow: 0 18px 45px rgba(30, 58, 95, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", "Songti SC", SimSun, serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--navy);
  background:
    linear-gradient(90deg, rgba(139, 90, 43, 0.025) 1px, transparent 1px),
    linear-gradient(180deg, rgba(139, 90, 43, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: var(--serif);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.btn:disabled {
  opacity: 0.72;
  transform: none;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.center-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.page {
  min-height: 100vh;
  padding: 24px;
}

.narrow {
  width: min(100%, 560px);
  margin: 0 auto;
}

.wide {
  width: min(100%, 1080px);
  margin: 0 auto;
}

.paper-card {
  position: relative;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.paper-card::before,
.paper-card::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  pointer-events: none;
}

.paper-card::before {
  top: -1px;
  left: -1px;
  border-top: 1px solid rgba(139, 90, 43, 0.42);
  border-left: 1px solid rgba(139, 90, 43, 0.42);
}

.paper-card::after {
  right: -1px;
  bottom: -1px;
  border-right: 1px solid rgba(139, 90, 43, 0.42);
  border-bottom: 1px solid rgba(139, 90, 43, 0.42);
}

.small-card {
  width: min(100%, 430px);
  padding: 30px;
  text-align: center;
}

.screen-title {
  margin: 0 0 12px;
  color: var(--navy);
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 500;
  letter-spacing: 0;
}

.subtle-title {
  margin: 0 0 18px;
  color: var(--brown);
  font-size: 13px;
  font-family: var(--sans);
  letter-spacing: 0.08em;
}

.body-text {
  color: var(--navy);
  font-size: 15px;
  line-height: 1.9;
  white-space: pre-wrap;
}

.muted {
  color: rgba(139, 90, 43, 0.82);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.7;
}

.hint {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid rgba(2, 132, 199, 0.16);
  background: var(--sky);
  color: var(--sky-text);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.65;
}

.hint-symbol {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(2, 132, 199, 0.5);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  line-height: 1;
}

.btn-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  padding: 10px 16px;
  background: var(--white);
  color: var(--navy);
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-primary {
  background: var(--navy);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--navy-2);
}

.btn-secondary {
  border-color: rgba(139, 90, 43, 0.38);
  color: var(--navy);
}

.btn-secondary:hover {
  border-color: rgba(139, 90, 43, 0.65);
  background: var(--paper);
}

.btn-text {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brown);
}

.btn-soft {
  background: var(--sky);
  color: var(--sky-text);
}

.btn-danger {
  border-color: rgba(139, 90, 43, 0.55);
  color: #6d3714;
}

.full {
  width: 100%;
}

.cover-card {
  padding: 24px;
}

.cover-image {
  aspect-ratio: 3 / 4;
  margin: 20px 0 22px;
  overflow: hidden;
  border: 1px solid rgba(139, 90, 43, 0.2);
  background: #f4efe8;
}

.cover-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-text {
  margin: 0 0 22px;
  text-align: center;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 58px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(139, 90, 43, 0.14);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.toolbar-title {
  font-size: 14px;
  color: var(--brown);
  font-family: var(--sans);
}

.toc-list {
  display: grid;
  gap: 12px;
  margin: 28px 0;
}

.toc-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--navy);
  text-align: left;
  box-shadow: 0 8px 22px rgba(30, 58, 95, 0.045);
}

.toc-item:hover {
  background: rgba(224, 242, 254, 0.42);
}

.toc-page {
  color: var(--brown);
  font-family: var(--sans);
  font-size: 13px;
}

.toc-date {
  color: rgba(139, 90, 43, 0.72);
  font-family: var(--sans);
  font-size: 12px;
}

.read-wrap {
  min-height: calc(100vh - 58px);
  display: grid;
  grid-template-rows: 1fr auto;
}

.read-card {
  width: min(100%, 620px);
  min-height: 58vh;
  margin: 32px auto;
  padding: 34px;
}

.read-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  border-bottom: 1px dashed rgba(139, 90, 43, 0.25);
  padding-bottom: 16px;
}

.read-author {
  margin: 0 0 5px;
  font-size: 22px;
  font-weight: 500;
}

.read-page-num {
  color: rgba(139, 90, 43, 0.55);
  font-family: var(--sans);
  font-size: 13px;
}

.page-location {
  margin-top: -6px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 24px;
}

.photo {
  display: block;
  width: 100%;
  padding: 5px 5px 16px;
  border: 1px solid rgba(139, 90, 43, 0.28);
  background: var(--white);
  box-shadow: 0 10px 18px rgba(30, 58, 95, 0.07);
  cursor: zoom-in;
}

.photo:nth-child(2n) {
  transform: rotate(0.7deg);
}

.photo:nth-child(2n + 1) {
  transform: rotate(-0.6deg);
}

.photo img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(21, 42, 69, 0.82);
}

.lightbox img {
  max-width: min(100%, 1080px);
  max-height: 88vh;
  object-fit: contain;
  background: var(--white);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  font-size: 28px;
  line-height: 1;
}

.read-actions {
  width: min(100%, 620px);
  margin: 0 auto 26px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.write-layout {
  width: min(100%, 720px);
  margin: 28px auto;
}

.write-card {
  margin-top: 18px;
  padding: 0;
  overflow: hidden;
}

.write-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 18px 22px 12px;
  border-bottom: 1px dashed rgba(139, 90, 43, 0.25);
  font-family: var(--sans);
  font-size: 12px;
  color: rgba(139, 90, 43, 0.82);
}

.save-state {
  margin-left: auto;
  color: var(--sky-text);
}

.write-location {
  display: grid;
  gap: 8px;
  padding: 16px 22px 0;
  font-family: var(--sans);
}

.write-location label {
  color: var(--brown);
  font-size: 13px;
}

.lined-textarea {
  --line-height: 34px;
  width: 100%;
  min-height: 410px;
  padding: 22px;
  border: 0;
  outline: 0;
  resize: vertical;
  color: var(--navy);
  background-image: linear-gradient(to bottom, transparent 25px, rgba(139, 90, 43, 0.12) 26px, transparent 27px);
  background-position: 0 22px;
  background-size: 100% var(--line-height);
  line-height: var(--line-height);
  font-size: 16px;
}

.upload-panel {
  padding: 18px 22px 22px;
  border-top: 1px solid rgba(139, 90, 43, 0.14);
  background: var(--paper);
}

.upload-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-progress {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
}

.photo-progress progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 0;
  background: rgba(139, 90, 43, 0.14);
}

.photo-progress progress::-webkit-progress-bar {
  background: rgba(139, 90, 43, 0.14);
}

.photo-progress progress::-webkit-progress-value {
  background: var(--sky-text);
}

.photo-progress progress::-moz-progress-bar {
  background: var(--sky-text);
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.thumb {
  position: relative;
  padding: 5px 5px 14px;
  border: 1px solid rgba(139, 90, 43, 0.2);
  background: var(--white);
  box-shadow: 0 8px 16px rgba(30, 58, 95, 0.06);
}

.thumb-preview {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.thumb-preview:hover {
  transform: none;
}

.thumb img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(139, 90, 43, 0.4);
  border-radius: 50%;
  background: var(--white);
  color: var(--brown);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(21, 42, 69, 0.36);
}

.modal {
  width: min(100%, 420px);
  padding: 26px;
  background: var(--white);
  border: 1px solid rgba(139, 90, 43, 0.32);
  box-shadow: 0 24px 65px rgba(21, 42, 69, 0.22);
}

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 120;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  transform: translateY(-8px);
  opacity: 0;
  padding: 12px 14px;
  border: 1px solid rgba(2, 132, 199, 0.28);
  background: var(--white);
  color: var(--navy);
  box-shadow: 0 16px 38px rgba(21, 42, 69, 0.18);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: rgba(109, 55, 20, 0.35);
  color: #6d3714;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--brown);
  font-family: var(--sans);
  font-size: 12px;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid rgba(139, 90, 43, 0.38);
  background: var(--paper);
  color: var(--navy);
  padding: 11px 12px;
  outline: 0;
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

.input:focus,
.textarea:focus {
  border-color: var(--navy);
}

.error {
  color: #6d3714;
  font-family: var(--sans);
  font-size: 13px;
}

.success-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(2, 132, 199, 0.36);
  border-radius: 50%;
  color: var(--sky-text);
  font-family: var(--sans);
  font-size: 26px;
}

.share-box {
  margin: 22px 0;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
  text-align: left;
  word-break: break-word;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  background: var(--white);
  font-family: var(--sans);
}

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(139, 90, 43, 0.15);
  background: var(--paper);
}

.admin-brand {
  padding: 22px;
  border-bottom: 1px solid rgba(139, 90, 43, 0.12);
}

.admin-brand h1 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
}

.admin-nav {
  flex: 1;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 4px;
}

.admin-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: var(--navy);
  text-align: left;
}

.admin-nav button.active,
.admin-nav button:hover {
  background: var(--sky);
  color: var(--sky-text);
}

.admin-main {
  padding: 34px;
  overflow: auto;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 26px;
  border-bottom: 1px solid rgba(139, 90, 43, 0.16);
  padding-bottom: 18px;
}

.admin-top h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 500;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card,
.admin-card {
  border: 1px solid rgba(139, 90, 43, 0.18);
  background: var(--white);
  padding: 18px;
}

.stat-label {
  margin: 0 0 6px;
  color: var(--brown);
  font-size: 12px;
}

.stat-value {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  background: var(--sky);
  color: var(--sky-text);
  font-size: 12px;
}

.admin-grid {
  display: grid;
  gap: 14px;
}

.page-row {
  border: 1px solid rgba(139, 90, 43, 0.18);
  padding: 16px;
}

.page-row.hidden {
  opacity: 0.62;
  background: #fbfbfb;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.admin-page-location {
  margin: 6px 0 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-input {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.link-input input {
  flex: 1;
}

.audit-list {
  display: grid;
  gap: 9px;
  color: rgba(30, 58, 95, 0.76);
  font-size: 13px;
}

.print-actions {
  display: flex;
  gap: 10px;
}

.final-cover {
  margin-bottom: 24px;
}

.final-reader {
  width: min(100%, 900px);
  margin: 0 auto;
}

.reading-toc {
  margin: 0 0 28px;
}

.reading-toc h2 {
  margin: 0 0 14px;
  color: var(--brown);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
}

.reading-toc .toc-list {
  margin: 0;
}

.reading-toc .toc-item {
  text-decoration: none;
}

.reading-toc .toc-item:hover {
  transform: none;
}

.final-page-card {
  width: min(100%, 740px);
  scroll-margin-top: 22px;
}

@media (max-width: 760px) {
  .page {
    padding: 18px;
  }

  .toolbar {
    gap: 10px;
  }

  .toolbar-title {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .toc-item {
    grid-template-columns: auto 1fr;
  }

  .toc-date {
    grid-column: 1 / -1;
  }

  .read-card {
    padding: 26px 22px;
  }

  .photo-grid,
  .thumb-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-shell {
    display: block;
  }

  .admin-sidebar {
    position: static;
    height: auto;
  }

  .admin-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-main {
    padding: 20px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .admin-top,
  .page-head,
  .upload-line,
  .btn-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media print {
  body {
    background: white;
  }

  .no-print,
  .toolbar {
    display: none !important;
  }

  .page {
    min-height: auto;
    padding: 0;
  }

  .wide,
  .narrow,
  .final-reader {
    width: 100%;
  }

  .paper-card {
    box-shadow: none;
    break-inside: avoid;
  }

  .read-card {
    width: 100%;
    min-height: auto;
    margin: 0 0 18mm;
    page-break-after: always;
  }

  .final-cover {
    page-break-after: always;
  }
}
