/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --paper:        #faf8f2;
  --paper-shadow: #f0ece0;
  --ink:          #1a1a2e;
  --ink-light:    #4a4a6a;
  --ink-faint:    #9898b8;
  --rule-blue:    #c8d8f0;
  --rule-red:     #e8a0a0;
  --accent:       #8b3a3a;
  --accent-soft:  #c47a7a;

  --line-height:  1.9rem;
  --page-max:     680px;
  --header-h:     64px;

  --font-body:    'Kalam', cursive;
  --font-hand:    'IM Fell English', Georgia, serif;
  --font-title:   'IM Fell English', Georgia, serif;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  background: #ddd8cc;
  background-image:
    radial-gradient(ellipse at 20% 50%, #d4cec2 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, #cec8bc 0%, transparent 60%);
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  line-height: var(--line-height);
}

/* ─── Page Wrap ─────────────────────────────────────────────── */
.page-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  border-bottom: 2px solid var(--rule-blue);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  height: var(--header-h);
}

.header-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-title {
  font-family: var(--font-hand);
  font-size: 1.7rem;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.01em;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.site-title:hover { opacity: 0.75; }

.site-nav {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
}

.site-nav a {
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: var(--ink-light);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.site-nav a:hover,
.site-nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent-soft);
}

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
}
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Notebook Page ─────────────────────────────────────────── */
.notebook-page {
  background: var(--paper);
  max-width: var(--page-max);
  margin: 2.5rem auto;
  border-radius: 2px;
  box-shadow:
    2px 2px 0 #ccc,
    4px 4px 0 #bbb,
    0 8px 32px rgba(0,0,0,0.18);
  position: relative;
  overflow: hidden;

  /* Ruled lines via repeating-linear-gradient */
  background-image:
    /* Red margin line */
    linear-gradient(
      to right,
      transparent 3.2rem,
      var(--rule-red) 3.2rem,
      var(--rule-red) calc(3.2rem + 1px),
      transparent calc(3.2rem + 1px)
    ),
    /* Horizontal rules */
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent calc(var(--line-height) - 1px),
      var(--rule-blue) calc(var(--line-height) - 1px),
      var(--rule-blue) var(--line-height)
    );
  background-attachment: local;
}

/* Spiral binding holes on left */
.notebook-page::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3.2rem;
  height: 100%;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2.8rem,
    rgba(0,0,0,0.06) 2.8rem,
    rgba(0,0,0,0.06) calc(2.8rem + var(--line-height))
  );
  pointer-events: none;
  z-index: 1;
}

/* Punch holes */
.notebook-page::after {
  content: '';
  position: absolute;
  top: 1.9rem;
  left: 1.1rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: #ddd8cc;
  box-shadow:
    0 calc(var(--line-height) * 4) 0 #ddd8cc,
    0 calc(var(--line-height) * 8) 0 #ddd8cc,
    0 calc(var(--line-height) * 12) 0 #ddd8cc,
    0 calc(var(--line-height) * 16) 0 #ddd8cc,
    0 calc(var(--line-height) * 20) 0 #ddd8cc,
    0 calc(var(--line-height) * 24) 0 #ddd8cc;
  pointer-events: none;
  z-index: 2;
}

/* ─── Content area (indented past margin line) ──────────────── */
.page-heading,
.poem-header,
.poem-body,
.poem-index,
.poem-nav,
.empty-state {
  padding-left: 4.5rem;
  padding-right: 2rem;
}

/* ─── List Page ─────────────────────────────────────────────── */
.poem-list-page { padding: 0 1.5rem; }

.page-heading {
  padding-top: calc(var(--line-height) * 1);
  padding-bottom: calc(var(--line-height) * 0.5);
  border-bottom: 1px solid var(--rule-blue);
  margin-bottom: calc(var(--line-height) * 0.5);
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.collection-title {
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--accent);
  font-weight: 400;
  font-style: italic;
}

.collection-meta {
  font-family: var(--font-hand);
  font-size: 0.95rem;
  color: var(--ink-faint);
  margin-left: auto;
}

.poem-index {
  list-style: none;
  padding-top: calc(var(--line-height) * 0.5);
  padding-bottom: calc(var(--line-height) * 2);
}

.poem-entry {
  min-height: var(--line-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.25rem 0;
}

.poem-link {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--ink);
  transition: color 0.15s;
}
.poem-link:hover .poem-entry-title { color: var(--accent); }
.poem-link:hover .poem-entry-date  { color: var(--accent-soft); }

.poem-entry-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-style: italic;
  transition: color 0.15s;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.poem-entry-date {
  font-family: var(--font-hand);
  font-size: 0.85rem;
  color: var(--ink-faint);
  flex-shrink: 0;
  transition: color 0.15s;
}

/* ─── Tags ──────────────────────────────────────────────────── */
.poem-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
  padding-left: 0;
}

.tag {
  font-family: var(--font-hand);
  font-size: 0.8rem;
  color: var(--accent-soft);
  background: rgba(139, 58, 58, 0.07);
  border: 1px solid var(--rule-red);
  border-radius: 2px;
  padding: 0 0.45rem;
  line-height: 1.6;
}

/* ─── Single Poem ───────────────────────────────────────────── */
.poem-single-page { padding: 0 1.5rem; }

.poem-header {
  padding-top: calc(var(--line-height) * 1.5);
  padding-bottom: calc(var(--line-height) * 0.5);
}

.poem-title {
  font-family: var(--font-title);
  font-size: 2rem;
  font-weight: 400;
  font-style: italic;
  color: var(--accent);
  line-height: 1.3;
  margin-bottom: 0.4rem;
}

.poem-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.poem-meta time {
  font-family: var(--font-hand);
  font-size: 0.9rem;
  color: var(--ink-faint);
}

/* ─── Poem Body ─────────────────────────────────────────────── */
.poem-body {
  padding-top: calc(var(--line-height) * 0.5);
  padding-bottom: calc(var(--line-height) * 1);
}

/* Paragraphs in poem body = stanzas */
.poem-body p {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: var(--line-height);
  color: var(--ink);
  margin-bottom: var(--line-height);
  white-space: pre-wrap; /* preserve line breaks within stanzas */
}

/* If poem is written in <pre> blocks */
.poem-body pre {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: var(--line-height);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: var(--line-height);
  background: none;
  border: none;
  padding: 0;
}

.poem-body em  { font-style: italic; }
.poem-body strong { font-weight: 500; color: var(--accent); }

/* ─── Poem Nav ──────────────────────────────────────────────── */
.poem-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: calc(var(--line-height) * 1);
  padding-bottom: calc(var(--line-height) * 1.5);
  border-top: 1px solid var(--rule-blue);
  margin-top: calc(var(--line-height) * 0.5);
}

.nav-prev, .nav-next {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  max-width: 45%;
}
.nav-next { text-align: right; margin-left: auto; }

.nav-label {
  font-family: var(--font-hand);
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.nav-title {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-light);
  transition: color 0.2s;
}
.nav-prev:hover .nav-title,
.nav-next:hover .nav-title { color: var(--accent); }

/* ─── Empty State ───────────────────────────────────────────── */
.empty-state {
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: var(--ink-faint);
  padding-top: calc(var(--line-height) * 2);
  padding-bottom: calc(var(--line-height) * 2);
  font-style: italic;
}

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
  margin-top: auto;
  padding: 1.5rem;
  text-align: center;
}

.footer-inner {
  font-family: var(--font-hand);
  font-size: 0.9rem;
  color: var(--ink-faint);
}

/* ─── Main Content ──────────────────────────────────────────── */
.main-content { flex: 1; }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root {
    --line-height: 1.75rem;
  }

  html { font-size: 16px; }

  .notebook-page {
    margin: 1rem auto;
    border-radius: 0;
    box-shadow: 0 4px 24px rgba(0,0,0,0.14);
  }

  .poem-list-page,
  .poem-single-page { padding: 0; }

  .site-nav {
    display: none;
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    background: var(--paper);
    flex-direction: column;
    gap: 0;
    border-bottom: 2px solid var(--rule-blue);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 0.5rem 0;
  }

  .site-nav.open { display: flex; }

  .site-nav a {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--rule-blue);
    border-left: none;
    font-size: 1.2rem;
  }

  .menu-toggle { display: flex; }

  .site-header { position: sticky; }

  /* Tighten left margin on mobile */
  :root { --rule-red-offset: 2.4rem; }

  .notebook-page {
    background-image:
      linear-gradient(
        to right,
        transparent 2.4rem,
        var(--rule-red) 2.4rem,
        var(--rule-red) calc(2.4rem + 1px),
        transparent calc(2.4rem + 1px)
      ),
      repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(var(--line-height) - 1px),
        var(--rule-blue) calc(var(--line-height) - 1px),
        var(--rule-blue) var(--line-height)
      );
  }

  .page-heading,
  .poem-header,
  .poem-body,
  .poem-index,
  .poem-nav,
  .empty-state {
    padding-left: 3.5rem;
    padding-right: 1.2rem;
  }

  .poem-title { font-size: 1.5rem; }

  .poem-entry-title { white-space: normal; }

  .poem-nav { flex-direction: column; gap: 0.75rem; }
  .nav-next { text-align: left; margin-left: 0; }
}

@media (max-width: 400px) {
  html { font-size: 15px; }

  .page-heading,
  .poem-header,
  .poem-body,
  .poem-index,
  .poem-nav,
  .empty-state {
    padding-left: 3rem;
    padding-right: 1rem;
  }
}

/* ─── Print ─────────────────────────────────────────────────── */
@media print {
  .site-header, .site-footer, .poem-nav { display: none; }
  .notebook-page { box-shadow: none; margin: 0; }
  body { background: white; }
}
