/* Tom Cox - site styles
   Colours and type follow the old Ghost site: cream background, IBM Plex Serif
   headings, Inter body. The red accent is taken from the Curious Events cover. */

:root {
  --cream: #fef3d0;
  --paper: #fff9e6;
  --ink: #1b1813;
  --ink-soft: #423b31;
  --muted: #6b6253;
  --rule: rgba(27, 24, 19, 0.15);
  --accent: #d24a2f;
  --accent-ink: #a8361f;

  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --container: 1200px;
  --gutter: clamp(16px, 4vw, 48px);
  --section-space: clamp(56px, 8vw, 112px);
  --radius: 4px;
  --shadow-book: 0 1px 2px rgba(27, 24, 19, 0.15), 0 14px 30px -10px rgba(27, 24, 19, 0.4);
}

/* ---------- Base ---------- */

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

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

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
}

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

.container {
  width: 100%;
  max-width: calc(var(--container) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  background: var(--ink);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: var(--radius);
  text-decoration: none;
}

.skip-link:focus {
  top: 16px;
}

.eyebrow {
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

/* ---------- Buttons & links ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 48px;
  padding: 0.75rem 1.4rem;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: #fff;
}

.button-outline {
  background: transparent;
  color: var(--ink);
}

.button-outline:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--cream);
}

.button-light {
  background: var(--cream);
  border-color: var(--cream);
  color: var(--ink);
}

.button-light:hover {
  background: #fff;
  border-color: #fff;
  color: var(--ink);
}

.button-small {
  min-height: 40px;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.link-arrow {
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.link-arrow::after {
  content: " \2192";
  display: inline-block;
  transition: transform 0.15s ease;
}

.link-arrow:hover {
  color: var(--accent-ink);
}

.link-arrow:hover::after {
  transform: translateX(3px);
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--cream);
  border-bottom: 1px solid var(--rule);
}

.header-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "nav logo actions";
  align-items: center;
  min-height: 72px;
  gap: 16px;
}

.site-logo {
  grid-area: logo;
  font-family: var(--serif);
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.site-nav {
  grid-area: nav;
}

.site-nav ul {
  display: flex;
  gap: 28px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav a {
  display: inline-block;
  padding: 6px 0;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover {
  color: var(--accent-ink);
}

.site-nav a[aria-current="page"] {
  border-bottom-color: var(--ink);
}

.header-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.nav-toggle .icon-close {
  display: none;
}

.nav-toggle[aria-expanded="true"] .icon-open {
  display: none;
}

.nav-toggle[aria-expanded="true"] .icon-close {
  display: block;
}

@media (max-width: 760px) {
  .header-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "logo actions"
      "nav nav";
    min-height: 64px;
    gap: 0 12px;
  }

  .site-logo {
    font-size: 1.5rem;
  }

  .nav-toggle {
    display: inline-flex;
  }

  /* Without JS the menu stays visible; main.js adds .js and hides it until opened */
  .js .site-nav {
    display: none;
  }

  .js .site-nav.is-open {
    display: block;
  }

  .site-nav ul {
    flex-direction: column;
    gap: 0;
    padding: 4px 0 12px;
  }

  .site-nav a {
    display: block;
    padding: 12px 0;
    border-bottom: 1px solid var(--rule);
    font-size: 1.125rem;
  }

  .site-nav li:last-child a {
    border-bottom: 0;
  }

  .site-nav a[aria-current="page"] {
    border-bottom-color: var(--rule);
    color: var(--accent-ink);
  }
}

/* ---------- Hero: latest book releases ---------- */

.hero {
  border-bottom: 1px solid var(--rule);
}

.hero-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  align-items: center;
  gap: clamp(32px, 6vw, 96px);
  padding-block: clamp(40px, 7vw, 96px);
}

.hero-copy {
  display: grid;
  gap: 20px;
  justify-items: start;
}

.hero-title {
  font-size: clamp(2.25rem, 3.6vw + 1rem, 4.25rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.hero-lede {
  max-width: 34ch;
  font-size: clamp(1.125rem, 0.6vw + 1rem, 1.375rem);
  color: var(--ink-soft);
}

.hero .button-row {
  margin-top: 8px;
}

.hero-note {
  font-size: 0.9375rem;
  color: var(--muted);
}

.hero-cover {
  justify-self: center;
  width: min(100%, 400px);
}

.hero-cover a {
  display: block;
  transform: rotate(1.5deg);
  transition: transform 0.25s ease;
}

.hero-cover a:hover {
  transform: rotate(0deg) translateY(-4px);
}

.hero-cover img {
  width: 100%;
  border-radius: 2px;
  box-shadow: var(--shadow-book);
}

.also-new {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 20px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  width: 100%;
  max-width: 520px;
}

.also-new img {
  width: 72px;
  flex-shrink: 0;
  border-radius: 2px;
  box-shadow: var(--shadow-book);
}

.also-new h2 {
  margin: 4px 0 6px;
  font-size: 1.3125rem;
}

.also-new-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
}

.signposts {
  border-top: 1px solid var(--rule);
}

.signposts ul {
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.signposts li + li {
  border-left: 1px solid var(--rule);
}

.signposts a {
  display: block;
  padding: 16px clamp(14px, 3vw, 32px);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
}

.signposts a:hover {
  color: var(--accent-ink);
}

@media (max-width: 760px) {
  .hero-inner {
    grid-template-columns: 1fr;
  }

  .hero-cover {
    order: -1;
    width: min(62%, 260px);
  }

  .hero-cover a {
    transform: none;
  }
}

/* ---------- Sections ---------- */

.section {
  padding-block: var(--section-space);
}

.section + .section {
  border-top: 1px solid var(--rule);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 32px;
  margin-bottom: clamp(28px, 4vw, 48px);
}

.section-title {
  font-size: clamp(1.875rem, 1.6vw + 1.25rem, 2.75rem);
}

.section-intro {
  margin-top: 8px;
  max-width: 52ch;
  color: var(--ink-soft);
}

.section-footer {
  display: flex;
  justify-content: center;
  margin-top: clamp(32px, 5vw, 56px);
}

/* ---------- Latest posts ---------- */

.posts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(28px, 3vw, 40px) clamp(20px, 2.5vw, 32px);
}

.post-link {
  display: grid;
  align-content: start;
  gap: 14px;
  height: 100%;
  text-decoration: none;
}

.post-media {
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--paper);
  border: 1px solid var(--rule);
}

.post-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.post-link:hover .post-media img {
  transform: scale(1.03);
}

.post-media-empty {
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 2rem;
  color: var(--muted);
}

.post-body {
  display: grid;
  align-content: start;
  gap: 8px;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  font-size: 0.875rem;
  color: var(--muted);
}

.post-title {
  font-size: 1.25rem;
  line-height: 1.25;
  text-wrap: pretty;
}

.post-link:hover .post-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.post-excerpt {
  color: var(--ink-soft);
  font-size: 0.9875rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-more {
  display: none;
  margin-top: 8px;
  font-weight: 600;
}

.post-featured {
  grid-column: 1 / -1;
  padding-bottom: clamp(28px, 3vw, 40px);
  border-bottom: 1px solid var(--rule);
}

.post-featured .post-link {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(20px, 4vw, 56px);
}

.post-featured .post-title {
  font-size: clamp(1.75rem, 1.6vw + 1.1rem, 2.5rem);
  line-height: 1.12;
}

.post-featured .post-excerpt {
  font-size: 1.0625rem;
  -webkit-line-clamp: 4;
}

.post-featured .post-more {
  display: inline-block;
}

.post-skeleton {
  aspect-ratio: 3 / 2;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--paper) 0%, #fdf6dd 50%, var(--paper) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.post-skeleton:first-child {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  height: clamp(220px, 30vw, 380px);
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

.posts-fallback {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 48px 24px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  text-align: center;
}

@media (max-width: 960px) {
  .posts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .posts {
    grid-template-columns: 1fr;
  }

  .post-featured .post-link {
    grid-template-columns: 1fr;
  }
}

/* ---------- Subscribe band ---------- */

.subscribe {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  color: #fff;
  background: #2a2420;
}

.subscribe-bg {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.subscribe::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgba(20, 16, 14, 0.82) 0%, rgba(20, 16, 14, 0.6) 55%, rgba(20, 16, 14, 0.45) 100%);
}

.subscribe-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 480px);
  align-items: center;
  gap: clamp(32px, 5vw, 72px);
  padding-block: var(--section-space);
}

.subscribe-copy {
  display: grid;
  gap: 18px;
  justify-items: start;
}

.subscribe .eyebrow {
  color: #ffd9a8;
}

.subscribe h2 {
  font-size: clamp(2rem, 2.4vw + 1.1rem, 3.25rem);
  line-height: 1.08;
}

.subscribe p {
  max-width: 44ch;
  font-size: 1.125rem;
  color: rgba(255, 255, 255, 0.88);
}

.subscribe .button-row {
  margin-top: 6px;
}

.subscribe .button-outline {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.7);
}

.subscribe .button-outline:hover {
  background: #fff;
  border-color: #fff;
  color: var(--ink);
}

.subscribe-embed {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.5);
}

.subscribe-embed iframe {
  display: block;
  width: 100%;
  height: 320px;
  border: 0;
  background: #fff;
}

@media (max-width: 860px) {
  .subscribe-inner {
    grid-template-columns: 1fr;
  }

  .subscribe::before {
    background: rgba(20, 16, 14, 0.72);
  }
}

/* ---------- Books ---------- */

.book-group + .book-group {
  margin-top: clamp(48px, 6vw, 80px);
}

.book-group-title {
  margin-bottom: 24px;
  font-size: 1.5rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(28px, 3vw, 44px) clamp(16px, 2.5vw, 32px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.book a {
  display: grid;
  gap: 14px;
  text-decoration: none;
}

.book img {
  width: 100%;
  aspect-ratio: 5 / 8;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: var(--shadow-book);
  transition: transform 0.2s ease;
}

.book a:hover img {
  transform: translateY(-4px);
}

.book h3 {
  font-size: 1.125rem;
  line-height: 1.25;
}

.book-cta {
  justify-self: start;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--cream);
}

.book a:hover .book-cta {
  background: var(--accent-ink);
  color: #fff;
}

.book-format {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: -8px;
}

@media (max-width: 860px) {
  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Quotes ---------- */

.quotes {
  background: var(--paper);
}

.quote-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(32px, 4vw, 56px);
}

.quote {
  margin: 0;
  text-align: center;
}

.quote blockquote {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.375rem, 0.8vw + 1.1rem, 1.75rem);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}

.quote blockquote::before {
  content: "\201C";
  display: block;
  font-size: 3.5rem;
  line-height: 0.8;
  color: var(--accent);
}

.quote figcaption {
  margin-top: 16px;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

@media (max-width: 760px) {
  .quote-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Inner pages ---------- */

.page-header {
  padding-block: clamp(48px, 7vw, 96px) clamp(28px, 4vw, 48px);
}

.page-title {
  font-size: clamp(2.5rem, 3.6vw + 1.2rem, 4.5rem);
  letter-spacing: -0.02em;
}

.page-lede {
  margin-top: 16px;
  max-width: 40ch;
  font-size: clamp(1.125rem, 0.6vw + 1rem, 1.375rem);
  color: var(--ink-soft);
}

.page-body {
  padding-bottom: var(--section-space);
}

.prose {
  max-width: 64ch;
  font-size: 1.125rem;
  line-height: 1.7;
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose h2 {
  font-size: 1.5rem;
  margin-top: 1.8em;
}

.prose a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.prose a:hover {
  color: var(--accent-ink);
}

.prose .button-row {
  margin-top: 2em;
}

.about-layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(32px, 6vw, 88px);
  align-items: start;
}

.about-photo {
  margin: 0;
  position: sticky;
  top: 104px;
}

.about-photo img {
  width: 100%;
  border-radius: var(--radius);
}

@media (max-width: 820px) {
  .about-layout {
    grid-template-columns: 1fr;
  }

  .about-photo {
    position: static;
    max-width: 440px;
  }
}

/* ---------- Contact ---------- */

.contact-layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(32px, 6vw, 88px);
  align-items: start;
}

.contact-aside {
  display: grid;
  gap: 28px;
}

.contact-card {
  padding: 24px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
}

.contact-card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.contact-card p {
  color: var(--ink-soft);
}

.contact-card .link-arrow {
  display: inline-block;
  margin-top: 12px;
}

.contact-form {
  display: grid;
  gap: 20px;
}

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

.field label {
  font-weight: 600;
  font-size: 0.9375rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(27, 24, 19, 0.35);
  border-radius: var(--radius);
  background: #fffdf5;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.field textarea {
  min-height: 180px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent-ink);
  outline-offset: 0;
  border-color: var(--accent-ink);
}

.field-hp {
  position: absolute;
  left: -9999px;
}

.form-status {
  min-height: 1.6em;
  font-weight: 500;
}

.form-status[data-state="success"] {
  color: #2f6b34;
}

.form-status[data-state="error"] {
  color: var(--accent-ink);
}

@media (max-width: 820px) {
  .contact-layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- 404 ---------- */

.not-found {
  padding-block: clamp(64px, 10vw, 140px);
}

.not-found .button-row {
  margin-top: 32px;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--rule);
  padding-block: clamp(48px, 6vw, 72px) 32px;
}

.footer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto;
  align-items: start;
  gap: 32px;
}

.footer-brand .site-logo {
  display: inline-block;
  margin-bottom: 8px;
}

.footer-brand p {
  max-width: 36ch;
  color: var(--ink-soft);
}

.footer-nav ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-nav a {
  text-decoration: none;
  font-weight: 500;
}

.footer-nav a:hover {
  color: var(--accent-ink);
}

.footer-bottom {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--muted);
}

@media (max-width: 760px) {
  .footer-inner {
    grid-template-columns: 1fr;
  }
}
