/* ===========================================================
   The Loom — shared styles
   Palette drawn from dye history: indigo ground, undyed linen,
   madder red, weld yellow. Mono = the machine. Serif = the story.
   =========================================================== */

:root {
  color-scheme: light dark;

  --ground:    #EDE7D9;
  --ground-2:  #E4DDCB;
  --ink:       #1A1F33;
  --ink-dim:   #5C6076;
  --ink-faint: #A49E8C;
  --madder:    #A3341F;
  --weld:      #7E600F;
  --cell-off:  #CFC7B2;

  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua",
           Palatino, Charter, Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
          Consolas, monospace;

  --measure: 66rem;
  --pad: clamp(1.25rem, 4vw, 3rem);
}

:root[data-theme="indigo"],
:root[data-theme="auto"] {
  /* placeholder so the attribute selector always exists */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="linen"]) {
    --ground:    #131729;
    --ground-2:  #1B2038;
    --ink:       #E6E0D2;
    --ink-dim:   #93907F;
    --ink-faint: #565B72;
    --madder:    #D4573C;
    --weld:      #D2A63F;
    --cell-off:  #2A3050;
  }
}

:root[data-theme="indigo"] {
  --ground:    #131729;
  --ground-2:  #1B2038;
  --ink:       #E6E0D2;
  --ink-dim:   #93907F;
  --ink-faint: #565B72;
  --madder:    #D4573C;
  --weld:      #D2A63F;
  --cell-off:  #2A3050;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--madder); text-underline-offset: 2px; }
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--madder);
  outline-offset: 3px;
  border-radius: 1px;
}

/* ---------- machine layer: mono, tracked, small ---------- */

.mono {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.wrap {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 var(--pad);
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0 0;
}

.masthead a { text-decoration: none; color: var(--ink-dim); }
.masthead a:hover { color: var(--madder); }

.theme-toggle {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--ink-dim);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--madder); }

/* ---------- the draft glyph (signature element) ----------
   A weaving draft: filled and empty cells, generated from the
   story slug, so every story carries its own pattern.        */

.draft {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  line-height: 0;
  vertical-align: middle;
}

.draft i {
  display: block;
  width: 6px;
  height: 6px;
  background: var(--cell-off);
}

.draft i.set { background: var(--ink-dim); }
.draft i.lit { background: var(--madder); }

.draft--lg i { width: 9px; height: 9px; }
.draft--sm i { width: 4px; height: 4px; }

/* ---------- index ---------- */

.realm-head {
  padding: 3.5rem 0 0.5rem;
}

.realm-head h1 {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0.4rem 0 0.6rem;
}

.realm-head p { margin: 0; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 2rem 0 0;
}

.chip {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: none;
  border: 1px solid var(--cell-off);
  color: var(--ink-dim);
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--madder); color: var(--madder); }
.chip[aria-pressed="true"] {
  border-color: var(--ink);
  color: var(--ground);
  background: var(--ink);
}

.shelf { padding: 2.5rem 0 5rem; margin: 0; }

.entry {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 1.25rem;
  padding: 1.5rem 0;
  text-decoration: none;
  color: inherit;
}

.entry .draft { padding-top: 0.7rem; }
.entry:hover .draft i.set { background: var(--madder); }

.entry h2 {
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 0.35rem;
}
.entry:hover h2 { color: var(--madder); }

.entry .meta { margin: 0 0 0.5rem; }

.entry .blurb {
  margin: 0;
  color: var(--ink-dim);
  font-size: 0.95rem;
  line-height: 1.55;
  max-width: var(--measure);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- reader ---------- */

.progress-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ground);
  padding: 0.85rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.progress-bar .draft { flex: 0 0 auto; }

.story-head { padding: 3.5rem 0 2rem; }

.story-head h1 {
  font-size: clamp(2.2rem, 7vw, 3.5rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0.5rem 0 1rem;
}

.story-head .draft { margin-top: 0.5rem; }

.prose {
  max-width: var(--measure);
  font-size: 1.15rem;
}

.prose p { margin: 0 0 1.35em; }

.prose > p:first-of-type::first-line {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
}

.prose h2 {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 400;
  margin: 3rem 0 1rem;
}

.prose blockquote {
  margin: 1.5em 0;
  padding-left: 1.25em;
  border-left: 2px solid var(--cell-off);
  color: var(--ink-dim);
  font-style: italic;
}

.prose hr {
  border: 0;
  text-align: center;
  margin: 2.5em 0;
}
.prose hr::after {
  content: "· · ·";
  letter-spacing: 0.5em;
  color: var(--ink-faint);
}

/* ---------- addendum ---------- */

.addendum {
  max-width: var(--measure);
  margin: 4rem 0 0;
  padding: 2rem 0 0;
  border-top: 1px solid var(--cell-off);
}

.addendum .prose { font-size: 1rem; color: var(--ink-dim); }

/* ---------- colophon ---------- */

.colophon {
  margin: 4rem 0 6rem;
  padding: 2rem;
  background: var(--ground-2);
}

.colophon h2 {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 400;
  color: var(--weld);
  margin: 0 0 1.25rem;
}

.credit-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
}

.credit-grid dt {
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}
.credit-grid dd { margin: 0; color: var(--ink); }
.credit-grid dd .host { color: var(--weld); }

.credit-raw {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  margin: 0;
  color: var(--ink);
}

/* ---------- states ---------- */

.note {
  padding: 4rem 0;
  max-width: var(--measure);
  color: var(--ink-dim);
}
.note strong { color: var(--ink); font-weight: 400; }
.note code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--madder);
}

@media (max-width: 34rem) {
  body { font-size: 17px; }
  .entry { grid-template-columns: 1fr; gap: 0.5rem; }
  .entry .draft { padding-top: 0; }
  .colophon { padding: 1.5rem; }
  .credit-grid { grid-template-columns: 1fr; gap: 0.15rem 0; }
  .credit-grid dd { margin-bottom: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .progress-bar, .masthead, .filters { display: none; }
  body { background: #fff; color: #000; }
}
