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

:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --text-muted: #555555;
  --text-faint: #767676; /* Minimum for WCAG AA contrast on white */
  --border: #e8e8e8;
  --link-hover: #555555;
  --input-bg: #ffffff;
  --input-border: #d0d0d0;
  --input-focus: #1a1a1a;
  --subscribe-bg: #f8f8f8;
  --toggle-bg: #e0e0e0;
  --toggle-knob: #ffffff;
  --toggle-active: #1a1a1a;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --text: #e0e0e0;
  --text-muted: #aaaaaa;
  --text-faint: #666666;
  --border: #2e2e2e;
  --link-hover: #aaaaaa;
  --input-bg: #222222;
  --input-border: #3a3a3a;
  --input-focus: #e0e0e0;
  --subscribe-bg: #222222;
  --toggle-bg: #555555;
  --toggle-knob: #e0e0e0;
  --toggle-active: #555555;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  height: -webkit-fill-available; /* Chrome iOS: anchor html height to visible viewport */
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Georgia, "Times New Roman", serif;
  line-height: 1.7;
  transition: background-color 0.2s ease, color 0.2s ease;
  min-height: 100vh;
  min-height: -webkit-fill-available; /* Chrome iOS: uses anchored html height as reference */
  min-height: 100dvh; /* Modern browsers: tracks actual visible viewport, prevents address-bar jump */
}

/* ============================================
   SKIP NAVIGATION
   ============================================ */
.skip-to-main {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  text-decoration: none;
  font-size: 0.875rem;
  z-index: 9999;
  transition: top 0.1s;
}

.skip-to-main:focus {
  top: 0;
}

/* ============================================
   FOCUS STYLES
   ============================================ */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Inputs already show a border on focus — keep that, just add outline */
.contact-field input:focus-visible,
.contact-field textarea:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 0;
}

/* ============================================
   LAYOUT
   ============================================ */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================
   NAV
   ============================================ */
nav {
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-left a {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}

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

.nav-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-right a {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.15s ease;
}

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

/* ============================================
   SEARCH TOGGLE BUTTON
   ============================================ */
.search-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.15s ease;
  line-height: 1;
}

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

.search-toggle.active {
  color: var(--text);
}

/* ============================================
   SEARCH DRAWER
   ============================================ */
.search-drawer {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease, margin-bottom 0.3s ease;
  margin-bottom: 0;
}

.search-drawer.open {
  max-height: 100px;
  opacity: 1;
  margin-bottom: 40px;
}

.search-drawer .search-input {
  width: 100%;
  padding: 10px 0;
  font-size: 1.0625rem;
  font-family: inherit;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}

.search-drawer .search-input::placeholder {
  color: var(--text-faint);
}

.search-drawer .search-input:focus {
  border-bottom-color: var(--text);
}

.search-drawer .search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cline x1='2' y1='2' x2='12' y2='12' stroke='%23888' stroke-width='1.5' stroke-linecap='round'/%3E%3Cline x1='12' y1='2' x2='2' y2='12' stroke='%23888' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  cursor: pointer;
  opacity: 0.6;
}

.search-drawer .search-input::-webkit-search-cancel-button:hover {
  opacity: 1;
}

/* ============================================
   DARK MODE TOGGLE
   ============================================ */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-family: inherit;
  transition: color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

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

.toggle-track {
  width: 48px;
  height: 22px;
  background: var(--toggle-bg);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

[data-theme="dark"] .toggle-track {
  background: var(--toggle-active);
}

.toggle-icon {
  display: block;
  flex-shrink: 0;
  color: #999999;
}

/* Light mode: show sun only */
.toggle-icon-sun  { visibility: visible; }
.toggle-icon-moon { visibility: hidden; }

/* Dark mode: show moon only */
[data-theme="dark"] .toggle-icon-sun  { visibility: hidden; }
[data-theme="dark"] .toggle-icon-moon { visibility: visible; }

.toggle-knob {
  width: 14px;
  height: 14px;
  background: var(--toggle-knob);
  border-radius: 50%;
  position: absolute;
  top: 4px;
  left: 4px;
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 1;
}

[data-theme="dark"] .toggle-knob {
  transform: translateX(26px);
}

/* ============================================
   HERO / BIO
   ============================================ */
.bio {
  margin-bottom: 72px;
}

.bio h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 20px;
  color: var(--text);
}

.bio p {
  font-size: 1.0625rem;
  color: var(--text-muted);
  line-height: 1.75;
  max-width: 560px;
}

.bio p + p {
  margin-top: 14px;
}

/* ============================================
   SEARCH
   ============================================ */

/* ============================================
   POST SECTIONS / CATEGORIES
   ============================================ */
.posts-section {
  margin-bottom: 60px;
}

.posts-section h2 {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 24px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

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

.post-item {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  transition: opacity 0.15s ease;
}

.post-item.hidden {
  display: none;
}

.post-item-left {
  flex: 1;
  min-width: 0;
}

.post-item a {
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 400;
  line-height: 1.4;
  transition: color 0.15s ease;
  display: block;
}

.post-item a:hover {
  color: var(--text-muted);
}

.post-item .excerpt {
  font-size: 0.875rem;
  color: var(--text-faint);
  margin-top: 4px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-item .date {
  font-size: 0.8125rem;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.post-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  gap: 4px;
}

.post-item-reading-time {
  font-size: 0.75rem;
  color: var(--text-faint);
  opacity: 0.6;
  white-space: nowrap;
}

.no-results {
  font-size: 0.9375rem;
  color: var(--text-faint);
  padding: 24px 0;
  display: none;
}

.no-results.visible {
  display: block;
}

/* ============================================
   SUBSCRIBE SECTION (disabled — uncomment to re-enable)
   ============================================ */
/*
.subscribe-section {
  background: var(--subscribe-bg);
  border-radius: 8px;
  padding: 36px 40px;
  margin: 72px 0 64px;
}

.subscribe-section h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--text);
}

.subscribe-section p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.subscribe-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subscribe-form input {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}

.subscribe-form input::placeholder {
  color: var(--text-faint);
}

.subscribe-form input:focus {
  border-color: var(--input-focus);
}

.subscribe-form button {
  align-self: flex-start;
  padding: 10px 22px;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.15s ease;
  letter-spacing: 0.01em;
}

.subscribe-form button:hover {
  opacity: 0.75;
}

.subscribe-message {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.subscribe-message:empty {
  display: none;
}

.subscribe-message.success {
  color: #2e7d32;
}

[data-theme="dark"] .subscribe-message.success {
  color: #81c784;
}

.subscribe-message.error {
  color: #c62828;
}

[data-theme="dark"] .subscribe-message.error {
  color: #e57373;
}
*/

/* ============================================
   FOOTER
   ============================================ */
footer {
  border-top: 1px solid var(--border);
  padding: 28px 0 40px;
  margin-top: 0;
  min-height: 69px; /* Reserves space before JS injects content, prevents layout shift */
}

footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

footer p {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 20px;
}

footer a {
  font-size: 0.8125rem;
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

/* ============================================
   ARCHIVE PAGE
   ============================================ */
.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 48px;
}

.archive-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 40px;
}

.archive-sort {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sort-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease;
}

.sort-btn:hover {
  color: var(--text-muted);
}

.sort-btn.active {
  color: var(--text);
}

.sort-divider {
  font-size: 0.875rem;
  color: var(--text-faint);
  user-select: none;
}

.archive-year {
  margin-bottom: 40px;
}

.archive-year h3 {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ============================================
   SINGLE POST PAGE
   ============================================ */
.post-header {
  margin-bottom: 48px;
}

.post-header .back-link {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 32px;
  transition: color 0.15s ease;
}

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

.post-header .back-link::before {
  content: "← ";
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.post-category {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.post-date {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

.reading-time {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

.reading-time::before {
  content: "·";
  margin-right: 14px;
}

.post-title {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin-bottom: 12px;
}

.post-lede {
  font-size: 1.0625rem;
  color: var(--text-muted);
  line-height: 1.7;
  font-style: italic;
}

.post-body {
  border-top: 1px solid var(--border);
  padding-top: 40px;
}

.post-body p {
  font-size: 1.0625rem;
  line-height: 1.8;
  margin-bottom: 24px;
  color: var(--text);
}

.post-body h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 40px 0 16px;
}

.post-body h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 32px 0 12px;
}

.post-body a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: text-decoration-color 0.15s ease;
}

.post-body a:hover {
  text-decoration-color: var(--text-muted);
}

.post-body blockquote {
  border-left: 2px solid var(--border);
  padding-left: 20px;
  margin: 28px 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-body ul, .post-body ol {
  padding-left: 24px;
  margin-bottom: 24px;
}

.post-body li {
  font-size: 1.0625rem;
  line-height: 1.75;
  margin-bottom: 6px;
}

.post-footer {
  border-top: 1px solid var(--border);
  padding-top: 32px;
  margin-top: 48px;
}

.copy-link-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.copy-link-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ============================================
   CONTACT FORM
   ============================================ */
.contact-form {
  margin-top: 40px;
  margin-bottom: 72px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.contact-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.contact-field input,
.contact-field textarea {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.6;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}

.contact-field input::placeholder,
.contact-field textarea::placeholder {
  color: var(--text-faint);
}

.contact-field input:focus,
.contact-field textarea:focus {
  border-color: var(--input-focus);
}

.contact-field textarea {
  resize: vertical;
  min-height: 140px;
}

.contact-footer {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.contact-footer button {
  padding: 10px 22px;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.15s ease;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.contact-footer button:hover {
  opacity: 0.75;
}

.contact-footer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.contact-message {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.contact-message:empty {
  display: none;
}

.contact-message.success {
  color: #2e7d32;
}

[data-theme="dark"] .contact-message.success {
  color: #81c784;
}

.contact-message.error {
  color: #c62828;
}

[data-theme="dark"] .contact-message.error {
  color: #e57373;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
  html {
    font-size: 17px;
  }

  .container {
    padding: 0 18px;
  }

  nav {
    padding: 20px 0 18px;
    margin-bottom: 44px;
  }

  .bio {
    margin-bottom: 48px;
  }

  .bio h1 {
    font-size: 1.5rem;
  }

  /* .subscribe-section {
    padding: 28px 24px;
    margin: 56px 0 48px;
  } */

  .post-item {
    flex-direction: column;
    gap: 4px;
  }

  .post-item .date {
    font-size: 0.75rem;
  }

  .post-item-right {
    align-items: flex-start;
  }

  .post-item .excerpt {
    white-space: normal;
  }

  .post-item a {
    overflow-wrap: break-word;
  }

  .post-title {
    font-size: 1.4rem;
  }

  footer .container {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
  }

  /* Prevent footer links from overflowing on narrow screens */
  .footer-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
  }

  /* Touch targets: 44×44px minimum per Apple HIG / WCAG 2.5.5 */
  .search-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  .theme-toggle {
    min-height: 44px;
  }

  /* Prevent iOS Safari from zooming the viewport on input focus.
     iOS zooms when font-size < 16px; 0.9375rem × 17px base = 15.9px. */
  /* .subscribe-form input, */
  .contact-field input,
  .contact-field textarea {
    font-size: 1rem;
  }

  /* Disable textarea resize on mobile — iOS Safari misreads resize drags as scroll gestures */
  .contact-field textarea {
    resize: none;
  }
}
