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

:root {
  --bg: #1a1a1a;
  --surface: #212121;
  --surface2: #2a2a2a;
  --text: #919191;
  --text-bright: #c0c0c0;
  --text-muted: #555;
  --border: #2d2d2d;
  --border2: #383838;
  --accent: #888;
  --code-bg: #161616;
  --tag-bg: #252525;
  --hl-theme: url("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark-dimmed.min.css");
}

[data-theme="light"] {
  --bg: #d8d8d8;
  --surface: #d0d0d0;
  --surface2: #c8c8c8;
  --text: #3d3d3d;
  --text-bright: #1a1a1a;
  --text-muted: #888;
  --border: #bfbfbf;
  --border2: #adadad;
  --accent: #666;
  --code-bg: #e4e4e4;
  --tag-bg: #c8c8c8;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ─────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2rem 2rem 1.5rem;
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  z-index: 20;
}

.site-title {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  font-weight: 600;
  text-transform: uppercase;
}

.site-title:hover { color: var(--text); }

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
}

.site-nav-link {
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  text-transform: uppercase;
  transition: color 0.15s;
}

.site-nav-link:hover { color: var(--text); }

.site-nav-sep {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.35;
  margin: 0 0.55rem;
  user-select: none;
}

.site-nav-dash {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.35;
  margin: 0 0.65rem;
  user-select: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.theme-toggle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface2);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
  padding: 0;
}

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

/* Width toggle — rectangle with two vertical tick marks */
.width-toggle {
  width: 24px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
  padding: 0;
}

.width-toggle:hover { border-color: var(--accent); background: var(--surface2); }

/* Two vertical marks — spread indicates layout width */
.width-toggle::before,
.width-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 2px;
  background: var(--text-muted);
  border-radius: 1px;
  transition: left 0.15s, right 0.15s;
}
.width-toggle::before { left: 4px; }
.width-toggle::after  { right: 4px; }

/* Wide mode — marks spread to edges */
[data-layout="wide"] .width-toggle::before { left: 2px; }
[data-layout="wide"] .width-toggle::after  { right: 2px; }

/* Full mode — marks at very edges, button slightly brighter */
[data-layout="full"] .width-toggle { border-color: var(--accent); }
[data-layout="full"] .width-toggle::before { left: 1px; }
[data-layout="full"] .width-toggle::after  { right: 1px; }

/* ── Main ────────────────────────────────────────── */

#app {
  flex: 1;
  max-width: 740px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
  width: 100%;
}

/* ── Post List ───────────────────────────────────── */

.post-list { list-style: none; }

.post-list-item {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
}

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

.post-list-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.2rem;
  margin-bottom: 0.35rem;
}

.post-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

.post-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.post-tag {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--tag-bg);
  padding: 0.15em 0.55em;
  border-radius: 2px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

a.post-tag:hover {
  color: var(--text-bright);
  background: var(--surface2);
}

a.post-tag-active {
  color: var(--text-bright);
  background: var(--surface2);
}

/* ── Tag filter header ───────────────────────────────── */

.tag-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.tag-filter-label { text-transform: lowercase; }

.tag-filter-name {
  color: var(--text-bright);
  background: var(--tag-bg);
  padding: 0.15em 0.55em;
  border-radius: 2px;
  letter-spacing: 0.06em;
  font-size: 0.65rem;
}

.tag-filter-clear {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
  transition: color 0.15s;
}

.tag-filter-clear:hover { color: var(--text-bright); }

.post-list-title {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 0;
}

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

.post-list-title a:hover { color: var(--text); text-decoration: underline; text-decoration-color: var(--border2); }

.post-excerpt {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.55;
  margin-bottom: 0.1rem;
}

.post-read-more {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.05em;
}

.post-read-more:hover { color: var(--text); }

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 3rem 0;
  text-align: center;
  letter-spacing: 0.05em;
}

/* ── Single Post ─────────────────────────────────── */

.post-header { margin-bottom: 2.5rem; }

.post-back {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.08em;
  margin-bottom: 1.5rem;
}

.post-back:hover { color: var(--text); }

.post-title {
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--text-bright);
  line-height: 1.3;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Post Body (rendered markdown) ──────────────── */

.post-body { color: var(--text); }

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4 {
  color: var(--text-bright);
  font-weight: 500;
  margin: 2rem 0 0.75rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.post-body h1 { font-size: 1.4rem; }
.post-body h2 { font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.post-body h3 { font-size: 1rem; }
.post-body h4 { font-size: 0.9rem; color: var(--text); }

.post-body p { margin: 1rem 0; }
.post-body p:first-child { margin-top: 0; }

.post-body a { color: var(--text-bright); text-decoration: underline; text-decoration-color: var(--border2); }
.post-body a:hover { text-decoration-color: var(--accent); }

.post-body strong { color: var(--text-bright); font-weight: 600; }
.post-body em { font-style: italic; }

.post-body ul,
.post-body ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.post-body li { margin: 0.3rem 0; }

.post-body blockquote {
  border-left: 2px solid var(--border2);
  margin: 1.5rem 0;
  padding: 0.25rem 1.25rem;
  color: var(--text-muted);
  font-style: italic;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.88rem;
}

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

.post-body th {
  background: var(--surface2);
  color: var(--text-bright);
  font-weight: 500;
}

.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 2px;
  margin: 1.5rem auto;
  cursor: zoom-in;
}

/* ── Code ────────────────────────────────────────── */

.post-body code {
  font-family: 'SFMono-Regular', 'Fira Code', Consolas, 'Liberation Mono', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  color: var(--text-bright);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.post-body pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}

.post-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.83rem;
  line-height: 1.65;
  color: inherit;
}

.code-block-wrapper { position: relative; }

.code-copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text-muted);
  font-size: 0.65rem;
  padding: 0.2em 0.6em;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 0.05em;
  font-family: inherit;
  transition: color 0.15s;
  z-index: 1;
}

.code-copy-btn:hover { color: var(--text); }

/* ── Embeds ──────────────────────────────────────── */

.embed-wrapper {
  position: relative;
  width: 100%;
  margin: 1.5rem 0;
}

.embed-youtube,
.embed-vimeo {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  background: var(--surface2);
  border-radius: 3px;
}

.embed-youtube iframe,
.embed-vimeo iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

.embed-soundcloud iframe {
  width: 100%;
  border: none;
  display: block;
  border-radius: 3px;
}

.embed-generic iframe {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 3px;
  display: block;
}

/* ── Gallery ─────────────────────────────────────── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.gallery-grid img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  cursor: zoom-in;
  margin: 0;
  border-radius: 2px;
  transition: opacity 0.15s;
}

.gallery-grid img:hover { opacity: 0.85; }

/* ── Lightbox ────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1000;
  padding: 2rem;
  cursor: zoom-out;
}

.lightbox[hidden] { display: none !important; }

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 2px;
  cursor: default;
}

.lightbox-caption {
  color: #777;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.lightbox-close {
  position: fixed;
  top: 1.25rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #666;
  font-size: 1.75rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.lightbox-close:hover { color: #aaa; }

/* ── Footer ──────────────────────────────────────── */

.site-footer {
  max-width: 740px;
  margin: 0 auto;
  padding: 1rem 2rem 1.5rem;
  width: 100%;
  text-align: right;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
}

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

/* ── Loading / Error ─────────────────────────────── */

.loading {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 3rem 0;
  letter-spacing: 0.08em;
}

.error-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 0;
}

/* ── Redaction ───────────────────────────────────── */

.redacted {
  display: inline;
  background: #111;
  color: transparent;
  border-radius: 2px;
  padding: 0.05em 0.3em;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, color 0.15s;
  /* prevent text selection revealing content */
  -webkit-user-select: none;
}

.redacted.revealed {
  background: var(--surface2);
  color: var(--text-bright);
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

/* keep highlight invisible while redacted */
.redacted:not(.revealed)::selection {
  background: transparent;
  color: transparent;
}

[data-theme="light"] .redacted { background: #1a1a1a; }

/* ── Layout width modes ──────────────────────────── */

/* Shared transition for smooth width changes */
.site-header, #app, .site-footer {
  transition: max-width 0.25s ease, padding 0.25s ease;
}

/* Wide — 1100px content column */
[data-layout="wide"] .site-header,
[data-layout="wide"] #app,
[data-layout="wide"] .site-footer {
  max-width: 1100px;
}

/* Full — uses available viewport, padded generously */
[data-layout="full"] .site-header,
[data-layout="full"] #app,
[data-layout="full"] .site-footer {
  max-width: none;
  padding-left: clamp(1.5rem, 4vw, 4rem);
  padding-right: clamp(1.5rem, 4vw, 4rem);
}

/* Wide/full gallery — more columns */
[data-layout="wide"] .gallery-grid,
[data-layout="full"] .gallery-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* Wide/full post list — slightly larger title */
[data-layout="wide"] .post-list-title,
[data-layout="full"] .post-list-title { font-size: 1.1rem; }

[data-layout="wide"] .post-title,
[data-layout="full"] .post-title { font-size: 1.8rem; }

/* ── Large screen baseline improvements ─────────── */

@media (min-width: 1200px) {
  html { font-size: 16px; }

  .site-header { padding: 2.5rem 2rem 2rem; }
  #app { padding: 0 2rem 5rem; }

  .post-list-item { padding: 1.4rem 0; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .gallery-grid img { height: 180px; }
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 600px) {
  html { font-size: 14px; }

  .site-header { padding: 1.25rem 1rem 1rem; }
  #app { padding: 0 1rem 3rem; }

  /* Tighten nav links on small screens */
  .site-nav-link { letter-spacing: 0.12em; }
  .site-nav-sep { margin: 0 0.35rem; }
  .site-nav-dash { margin: 0 0.45rem; }
  .site-footer { padding: 0.75rem 1rem 1.25rem; }

  /* Typography */
  .post-title { font-size: 1.2rem; }
  .post-list-title { font-size: 1rem; }

  /* Touch targets — 44px minimum */
  .post-back { display: inline-block; padding: 0.6rem 0; margin-bottom: 1rem; }
  .post-read-more { padding: 0.4rem 0; }
  .theme-toggle { width: 28px; height: 28px; }
  .lightbox-close {
    font-size: 2rem;
    top: 0.75rem; right: 1rem;
    padding: 0.5rem 0.75rem;
  }
  .code-copy-btn { padding: 0.4em 0.8em; font-size: 0.7rem; }

  /* Tables — horizontal scroll */
  .post-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Gallery */
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .gallery-grid img { height: 100px; }

  /* Meta & spacing */
  .post-meta { gap: 0.4rem; }
  .post-list-meta { gap: 0.6rem; }

  /* Lightbox */
  .lightbox { padding: 1rem; gap: 0.5rem; }
  .lightbox-img { max-width: 95vw; max-height: 80vh; }
  .lightbox-caption { font-size: 0.72rem; }

  /* Code blocks */
  .post-body pre { padding: 0.875rem 1rem; }
  .post-body pre code { font-size: 0.78rem; }
}

/* ── highlight.js theme swap ─────────────────────── */

[data-theme="light"] #hl-theme { }
