:root {
  /* Notify light dark theme */
  color-scheme: light dark;

  /* ---------- Raw palette ---------- */
  --color-lobster:        #db5461; /* Lobster Pink  */
  --color-lobster-deep:   #c0424f; /* deepened so link text clears WCAG AA on paper */
  --color-lobster-deeper: #a5333f; /* link hover */
  --color-dim-grey:       #686963; /* Dim Grey      */
  --color-teal:           #8aa29e; /* Muted Teal    */
  --color-teal-deep:      #6f8b86; /* Teal that reads on the light ground */
  --color-charcoal:       #3d5467; /* Charcoal Blue */
  --color-coarse-wool:    #182027; /* Coarse Wool */
  --color-smoke:          #f1edee; /* White Smoke   */
  --color-rule:           #d4d9d3; /* Teal-Grey hairline */

  /* ---------- Core main roles ---------- */
  --bg:           light-dark(var(--color-smoke), var(--color-coarse-wool));
  --fg:           light-dark(var(--color-charcoal), var(--color-smoke));
  --muted:        var(--color-dim-grey);
  --rule:         light-dark(var(--color-rule), var(--color-charcoal));
  --accent:       var(--color-lobster-deep);
  --accent-hover: var(--color-lobster-deeper);
  --accent-2:     var(--color-teal-deep);
  --code-block:   light-dark(var(--color-charcoal), var(--color-coarse-wool));
  --code-bg:      rgba(192, 66, 79, 0.06);

  /* ---------- Per-element hooks ---------- */
  --link:            var(--accent);
  --link-hover:      var(--accent-hover);
  --brand:           var(--fg);
  --nav-link:        var(--fg);
  --nav-link-hover:  var(--accent);
  --heading:         var(--fg);
  --subtitle:        var(--muted);
  --dropcap:         var(--accent);
  --post-label:      var(--accent);
  --blockquote-bar:  var(--accent-2);
  --tax-chip:        var(--muted);
  --tax-chip-border: var(--rule);
  --tax-chip-hover:  var(--accent);
  --catalog-accent:  var(--accent);
  --selection-bg:    var(--accent-2);
  --selection-fg:    var(--bg);
  --focus-ring:      var(--accent);

  /* ---------- Type ---------- */
  --font-sans: "Rethink Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-serif: "Lora", Georgia, serif;

  --frame-pad: 2.5rem;
}

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

html, body {
  min-height: 100%;
  overflow-x: hidden;
}

html {
  background-color: var(--bg);
  color: var(--fg);
}

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

body {
  font-family: var(--font-serif);
  font-optical-sizing: auto;
  font-style: normal;
  font-size: 16px;
  line-height: 1.6;
  text-align: left;
  /* The frame: a centered column with vertical rules down each edge. */
  margin: 0 auto;
  max-width: 60rem;
  min-height: 100vh;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

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

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2rem 0;
}

/* ---------- Frame bands ---------- */

.site-header {
  font-family: var(--font-sans);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1.5rem var(--frame-pad);
  border-bottom: 1px solid var(--rule);
  font-size: 0.95em;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--brand);
}

.site-brand-icon {
  position: relative;
  display: block;
  width: 1.4em;
  height: 1.4em;
}

.site-brand-icon img {
  display: block;
  width: 1.4em;
  height: 1.4em;
  margin: 0;
}

.site-brand-icon-hover {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.site-brand:hover .site-brand-icon-default {
  opacity: 0;
}

.site-brand:hover .site-brand-icon-hover {
  opacity: 1;
}

.site-nav {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
}

.links a {
  color: var(--nav-link);
  margin-right: 0.75rem;
}

.links a:last-child {
  margin-right: 0;
}

.links a:hover {
  color: var(--nav-link-hover);
}

.has-dropdown {
  position: relative;
}

/* Priority nav: optional categories appear as the header gains width.
   When hidden they stay reachable from the Content index. Gear needs the
   most room (revealed last); Photography appears first. */
.nav-opt {
  display: none;
}

@media (min-width: 38rem) {
  .nav-opt-1 { display: inline; }
}

@media (min-width: 46rem) {
  .nav-opt-2 { display: inline; }
}

@media (min-width: 56rem) {
  .nav-opt-3 { display: inline; }
}

@media (min-width: 66rem) {
  .nav-opt-4 { display: inline; }
}

.dropdown {
  /* Hidden until the parent item is hovered/focused */
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  margin: 0;
  padding: 0.5rem 0;
  min-width: 14rem;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--rule);
}

.has-dropdown:hover .dropdown,
.has-dropdown:focus-within .dropdown {
  display: block;
}

/* On desktop the nav is right-aligned, so anchor menus to their item's right
   edge and open leftward — otherwise the rightmost menus spill past the body
   and get clipped by overflow-x: hidden. On mobile the nav sits at the left,
   where the default left-alignment is correct. */
@media (min-width: 641px) {
  .dropdown {
    left: auto;
    right: 0;
  }
}

.dropdown li {
  margin: 0;
}

.dropdown a {
  display: block;
  margin: 0;
  padding: 0.35rem 1rem;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown a:hover {
  color: var(--nav-link-hover);
  background: var(--rule);
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: none;
}

.js-theme .theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center; /* header aligns to baseline; center the icon box */
  margin-left: 0.25rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--nav-link);
  line-height: 0;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--nav-link-hover);
}

.theme-icon {
  display: none;
  width: 1.15rem;
  height: 1.15rem;
}

/* Reveal only the icon for the active state, and fade it in on change. */
:root[data-theme="system"] .theme-icon-system,
:root[data-theme="light"] .theme-icon-light,
:root[data-theme="dark"] .theme-icon-dark,
:root:not([data-theme]) .theme-icon-system {
  display: block;
  animation: theme-icon-in 0.2s ease;
}

@keyframes theme-icon-in {
  from { opacity: 0; transform: rotate(-25deg) scale(0.85); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  :root[data-theme] .theme-icon {
    animation: none;
  }
}

.content {
  padding: var(--frame-pad);
}

.site-footer {
  font-family: var(--font-sans);
  padding: var(--frame-pad);
  border-top: 1px solid var(--rule);
  font-size: 0.9em;
}

.site-footer .quote {
  font-family: var(--font-serif);
}

.site-footer .muted {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  margin-top: 1.5rem;
}

.footer-nav {
  margin-top: 1.5rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

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

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

/* ---------- Headings ---------- */

h1, h2, h3, h4, h5, h6 {
  color: var(--accent);
  font-family: var(--font-sans);
  letter-spacing: -0.01em;
  line-height: 1.2;
  text-wrap: balance;
}

.heading-anchor {
  color: var(--accent);
  text-decoration: none;
}

h1 {
  /* Editorial masthead scale: confident on wide screens, calm on phones. */
  font-size: clamp(2.1rem, 1.5rem + 2.5vw, 3.15rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: left;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.35em;
  font-weight: 600;
  text-align: left;
  margin-bottom: 1.5rem;
}

.post-body h2,
.post-body h3,
.post-body h4 {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.subtitle {
  font-family: var(--font-sans);
  color: var(--subtitle);
  font-size: 1.05em;
  text-align: left;
  margin-bottom: 2rem;
}

/* ---------- Post banner ---------- */

/* Full-bleed image at the very top of a post. Negative margins cancel the
   .content frame padding so the banner reaches the frame's edge rules and sits
   flush under the site header; its own bottom rule closes it off from the post. */
.post-banner {
  margin: calc(var(--frame-pad) * -1) calc(var(--frame-pad) * -1) var(--frame-pad);
  border-bottom: 1px solid var(--rule);
}

.post-banner img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- Article header ---------- */

.post-head {
  margin-bottom: 3rem;
}

.post-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--post-label);
  margin-bottom: 1rem;
}

.post-head h1 {
  margin-bottom: 0.75rem;
}

.post-head .subtitle {
  margin-bottom: 0;
}

.post-rule {
  margin: 1.5rem 0;
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.5rem;
}

.post-meta .author {
  color: var(--fg);
}

.post-tax {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.tax-chip {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tax-chip);
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--tax-chip-border);
  border-radius: 999px;
}

a.tax-chip:hover {
  border-color: var(--tax-chip-hover);
  color: var(--tax-chip-hover);
}

/* ---------- Body prose ---------- */

p {
  margin-bottom: 1rem;
  hyphens: auto;
  hyphenate-character: '—';
  text-wrap: pretty;
}

.post-body a,
.subtitle a,
.footnotes a {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.post-body a.heading-anchor {
  text-decoration: none;
}

/* Let long unbreakable strings (bare URLs in prose or footnotes) wrap rather
   than run off the edge of a narrow phone column. */
.post-body {
  overflow-wrap: break-word;
}

.post-body > p:first-of-type::first-letter {
  float: left;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 3.6em;
  line-height: 0.72;
  padding: 0.05em 0.08em 0 0;
  margin-top: 0.02em;
  color: var(--dropcap);
}

ul, ol {
  margin-bottom: 1.5rem;
  padding-left: 1.4rem;
}

li {
  margin-bottom: 0.5rem;
}

dl {
  margin-bottom: 2rem;
}

dt {
  margin-top: 1rem;
  font-weight: 600;
}

dd {
  margin-left: 0;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  hyphens: auto;
}

blockquote {
  margin: 1rem 0 1.5rem;
  padding: 0.25rem 1.25rem;
  border-left: 2px solid var(--blockquote-bar);
  color: var(--muted);
}

.quote {
  color: var(--muted);
  display: block;
}

.italic {
  font-style: italic;
}

.muted {
  color: var(--muted);
}

/* ---------- Code ---------- */

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.85em;
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--code-bg);
  white-space: pre-wrap;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

.highlight pre {
  background-color: var(--code-block) !important;
}

/* Read-only plaintext decklist: styled like a <pre>, but a real form control so
   focus is scoped to it — click in, Ctrl+A selects only the list, Ctrl+C copies. */
textarea.decklist-raw {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 0.85em;
  line-height: 1.5;
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--code-bg);
  color: inherit;
  resize: vertical;
  cursor: text;
}

textarea.decklist-raw:focus {
  outline: 2px solid var(--color-charcoal, currentColor);
  outline-offset: 2px;
}

/* ---------- Tables ---------- */

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  font-size: 0.95em;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
}

th {
  font-family: var(--font-sans);
  font-weight: 600;
  border-bottom: 2px solid var(--rule);
}

/* ---------- Images & figures ---------- */

img {
  width: 100%;
  display: block;
  margin: 1.5rem 0;
}

.post-figure {
  margin: 1.5rem 0;
}

.post-figure img {
  margin: 0;
}

.post-figure figcaption {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--muted);
}

.post-figure figcaption::before {
  content: "";
  display: block;
  height: 20px;
  width: 100%;
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin-top: 10px;
  margin-bottom: 8px;
  grid-column: 1 / -1;
}

.figcaption-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.figcaption-grid:not(:has(.figcaption-grid-col + .figcaption-grid-col)) {
  grid-template-columns: 1fr;
}

.figcaption-grid-col + .figcaption-grid-col {
  text-align: right;
}

.figcaption-grid-col-title {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
  color: var(--fg);
  margin-bottom: 0.15rem;
}

/* ---------- Post list (index / list / terms) ---------- */

.post-list {
  font-family: var(--font-sans);
  list-style: none;
  padding-left: 0;
  margin: 0 0 1.5rem;
}

.post-list li {
  color: var(--fg);
  margin: 0;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}

.post-list li:first-child {
  border-top: 1px solid var(--rule);
}

.post-list li a {
  color: var(--fg);
  font-weight: 600;
}

.post-list li a:hover {
  color: var(--accent);
}

.post-list-subtitle {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ---------- Footnotes ---------- */

@counter-style footnote-symbols {
  system: symbolic;
  symbols: "*" "\2020" "\2021" "\A7" "\2016" "\B6";
  suffix: " ";
}

body {
  counter-reset: fn-symbol;
}

.footnotes hr::after {
  margin: 1rem;
  content: "Footnotes";
  color: var(--accent);
}

.footnotes ol {
  list-style: footnote-symbols;
}

.footnotes p {
  margin-left: 0;
}

a.footnote-ref {
  font-size: 0;
}

a.footnote-ref::before {
  counter-increment: fn-symbol;
  content: counter(fn-symbol, symbols(symbolic "*" "\2020" "\2021" "\A7" "\2016" "\B6"));
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.75rem;
  vertical-align: super;
}

/* ---------- MTG card hover preview ---------- */

.mtg-card {
  position: relative;
  border-bottom: 1px dotted var(--muted);
  cursor: help;
  white-space: nowrap;
}

.mtg-card-preview {
  position: absolute;
  bottom: 1.6em;
  left: 0;
  z-index: 50;
  display: none;
  pointer-events: none;
}

html:not(.js-mtg) .mtg-card:hover .mtg-card-preview,
html:not(.js-mtg) .mtg-card:focus .mtg-card-preview {
  display: block;
}

.js-mtg .mtg-card-preview {
  position: fixed;
  top: 0;
  left: 0;
  bottom: auto;
}

.js-mtg .mtg-card-preview.is-visible {
  display: block;
}

.mtg-card-preview img {
  width: 240px;
  max-width: 60vw;
  aspect-ratio: 488 / 680;
  margin: 0;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.5));
}

/* ---------- Content catalog (index of categories) ---------- */

.catalog {
  /* Broadsheet index: hairline gridlines drawn by the 1px gap over --rule. */
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  margin: 2rem 0 0;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.catalog-entry {
  display: block;
  padding: 1.25rem 1.5rem;
  background: var(--bg);
  color: var(--fg);
  transition: background 0.15s ease;
}

.catalog-entry:hover {
  background: var(--code-bg);
}

.catalog-entry:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

.catalog-label {
  display: block;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  color: var(--muted);
}

.catalog-title {
  display: block;
  margin: 0.3rem 0 0.4rem;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.2;
}

.catalog-entry:hover .catalog-title,
.catalog-entry:focus-visible .catalog-title {
  color: var(--catalog-accent);
}

.catalog-go {
  display: inline-block;
  margin-left: 0.4rem;
  color: var(--catalog-accent);
  opacity: 0;
  transform: translateX(-0.25rem);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.catalog-entry:hover .catalog-go,
.catalog-entry:focus-visible .catalog-go {
  opacity: 1;
  transform: translateX(0);
}

.catalog-desc {
  display: block;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--muted);
}

@media (max-width: 40rem) {
  .catalog {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .catalog-entry,
  .catalog-go {
    transition: none;
  }
  .catalog-go {
    transform: none;
  }
}

/* ---------- Post links (side rail + inline fallback) ----------
   A post's `links` list renders twice: as a sticky rail beside the article and
   as an end-of-post block. The frame is only wide enough for the rail past the
   breakpoint below; there the rail shows and the inline block hides, otherwise
   the reverse. Nothing here applies unless the post actually has links. */

.post-layout {
  display: grid;
  /* minmax(0, 1fr) not 1fr: a bare 1fr track's minimum is its content's
     min-content width, so a single unbreakable token (e.g. a long footnote
     URL) blows the column out past the viewport, dragging the full-width
     images with it. minmax(0, …) lets the track shrink to the frame instead. */
  grid-template-columns: minmax(0, 1fr);
}

.post-links-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--post-label);
  margin-bottom: 0.75rem;
}

.post-links-group {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin: 1.25rem 0 0.5rem;
}

.post-links-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.post-links-list li {
  margin: 0;
  padding: 0.55rem 0;
  border-top: 1px solid var(--rule);
}

.post-links-list li:last-child {
  border-bottom: 1px solid var(--rule);
}

.post-links-list a {
  color: var(--fg);
  text-decoration: none;
}

.post-links-list a:hover {
  color: var(--accent);
}

/* End-of-post fallback, shown when the rail can't fit. */
.post-links-inline {
  margin-top: 3rem;
}

/* The rail is hidden until the frame widens (see the min-width rule below). */
.post-aside {
  display: none;
}

@media (min-width: 80rem) {
  body.has-aside {
    max-width: 78rem;
  }

  .has-aside .post-layout {
    grid-template-columns: minmax(0, 1fr) 15rem;
    gap: 0;
  }

  /* A hairline divider between content and the rail, echoing the frame's
     edge rules. It sits on post-main (which stretches to the full column
     height) so the rule spans the whole article, not just the sticky rail. */
  .has-aside .post-main {
    border-right: 1px solid var(--rule);
    padding-right: 3rem;
  }

  .has-aside .post-aside {
    display: block;
    position: sticky;
    top: var(--frame-pad);
    align-self: start;
    padding-left: 3rem;
  }

  .has-aside .post-links-inline {
    display: none;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  body {
    font-size: 15px;
    max-width: 100%;
    border-left: none;
    border-right: none;
  }

  :root {
    --frame-pad: 1.25rem;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .figcaption-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .figcaption-grid-col + .figcaption-grid-col {
    text-align: left;
  }
}
