/* ==========================================================================
   Pan Nie — CV / personal homepage
   Deliberately restrained: typography-led, no decorative motion, print-first.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --bg:            #ffffff;
  --bg-soft:       #f7f8fa;
  --fg:            #16181d;
  --fg-muted:      #5b6270;
  --fg-faint:      #878e9c;
  --rule:          #e3e6ec;
  --rule-strong:   #c9cfda;
  --accent:        #16457d;
  --accent-soft:   #eef3fa;
  --todo:          #a8500f;
  --todo-bg:       #fdf4e8;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --wrap: 54rem;
  --radius: 6px;
}

html[data-theme="dark"] {
  --bg:          #14161a;
  --bg-soft:     #1b1e24;
  --fg:          #e8eaef;
  --fg-muted:    #a2a9b8;
  --fg-faint:    #767d8c;
  --rule:        #2a2f38;
  --rule-strong: #3c434f;
  --accent:      #7fb0ea;
  --accent-soft: #1c2733;
  --todo:        #e0a45f;
  --todo-bg:     #2b2317;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:          #14161a;
    --bg-soft:     #1b1e24;
    --fg:          #e8eaef;
    --fg-muted:    #a2a9b8;
    --fg-faint:    #767d8c;
    --rule:        #2a2f38;
    --rule-strong: #3c434f;
    --accent:      #7fb0ea;
    --accent-soft: #1c2733;
    --todo:        #e0a45f;
    --todo-bg:     #2b2317;
  }
}

/* ---------- i18n switching (en / zh / es) ----------
   Whatever language is selected, hide every other language's copy. Written with
   :not() so adding a fourth language means adding one selector, not three. */
html[data-lang="en"] [data-lang]:not([data-lang="en"]),
html[data-lang="zh"] [data-lang]:not([data-lang="zh"]),
html[data-lang="es"] [data-lang]:not([data-lang="es"]) { display: none !important; }

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: oldstyle-nums;
  /* Long repository URLs must never widen the layout on narrow screens. */
  overflow-wrap: break-word;
}

.wrap {
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 1.75rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  transition: border-color .15s ease, background-color .15s ease;
}
a:hover { border-bottom-color: var(--accent); }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }
p { margin: 0 0 1rem; }
ul { margin: 0; padding: 0; }

code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .08em .38em;
}

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--rule);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 3.25rem;
}

.brand {
  font-weight: 650;
  font-size: .95rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  border: 0;
  white-space: nowrap;
}

.site-nav {
  display: flex;
  gap: 1.15rem;
  margin-inline-start: auto;
  font-size: .875rem;
}
.site-nav a {
  color: var(--fg-muted);
  border: 0;
}
.site-nav a:hover { color: var(--accent); }

.controls {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-inline-start: .25rem;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.lang-switch button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  font: inherit;
  font-size: .78rem;
  font-weight: 550;
  letter-spacing: .02em;
  padding: .28rem .6rem;
  cursor: pointer;
}
.lang-switch button + button { border-left: 1px solid var(--rule-strong); }
.lang-switch button:hover { color: var(--fg); background: var(--bg-soft); }
html[data-lang="en"] .lang-switch button[data-set-lang="en"],
html[data-lang="zh"] .lang-switch button[data-set-lang="zh"],
html[data-lang="es"] .lang-switch button[data-set-lang="es"] {
  background: var(--accent);
  color: #fff;
}

.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.icon-btn svg { display: block; }

/* Show the mode you would switch TO: moon while light, sun while dark.
   Default (no data-theme) follows the OS; an explicit choice overrides it. */
#theme-toggle .i-sun  { display: none; }
#theme-toggle .i-moon { display: block; }

html[data-theme="dark"] #theme-toggle .i-sun  { display: block; }
html[data-theme="dark"] #theme-toggle .i-moon { display: none; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #theme-toggle .i-sun  { display: block; }
  html:not([data-theme="light"]) #theme-toggle .i-moon { display: none; }
}

/* ---------- hero ---------- */
.hero { padding: 3.5rem 0 2.25rem; }

.hero h1 {
  margin: 0 0 .5rem;
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 680;
  letter-spacing: -0.03em;
  text-align: center;
}

.contact {
  list-style: none;
  display: grid;
  gap: .3rem .5rem;
  font-size: .9rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
.contact li { display: flex; gap: .6rem; align-items: baseline; }
.contact .lbl {
  flex: 0 0 5.5rem;
  color: var(--fg-faint);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 600;
}
.contact a { border-bottom-color: transparent; }
.contact a:hover { border-bottom-color: currentColor; }

/* ---------- sections ---------- */
main section { padding: 2rem 0; border-top: 1px solid var(--rule); }
main section:first-child { border-top: 0; }

main h2 {
  margin: 0 0 1.35rem;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--fg-faint);
}

.section-note {
  margin: -0.75rem 0 1.5rem;
  font-size: .875rem;
  color: var(--fg-faint);
}

#about p { max-width: 46rem; font-size: 1.02rem; }

/* ---------- entries ---------- */
.entry { margin-bottom: 2.1rem; }
.entry:last-of-type { margin-bottom: 1rem; }

.entry-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .2rem;
}
.entry-head h3 {
  margin: 0;
  font-size: 1.075rem;
  font-weight: 640;
}
.period {
  margin-inline-start: auto;
  font-size: .8rem;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.entry-sub {
  margin: 0 0 .6rem;
  font-size: .875rem;
  color: var(--fg-muted);
}

.bullets { list-style: none; }
.bullets li {
  position: relative;
  padding-left: 1.1rem;
  margin-bottom: .35rem;
  font-size: .935rem;
}
.bullets li::before {
  content: "";
  position: absolute;
  left: .1rem;
  top: .68em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--rule-strong);
}

.links {
  margin: .6rem 0 0;
  font-size: .82rem;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1rem;
}
/* Monospaced URLs are long unbreakable tokens; allow them to break mid-word so a
   single link cannot push the whole page wider than the viewport. */
.links a { font-family: var(--font-mono); font-size: .95em; overflow-wrap: anywhere; min-width: 0; }

.also {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--rule);
  font-size: .875rem;
  color: var(--fg-muted);
  overflow-wrap: anywhere;
}

/* ---------- skills ---------- */
.skills { margin: 0; }
.skill-row {
  display: grid;
  grid-template-columns: 10.5rem 1fr;
  gap: 1rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--rule);
}
.skill-row:last-child { border-bottom: 0; }
.skill-row dt {
  font-size: .75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--fg-faint);
  padding-top: .18rem;
}
.skill-row dd { margin: 0; font-size: .935rem; }

/* ---------- placeholders ---------- */
.todo-inline {
  color: var(--todo);
  background: var(--todo-bg);
  border-bottom: 1px dashed var(--todo);
  border-radius: 3px;
  padding: .04em .3em;
  font-style: normal;
  font-size: .95em;
}
.placeholder-entry {
  border-left: 2px dashed var(--rule-strong);
  padding-left: 1.1rem;
}
.hint {
  font-size: .84rem;
  color: var(--fg-faint);
  font-style: italic;
  max-width: 40rem;
}

/* ---------- footer ---------- */
.site-footer {
  margin-top: 2rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--rule);
  background: var(--bg-soft);
  font-size: .875rem;
  color: var(--fg-muted);
}
.site-footer p { margin: 0 0 .35rem; }
.site-footer .sep { color: var(--fg-faint); margin-inline: .1rem; }
.site-footer .fine { font-size: .8rem; color: var(--fg-faint); }

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

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .wrap { padding-inline: 1.15rem; }
  .site-nav { display: none; }
  .header-inner { justify-content: space-between; }
  .controls { margin-inline-start: 0; }
  .hero { padding-top: 2.25rem; }
  .contact .lbl { flex-basis: 4.5rem; }
  .skill-row { grid-template-columns: 1fr; gap: .15rem; }
  .period { margin-inline-start: 0; flex-basis: 100%; }
}

/* ==========================================================================
   PRINT — this is the point of the page: Cmd/Ctrl+P yields a clean A4 CV.
   ========================================================================== */
@media print {
  /* The theme attribute selectors below outrank a bare :root, and `!important` on
     a custom property wins regardless of the caller's specificity — so printing
     from dark mode still yields black on white. */
  :root,
  html[data-theme="dark"],
  html[data-theme="light"],
  html:not([data-theme]) {
    --bg: #fff !important;
    --bg-soft: #fff !important;
    --fg: #000 !important;
    --fg-muted: #333 !important;
    --fg-faint: #555 !important;
    --rule: #bbb !important;
    --rule-strong: #999 !important;
    --accent: #000 !important;
    --todo: #000 !important;
    --todo-bg: transparent !important;
    --wrap: none;
  }

  @page { size: A4; margin: 12mm 14mm; }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 9.5pt;
    line-height: 1.33;
  }

  /* chrome away */
  .site-header, .site-nav, .controls, .hint, .placeholder-entry { display: none !important; }

  /* A section that is still nothing but prompts would otherwise print as a bare
     heading with no content beneath it. */
  .is-placeholder { display: none !important; }

  /* The first content section under the hero must not draw a second rule under
     the contact strip when the section in between is a hidden placeholder.
     Deliberately narrow: every other section keeps its separator. */
  .hero + section,
  .hero + .is-placeholder + section { border-top: 0 !important; }

  .wrap { max-width: none; padding: 0; }

  /* placeholders read as plain text on paper */
  .todo-inline {
    background: none !important;
    border: 0 !important;
    color: #000 !important;
    padding: 0 !important;
  }

  a { color: #000 !important; border-bottom: 0 !important; text-decoration: none; }

  p { margin-bottom: .4rem; }

  .hero { padding: 0 0 .45rem; }
  .hero h1 { font-size: 17pt; margin-bottom: .2rem; }
  .contact {
    border-top: 1px solid #000;
    padding-top: .4rem;
    grid-template-columns: 1fr 1fr;
    font-size: 8.5pt;
  }

  main section { padding: .38rem 0; border-top: 1px solid #999; }
  main h2 { font-size: 8pt; margin-bottom: .32rem; color: #000; }
  #about p { font-size: 9.4pt; }
  .section-note, .also { font-size: 8.4pt; }

  .entry { margin-bottom: .5rem; }
  .entry-head { margin-bottom: .05rem; }
  .entry-head h3 { font-size: 10.2pt; }
  .period { font-size: 8pt; color: #333; }
  .entry-sub { font-size: 8.4pt; margin-bottom: .18rem; }
  .bullets li { font-size: 8.8pt; margin-bottom: .05rem; padding-left: .8rem; }
  .bullets li::before { top: .58em; background: #666; }
  .links { font-size: 7.8pt; margin-top: .12rem; }

  .skill-row { padding: .14rem 0; grid-template-columns: 10.5rem 1fr; gap: .6rem; }
  .skill-row dt { font-size: 7.6pt; }
  .skill-row dd { font-size: 8.8pt; }

  .site-footer { margin-top: .4rem; padding: .5rem 0 0; background: none; font-size: 8.5pt; }
  .site-footer .fine { display: none; }

  /* keep entries and headings from splitting across pages */
  .entry, .skill-row, .contact { break-inside: avoid; page-break-inside: avoid; }
  main h2 { break-after: avoid; page-break-after: avoid; }
  h3 { break-after: avoid; page-break-after: avoid; }
  /* keep project entries whole too — an entry split across the page break leaves
     a stray bullet and its link line orphaned on the next page */
  #projects .entry { break-inside: avoid; page-break-inside: avoid; }
}
