/* ==========================================================================
   Nightjar — design tokens, reset and shared components
   ========================================================================== */

:root {
  /* Surfaces */
  --paper: #f5f0e6;
  --paper-2: #ebe3d3;
  --card: #fbf8f2;
  --line: #dcd2bf;
  --line-strong: #c4b8a1;

  /* Ink */
  --ink: #1a1822;
  --ink-2: #47424f;
  --ink-3: #625d6c;

  /* Night bands */
  --night: #16141d;
  --night-2: #221f2b;
  --night-3: #2e2a39;
  --night-fg: #f1eadc;
  --night-muted: #b2abbd;

  /* Accents */
  --ember: #b8401b;
  --ember-hover: #9c3412;
  --ember-bright: #f28a52;
  --moss: #2f5d50;
  --gold: #b7862b;

  /* Status */
  --ongoing: #2f5d50;
  --completed: #3a4fa0;
  --hiatus: #8a5a1f;

  /* Type */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: clamp(1.35rem, 1.1rem + 0.9vw, 1.65rem);
  --fs-2xl: clamp(1.7rem, 1.2rem + 1.8vw, 2.4rem);
  --fs-3xl: clamp(2.3rem, 1.4rem + 3.6vw, 4.2rem);

  /* Space (4px grid) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;
  --s9: 96px;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 18px;
  --shadow-1: 0 1px 2px rgba(26, 24, 34, 0.06), 0 2px 8px rgba(26, 24, 34, 0.05);
  --shadow-2: 0 2px 6px rgba(26, 24, 34, 0.08), 0 14px 34px rgba(26, 24, 34, 0.12);
  --shadow-cover: 0 1px 1px rgba(0, 0, 0, 0.12), 0 6px 16px -4px rgba(26, 18, 30, 0.35);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --wrap: 1240px;
  --head-h: 64px;
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--head-h) + 16px);
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img,
svg {
  display: block;
  max-width: 100%;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 72, "SOFT" 30;
}
p {
  margin: 0;
}
a {
  color: inherit;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
ul,
ol {
  margin: 0;
  padding: 0;
}
:focus-visible {
  outline: 2.5px solid var(--ember);
  outline-offset: 2px;
  border-radius: 4px;
}
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.skip-link:focus {
  top: 12px;
}
[hidden] {
  display: none !important;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px);
}

.ico {
  width: 20px;
  height: 20px;
  flex: none;
}
.ico--xs {
  width: 13px;
  height: 13px;
  display: inline-block;
  vertical-align: -1px;
  margin-right: 2px;
}
.ico--sm {
  width: 16px;
  height: 16px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: var(--ember);
  color: #fff;
}
.btn--primary:hover {
  background: var(--ember-hover);
}
.btn--ink {
  background: var(--ink);
  color: var(--paper);
}
.btn--ink:hover {
  background: #312d3c;
}
.btn--ghost {
  background: transparent;
  border-color: var(--line-strong);
}
.btn--ghost:hover {
  background: var(--paper-2);
}
.btn--light {
  background: var(--night-fg);
  color: var(--night);
}
.btn--light:hover {
  background: #fff;
}
.btn--outline-light {
  border-color: rgba(241, 234, 220, 0.35);
  color: var(--night-fg);
  background: transparent;
}
.btn--outline-light:hover {
  background: rgba(241, 234, 220, 0.1);
}
.btn--sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: var(--fs-xs);
}
.btn[aria-pressed="true"] .ico {
  fill: currentColor;
}
.btn--danger {
  background: #a3242f;
  color: #fff;
}
.btn--danger:hover {
  background: #861b25;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: rgba(26, 24, 34, 0.07);
}

/* ---------- small elements ---------- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember);
}
.eyebrow::before {
  content: "";
  width: 18px;
  height: 1.5px;
  background: currentColor;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--c, var(--ink-3)) 13%, transparent);
  color: var(--c, var(--ink-2));
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge--ongoing {
  --c: var(--ongoing);
}
.badge--completed {
  --c: var(--completed);
}
.badge--hiatus {
  --c: var(--hiatus);
}
.badge--published {
  --c: #2f6b3a;
}
.badge--draft {
  --c: #5e5868;
}
.badge--scheduled {
  --c: #3a4fa0;
}
.badge--new {
  --c: var(--ember);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--card);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.chip:hover {
  border-color: var(--ink-3);
}
.chip[aria-pressed="true"],
.chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.chip .dot,
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  text-align: center;
  color: var(--ink-2);
  background: var(--card);
}

/* ---------- form controls ---------- */
.field {
  display: grid;
  gap: 6px;
}
.field > label,
.field > .label {
  font-size: var(--fs-sm);
  font-weight: 600;
}
.field .hint {
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.textarea {
  min-height: 120px;
  line-height: 1.6;
  resize: vertical;
}
.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2347424f' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(184, 64, 27, 0.18);
}
.input[aria-invalid="true"] {
  border-color: #a3242f;
}
.error-text {
  font-size: var(--fs-xs);
  color: #a3242f;
}

/* ---------- cover ---------- */
.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 3px 6px 6px 3px;
  overflow: hidden;
  background: var(--paper-2);
  box-shadow: var(--shadow-cover);
}
.cover .cover-art {
  width: 100%;
  height: 100%;
}

/* ---------- story card ---------- */
.scard {
  position: relative;
  min-width: 0;
}
.scard__link {
  display: block;
  text-decoration: none;
}
.scard__link .cover {
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}
.scard__link:hover .cover {
  transform: translateY(-4px) rotate(-0.6deg);
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.12), 0 18px 30px -10px rgba(26, 18, 30, 0.45);
}
.scard__title {
  margin-top: 12px;
  font-size: 1.02rem;
  line-height: 1.22;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.scard__link:hover .scard__title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.scard__author {
  margin-top: 3px;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.scard__meta {
  margin-top: 4px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.scard__prog {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: rgba(0, 0, 0, 0.35);
}
.scard__prog::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--p);
  background: var(--ember-bright);
}

/* ---------- section heads & shelves ---------- */
.sec {
  padding: var(--s8) 0;
}
.sec--tight {
  padding: var(--s7) 0;
}
.sec-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s5);
}
.sec-head h2 {
  font-size: var(--fs-2xl);
}
.sec-head p {
  margin-top: 6px;
  color: var(--ink-2);
  max-width: 56ch;
}
.link-more {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  color: var(--ember);
}
.link-more:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.shelf {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(132px, 16vw, 176px);
  gap: clamp(16px, 2.2vw, 28px);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 6px 4px 18px;
  margin: 0 -4px;
  scrollbar-width: thin;
}
.shelf > * {
  scroll-snap-align: start;
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 32px clamp(16px, 2.4vw, 28px);
}

/* ---------- masthead ---------- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(245, 240, 230, 0.92);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.masthead.is-scrolled {
  border-color: var(--line);
  box-shadow: 0 6px 20px -16px rgba(26, 24, 34, 0.5);
}
.masthead__in {
  display: flex;
  align-items: center;
  gap: var(--s5);
  height: var(--head-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  font-style: italic;
  letter-spacing: -0.02em;
}
.brand__mark {
  width: 32px;
  height: 32px;
}
.mainnav ul {
  display: flex;
  gap: 2px;
  list-style: none;
}
.mainnav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  color: var(--ink-2);
  transition: color 0.2s, background 0.2s;
}
.mainnav a:hover {
  color: var(--ink);
  background: rgba(26, 24, 34, 0.05);
}
.mainnav a[aria-current="page"] {
  color: var(--ink);
  background: var(--paper-2);
  font-weight: 600;
}
.masthead__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.searchbtn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: clamp(200px, 22vw, 280px);
  min-height: 40px;
  padding: 0 8px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-3);
  font-size: var(--fs-sm);
  text-align: left;
}
.searchbtn span {
  flex: 1;
}
.searchbtn:hover {
  border-color: var(--ink-3);
}
.saved-link {
  position: relative;
}
.count-pill {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--ember);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.studio-link {
  font-size: var(--fs-sm);
}

/* Mobile tab bar */
.tabbar {
  display: none;
}

@media (max-width: 860px) {
  .mainnav,
  .studio-link,
  .searchbtn span,
  .searchbtn kbd {
    display: none;
  }
  .searchbtn {
    width: 40px;
    padding: 0;
    justify-content: center;
  }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(251, 248, 242, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
  .tabbar a,
  .tabbar button {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 6px 0;
    border: 0;
    background: none;
    font-size: 0.68rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--ink-3);
  }
  .tabbar [aria-current="page"] {
    color: var(--ember);
  }
  body.has-tabbar {
    padding-bottom: 68px;
  }
}

/* ---------- footer ---------- */
.footer {
  background: var(--night);
  color: var(--night-muted);
  padding: var(--s8) 0 var(--s6);
  font-size: var(--fs-sm);
}
.footer__grid {
  display: grid;
  grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: var(--s6);
}
.footer .brand {
  color: var(--night-fg);
}
.footer__about {
  margin-top: var(--s3);
  max-width: 34ch;
}
.footer h2 {
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--night-fg);
  margin-bottom: var(--s3);
}
.footer ul {
  list-style: none;
  display: grid;
  gap: 8px;
}
.footer a {
  text-decoration: none;
}
.footer a:hover {
  color: var(--night-fg);
  text-decoration: underline;
}
.footer__base {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s7);
  padding-top: var(--s5);
  border-top: 1px solid var(--night-3);
}
@media (max-width: 760px) {
  .footer__grid {
    grid-template-columns: 1fr 1fr;
  }
  .footer__grid > :first-child {
    grid-column: 1 / -1;
  }
}

/* ---------- search dialog ---------- */
dialog {
  color: inherit;
}
dialog::backdrop {
  background: rgba(16, 14, 22, 0.55);
  backdrop-filter: blur(3px);
}
.search-dlg {
  width: min(640px, calc(100vw - 24px));
  max-height: min(620px, calc(100vh - 80px));
  margin: 8vh auto auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.search-dlg[open] {
  display: flex;
  flex-direction: column;
  animation: pop 0.22s var(--ease);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}
.search-dlg__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--line);
}
.search-dlg__bar input {
  flex: 1;
  min-height: 44px;
  border: 0;
  background: none;
  font-size: var(--fs-lg);
}
.search-dlg__bar input:focus {
  outline: none;
}
.search-dlg__body {
  overflow-y: auto;
  padding: 8px;
}
.search-dlg__results {
  list-style: none;
}
.search-dlg__label {
  padding: 8px 12px 4px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.search-dlg__empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-2);
}
.search-hit {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.search-hit:hover,
.search-hit[aria-selected="true"] {
  background: var(--paper-2);
}
.search-hit strong {
  display: block;
  font-weight: 600;
}
.search-hit small {
  color: var(--ink-3);
}
.search-hit__cover {
  width: 36px;
  flex: none;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: var(--shadow-cover);
}
.search-hit--genre .dot {
  width: 12px;
  height: 12px;
  margin: 0 12px;
}
.search-hit--all span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-weight: 600;
  color: var(--ember);
}
.search-dlg__foot {
  display: flex;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
@media (max-width: 600px) {
  .search-dlg {
    margin-top: 12px;
  }
  .search-dlg__foot {
    display: none;
  }
}

/* ---------- modal dialog ---------- */
.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-2);
}
.modal[open] {
  animation: pop 0.22s var(--ease);
}
.modal--wide {
  width: min(820px, calc(100vw - 24px));
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px 24px;
  border-bottom: 1px solid var(--line);
}
.modal__head h2 {
  font-size: var(--fs-xl);
}
.modal__body {
  padding: 20px 24px;
  display: grid;
  gap: 18px;
}
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px 20px;
}

/* ---------- toast ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.3s var(--ease);
  transition: opacity 0.3s, transform 0.3s;
}
.toast .ico {
  color: #8fd19e;
}
.toast.is-out {
  opacity: 0;
  transform: translateY(8px);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@media (max-width: 860px) {
  .has-tabbar .toast-host {
    bottom: 84px;
  }
}

/* ---------- empty state ---------- */
.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: var(--s8) var(--s5);
  text-align: center;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--ink-2);
}
.empty h3 {
  font-size: var(--fs-xl);
  color: var(--ink);
}
.empty .ico {
  width: 36px;
  height: 36px;
  color: var(--ink-3);
}

.noscript {
  padding: 16px;
  background: #fff3cd;
  text-align: center;
}

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