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

/* ── theme variables ── */
:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --nav-bg:    rgba(245,247,250,0.82);
  --glow:      rgba(145,195,230,0.16);
  --blue:      #5a9dc8;
  --blue-l:    #b5d7ee;
  --blue-ll:   #e3f1fa;
  --blue-d:    #2a6fa0;
  --line:      #dde5ee;
  --ink:       #1c2533;
  --ink2:      #4a5a6d;
  --ink3:      #8798ab;
  --ink4:      #c2cdd8;
  --hover:     #d4ebf8;
  --selection: rgba(90,157,200,0.18);
  --shadow-sm: 0 1px 2px rgba(22,40,62,0.04), 0 4px 12px rgba(22,40,62,0.04);
  --shadow-md: 0 4px 6px rgba(22,40,62,0.03), 0 10px 24px rgba(22,40,62,0.05);
}

[data-theme="dark"] {
  --bg:        #0b0f14;
  --surface:   #141b24;
  --nav-bg:    rgba(11,15,20,0.82);
  --glow:      rgba(70,130,200,0.14);
  --blue:      #6eb3ec;
  --blue-l:    #365575;
  --blue-ll:   #1b2836;
  --blue-d:    #93cbff;
  --line:      #253039;
  --ink:       #e6edf5;
  --ink2:      #9fb3c7;
  --ink3:      #6a7f94;
  --ink4:      #465565;
  --hover:     #223244;
  --selection: rgba(110,179,236,0.22);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.15);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.18), 0 10px 24px rgba(0,0,0,0.22);
}

html {
  scroll-behavior: smooth;
  color-scheme: light dark;
}

::selection { background: var(--selection); }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans SC', 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.7;
  transition: background .35s ease, color .35s ease;
}

/* subtle top-right glow */
body::before {
  content: '';
  position: fixed; top: -200px; right: -150px;
  width: 700px; height: 700px;
  background: radial-gradient(ellipse, var(--glow) 0%, transparent 65%);
  pointer-events: none; z-index: 0;
  transition: background .35s ease;
}

/* dim images slightly in dark mode for less eye strain */
[data-theme="dark"] img { filter: brightness(.96) contrast(1.02); }

/* subtle paper grain texture */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.025;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: multiply;
}
[data-theme="dark"] body::after { opacity: 0.04; mix-blend-mode: screen; }

/* refined custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink4); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink3); }

/* ── nav ── */
nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-bottom: 1px solid var(--line);
  transition: background .35s ease, border-color .35s ease;
}
.nav-inner {
  max-width: 680px; margin: 0 auto;
  padding: 0 2rem; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none;
}
.nav-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue-l));
  flex-shrink: 0;
}
.nav-name {
  font-size: 13px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink);
}
.nav-links { display: flex; gap: 0; list-style: none; margin-left: auto; }
.nav-links a {
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink3); text-decoration: none;
  padding: 6px 12px; border-radius: 99px;
  transition: color .2s, background .2s;
}
.nav-links a:hover { color: var(--ink); background: var(--blue-ll); }

/* back button variant (used by writing.html / gallery.html) */
.nav-back {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink3); text-decoration: none;
  padding: 6px 12px; border-radius: 99px;
  transition: color .2s, background .2s;
  margin-left: auto;
}
.nav-back:hover { color: var(--ink); background: var(--blue-ll); }

/* ── page ── */
.page {
  max-width: 680px; margin: 0 auto;
  padding: 0 2rem 8rem;
  position: relative; z-index: 1;
}

/* ── page header ── */
.page-header { padding-top: 6rem; padding-bottom: 4rem; border-bottom: 1px solid var(--line); }
.page-eyebrow {
  font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--blue); display: flex; align-items: center; gap: 10px;
  margin-bottom: 2rem;
}
.page-eyebrow::before {
  content: ''; width: 14px; height: 1px;
  background: var(--blue); border-radius: 1px; display: block;
}
.page-title {
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 300; color: var(--ink);
  line-height: 1.3; margin-bottom: 1rem;
}
.page-sub { font-size: 13px; color: var(--ink3); line-height: 1.8; }

/* ── footer ── */
footer {
  margin-top: 7rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  position: relative;
}
footer p { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink4); }
footer .busuanzi-count { position: absolute; left: 50%; transform: translateX(-50%); }
@media (max-width: 600px) {
  footer { flex-wrap: wrap; row-gap: 0.9rem; }
  footer .busuanzi-count {
    position: static; transform: none;
    width: 100%; order: 3; text-align: center;
  }
}

/* ── empty state ── */
.empty { padding: 4rem 0; text-align: center; }
.empty p { font-size: 13px; color: var(--ink4); letter-spacing: 0.06em; }

/* ── theme switch ── */
.theme-switch {
  background: none; border: none; padding: 0;
  cursor: pointer;
  margin-left: 10px;
  display: inline-flex;
  align-items: center;
}
.theme-switch:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 99px; }
.switch-track {
  width: 68px; height: 28px;
  background: var(--blue-ll);
  border: 1px solid var(--blue-l);
  border-radius: 99px;
  display: flex; align-items: center;
  padding: 0 4px;
  transition: background .35s ease, border-color .35s ease;
  position: relative;
}
.switch-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  transform: translateX(0);
  transition: transform .4s cubic-bezier(.34,1.56,.64,1), background .35s ease, box-shadow .35s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.switch-thumb svg {
  width: 12px; height: 12px;
  fill: none; stroke: var(--blue);
  stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  transition: opacity .25s ease, transform .25s ease;
}
.switch-thumb .sun,
.switch-thumb .auto,
.switch-thumb .moon { position: absolute; }
.switch-thumb .sun { opacity: 1; transform: rotate(0deg) scale(1); }
.switch-thumb .auto { opacity: 0; transform: rotate(0deg) scale(0.6); fill: var(--blue); stroke: none; }
.switch-thumb .moon { opacity: 0; transform: rotate(-45deg) scale(0.7); }

[data-theme-mode="system"] .switch-thumb { transform: translateX(22px); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
[data-theme-mode="system"] .switch-thumb .sun { opacity: 0; transform: rotate(45deg) scale(0.7); }
[data-theme-mode="system"] .switch-thumb .auto { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme-mode="system"] .switch-thumb .moon { opacity: 0; transform: rotate(-45deg) scale(0.7); }

[data-theme-mode="dark"] .switch-track { background: var(--blue-l); border-color: var(--blue); }
[data-theme-mode="dark"] .switch-thumb { transform: translateX(44px); box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
[data-theme-mode="dark"] .switch-thumb .sun { opacity: 0; transform: rotate(45deg) scale(0.7); }
[data-theme-mode="dark"] .switch-thumb .auto { opacity: 0; transform: rotate(0deg) scale(0.6); }
[data-theme-mode="dark"] .switch-thumb .moon { opacity: 1; transform: rotate(0deg) scale(1); }

/* ── mobile base ── */
@media (max-width: 600px) {
  .nav-inner { flex-wrap: wrap; height: auto; padding: 0.6rem 1.2rem; row-gap: 0.55rem; }
  .theme-switch { margin-left: 6px; }
  .nav-links {
    order: 3; width: 100%; margin-left: 0;
    justify-content: space-between;
    padding-top: 0.55rem;
    border-top: 1px solid var(--line);
  }
  .nav-links a { padding: 5px 10px; font-size: 10.5px; }
  /* collapse wide 3-state switch into a compact icon button */
  .switch-track { width: 32px; height: 32px; padding: 0; background: var(--surface); border-color: var(--line); justify-content: center; }
  .switch-thumb { transform: none !important; width: 24px; height: 24px; background: transparent; box-shadow: none; }
  [data-theme-mode="system"] .switch-thumb,
  [data-theme-mode="dark"] .switch-thumb { transform: none !important; box-shadow: none; }
  .switch-thumb svg { width: 16px; height: 16px; }
  .switch-thumb .sun,
  .switch-thumb .auto,
  .switch-thumb .moon { opacity: 0; }
  [data-theme-mode="light"] .switch-thumb .sun { opacity: 1; }
  [data-theme-mode="system"] .switch-thumb .auto { opacity: 1; }
  [data-theme-mode="dark"] .switch-thumb .moon { opacity: 1; }
  .page { padding: 0 1.4rem 6rem; }
}

/* ── entrance: staggered rise ── */
.page > *, .page-header > * {
  opacity: 0;
  animation: head-in .55s cubic-bezier(.2,.8,.2,1) forwards;
}
.page > *:nth-child(1) { animation-delay: .05s; }
.page > *:nth-child(2) { animation-delay: .18s; }
.page > *:nth-child(3) { animation-delay: .28s; }
.page > *:nth-child(4) { animation-delay: .38s; }
.page > *:nth-child(n+5) { animation-delay: .46s; }
.page-header > *:nth-child(1) { animation-delay: .1s; }
.page-header > *:nth-child(2) { animation-delay: .2s; }
.page-header > *:nth-child(3) { animation-delay: .3s; }
@keyframes head-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .page > *, .page-header > * { animation: none; opacity: 1; }
}
