/* ===== Custom Properties ===== */
:root {
  --bg: #fafaf7;
  --bg-secondary: #f2f1ed;
  --text: #1a1a1a;
  --text-secondary: #555;
  --text-muted: #888;
  --link: #0055cc;
  --link-hover: #003d99;
  --border: #e0ddd8;
  --selection-bg: rgba(0, 100, 255, 0.15);
  --tag-bg: #eee;
  --tag-text: #555;
}

[data-theme="dark"] {
  --bg: #161618;
  --bg-secondary: #1e1e22;
  --text: #e0ddd8;
  --text-secondary: #9a978f;
  --text-muted: #6b6860;
  --link: #6cb4ff;
  --link-hover: #9ccbff;
  --border: #2a2a30;
  --selection-bg: rgba(108, 180, 255, 0.2);
  --tag-bg: #2a2a30;
  --tag-text: #9a978f;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.3s ease;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.2s;
}

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

strong {
  font-weight: 600;
}

/* ===== Layout ===== */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px;
  padding-top: 100px;
  padding-bottom: 60px;
}

/* ===== Header / Navigation ===== */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease;
}

.nav {
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  transition: opacity 0.2s;
}

.logo-link:hover {
  opacity: 0.6;
  color: var(--text);
}

.km-logo {
  width: 48px;
  height: 30px;
  flex-shrink: 0;
}

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

.nav-right a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

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


.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  border-radius: 4px;
}

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

/* Show/hide sun and moon icons based on theme */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ===== Section Rules ===== */
.section-rule {
  border: none;
  border-top: 1px solid var(--border);
  margin: 48px 0;
}

/* ===== Bio ===== */
.bio {
  padding-top: 12px;
}

.bio-name {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 2.2rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.03em;
  margin-bottom: 20px;
  text-wrap: balance;
}

.bio p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 16px;
}

.bio p:last-child {
  margin-bottom: 0;
}

.bio strong {
  color: var(--text);
}

.bio-cv-link {
  margin-top: 20px;
}

.bio-cv-link a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--link);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, color 0.2s;
}

.bio-cv-link a:hover {
  border-bottom-color: var(--link-hover);
}

/* ===== Section Headings ===== */
section h2 {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.subsection {
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 32px;
  margin-bottom: 12px;
}

.section-intro {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.7;
}

/* ===== Essays ===== */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.entry {}

.entry-meta time {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.entry h3 {
  margin-top: 4px;
  margin-bottom: 6px;
}

.entry-link {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.entry-link:hover {
  color: var(--link);
}

.placeholder-link {
  cursor: default;
}

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

.entry-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

/* ===== Short Posts (compact list) ===== */
.entry-list.compact {
  gap: 0;
}

.entry-compact {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.entry-compact:first-child {
  border-top: 1px solid var(--border);
}

.entry-compact time {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 90px;
  font-variant-numeric: tabular-nums;
}

.entry-compact a {
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
}

.entry-compact a:not(.placeholder-link):hover {
  color: var(--link);
}

/* ===== Publications ===== */
.pub-list {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.pub {
  padding-left: 16px;
  border-left: 2px solid var(--border);
}

.pub-title {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  font-weight: 500;
  font-style: italic;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 4px;
}

.pub-authors {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.pub-authors strong {
  color: var(--text);
}

.pub-venue {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.pub-venue strong {
  color: var(--text-secondary);
}

.tag-review {
  display: inline-block;
  padding: 1px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
  vertical-align: middle;
}

.pub-link {
  font-size: 0.85rem;
}

.research-areas {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* ===== Experience ===== */
.exp-list {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.exp {}

.exp-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.exp-header h3 {
  font-size: 0.95rem;
}

.exp-company {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.exp-company::before {
  content: "at ";
}

.exp time {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.exp ul {
  list-style: none;
  padding: 0;
}

.exp li {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
  padding-left: 16px;
  position: relative;
  margin-bottom: 4px;
}

.exp li::before {
  content: "\2022";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

/* ===== Education ===== */
.edu-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.edu-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.edu-header time {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.edu p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.edu-detail {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Awards ===== */
.awards-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.award h3 {
  margin-bottom: 6px;
}

.award p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

/* ===== Skills ===== */
.skills-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.skill-group h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.skill-group p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Projects ===== */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.project-item {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

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

.project-item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.project-item-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.project-item-header a {
  font-size: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  flex-shrink: 0;
  transition: color 0.2s;
}

.project-item:hover .project-item-header a {
  color: var(--link);
}

.project-item p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 10px;
}

.project-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.project-tags span {
  padding: 2px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Writing Section ===== */
.writing-title {
  display: flex;
  align-items: baseline;
  gap: 0;
}

.cursor-blink {
  color: var(--link);
  font-weight: 300;
  animation: cursorBlink 1s step-end infinite;
  margin-left: 1px;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.featured-essay {
  display: block;
  padding: 28px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 36px;
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.featured-essay:hover {
  border-color: var(--text-muted);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  color: inherit;
}

[data-theme="dark"] .featured-essay:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.featured-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--link);
  margin-bottom: 12px;
}

.featured-title {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}

.featured-tagline {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.featured-read {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--link);
  transition: color 0.2s;
}

.featured-essay:hover .featured-read {
  color: var(--link-hover);
}

/* ===== Sidenotes (Tufte-style) ===== */
.sidenote-wrapper {
  position: relative;
}

.sn-num {
  font-size: 0.7em;
  color: var(--link);
  cursor: pointer;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
}

.sidenote {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  transition: opacity 0.2s ease;
}

.sidenote sup {
  font-size: 0.75em;
  color: var(--link);
  margin-right: 3px;
}

/* Wide screens: margin notes */
@media (min-width: 1100px) {
  .sn-num {
    cursor: default;
  }

  .sidenote {
    float: right;
    clear: right;
    margin-right: -220px;
    width: 180px;
    margin-top: 0;
    margin-bottom: 12px;
    position: relative;
  }
}

/* Left sidenotes: author's witty asides */
.sidenote-left {
  font-style: italic;
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
}

/* Wide screens: left margin notes */
@media (min-width: 1100px) {
  .sidenote-left {
    float: left;
    clear: left;
    margin-left: -220px;
    margin-right: 0;
    width: 180px;
  }
}

/* Narrow screens: inline toggle */
@media (max-width: 1099px) {
  .sidenote {
    display: none;
    background: var(--bg-secondary);
    padding: 10px 14px;
    border-radius: 4px;
    margin: 8px 0;
  }

  .sidenote.active {
    display: block;
  }
}

/* ===== Temperature Slider ===== */
.opinions-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.opinions-header h2 {
  margin-bottom: 0;
}

.temp-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.temp-label {
  font-family: 'Inter', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.temp-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  outline: none;
  cursor: pointer;
}

.temp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--link);
  cursor: pointer;
  border: none;
}

.temp-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--link);
  cursor: pointer;
  border: none;
}

[data-temp] {
  transition: opacity 0.25s ease;
}

.essay-excerpt {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 0.88rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 8px;
}

/* ===== Essay Page ===== */
.essay {
  padding-top: 12px;
}

.essay-header {
  margin-bottom: 48px;
}

.essay-back {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: inline-block;
  margin-bottom: 32px;
  transition: color 0.2s;
}

.essay-back:hover {
  color: var(--link);
}

.essay-title {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 2.4rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 8px;
  text-wrap: balance;
}

.essay-subtitle {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.essay-date {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: block;
}

.essay-author {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.essay-body p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.85;
  margin-bottom: 20px;
}

.essay-body p em {
  color: var(--text);
  font-style: italic;
}

.essay-body p strong {
  color: var(--text);
  font-weight: 600;
}

.essay-break {
  border: none;
  text-align: center;
  margin: 36px 0;
}

.essay-break::after {
  content: "\2022\2009\2022\2009\2022";
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.2em;
}

@media (max-width: 600px) {
  .essay-title {
    font-size: 1.8rem;
  }

  .essay-subtitle {
    font-size: 1rem;
  }

  .essay-body p {
    font-size: 0.9rem;
    line-height: 1.8;
  }
}

/* ===== Footer ===== */
footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-links {
  margin-bottom: 12px;
}

.footer-links a {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.footer-links a:hover {
  color: var(--link);
}

.footer-dot {
  color: var(--text-muted);
  margin: 0 8px;
  font-size: 0.8rem;
}

.footer-copy {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  main {
    padding-top: 80px;
  }

  .nav-right {
    gap: 16px;
  }

  .nav-right a {
    font-size: 0.8rem;
  }

  section h2 {
    font-size: 1.3rem;
  }

  .entry-link {
    font-size: 1.05rem;
  }

  .entry-compact {
    flex-direction: column;
    gap: 2px;
  }

  .entry-compact time {
    min-width: auto;
  }

  .edu-header {
    flex-direction: column;
    gap: 2px;
  }

  .exp-header {
    flex-direction: column;
    gap: 0;
  }

  .section-rule {
    margin: 36px 0;
  }
}
