/* ── 0. CSS HOUDINI @PROPERTY REGISTRATIONS ────────────────────── */
@property --bg-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #ffffff;
}
@property --text-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #222222;
}
@property --meta-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #79828B;
}
@property --border-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #e8e8e8;
}
@property --code-bg {
  syntax: '<color>';
  inherits: true;
  initial-value: #f4f4f5;
}
@property --link-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #222222;
}
@property --link-hover {
  syntax: '<color>';
  inherits: true;
  initial-value: #555555;
}
@property --blockquote-bar {
  syntax: '<color>';
  inherits: true;
  initial-value: #222222;
}

/* ── 1. CSS CUSTOM PROPERTIES ──────────────────────────────────── */
:root {
  /* Light mode (default) */
  --bg-color:       #ffffff;
  --text-color:     #222222;
  --meta-color:     #79828B;
  --border-color:   #e8e8e8;
  --code-bg:        #f4f4f5;
  --link-color:     #222222;
  --link-hover:     #555555;
  --blockquote-bar: #222222;

  /* Layout */
  --col-max:  680px;
  --col-pad:  20px;

  /* Typography — Serif body */
  --font-body: Georgia, Cambria, "Times New Roman", Times, serif;
  --body-size: 18px;
  --body-lh:   1.58;

  /* Typography — Sans UI / headings */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
             Helvetica, Arial, sans-serif;

  /* Type scale */
  --h1-size:   32px;
  --h1-lh:     1.2;
  --h2-size:   24px;
  --h2-lh:     1.3;
  --meta-size: 15px;
}

/* ── 2. DARK MODE TOKEN OVERRIDES ──────────────────────────────── */
[data-theme="dark"] {
  --bg-color:       #181818;
  --text-color:     #e5e5e5;
  --meta-color:     #9ca3af;
  --border-color:   #27272a;
  --code-bg:        #1f1f23;
  --link-color:     #e5e5e5;
  --link-hover:     #aaaaaa;
  --blockquote-bar: #e5e5e5;
}

/* ── 3. RESET & BASE ───────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-y: scroll; /* reserve scrollbar gutter — prevents layout shift */
}

body {
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: var(--body-lh);
  color: var(--text-color);
  background: var(--bg-color);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  /* Targeted fallback transitions — only colour props, no layout reflow */
  transition:
    color            400ms ease,
    background-color 400ms ease;
}

/* ── 4. COLUMN ─────────────────────────────────────────────────── */
.col {
  width: 100%;
  max-width: var(--col-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--col-pad);
  padding-right: var(--col-pad);
  box-sizing: border-box;
}

/* ── 5. SITE HEADER ────────────────────────────────────────────── */
.site-header {
  padding: 16px 0;
  margin-bottom: 48px;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-header__logo {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-color);
  text-decoration: none;
  transition: color 400ms ease, opacity 0.2s ease;
}
.site-header__logo:hover { opacity: 0.6; }

/* Right cluster: nav + toggle */
.site-header__right {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* ── 6. NAVIGATION ─────────────────────────────────────────────── */
.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-nav a {
  font-family: var(--font-ui);
  font-size: var(--meta-size);
  color: var(--meta-color);
  text-decoration: none;
  transition: color 400ms ease;
}
.site-nav a:hover { color: var(--text-color); }

/* ── 7. THEME TOGGLE BUTTON ────────────────────────────────────── */
#theme-toggle {
  background: none;
  border: none;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  cursor: pointer;
  color: var(--meta-color);
  display: grid;
  place-items: center;
  border-radius: 4px;
  flex-shrink: 0;

  /* Interaction & touch/selection rules */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;

  transition: color 400ms ease;
}

#theme-toggle:hover {
  color: var(--text-color);
}

#theme-toggle:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 3px;
}

/* ── 8. SVG SUN ↔ CRESCENT MOON SPRING MORPHING ────────────── */
#theme-icon {
  display: block;
  width: 20px;
  height: 20px;
  overflow: visible;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
  image-rendering: -webkit-optimize-contrast;

  /* Anchored 2D scale on press — scale icon instead of button to prevent compound transform drift */
  transform-box: view-box;
  -webkit-transform-origin: 12px 12px;
  transform-origin: 12px 12px;
  transition: transform 0.1s ease;
}

/* Crisp press feedback on the SVG icon centered at (12, 12) */
#theme-toggle:active #theme-icon {
  transform: scale(0.9);
}

.sun-rays,
.sun-center,
.moon-crescent {
  transform-box: view-box;
  -webkit-transform-origin: 12px 12px;
  transform-origin: 12px 12px;
  transition-property: transform, opacity;
  transition-duration: 450ms, 350ms;
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Mode State (Default) */
.sun-rays {
  transform: scale(1) rotate(0deg);
  opacity: 1;
}

.sun-center {
  transform: scale(1);
  opacity: 1;
}

.moon-crescent {
  transform: scale(0) rotate(-90deg);
  opacity: 0;
}

/* Dark Mode State ([data-theme="dark"]) */
[data-theme="dark"] .sun-rays {
  transform: scale(0) rotate(90deg);
  opacity: 0;
}

[data-theme="dark"] .sun-center {
  transform: scale(0);
  opacity: 0;
}

[data-theme="dark"] .moon-crescent {
  transform: scale(1) rotate(0deg);
  opacity: 1;
}

/* ── 9. FULL-SCREEN FADE TRANSITIONS (EXACTLY 400MS) ──────────── */
html,
body {
  transition:
    background-color 400ms cubic-bezier(0.4, 0, 0.2, 1),
    color            400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── 10. PAGE HEADING (Home & Weekly Reviews) ──────────────────── */
.page-heading {
  font-family: var(--font-ui);
  font-size: var(--h1-size);
  font-weight: 700;
  line-height: var(--h1-lh);
  color: var(--text-color);
  margin-bottom: 6px;
}

.page-subtitle {
  font-family: var(--font-ui);
  font-size: var(--meta-size);
  color: var(--meta-color);
  line-height: 1.4;
  margin-bottom: 24px;
}

/* ── 11. ARTICLE TYPOGRAPHY ────────────────────────────────────── */
.article-header { margin-bottom: 32px; }

.article-title {
  font-family: var(--font-ui);
  font-size: var(--h1-size);
  font-weight: 700;
  line-height: var(--h1-lh);
  color: var(--text-color);
  margin-bottom: 8px;
}

.article-meta {
  font-family: var(--font-ui);
  font-size: var(--meta-size);
  color: var(--meta-color);
  line-height: 1.4;
}
.article-meta a {
  color: var(--meta-color);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 400ms ease;
}
.article-meta a:hover { border-bottom-color: var(--meta-color); }

.article-body p { margin-bottom: 24px; }

.article-body h2 {
  font-family: var(--font-ui);
  font-size: var(--h2-size);
  font-weight: 700;
  line-height: var(--h2-lh);
  color: var(--text-color);
  margin-top: 40px;
  margin-bottom: 16px;
}

.article-body a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 400ms ease;
}
.article-body a:hover { color: var(--link-hover); }

.article-body blockquote {
  border-left: 3px solid var(--blockquote-bar);
  padding-left: 16px;
  font-style: italic;
  margin: 24px 0;
  color: var(--text-color);
  transition: border-color 400ms ease;
}
.article-body blockquote p:last-child { margin-bottom: 0; }

.article-body figure { margin: 32px 0; }
.article-body figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
}
.article-body figcaption {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--meta-color);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}

.article-body ul,
.article-body ol {
  margin-bottom: 24px;
  padding-left: 28px;
}
.article-body li { margin-bottom: 8px; }

.article-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 40px 0;
  transition: border-color 400ms ease;
}

.article-body code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--text-color);
  padding: 2px 5px;
  border-radius: 3px;
  transition: background-color 400ms ease, color 400ms ease;
}
.article-body pre {
  background: var(--code-bg);
  padding: 16px 20px;
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 24px;
  transition: background-color 400ms ease;
}
.article-body pre code { background: none; padding: 0; }

/* ── 12. READINGS LIST ─────────────────────────────────────────── */
.readings-list {
  list-style: none;
  padding: 0;
}

.readings-list li { margin-bottom: 24px; }

.readings-list__title {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.58;
  margin-bottom: 2px;
}

.readings-list__title a {
  color: var(--text-color);
  text-decoration: none;
  transition: opacity 0.2s ease;
}
.readings-list__title a:hover { opacity: 0.55; }

.readings-list__date {
  font-family: var(--font-ui);
  font-size: var(--meta-size);
  color: var(--meta-color);
}

/* ── 13. FOOTER ────────────────────────────────────────────────── */
.site-footer {
  margin-top: 64px;
  padding: 24px 0 48px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--meta-color);
}

/* ── 14. RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root {
    --h1-size:   26px;
    --h2-size:   21px;
    --body-size: 17px;
  }

  .site-header { margin-bottom: 32px; }

  .article-body figure {
    margin-left:  calc(-1 * var(--col-pad));
    margin-right: calc(-1 * var(--col-pad));
  }
  .article-body figure img { border-radius: 0; }
}

/* ── 15. LOGSEQ-STYLE HOVER EXPAND BUTTON & FULL SCALE LIGHTBOX ──── */
.article-body figure,
.article-body figure img,
.article-body img {
  cursor: zoom-in;
}

/* Hover square expand button (Logseq / Notion style) */
.image-expand-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  background: rgba(18, 18, 18, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  padding: 0;
}

.article-body figure:hover .image-expand-btn,
.article-body div:hover > .image-expand-btn {
  opacity: 1;
  transform: scale(1);
}

.image-expand-btn:hover {
  background: rgba(0, 0, 0, 0.92);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.05);
}

/* Full-scale overlay modal */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(12, 12, 12, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.lightbox-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-toolbar {
  position: absolute;
  top: 18px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 100000;
}

.lightbox-action-btn {
  color: rgba(255, 255, 255, 0.8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: all 0.2s ease;
  text-decoration: none;
}

.lightbox-action-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-close {
  color: rgba(255, 255, 255, 0.85);
  font-size: 32px;
  font-weight: 300;
  cursor: pointer;
  line-height: 1;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.2s ease, background 0.2s ease;
}

.lightbox-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-content {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}

.lightbox-img {
  max-width: 95vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}
