:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --fg: #111;
  --muted: #555;
  --card: #ffffff;
  --border: rgba(127,127,127,0.25);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --overlay: rgba(0,0,0,0.85);
  --accent: #0f62fe;
}

.theme-dark {
  --bg: #0b0b0d;
  --fg: #e9e9ee;
  --muted: #a7a7b0;
  --card: #17171c;
  --shadow: 0 2px 10px rgba(0,0,0,0.45);
  --overlay: rgba(0,0,0,0.88);
  --accent: #6aa0ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--fg); }

/* Header + nav */
.site-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; max-width: 1200px; margin: 0 auto; padding: 12px 16px; }
.brand { margin-right: auto; font-size: 1.3rem; font-weight: 700; color: var(--fg); text-decoration: none; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.site-nav a { padding: 6px 0; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.site-nav a:hover { color: var(--fg); }
.site-nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }

.theme-toggle { background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; box-shadow: var(--shadow); cursor: pointer; }
.theme-toggle .theme-icon { font-size: 1.1rem; }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-footer { padding: 16px; text-align: center; color: var(--muted); font-size: .9rem; }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* Text pages */
.prose { max-width: 820px; line-height: 1.6; overflow-wrap: anywhere; }
.prose h1 { margin: .3em 0 .6em; font-size: 2rem; line-height: 1.2; }
.prose h2 { margin: 1.6em 0 .5em; font-size: 1.6rem; line-height: 1.25; }
.prose h3 { margin: 1.4em 0 .4em; font-size: 1.2rem; line-height: 1.3; }
.prose a { color: var(--accent); }
.prose img { max-width: 100%; height: auto; }
.prose li { margin: .25em 0; }

.card-back { float: right; width: 214px; margin: 0 0 16px 24px; }
.card-img { display: block; width: 300px; border-radius: 4.75% / 3.4%; box-shadow: var(--shadow); }
.card-pair { display: flex; flex-wrap: wrap; gap: 16px; margin: 24px 0; clear: both; }
.card-pair a { flex: 1 1 240px; max-width: 357px; }
.card-pair .card-img { width: 100%; }
.wide-img { display: block; margin: 16px 0; border-radius: 10px; box-shadow: var(--shadow); }

.prose a.button { display: inline-block; padding: 12px 24px; border-radius: 999px; background: var(--accent); color: var(--bg); font-weight: 600; text-decoration: none; }

/* Release notes: numbered rules */
.rule { padding-left: 40px; }
.rule.example { padding-left: 80px; }
.rule-no { color: #999; }

/* Card gallery */
.gallery-section h2 { margin: 1.4em 0 .6em; font-size: 1.6rem; }
.gallery-section:first-child h2 { margin-top: .3em; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.card-tile { display: block; aspect-ratio: 5 / 7; background: var(--card); border-radius: 4.75% / 3.4%; overflow: hidden; box-shadow: var(--shadow); transition: transform .12s ease; }
.card-tile:hover { transform: translateY(-2px); }
.card-tile img { width: 100%; height: 100%; display: block; object-fit: cover; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; display: none; z-index: 10; }
.lightbox[aria-hidden="false"] { display: grid; place-items: center; }
.lightbox-backdrop { position: absolute; inset: 0; background: var(--overlay); }
/* Clicks outside the image fall through to the backdrop and close the lightbox */
.lightbox-content { position: relative; z-index: 2; display: grid; gap: 10px; justify-items: center; pointer-events: none; }
.lightbox-image-wrap { position: relative; display: grid; place-items: center; pointer-events: auto; touch-action: pan-x pinch-zoom; }
/* Fixed 5:7 box so swapping the thumbnail for the full-size image doesn't resize it */
.lightbox-image-wrap img { height: min(84vh, calc(92vw * 1.4)); aspect-ratio: 5 / 7; border-radius: 4.75% / 3.4%; box-shadow: 0 6px 24px rgba(0,0,0,0.4); background: #111; }
.card-name { color: #e9e9ee; font-weight: 600; }

.lightbox-close, .lightbox-prev, .lightbox-next {
  position: absolute; top: 12px; background: rgba(0,0,0,0.6); color: #fff; border: none; border-radius: 50%; width: 42px; height: 42px; cursor: pointer; z-index: 3;
}
.lightbox-close { right: 12px; font-size: 24px; line-height: 42px; }
.lightbox-prev, .lightbox-next { top: 50%; transform: translateY(-50%); font-size: 26px; }
.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }

/* Spinner while the full-size image loads */
.lb-spinner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.2s;
}
.lb-spinner.active { opacity: 1; }

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@media (max-width: 600px) {
  /* Brand + theme toggle on the first row, nav links on their own row below */
  .site-nav { order: 3; width: 100%; gap: 4px 14px; font-size: .9rem; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .card-back { width: 120px; margin-left: 16px; }
  .rule { padding-left: 16px; }
  .rule.example { padding-left: 32px; }
}

/* Bigger cards on desktop */
@media (min-width: 1024px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
}
