/* ===== CUSTOM PROPERTIES ===== */
:root {
  color-scheme: light dark;

  /* Typography */
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  --font-mono: "Berkeley Mono", "SF Mono", Menlo, Monaco,
               "Cascadia Code", "Roboto Mono", monospace;

  /* Sizing */
  --content-width: 640px;
  --spacing: 1rem;
  --line-height: 1.6;

  /* Colors using light-dark() */
  --color-text: light-dark(#1a1a1a, #e0e0e0);
  --color-text-muted: light-dark(#666, #999);
  --color-bg: light-dark(#fff, #111);
  --color-border: light-dark(#e0e0e0, #333);
  --color-link: light-dark(#0066cc, #6db3f2);
  --color-code-bg: light-dark(#f5f5f5, #1e1e1e);
}

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
.wrapper {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 calc(var(--spacing) * 1.5);
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4 {
  margin: calc(var(--spacing) * 2) 0 var(--spacing);
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

p { margin: 0 0 var(--spacing); }

a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover { text-decoration: none; }

/* ===== HEADER ===== */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--spacing) * 2) 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: calc(var(--spacing) * 2);
}

.site-header nav {
  display: flex;
  gap: calc(var(--spacing) * 1.5);
  align-items: baseline;
}

.site-header .site-title {
  font-weight: 600;
  text-decoration: none;
  color: var(--color-text);
}

.site-header nav a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.site-header nav a:hover,
.site-header nav a[aria-current="page"] {
  color: var(--color-text);
}

/* Theme Toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  padding: 0;
  line-height: 1;
  transition: color 0.2s ease;
}

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

/* Show sun in dark mode, moon in light mode */
:root { --is-dark: 0; }
@media (prefers-color-scheme: dark) { :root { --is-dark: 1; } }
[data-theme="dark"] { --is-dark: 1; }
[data-theme="light"] { --is-dark: 0; }

.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: inline; }

@media (prefers-color-scheme: dark) {
  .theme-toggle .sun { display: inline; }
  .theme-toggle .moon { display: none; }
}

[data-theme="dark"] .theme-toggle .sun { display: inline; }
[data-theme="dark"] .theme-toggle .moon { display: none; }
[data-theme="light"] .theme-toggle .sun { display: none; }
[data-theme="light"] .theme-toggle .moon { display: inline; }

/* ===== FOOTER ===== */
.site-footer {
  padding: calc(var(--spacing) * 2) 0;
  margin-top: calc(var(--spacing) * 3);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.site-footer a {
  color: var(--color-text-muted);
}

/* ===== POST LIST ===== */
.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  display: flex;
  gap: var(--spacing);
  margin-bottom: calc(var(--spacing) * 0.75);
  align-items: baseline;
}

.post-list time {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.post-list a {
  text-decoration: none;
}

.post-list a:hover {
  text-decoration: underline;
}

/* ===== ARTICLE ===== */
article header {
  margin-bottom: calc(var(--spacing) * 2);
}

article header h1 {
  margin-bottom: calc(var(--spacing) * 0.5);
}

article header time {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* ===== INTRO ===== */
.intro {
  margin-bottom: calc(var(--spacing) * 2);
}

.intro p:first-child {
  font-size: 1.1rem;
}

/* ===== CODE ===== */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--color-code-bg);
  padding: 0.125em 0.375em;
  border-radius: 3px;
}

pre {
  background-color: var(--color-code-bg);
  padding: var(--spacing);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
  border: 1px solid var(--color-border);
}

pre code {
  background: none;
  padding: 0;
}

/* ===== SYNTAX HIGHLIGHTING ===== */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: light-dark(#6a737d, #8b949e);
}

.token.punctuation {
  color: var(--color-text);
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
  color: light-dark(#005cc5, #79c0ff);
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin {
  color: light-dark(#22863a, #7ee787);
}

.token.operator,
.token.entity,
.token.url,
.token.keyword {
  color: light-dark(#d73a49, #ff7b72);
}

.token.function,
.token.class-name {
  color: light-dark(#6f42c1, #d2a8ff);
}

/* ===== PHOTO GRID (Homepage) ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--spacing) * 0.5);
  margin-bottom: var(--spacing);
}

.photo-thumb {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.photo-thumb:hover img {
  transform: scale(1.05);
}

/* ===== PHOTO GALLERY (Full page) ===== */
.photo-gallery {
  display: flex;
  flex-direction: column;
  gap: 15vh;
  padding: 5vh 0;
}

.photo-item {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 80vh;
  justify-content: center;
  /* Break out of wrapper to allow full-width landscape photos */
  width: 90vw;
  max-width: 1200px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  /* Fade in when image loaded */
  opacity: 1;
  transition: opacity 0.4s ease;
}

/* Hide until image loaded */
.photo-item[data-loading="true"] {
  opacity: 0;
}

.photo-item img {
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
}

.photo-item a {
  display: block;
  line-height: 0;
}

.photo-item figcaption {
  margin-top: calc(var(--spacing) * 0.75);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-style: italic;
  text-align: center;
}

/* ===== PHOTO DETAIL PAGE ===== */
.photo-detail-image {
  margin: 0;
  /* Break out of wrapper for full-width display */
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.photo-detail-image img {
  max-width: 95vw;
  max-height: calc(100vh - 120px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.photo-meta {
  margin-top: calc(var(--spacing) * 2);
  color: var(--color-text-muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

.photo-caption {
  color: var(--color-text);
  font-style: italic;
  margin-bottom: var(--spacing);
}

.photo-info {
  margin-bottom: var(--spacing);
}

.photo-nav {
  margin: 0;
}

.photo-nav a {
  text-decoration: none;
  color: var(--color-text-muted);
}

.photo-nav a:hover {
  color: var(--color-text);
}

/* ===== VIEW TRANSITIONS ===== */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: fade-out 0.15s ease-out;
}

::view-transition-new(root) {
  animation: fade-in 0.15s ease-in;
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  :root {
    --spacing: 0.875rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .post-list li {
    flex-direction: column;
    gap: 0.25rem;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
