:root {
  --paper: #fbfaf5;
  --paper-deep: #f3eadb;
  --ink: #252627;
  --muted: #6f706c;
  --blue: #173a5e;
  --blue-soft: #dbe6ea;
  --teal: #6e8f8c;
  --gold: #d9bf79;
  --sun: #e7b85d;
  --line: rgba(37, 38, 39, .12);
  --shadow: 0 24px 70px rgba(23, 58, 94, .16);
  --radius: 14px;
  color-scheme: light;
  font-family: Manrope, Montserrat, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(120deg, rgba(219, 230, 234, .72), transparent 34%),
    linear-gradient(240deg, rgba(231, 184, 93, .22), transparent 32%),
    var(--paper);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  max-width: 760px;
  margin: 0 auto;
  overflow: hidden;
  background: rgba(251, 250, 245, .72);
  border-left: 1px solid rgba(255,255,255,.7);
  border-right: 1px solid rgba(23,58,94,.08);
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px 10px;
}

.reader-meta {
  min-width: 0;
}

.reader-meta span,
.kicker,
.save-state,
.record-date {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.reader-meta strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--blue);
  font-size: 15px;
}

.icon-button,
.icon-close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.6);
  color: var(--blue);
}

.icon-button {
  display: grid;
  place-content: center;
  gap: 4px;
}

.icon-button span {
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.icon-close {
  position: relative;
  flex: 0 0 auto;
}

.icon-close::before,
.icon-close::after {
  content: "";
  position: absolute;
  left: 13px;
  top: 20px;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.icon-close::before {
  transform: rotate(45deg);
}

.icon-close::after {
  transform: rotate(-45deg);
}

.text-button {
  min-height: 40px;
  border: 1px solid rgba(23,58,94,.18);
  border-radius: 999px;
  padding: 0 13px;
  background: rgba(255,255,255,.64);
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
}

.progress-shell {
  height: 3px;
  background: rgba(23,58,94,.08);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width .32s ease;
}

.viewport {
  min-width: 0;
  min-height: 0;
  display: grid;
  overflow: hidden;
  padding: 10px 12px 14px;
  perspective: 1500px;
  touch-action: pan-y;
}

.page-stack {
  position: relative;
  min-height: 0;
  height: 100%;
  transform-style: preserve-3d;
}

.page {
  min-height: 0;
  height: 100%;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.86), rgba(251,250,245,.96)),
    var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.82);
  padding: clamp(20px, 5.2vw, 48px) clamp(20px, 5vw, 42px);
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
}

.page-current,
.page-turn-sheet {
  width: 100%;
  min-height: 100%;
}

.page-turn-sheet {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  transform-origin: left center;
  will-change: transform, filter;
  backface-visibility: hidden;
}

.page-underlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: .98;
}

.page-scroll {
  max-height: 100%;
  overflow: hidden;
}

.page::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(90deg, rgba(23,58,94,.045) 0 1px, transparent 1px 100%),
    linear-gradient(180deg, rgba(23,58,94,.028) 0 1px, transparent 1px 100%);
  background-size: 34px 34px;
  pointer-events: none;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.45), transparent 70%);
}

.page > * {
  position: relative;
  z-index: 1;
}

.page-stack.is-turning {
  pointer-events: none;
}

.page-turn-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, rgba(255,255,255,.18), transparent 34%);
}

.page-turn-sheet::before {
  z-index: 2;
}

.page-turn-sheet-next.is-animating {
  animation: softPageNext .42s cubic-bezier(.22, .86, .24, 1) both;
}

.page-turn-sheet-prev.is-animating {
  animation: softPagePrev .42s cubic-bezier(.22, .86, .24, 1) both;
}

.page-turn-sheet-next.is-animating::after,
.page-turn-sheet-prev.is-animating::after {
  animation: softPageVeil .42s cubic-bezier(.22, .86, .24, 1) both;
}

@keyframes softPageNext {
  0% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: drop-shadow(0 12px 24px rgba(23,58,94,.08));
  }
  100% {
    opacity: 0;
    transform: translateX(-22px) scale(.992);
    filter: drop-shadow(0 8px 16px rgba(23,58,94,0));
  }
}

@keyframes softPagePrev {
  0% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: drop-shadow(0 12px 24px rgba(23,58,94,.08));
  }
  100% {
    opacity: 0;
    transform: translateX(22px) scale(.992);
    filter: drop-shadow(0 8px 16px rgba(23,58,94,0));
  }
}

@keyframes softPageVeil {
  0% { opacity: 0; }
  45% { opacity: .18; }
  100% { opacity: 0; }
}

.cover-mark,
.visual-mark {
  width: min(62vw, 280px);
  aspect-ratio: 1;
  margin: 8px auto 24px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 34%, rgba(255,255,255,.94) 0 14%, transparent 15%),
    radial-gradient(circle at 58% 48%, rgba(217,191,121,.72) 0 21%, transparent 22%),
    radial-gradient(circle at 40% 62%, rgba(110,143,140,.68) 0 28%, transparent 29%),
    radial-gradient(circle at 53% 42%, rgba(23,58,94,.92) 0 44%, transparent 45%);
  box-shadow: inset 0 0 0 1px rgba(23,58,94,.06), 0 22px 54px rgba(23,58,94,.16);
}

.visual-mark {
  width: min(48vw, 170px);
  margin: 0 0 22px;
  border-radius: 30px 70px 42px 70px;
}

.story-figure {
  width: min(72%, 260px);
  margin: 0 auto 20px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(23,58,94,.1);
  background: rgba(255,255,255,.7);
  box-shadow: 0 18px 42px rgba(23,58,94,.12);
}

.story-figure img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.story-figure img[data-fit="top"] {
  object-position: center top;
}

.cover-figure {
  width: min(100%, 430px);
  margin: 0 auto 22px;
  border-radius: 20px;
}

.cover-figure img {
  aspect-ratio: 16 / 11;
}

.cover-title {
  color: var(--blue);
  font-size: 34px;
  line-height: 1.06;
  letter-spacing: 0;
  margin: 0 0 14px;
}

.subtitle {
  color: #394044;
  font-size: 17px;
  line-height: 1.48;
  margin: 0 0 22px;
}

.author {
  color: var(--blue);
  font-weight: 800;
  margin-top: 20px;
}

h1,
h2,
h3 {
  color: var(--blue);
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.08;
  margin: 0 0 18px;
}

h2 {
  font-size: 27px;
  line-height: 1.12;
  margin: 0 0 18px;
}

h3 {
  font-size: 18px;
  line-height: 1.25;
  margin: 28px 0 12px;
}

.page-subtitle {
  color: var(--teal);
  font-weight: 900;
  font-size: 18px;
  line-height: 1.2;
  margin: -8px 0 20px;
}

p,
li {
  font-size: 16.5px;
  line-height: 1.62;
}

p {
  margin: 0 0 13px;
}

.quote-line {
  color: var(--blue);
  font-weight: 750;
  font-size: 17px;
  line-height: 1.55;
  margin: 12px 0;
}

.margin-note,
.journal-zone,
.system-note,
.share-preview {
  border-radius: var(--radius);
  border: 1px solid rgba(23,58,94,.12);
  background: rgba(219,230,234,.34);
  padding: 16px;
  margin: 22px 0 6px;
}

.margin-note {
  color: var(--blue);
  font-weight: 800;
}

.journal-zone h3 {
  margin-top: 0;
}

.field {
  margin: 18px 0;
}

.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 15px;
  font-weight: 800;
}

textarea {
  width: 100%;
  min-height: 94px;
  resize: vertical;
  border: 1px solid rgba(23,58,94,.18);
  border-radius: 12px;
  padding: 13px 14px;
  background: rgba(255,255,255,.84);
  color: var(--ink);
  outline: none;
  line-height: 1.55;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23,58,94,.12);
}

.save-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.save-button,
.small-action {
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 800;
}

.small-action {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.ghost-action {
  border: 1px solid rgba(23,58,94,.18);
  border-radius: 999px;
  background: rgba(255,255,255,.7);
  color: var(--blue);
  min-height: 36px;
  padding: 0 14px;
  font-weight: 800;
  font-size: 13px;
}

.bottom-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px 18px;
}

.nav-button {
  min-height: 52px;
  border-radius: 999px;
  border: 1px solid rgba(23,58,94,.16);
  font-weight: 900;
}

.nav-button.primary {
  background: var(--blue);
  color: #fff;
}

.nav-button.secondary {
  background: rgba(255,255,255,.68);
  color: var(--blue);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}

.panel.is-open {
  pointer-events: auto;
  opacity: 1;
}

.panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 31, 39, .28);
}

.panel-card {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(18px);
  width: min(760px, 100%);
  max-height: 82dvh;
  overflow: auto;
  border-radius: 24px 24px 0 0;
  background: var(--paper);
  box-shadow: 0 -26px 70px rgba(23,58,94,.18);
  padding: 18px;
  transition: transform .22s ease;
}

.panel.is-open .panel-card {
  transform: translateX(-50%) translateY(0);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 24px;
}

.panel-body {
  padding: 16px 0 4px;
}

.menu-grid {
  display: grid;
  gap: 10px;
}

.menu-item,
.record-card,
.section-card {
  border: 1px solid rgba(23,58,94,.12);
  border-radius: var(--radius);
  background: rgba(255,255,255,.58);
  padding: 14px;
}

.menu-item {
  width: 100%;
  text-align: left;
  color: var(--blue);
  font-weight: 850;
}

.records-group {
  margin-bottom: 18px;
}

.records-group h3 {
  margin: 0 0 10px;
}

.record-card {
  margin-bottom: 10px;
}

.record-card p {
  margin-bottom: 8px;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.empty-record {
  color: var(--muted);
}

.check-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  margin: 11px 0;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(18px);
  max-width: min(92vw, 520px);
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  padding: 12px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 719px) {
  .topbar {
    min-height: 64px;
    padding: 10px 14px 8px;
  }

  .bottom-nav {
    padding: 10px 14px 14px;
  }

  .nav-button {
    min-height: 48px;
  }

  .viewport {
    padding: 8px 10px 10px;
  }

  .page {
    padding: 16px 17px;
  }

  .cover-title,
  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 23px;
    margin-bottom: 12px;
  }

  h3 {
    font-size: 16px;
    margin: 18px 0 9px;
  }

  .subtitle,
  .page-subtitle {
    font-size: 15px;
  }

  p,
  li {
    font-size: 15px;
    line-height: 1.45;
  }

  p {
    margin-bottom: 9px;
  }

  .quote-line {
    font-size: 15.5px;
    line-height: 1.4;
    margin: 8px 0;
  }

  .story-figure {
    width: min(58%, 210px);
    margin-bottom: 12px;
  }

  .cover-figure {
    width: min(88%, 300px);
    margin-bottom: 14px;
  }

  .journal-zone,
  .margin-note,
  .system-note,
  .share-preview {
    padding: 12px;
    margin: 14px 0 4px;
  }

  .field {
    margin: 12px 0;
  }

  textarea {
    min-height: 74px;
    padding: 10px 11px;
  }
}

@media (min-width: 720px) {
  body {
    padding: 18px;
  }

  .app {
    min-height: calc(100dvh - 36px);
    height: calc(100dvh - 36px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 30px 100px rgba(23,58,94,.13);
  }

  .page-stack,
  .page {
    min-height: calc(100dvh - 206px);
  }

  .cover-title {
    font-size: 52px;
  }

  h1 {
    font-size: 46px;
  }

  h2 {
    font-size: 36px;
  }

  .story-figure {
    width: min(58%, 310px);
  }

  .cover-figure {
    width: min(76%, 520px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }

  .page-turn-sheet,
  .page-underlay {
    animation: none !important;
    transition: none !important;
  }
}
