/* ---------- tokens ----------
   Three states:
     1. data-theme="light"    -> force light
     2. data-theme="dark"     -> force dark
     3. no attribute          -> follow OS via prefers-color-scheme
   The early-init script in _head.html sets the attribute from localStorage
   before this stylesheet loads, so there's no flash on persisted choices. */
:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #666;
  --link: #2a4d3e;
  --border: #e5e5e0;
  --code-bg: #f0efe8;
}

/* Auto-dark when no explicit choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181a;
    --fg: #e5e5e0;
    --muted: #999;
    --link: #8fb3a3;
    --border: #2a2d2f;
    --code-bg: #1f2224;
  }
}

/* Explicit dark override (wins over OS-light). */
:root[data-theme="dark"] {
  --bg: #15181a;
  --fg: #e5e5e0;
  --muted: #999;
  --link: #8fb3a3;
  --border: #2a2d2f;
  --code-bg: #1f2224;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

body {
  min-height: 100vh;        /* fallback */
  min-height: 100dvh;       /* avoids iOS Safari address-bar jumps */
  display: flex;
  flex-direction: column;
  overflow-x: hidden;       /* hard guard against rogue overflow */
}

img, svg, video, canvas { max-width: 100%; height: auto; display: block; }

/* ---------- header / nav (sticky) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.4rem 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}
.site-header a {
  color: var(--fg);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  font-size: 0.95rem;
}
.site-header a:hover,
.site-header a:focus-visible { background: var(--border); }

.theme-toggle {
  margin-left: auto;            /* shove to the right edge of the nav */
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--border);
  outline: none;
}


/* ---------- main column ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 36rem;                 /* mobile-first: keeps line length readable */
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

main, article, section {
  overflow-wrap: anywhere;          /* break long URLs/words instead of overflowing */
  word-wrap: break-word;
}

h1 { font-size: 1.5rem;  margin: 0 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.2rem;  margin: 1.75rem 0 0.5rem; line-height: 1.25; }
h3 { font-size: 1.05rem; margin: 1.25rem 0 0.25rem; line-height: 1.3; }
p  { margin: 0.7rem 0; }
a  { color: var(--link); }
time { color: var(--muted); font-size: 0.85rem; }

ul, ol { padding-left: 1.25rem; }

/* ---------- home ---------- */
.home-resume {
  text-align: center;
  margin: 0 0 1.75rem;
}
.home-resume .btn-ghost { min-width: 180px; }

.home-portrait {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0.5rem auto 1.5rem;
  border: 3px solid var(--border);
}

@media (min-width: 720px) {
  .home-portrait {
    width: 260px;
    height: 260px;
    margin: 1rem auto 2rem;
    border-width: 4px;
  }
}

/* h2 outside <details> (e.g. "Off-keyboard") still gets the section divider. */
.home-body > h2 {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* Collapsible section: border + chevron + summary text that disappears when open. */
.home-body details {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.home-body details > summary {
  cursor: pointer;
  list-style: none;          /* hide default disclosure triangle */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  user-select: none;
  padding: 0.6rem 0.85rem;
  margin: 0 -0.85rem;        /* keep heading visually aligned with body */
  border-radius: 8px;
  transition: background 0.15s ease;
}
.home-body details > summary:hover,
.home-body details > summary:focus-visible {
  background: var(--code-bg);
  outline: none;
}
.home-body details > summary::-webkit-details-marker { display: none; }
.home-body details > summary h2 {
  order: 0;
  flex: 1 1 auto;            /* eat the row, push the chevron to the right */
}
/* Outline chevron drawn from two borders rotated into a V, single-stroke
   feel, no Unicode dependency, scales with the heading font-size. */
.home-body details > summary::after {
  content: '';
  order: 1;
  margin-left: auto;
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  border-right: 2.5px solid var(--muted);
  border-bottom: 2.5px solid var(--muted);
  transform: translateY(-30%) rotate(45deg);
  flex-shrink: 0;
  transition: transform 0.25s ease, border-color 0.15s ease;
}
.home-body details[open] > summary::after {
  transform: translateY(15%) rotate(-135deg);  /* flip to point up when expanded */
  border-color: var(--link);
}
.home-body details > summary:hover::after,
.home-body details > summary:focus-visible::after { border-color: var(--fg); }
.home-body details > summary:hover h2,
.home-body details > summary:focus-visible h2 { color: var(--link); }
.home-body details > summary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 4px;
  border-radius: 4px;
}
.home-body details > summary h2 {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  font-size: 1.2rem;
  line-height: 1.25;
}
.home-body details[open] > summary { margin-bottom: 0.75rem; }

@media (min-width: 720px) {
  .home-body details > summary h2 { font-size: 1.4rem; }
}
@media (min-width: 1100px) {
  .home-body details > summary h2 { font-size: 1.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  .home-body details > summary::before { transition: none; }
}

.home-body h3 + p em { color: var(--muted); font-size: 0.9rem; font-style: normal; }
.home-body h3 { margin-top: 1.75rem; }

.home-cta {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 2rem 0 0;
  align-items: stretch;
}

.btn, .btn-ghost {
  display: inline-block;
  text-align: center;
  padding: 0.7rem 1rem;
  border: 1px solid var(--link);
  border-radius: 4px;
  text-decoration: none;
  min-height: 44px;
  line-height: 1.5;
}
.btn        { background: var(--link); color: var(--bg); }
.btn-ghost  { color: var(--link); }
.btn:hover, .btn:focus-visible        { opacity: 0.9; }
.btn-ghost:hover, .btn-ghost:focus-visible { background: var(--link); color: var(--bg); }

/* ---------- blog list ---------- */
.post-list ul { list-style: none; padding: 0; margin: 1rem 0; }
.post-list li {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.post-list li time { display: block; margin-top: 0.25rem; }
.post-list li a { font-weight: 500; }

/* ---------- post body ---------- */
article header { margin-bottom: 1rem; }

.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin: 0.25rem 0 0;
}
.post-meta time { color: var(--muted); font-size: 0.85rem; }

.ai-marker,
.human-marker {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ---------- post media (images & video) ---------- */
.post-body img,
.post-body video {
  margin: 1.5rem auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.post-body figure { margin: 1.5rem 0; }
.post-body figure img,
.post-body figure video,
.post-body figure iframe { margin: 0 auto; }

/* Portrait (phone-shot) video: cap the height so it shows as a centered
   phone-shaped player instead of a column-wide, very tall block. */
.post-body video.portrait {
  width: auto;
  max-width: 100%;
  max-height: 80vh;
}

/* Embedded players (YouTube): full-width, 16:9. */
.post-body iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.post-body figcaption {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.4rem;
}

/* ---------- code & tables ---------- */
pre, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}
code {
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  word-break: break-word;
}
pre {
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
pre code { background: none; padding: 0; word-break: normal; white-space: pre; }

table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  -webkit-overflow-scrolling: touch;
}
th, td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; }

/* ---------- tablet / small desktop ---------- */
@media (min-width: 720px) {
  html, body { font-size: 17px; }

  .site-header { padding: 1rem 1.5rem; }
  .site-header nav { gap: 0.5rem; }

  main {
    max-width: 44rem;               /* ~704px, more breathing room than mobile */
    padding: 2rem 1.5rem 4rem;
  }

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

  .home-cta { flex-direction: row; flex-wrap: wrap; gap: 1rem; align-items: center; }
  .btn, .btn-ghost { min-width: 200px; }
}

/* ---------- larger desktop ---------- */
@media (min-width: 1100px) {
  main {
    max-width: 56rem;               /* ~896px, uses the page on big screens */
    padding: 3rem 2rem 4rem;
  }

  h1 { font-size: 2.1rem; }
  h2 { font-size: 1.55rem; line-height: 1.3; }

  .home-portrait {
    width: 280px;
    height: 280px;
    margin: 1.25rem auto 2.25rem;
  }
}
