:root {
  color-scheme: dark;
  --bg: #050816;
  --text: #f4f3ee;
  --muted: rgba(244, 243, 238, 0.68);
  --blue: #9cc8ff;
  --gold: #dcc98a;
  --line: rgba(156, 200, 255, 0.18);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius-xl: 30px;
  --body-font: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
  --title-font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(84, 108, 168, 0.16), transparent 30%),
    radial-gradient(circle at 20% 20%, rgba(156, 200, 255, 0.08), transparent 22%),
    linear-gradient(180deg, #040712 0%, #050816 45%, #03050d 100%);
  color: var(--text);
  font-family: var(--body-font);
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.04), transparent 0.7px),
    radial-gradient(circle at 80% 30%, rgba(255, 255, 255, 0.05), transparent 0.9px),
    radial-gradient(circle at 35% 70%, rgba(255, 255, 255, 0.04), transparent 0.6px),
    radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.05), transparent 0.75px);
  background-size: 240px 240px;
  mix-blend-mode: screen;
  opacity: 0.45;
  pointer-events: none;
  z-index: -1;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

canvas#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  isolation: isolate;
}

.view {
  position: absolute;
  inset: 0;
  padding:
    calc(env(safe-area-inset-top) + clamp(28px, 5vw, 56px))
    clamp(16px, 4vw, 44px)
    calc(env(safe-area-inset-bottom) + clamp(18px, 4vw, 34px));
}

.home {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 26px;
  align-items: start;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(env(safe-area-inset-bottom) + 72px);
}

body.is-reading .home {
  display: none !important;
}

.home__ambient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(156, 200, 255, 0.08), transparent 18%),
    radial-gradient(circle at 58% 44%, rgba(220, 201, 138, 0.06), transparent 14%);
  filter: blur(30px);
  pointer-events: none;
}

.home__header,
.home__summary,
.chapter-list,
.home__footer {
  position: relative;
  z-index: 1;
}

.home__header {
  max-width: 720px;
  padding-top: 6px;
}

.eyebrow {
  margin: 0 0 10px;
  color: rgba(156, 200, 255, 0.82);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: 0.02em;
}

h1 {
  font-size: clamp(3rem, 8vw, 6.2rem);
  text-wrap: balance;
}

h2 {
  font-size: clamp(2rem, 5vw, 3.2rem);
}

h3 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.subtitle {
  margin: 24px 0 0;
  max-width: 48ch;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.08rem);
  line-height: 1.6;
}

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

.summary-card {
  display: grid;
  gap: 18px;
  padding: 30px 32px;
  border-radius: 30px;
  border: 1px solid rgba(156, 200, 255, 0.18);
  background:
    radial-gradient(circle at 15% 20%, rgba(156, 200, 255, 0.12), transparent 25%),
    radial-gradient(circle at 85% 10%, rgba(220, 201, 138, 0.1), transparent 22%),
    linear-gradient(180deg, rgba(7, 12, 27, 0.58), rgba(7, 12, 27, 0.2));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.summary-card__row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.summary-card__label {
  color: rgba(156, 200, 255, 0.86);
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.summary-card strong {
  font-family: var(--title-font);
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 600;
  line-height: 1;
}

.summary-card__bar,
.reader__progressLine,
.chapter-card__bar {
  height: 2px;
  border-radius: 999px;
  background: rgba(156, 200, 255, 0.14);
  overflow: hidden;
}

.summary-card__bar span,
.reader__progressLine span,
.chapter-card__bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(156, 200, 255, 0.14), rgba(220, 201, 138, 0.82));
  box-shadow: 0 0 16px rgba(220, 201, 138, 0.45);
  transition: width 420ms ease;
}

.summary-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.98rem;
}

.chapter-list {
  width: min(100%, 920px);
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.chapter-card {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 16px 18px 15px;
  border-radius: 22px;
  border: 1px solid rgba(156, 200, 255, 0.14);
  background:
    radial-gradient(circle at 10% 0%, rgba(156, 200, 255, 0.06), transparent 35%),
    linear-gradient(180deg, rgba(7, 12, 27, 0.42), rgba(7, 12, 27, 0.16));
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
  touch-action: pan-y;
}

.chapter-card:hover,
.chapter-card:focus-visible {
  transform: translateY(-1px);
  outline: none;
  border-color: rgba(220, 201, 138, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
}

.chapter-card[data-state="current"] {
  border-color: rgba(156, 200, 255, 0.22);
}

.chapter-card[data-state="done"] {
  border-color: rgba(220, 201, 138, 0.24);
}

.chapter-card__top,
.chapter-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chapter-card__kicker {
  color: rgba(156, 200, 255, 0.82);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.chapter-card__percent {
  font-family: var(--title-font);
  font-size: 1.05rem;
  font-weight: 600;
}

.chapter-card h3 {
  font-size: clamp(1.28rem, 2.8vw, 1.9rem);
  line-height: 1.02;
  text-wrap: balance;
}

.chapter-card__subtitle {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.96rem;
}

.chapter-card__status {
  color: var(--text);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.chapter-card__bar {
  flex: 1;
}

.chapter-card__info {
  color: var(--muted);
  font-size: 0.82rem;
}

.home__footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
}

.reader {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 22px;
  position: fixed;
  inset: 0;
  z-index: 3;
  opacity: 0;
  transform: scale(0.985);
  pointer-events: none;
  transition:
    opacity 800ms ease,
    transform 900ms ease;
}

.reader.is-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

body.is-reading .reader {
  display: grid;
}

body:not(.is-reading) .reader[hidden] {
  display: none !important;
}

.reader__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 34%, rgba(156, 200, 255, 0.08), transparent 20%),
    radial-gradient(circle at 50% 44%, rgba(220, 201, 138, 0.05), transparent 18%),
    linear-gradient(180deg, rgba(5, 8, 22, 0.1), rgba(5, 8, 22, 0.82));
  opacity: 0;
  transition: opacity 800ms ease;
  pointer-events: none;
}

.reader.is-visible .reader__backdrop {
  opacity: 1;
}

.reader__header {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
}

.reader__meta {
  justify-self: center;
  text-align: center;
}

.reader__percent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(156, 200, 255, 0.18);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-family: var(--title-font);
  font-size: 1.2rem;
}

.reader__content {
  position: relative;
  z-index: 1;
  width: min(100%, 880px);
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid rgba(156, 200, 255, 0.12);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(7, 12, 27, 0.38), rgba(7, 12, 27, 0.18));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.reader__progress {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.reader__progressLine {
  flex: 1;
}

.reader__body {
  min-height: min(50vh, 620px);
  padding: clamp(8px, 2vw, 16px) 0;
  width: min(100%, 700px);
  justify-self: start;
  display: grid;
  align-content: start;
  gap: 20px;
  font-size: clamp(1.18rem, 2vw, 1.35rem);
  line-height: 1.8;
  letter-spacing: 0.01em;
}

.paragraph {
  margin: 0;
  color: rgba(244, 243, 238, 0.88);
  text-wrap: pretty;
}

.paragraph.is-typing::after {
  content: " ";
  display: inline-block;
  width: 0.55ch;
  height: 1em;
  margin-left: 2px;
  border-right: 2px solid rgba(244, 243, 238, 0.75);
  animation: blink 1s steps(1) infinite;
  vertical-align: -0.1em;
}

.reader__nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.ghost-button,
.action-button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  letter-spacing: 0.01em;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(156, 200, 255, 0.18);
  backdrop-filter: blur(10px);
}

.action-button {
  color: var(--text);
  background: rgba(156, 200, 255, 0.12);
  border: 1px solid rgba(156, 200, 255, 0.2);
}

.action-button--primary {
  background: linear-gradient(135deg, rgba(156, 200, 255, 0.22), rgba(220, 201, 138, 0.14));
  border-color: rgba(220, 201, 138, 0.34);
  box-shadow: 0 0 0 1px rgba(220, 201, 138, 0.08) inset;
}

.ghost-button:hover,
.ghost-button:focus-visible,
.action-button:hover,
.action-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.22);
}

.ghost-button:disabled,
.action-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}


@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden auto;
  }

  body.is-reading {
    overflow: hidden;
  }

  .view {
    padding:
      calc(env(safe-area-inset-top) + 28px)
      16px
      calc(env(safe-area-inset-bottom) + 18px);
  }

  .home {
    gap: 22px;
  }

  .summary-card {
    padding: 20px 18px;
  }

  .chapter-card {
    padding: 16px 16px 15px;
  }

  .chapter-card__top,
  .chapter-card__meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-card__row {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-card strong {
    font-size: clamp(2.3rem, 11vw, 3rem);
  }

  h1 {
    font-size: clamp(2.5rem, 14vw, 4.2rem);
  }

  .subtitle {
    margin-top: 12px;
    font-size: 0.98rem;
  }

  .chapter-list {
    gap: 10px;
  }

  .home__footer {
    flex-direction: column;
    align-items: stretch;
  }

  .reader__header {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .reader__meta {
    order: -1;
  }

  .reader__body {
    width: 100%;
    min-height: 42vh;
    font-size: 1.08rem;
  }
}

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