:root {
  color-scheme: light;
  --ink: #222426;
  --muted: #6f746f;
  --paper: #f3f3ed;
  --paper-deep: #dfddd2;
  --line: #222426;
  --accent: #d7a640;
  --blue: #5b8fdc;
  --green: #51705d;
  --shadow: rgba(59, 70, 78, 0.22);
  --stage: #dfe9f6;
  --radius: 4px;
  --turn-ms: 560ms;
  --grid-blue: rgba(111, 161, 224, 0.34);
  --grid-blue-soft: rgba(111, 161, 224, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, var(--grid-blue) 1px, transparent 1px),
    linear-gradient(var(--grid-blue) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-blue-soft) 1px, transparent 1px),
    linear-gradient(var(--grid-blue-soft) 1px, transparent 1px),
    #f8f8f2;
  background-size:
    24px 24px,
    24px 24px,
    8px 8px,
    8px 8px;
  font-family: "SFMono-Regular", "Roboto Mono", "Cascadia Mono", "Liberation Mono", Menlo, monospace;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(18px, 2vw, 30px);
  padding: 0 clamp(16px, 2.2vw, 32px) clamp(16px, 2.2vw, 32px);
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin: 0 calc(clamp(16px, 2.2vw, 32px) * -1);
  padding: 22px clamp(16px, 9vw, 178px) 20px;
  border-bottom: 1.5px dashed rgba(91, 143, 220, 0.42);
  background: rgba(255, 255, 251, 0.88);
  backdrop-filter: blur(8px);
}

.brand-lockup {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: start;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: block;
  margin-top: 2px;
  background:
    linear-gradient(90deg, transparent 44%, var(--blue) 44% 58%, transparent 58%),
    linear-gradient(transparent 44%, var(--blue) 44% 58%, transparent 58%),
    #dce9fb;
  border: 1.5px solid var(--blue);
}

.brand-lockup h1 {
  grid-column: 2;
}

.brand-lockup .eyebrow {
  grid-column: 2;
}

.paper-links {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2vw, 28px);
  margin-left: auto;
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: none;
}

.paper-links a {
  color: var(--ink);
  text-decoration: none;
}

.paper-links a:hover,
.paper-links a:focus-visible {
  color: var(--blue);
  outline: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.45rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: none;
}

.ticker {
  min-width: min(100%, 320px);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 3px;
  padding: 10px 12px;
  background: rgba(251, 245, 232, 0.72);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.reader {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 20px;
  min-height: 0;
}

.compose-card {
  width: min(1120px, 100%);
  margin: 0 auto;
  border: 1.5px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(90deg, rgba(91, 143, 220, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(91, 143, 220, 0.12) 1px, transparent 1px),
    rgba(255, 255, 251, 0.88);
  background-size: 18px 18px;
  box-shadow: 8px 8px 0 rgba(91, 143, 220, 0.14);
}

.composer {
  display: grid;
  gap: 12px;
  padding: clamp(14px, 2vw, 20px);
}

.composer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.composer label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.composer input,
.composer select,
.composer textarea,
.filter-select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
}

.composer input,
.composer select,
.filter-select {
  min-height: 40px;
  padding: 0 12px;
}

.composer textarea {
  min-height: 84px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.feed-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.composer input:focus,
.composer select:focus,
.composer textarea:focus,
.filter-select:focus {
  outline: 2px solid rgba(91, 143, 220, 0.34);
  outline-offset: 2px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#char-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.book-stage {
  min-height: min(760px, calc(100vh - 168px));
  display: grid;
  grid-template-columns: auto minmax(0, 1120px) auto;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vw, 28px);
  perspective: 1400px;
}

.book {
  position: relative;
  width: min(1048px, 100%);
  aspect-ratio: 1.64;
  min-height: 430px;
  transform-style: preserve-3d;
  box-shadow: 18px 20px 0 rgba(91, 143, 220, 0.16), 0 22px 34px var(--shadow);
  contain: layout paint;
  touch-action: pan-y;
}

.book.settling-next .page-right,
.book.settling-prev .page-left,
.book.settling-mobile .page-right {
  animation: paperSettle 520ms cubic-bezier(0.22, 1, 0.36, 1);
}

.book::before {
  content: "S";
  position: absolute;
  inset: -3% 48% -4% -4%;
  z-index: 3;
  color: rgba(34, 36, 38, 0.2);
  font-family: "Times New Roman", serif;
  font-size: clamp(24rem, 44vw, 39rem);
  line-height: 0.86;
  font-weight: 400;
  pointer-events: none;
  -webkit-text-stroke: 1.2px rgba(34, 36, 38, 0.38);
  color: transparent;
}

.book::after {
  content: "303, 126, cs\a 420, 136, cs\a 512, 448, cs\a 430, 692, cs\a 605, 710, px";
  white-space: pre;
  position: absolute;
  left: 17%;
  top: 6%;
  z-index: 3;
  color: rgba(34, 36, 38, 0.2);
  font-size: clamp(0.58rem, 1vw, 0.82rem);
  line-height: 1.14;
  pointer-events: none;
}

.spec-panel {
  position: absolute;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 18px;
  min-width: 154px;
  border: 1.5px solid var(--blue);
  background: rgba(243, 243, 237, 0.84);
  color: #4c4f52;
  padding: 10px 12px;
  font-size: 0.74rem;
  line-height: 1.25;
  box-shadow: 4px 4px 0 rgba(91, 143, 220, 0.28);
  pointer-events: none;
}

.spec-panel span {
  color: #61676a;
}

.spec-panel b {
  color: var(--blue);
}

.panel-one {
  right: 3%;
  top: 7%;
}

.panel-two {
  right: 13%;
  bottom: 11%;
}

.sheet,
.page,
.flip-page,
.flip-face {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.9), transparent 22%),
    linear-gradient(rgba(34, 36, 38, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 100% 9px, auto;
  border: 1.5px solid var(--line);
}

.sheet {
  z-index: 1;
  pointer-events: none;
}

.sheet-left,
.page-left {
  left: 0;
  border-radius: var(--radius) 0 0 var(--radius);
}

.sheet-right,
.page-right {
  right: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.sheet-left {
  transform: translate(-8px, 8px);
  background:
    linear-gradient(rgba(91, 143, 220, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.18) 1px, transparent 1px),
    var(--paper-deep);
  background-size: 18px 18px;
}

.sheet-right {
  transform-origin: left center;
  transform: translate(8px, 8px);
  background:
    linear-gradient(90deg, rgba(91, 143, 220, 0.24), transparent 32px),
    linear-gradient(rgba(91, 143, 220, 0.15) 1px, transparent 1px),
    var(--paper-deep);
  background-size: auto, 18px 18px, auto;
}

.page {
  z-index: 2;
  overflow: hidden;
}

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

.book.is-turning .spec-panel,
.book.is-turning::before,
.book.is-turning::after {
  opacity: 0.32;
}

.page-left {
  background:
    linear-gradient(90deg, transparent calc(100% - 28px), rgba(91, 143, 220, 0.13)),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.page-right {
  background:
    linear-gradient(90deg, rgba(91, 143, 220, 0.14), transparent 30px),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.page::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1.5px solid rgba(91, 143, 220, 0.42);
  pointer-events: none;
}

.page::after {
  content: "";
  position: absolute;
  width: 58%;
  aspect-ratio: 1;
  right: 7%;
  top: 12%;
  border: 1.5px solid rgba(34, 36, 38, 0.42);
  border-radius: 50%;
  opacity: 0.42;
  pointer-events: none;
}

.flip-page {
  z-index: 4;
  display: none;
  width: 50%;
  transform-style: preserve-3d;
  pointer-events: none;
  will-change: transform;
  transform: translateZ(0);
  box-shadow: 0 18px 34px rgba(59, 70, 78, 0.18);
  overflow: visible;
}

.flip-page::before,
.flip-page::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
}

.flip-page::before {
  background:
    linear-gradient(
      90deg,
      rgba(34, 36, 38, 0.28),
      rgba(34, 36, 38, 0.08) 9%,
      transparent 24%,
      rgba(255, 255, 255, 0.34) 52%,
      transparent 78%
    );
  mix-blend-mode: multiply;
}

.flip-page::after {
  left: auto;
  width: 36px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.72), rgba(91, 143, 220, 0.16), transparent);
}

.book.is-turning .flip-page {
  display: block;
}

.book.is-turning .flip-page::before {
  animation: foldShade 780ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

.book.is-turning .flip-page::after {
  animation: foldHighlight 780ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

.book.turning-next .flip-page {
  right: 0;
  transform-origin: left center;
}

.book.turning-prev .flip-page {
  left: 0;
  transform-origin: right center;
}

.book.turning-prev .flip-page::before {
  transform: scaleX(-1);
}

.book.turning-prev .flip-page::after {
  left: 0;
  right: auto;
  transform: scaleX(-1);
}

.flip-face {
  inset: 0;
  width: 100%;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  contain: paint;
  transform: translateZ(0);
  box-shadow: inset 0 0 0 1px rgba(91, 143, 220, 0.18);
}

.flip-face:empty {
  display: none;
}

.flip-front {
  background:
    linear-gradient(90deg, rgba(91, 143, 220, 0.16), transparent 34px),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.flip-back {
  background:
    linear-gradient(90deg, transparent calc(100% - 34px), rgba(91, 143, 220, 0.16)),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
  transform: rotateY(180deg);
}

.book.turning-prev .flip-front {
  background:
    linear-gradient(90deg, transparent calc(100% - 34px), rgba(91, 143, 220, 0.16)),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.book.turning-prev .flip-back {
  background:
    linear-gradient(90deg, rgba(91, 143, 220, 0.16), transparent 34px),
    linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.flip-face::before {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(45, 40, 33, 0.18);
  pointer-events: none;
}

.page-shadow {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.12), transparent 34%);
  opacity: 0.28;
}

.page-inner {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: clamp(12px, 1.6vw, 20px);
  padding: clamp(24px, 4vw, 52px);
  position: relative;
  z-index: 1;
}

.page-header,
.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: clamp(0.72rem, 1.2vw, 0.86rem);
  text-transform: uppercase;
}

.section-label,
.page-number {
  white-space: nowrap;
}

.story-title {
  display: block;
  max-width: 16ch;
  margin: 0;
  color: var(--blue);
  font-size: clamp(1.6rem, 3.5vw, 3.9rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-decoration: none;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.story-title:hover,
.story-title:focus-visible {
  color: var(--accent);
  outline: none;
}

.story-meta {
  margin: 0;
  color: var(--accent);
  font-size: clamp(0.82rem, 1.3vw, 1rem);
  font-weight: 800;
  text-transform: uppercase;
}

.story-summary {
  max-width: 34rem;
  margin: 0;
  align-self: end;
  color: #34302a;
  font-family: "SFMono-Regular", "Roboto Mono", "Cascadia Mono", "Liberation Mono", Menlo, monospace;
  font-weight: 400;
  font-size: clamp(1rem, 1.55vw, 1.28rem);
  line-height: 1.48;
}

@keyframes paperSettle {
  0% {
    opacity: 0.68;
    transform: translate3d(2.4%, 0.8%, 0) scale(0.985);
  }
  58% {
    opacity: 1;
    transform: translate3d(-0.4%, -0.15%, 0) scale(1.002);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes foldShade {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  18% {
    opacity: 0.52;
  }
  54% {
    opacity: 0.72;
    transform: translateX(-8%);
  }
  82% {
    opacity: 0.38;
  }
  100% {
    opacity: 0;
    transform: translateX(-16%);
  }
}

@keyframes foldHighlight {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  24% {
    opacity: 0.65;
  }
  58% {
    opacity: 0.9;
    transform: translateX(-220px);
  }
  100% {
    opacity: 0;
    transform: translateX(-420px);
  }
}

.post-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.post-action {
  border: 1.5px solid rgba(34, 36, 38, 0.56);
  border-radius: 3px;
  color: var(--green);
  background: rgba(243, 243, 237, 0.78);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 6px 8px;
}

.post-action:hover,
.post-action:focus-visible,
.post-action.active {
  color: var(--paper);
  background: var(--green);
  outline: none;
}

.source-host {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-button,
.control-button,
.feed-option {
  border: 1.5px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  transition:
    transform 160ms cubic-bezier(0.22, 1, 0.36, 1),
    background 160ms ease;
}

.nav-button {
  width: clamp(44px, 5vw, 62px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: clamp(2rem, 4vw, 3rem);
}

.control-button {
  min-height: 40px;
  padding: 0 16px;
  font-weight: 800;
  text-transform: uppercase;
}

.feed-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.feed-option {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
  text-transform: uppercase;
}

.feed-option.active {
  color: var(--paper);
  background: var(--line);
}

.nav-button:hover,
.control-button:hover,
.feed-option:hover {
  transform: translateY(-1px);
  background: #fffaf0;
}

.feed-option.active:hover {
  background: var(--line);
}

.nav-button:disabled,
.feed-option:disabled,
.control-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(130px, 170px) minmax(130px, 170px) minmax(140px, 1fr) auto;
  gap: 14px;
  align-items: center;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.progress-wrap {
  height: 12px;
  border: 1.5px solid var(--line);
  background: var(--paper);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--blue);
  transition: width 260ms ease;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

@media (max-width: 760px) {
  .app-shell {
    gap: 14px;
    padding-top: 0;
  }

  .masthead,
  .composer-grid,
  .ticker,
  .controls {
    grid-template-columns: 1fr;
  }

  .masthead {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    margin: 0 -16px;
    padding: 16px;
  }

  .brand-lockup {
    grid-template-columns: auto 1fr;
  }

  .paper-links {
    justify-content: space-between;
    margin-left: 0;
    font-size: 0.78rem;
  }

  .book-stage {
    min-height: auto;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .book {
    grid-column: 1 / -1;
    aspect-ratio: 0.72;
    min-height: min(620px, 64vh);
    order: -1;
  }

  .book::before {
    inset: 1% 6% auto 10%;
    font-size: clamp(18rem, 86vw, 23rem);
    line-height: 0.7;
  }

  .book::after,
  .spec-panel {
    display: none;
  }

  .sheet,
  .page,
  .flip-page,
  .flip-face {
    width: 100%;
  }

  .sheet-left,
  .page-left {
    display: none;
  }

  .sheet-right,
  .page-right,
  .book.turning-next .flip-page,
  .book.turning-prev .flip-page {
    left: 0;
    right: auto;
    border-radius: var(--radius);
  }

  .page-right {
    background:
      linear-gradient(rgba(91, 143, 220, 0.16) 1px, transparent 1px),
      linear-gradient(90deg, rgba(91, 143, 220, 0.16) 1px, transparent 1px),
      var(--paper);
    background-size: 22px 22px;
  }

  .page-inner {
    gap: 14px;
    padding: 26px 22px 24px;
  }

  .story-title {
    max-width: 15ch;
    font-size: clamp(1.65rem, 8.6vw, 3rem);
  }

  .story-summary {
    align-self: start;
    font-size: 1rem;
    line-height: 1.45;
  }

  .prev {
    justify-self: start;
  }

  .next {
    justify-self: end;
  }

  .hint {
    text-align: center;
  }
}

@media (max-width: 440px) {
  .app-shell {
    padding: 12px;
  }

  .ticker,
  .controls {
    gap: 10px;
  }

  .book {
    min-height: min(560px, 62vh);
  }

  .page-header,
  .page-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .story-meta {
    font-size: 0.76rem;
  }

  .story-summary {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
  }
}

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