/* ============================================================
   Tufte-Inspired Academic Stylesheet
   Can Konuk — Personal Research Website

   Layout: 60% main column + right margin for sidenotes
   Typography: Source Serif 4 (body) + Source Sans 3 (UI)
   Colors: light-dark() for automatic light/dark theming
   ============================================================ */

/* --- Reset & Base --- */

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

::selection {
  background: light-dark(rgba(139, 37, 0, 0.12), rgba(232, 119, 90, 0.2));
  color: inherit;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 18px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- CSS Custom Properties --- */

:root {
  --bg:          light-dark(#fdfbf7, #1a1a28);
  --fg:          light-dark(#1a1a1a, #dcdcdc);
  --fg-muted:    light-dark(#5c5c5c, #9a9aaa);
  --accent:      light-dark(#8b2500, #e8775a);
  --accent-hover: light-dark(#6b1a00, #f09878);
  --border:      light-dark(#d8d0c0, #30304a);
  --bg-code:     light-dark(#f3ede4, #242440);
  --bg-sidenote: light-dark(#f6f2ea, #222238);
  --bg-equation: light-dark(#f8f4ec, #222238);
  --header-rule: light-dark(#c4bca8, #383858);
}


/* --- Layout --- */

article {
  max-width: 52rem;
  margin: 0 auto;
  padding: 3rem 2rem 5rem;
  position: relative;
}

/* The main content column. */
section {
  width: 100%;
  margin-bottom: 1rem;
}

/* On narrow screens, sections go full width and sidenotes
   become inline footnotes (handled below in @media). */


/* --- Typography --- */

h1 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1.1;
  margin: 0 0 0.3rem;
  letter-spacing: -0.02em;
  color: var(--fg);
}

h2 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.7rem;
  font-weight: 600;
  margin: 4rem 0 1.2rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  letter-spacing: -0.01em;
}

h3 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 600;
  font-style: italic;
  margin: 2.2rem 0 0.8rem;
  color: var(--fg);
}

h4 {
  font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

p {
  margin: 0 0 1.25rem;
}

em {
  font-style: italic;
}

strong {
  font-weight: 600;
}

blockquote {
  margin: 1.5rem 0 1.5rem 1.5rem;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
  font-style: italic;
}


/* --- Links --- */

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}


/* --- Header --- */

header {
  width: 100%;
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--header-rule);
  display: flex;
  align-items: center;
  gap: 2rem;
}

header .portrait {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

header .portrait:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  transform: translateY(-2px);
}

header .header-text {
  flex: 1;
}

.subtitle {
  font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
  font-size: 1.05rem;
  color: var(--fg-muted);
  margin: 0.35rem 0 0.7rem;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.header-links {
  font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.header-links a {
  color: var(--accent);
}

.header-links .sep {
  color: var(--fg-muted);
  user-select: none;
}


/* --- Theme Toggle --- */

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--fg-muted);
  font-family: 'Source Sans 3', sans-serif;
  transition: border-color 0.2s, color 0.2s;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--fg);
}


/* --- About Section --- */

#about {
  padding-bottom: 1rem;
}

#about p {
  font-size: 1.05rem;
  color: var(--fg);
}

#about p:first-of-type {
  font-size: 1.08rem;
}


/* --- Drop Cap (Research section opening) --- */

#research > p:first-of-type::first-letter {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 3.5rem;
  font-weight: 700;
  float: left;
  line-height: 0.8;
  margin-right: 0.12em;
  margin-top: 0.08em;
  color: var(--accent);
}


/* --- Section Separators --- */

#publications::before,
#models::before {
  content: '* * *';
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: var(--border);
  margin-bottom: 1.5rem;
  letter-spacing: 0.6em;
  font-family: 'Source Serif 4', Georgia, serif;
}


/* --- Sidenotes & Margin Notes ---
   Tufte's signature feature. Sidenotes are numbered;
   margin notes are unnumbered. Both float in the right
   margin on wide screens. */

.sidenote,
.marginnote {
  float: right;
  clear: right;
  width: 55%;             /* of the parent, which is ~60% of page */
  margin-right: -62%;     /* push into the right margin */
  margin-bottom: 1rem;
  padding: 0.4rem 0;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--fg-muted);
  vertical-align: baseline;
  position: relative;
}

.sidenote-number {
  font-size: 0.75rem;
  position: relative;
  top: -0.4em;
  color: var(--accent);
  font-weight: 600;
  cursor: default;
}

.sidenote::before {
  content: counter(sidenote-counter) " ";
  font-size: 0.75rem;
  position: relative;
  top: -0.4em;
  color: var(--accent);
  font-weight: 600;
}

/* Counter for sidenotes */
article {
  counter-reset: sidenote-counter;
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number::after {
  content: counter(sidenote-counter);
}

/* Margin toggle checkbox (for mobile sidenote collapse) */
input.margin-toggle {
  display: none;
}

label.margin-toggle {
  display: none;
}


/* --- Figures --- */

figure {
  margin: 2.2rem auto;
  padding: 0;
  text-align: center;
}

figure img,
figure svg,
figure object {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

figure:hover img,
figure:hover svg,
figure:hover object {
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Blend mode: multiply makes white areas in figures transparent
   against the cream page background (white × cream = cream).
   Colored content is barely affected on a near-white background. */
figure img {
  mix-blend-mode: multiply;
}

/* In dark mode, use filter inversion to adapt figures:
   - invert(0.88): white (255) → ~31, matching our dark bg (~30)
   - hue-rotate(180deg): corrects color shift from inversion
   This makes white backgrounds dark, black text light, and
   preserves colored content (red→red, blue→blue). */
[data-theme="dark"] figure img {
  mix-blend-mode: normal;
  filter: invert(0.88) hue-rotate(180deg);
}

figcaption {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--fg-muted);
  margin-top: 0.8rem;
  text-align: left;
  padding: 0.6rem 0 0;
  border-top: 1px solid var(--border);
}

figcaption strong {
  color: var(--fg);
  font-weight: 600;
  display: block;
  margin-bottom: 0.15rem;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}

/* Full-width figures span into the margin area on wide screens,
   but are clamped so they never cause horizontal overflow. */
figure.fullwidth {
  width: calc(100% + 8rem);
  max-width: 90vw;
  clear: both;
}

/* Margin figures sit in the right margin alongside text. */
figure.margin-figure {
  float: right;
  clear: right;
  width: 55%;
  margin-right: -62%;
  margin-bottom: 1rem;
  margin-top: 0;
}

figure.margin-figure figcaption {
  font-size: 0.8rem;
}


/* --- Equation Blocks --- */

.equation-block {
  background: var(--bg-equation);
  padding: 1.4rem 2rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  overflow-x: auto;
  margin: 2rem auto;
  max-width: fit-content;
  min-width: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  text-align: center;
}


/* --- Publications --- */

.pub-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.pub-list li {
  margin-bottom: 0;
  padding: 1.1rem 0;
  padding-left: 5.5rem;
  text-indent: -5.5rem;
  font-size: 0.95rem;
  line-height: 1.65;
  border-bottom: 1px solid var(--border);
}

.pub-list li:last-child {
  border-bottom: none;
}

.pub-list .venue {
  font-style: italic;
  color: var(--fg-muted);
}

.pub-list .year {
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 1rem;
  display: inline-block;
  min-width: 4.2rem;
}

.pub-list a {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.78rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-left: 0.3rem;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pub-list a:hover {
  text-decoration: none;
  background: var(--bg-sidenote);
  border-color: var(--accent);
}


/* --- Interactive Models --- */

.model-list {
  list-style: none;
  padding: 0;
}

.model-list li {
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  background: var(--bg-sidenote);
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.model-list li:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.model-list li strong {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.model-list .model-desc {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.88rem;
  color: var(--fg-muted);
  line-height: 1.5;
}

.model-list .model-links {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.model-list .model-links a {
  font-size: 0.82rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.model-list .model-links a:hover {
  text-decoration: none;
  background: var(--bg-equation);
  border-color: var(--accent);
}


/* --- Footer --- */

footer {
  width: 100%;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.88rem;
  color: var(--fg-muted);
  letter-spacing: 0.01em;
}


/* --- Part Headings --- */

h3.part-heading {
  font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 3.5rem 0 1.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}


/* --- Collapsible Sections --- */

details {
  margin: 1.5rem 0;
  border-left: 3px solid transparent;
  padding-left: 0;
  transition: border-color 0.25s ease, padding-left 0.25s ease;
}

details[open] {
  border-left-color: var(--accent);
  padding-left: 1.2rem;
}

details > summary {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  font-style: italic;
  color: var(--fg);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.8rem;
  user-select: none;
  transition: color 0.15s ease;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::before {
  content: '▸';
  font-size: 0.85rem;
  color: var(--accent);
  transition: transform 0.25s ease;
  display: inline-block;
  width: 1em;
  flex-shrink: 0;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

details > summary:hover {
  color: var(--accent);
}

details > summary:focus {
  outline: none;
}

details > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Brief preview text shown when collapsed */
.section-preview {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.9rem;
  color: var(--fg-muted);
  margin-top: -0.4rem;
  margin-bottom: 0.5rem;
  font-style: italic;
  line-height: 1.5;
}

details:not([open]) .section-preview {
  display: block;
}

details[open] .section-preview {
  display: none;
}

/* Content inside details */
.detail-content {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}


/* --- KaTeX Overrides --- */

.katex {
  font-size: 1.05em;
}


/* ============================================================
   Responsive Design
   ============================================================ */

/* Tablets and small desktops */
@media (max-width: 1100px) {
  figure.fullwidth {
    width: 100%;
  }
}

/* Mobile: sidenotes collapse inline */
@media (max-width: 768px) {
  article {
    padding: 1.5rem 1.2rem 3rem;
  }

  details[open] {
    padding-left: 0.8rem;
  }

  section,
  header,
  footer {
    width: 100%;
    padding-right: 0;
  }

  h1 { font-size: 1.9rem; }
  h2 { font-size: 1.35rem; }

  /* Sidenotes become inline blocks on mobile */
  label.margin-toggle {
    display: inline;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.8rem;
    position: relative;
    top: -0.3em;
    font-weight: 600;
  }

  .sidenote,
  .marginnote {
    display: none;
    float: none;
    width: 100%;
    margin: 0.8rem 0;
    padding: 0.8rem 1rem;
    background: var(--bg-sidenote);
    border-left: 3px solid var(--border);
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
  }

  /* Show sidenote when checkbox is toggled */
  input.margin-toggle:checked + .sidenote,
  input.margin-toggle:checked + .marginnote {
    display: block;
  }

  figure.fullwidth,
  figure.margin-figure {
    width: 100%;
    float: none;
    margin-right: 0;
  }

  .equation-block {
    padding: 0.8rem;
    font-size: 0.9rem;
  }

  header {
    flex-direction: column;
    text-align: center;
  }

  header .portrait {
    width: 100px;
    height: 100px;
  }

  .header-links {
    justify-content: center;
  }
}

/* Small phones */
@media (max-width: 480px) {
  body {
    font-size: 16px;
  }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.2rem; }

  .pub-list li {
    padding-left: 0;
    text-indent: 0;
  }

  .pub-list .year {
    display: block;
    margin-bottom: 0.2rem;
  }
}

/* Wide screens: allow figures to break out of the text column */
@media (min-width: 1000px) {
  figure {
    margin-left: -2rem;
    margin-right: -2rem;
  }
}
