@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("assets/literata.ttf") format("truetype");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Work Sans";
  src: url("assets/work-sans.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f4f0e6;
  --surface: #fbf9f3;
  --ink: #1c1a16;
  --muted: #5b5650;
  --rule: #1c1a16;
  --hair: #cfc8b8;
  --accent: #8e2c1a;
  --accent-ink: #fbf9f3;
  --dark-bg: #1c1a16;
  --dark-ink: #f1ece0;
  --dark-muted: #c9c1b0;
  --display: "DM Serif Display", "Iowan Old Style", Georgia, serif;
  --text: Literata, Charter, Georgia, serif;
  --ui: "Work Sans", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --wrap: min(100% - 40px, 1160px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 18px;
  line-height: 1.6;
  overflow-x: clip;
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.skip-link {
  position: absolute;
  left: 20px;
  top: -100px;
  z-index: 10;
  padding: 12px 20px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--ui);
  font-weight: 600;
}

.skip-link:focus-visible {
  top: 12px;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* Masthead: inverted band */

.masthead {
  background: var(--dark-bg);
  color: var(--dark-ink);
  padding-block: 32px 96px;
  overflow: clip;
}

.masthead > * {
  width: var(--wrap);
  margin-inline: auto;
}

.masthead-rule {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding-block: 12px;
  border-top: 2px solid var(--dark-ink);
  border-bottom: 1px solid var(--dark-ink);
}

.dateline {
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dark-muted);
}

.masthead-title {
  margin-top: 48px;
  font-family: var(--display);
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: -0.03em;
  display: grid;
  gap: 0;
}

.title-the {
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dark-muted);
  margin-bottom: 16px;
}

.title-corner,
.title-ledger {
  font-size: clamp(3.4rem, 17vw, 13rem);
  display: block;
}

.title-ledger {
  font-style: italic;
  padding-left: 0.6em;
  color: var(--dark-ink);
}

.title-corner,
.title-ledger {
  animation: rise 700ms var(--ease) both;
}

.title-ledger {
  animation-delay: 110ms;
}

.masthead-deck {
  margin-top: 40px;
  max-width: 34em;
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  line-height: 1.5;
  color: var(--dark-ink);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Browse */

.browse {
  padding-block: 96px 128px;
}

.browse > * {
  width: var(--wrap);
  margin-inline: auto;
}

.browse-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule);
}

.section-label {
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.browse-count {
  font-family: var(--ui);
  font-size: 13px;
  color: var(--muted);
}

.controls {
  display: grid;
  gap: 16px;
  margin-block: 32px 40px;
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.field input,
.field select {
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  font-family: var(--text);
  font-size: 16px;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}

.field input:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 20px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
  font-family: var(--ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

.toggle:active,
.btn:active,
.open-item:active {
  transform: scale(0.97);
}

.toggle-mark {
  width: 12px;
  height: 12px;
  border: 1.5px solid currentColor;
  flex: none;
}

.toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.toggle[aria-pressed="true"] .toggle-mark {
  background: var(--accent);
  border-color: var(--accent);
}

.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.story {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 24px;
  padding-block: 32px;
  border-bottom: 1px solid var(--hair);
}

.story-num {
  font-family: var(--display);
  font-size: clamp(2.5rem, 6vw, 5rem);
  line-height: 0.9;
  color: var(--accent);
  min-width: 2ch;
}

.story-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.story-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.story-saved {
  color: var(--accent);
}

.story-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.6rem, 3.2vw, 2.4rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
}

.open-item {
  display: inline-block;
  min-height: 44px;
  padding: 6px 0;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: transparent;
  transition: text-decoration-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

.open-item:focus-visible {
  text-decoration-color: var(--accent);
}

.story-summary {
  max-width: 60ch;
  color: var(--muted);
  font-size: 17px;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 16px;
  padding: 48px 0;
  border-top: 1px solid var(--rule);
}

.empty-title {
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.1;
}

.btn {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 20px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
  font-family: var(--ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

/* Detail dialog */

.detail {
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
}

.detail::backdrop {
  background: var(--bg);
}

.detail-sheet {
  width: var(--wrap);
  max-width: 720px;
  margin-inline: auto;
  padding-block: 24px 128px;
}

.detail-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule);
}

.detail-kicker {
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: var(--ink);
  color: var(--bg);
}

.detail-head {
  display: grid;
  gap: 20px;
  padding-block: 48px 40px;
  border-bottom: 1px solid var(--hair);
}

.detail-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.4rem, 6.5vw, 4.25rem);
  line-height: 1.02;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.detail-summary {
  font-size: clamp(1.15rem, 2.2vw, 1.35rem);
  line-height: 1.5;
  color: var(--muted);
}

.detail-meta {
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.save-item[aria-pressed="false"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  justify-self: start;
}

.save-item[aria-pressed="true"] .toggle-mark {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

.detail-body {
  padding-top: 40px;
  max-width: 65ch;
}

.detail-body p {
  font-size: 18px;
  line-height: 1.7;
}

.detail-body p + p {
  margin-top: 1.1em;
}

.detail-body p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.12em 0 0;
  font-family: var(--display);
  font-size: 4.2em;
  line-height: 0.8;
  color: var(--accent);
}

.colophon {
  padding-block: 48px 64px;
  border-top: 2px solid var(--rule);
}

.colophon > p {
  width: var(--wrap);
  margin-inline: auto;
  font-family: var(--ui);
  font-size: 14px;
  color: var(--muted);
}

/* Responsive */

@media (min-width: 720px) {
  .controls {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
    align-items: end;
  }
}

@media (max-width: 719px) {
  .masthead {
    padding-block: 24px 72px;
  }

  .masthead-title {
    margin-top: 40px;
  }

  .browse {
    padding-block: 64px 96px;
  }

  .story {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .story-num {
    font-size: 2.25rem;
  }

  .toggle {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Hover (fine pointers only) */

@media (hover: hover) and (pointer: fine) {
  .toggle:hover {
    background: var(--ink);
    color: var(--bg);
  }

  .toggle[aria-pressed="true"]:hover {
    background: var(--accent);
    border-color: var(--accent);
  }

  .save-item[aria-pressed="false"]:hover {
    background: var(--ink);
    border-color: var(--ink);
  }

  .btn:hover {
    background: var(--ink);
    color: var(--bg);
    transform: translateY(-2px);
  }

  .field input:hover,
  .field select:hover {
    border-color: var(--accent);
  }

  .open-item:hover {
    color: var(--accent);
    text-decoration-color: currentColor;
  }

  .story:hover .story-title {
    color: var(--accent);
  }

  .story-title {
    transition: color 180ms var(--ease);
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-corner,
  .title-ledger {
    animation: none;
  }

  .btn:hover,
  .toggle:active,
  .btn:active,
  .open-item:active {
    transform: none;
  }
}
