/* ==========================================================================
   Thanathai Lertpetchpun — site styles

   Hand-written CSS, no framework. Nearly everything is driven by the custom
   properties in the "Tokens" block, so changing the look usually means
   editing a value there rather than hunting through rules.

   Dark is the default theme. Light is opt-in: the toggle writes
   data-theme="light" on <html> and remembers it.

   Structure:
     1. Tokens
     2. Reset
     3. Typography
     4. Layout        the sidebar + content frame
     5. Sidebar
     6. Content       section headings, prose
     7. Home page     news, projects, awards, service
     8. Publications
     9. Print
   ========================================================================== */

/* 1. Tokens =============================================================== */

:root {
  /* Dark — the default. */
  --bg: #141619;
  --panel: #0f1113;
  --raised: #191c20;
  --fg: #f0f2f5;
  --body: #a9b2bb;
  --muted: #6e7781;
  --line: #242930;
  --line-strong: #333a42;
  --accent: #e4737b;
  --accent-hover: #f09098;
  --accent-faint: rgba(228, 115, 123, 0.32);
  --self: #e4737b;
  --selection: rgba(228, 115, 123, 0.25);
  --photo-filter: brightness(0.95) saturate(0.95);

  /* Type */
  --font: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --size-base: 1.0313rem; /* 16.5px */
  --size-small: 0.9375rem;
  --size-label: 0.72rem;
  --leading: 1.72;

  /* Layout */
  --sidebar-width: 17.5rem;
  --content-max: 46rem;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f6f7f8;
  --raised: #fbfbfc;
  --fg: #1b1f23;
  --body: #41474d;
  --muted: #8a9199;
  --line: #e6e9ec;
  --line-strong: #d2d7dc;
  --accent: #9b2226;
  --accent-hover: #7d1b1e;
  --accent-faint: rgba(155, 34, 38, 0.3);
  --self: #9b2226;
  --selection: rgba(155, 34, 38, 0.14);
  --photo-filter: none;
}

/* 2. Reset ================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
}

body,
h1,
h2,
h3,
p,
ul,
ol,
li,
figure {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

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

/* 3. Typography =========================================================== */

body {
  background: var(--bg);
  color: var(--body);
  overflow-wrap: break-word;
  font-family: var(--font);
  font-size: var(--size-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  color: var(--fg);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.012em;
}

p + p {
  margin-top: 0.9em;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-faint);
  transition: color 0.15s ease, border-color 0.15s ease;
}

a:hover {
  color: var(--accent-hover);
  border-bottom-color: currentColor;
}

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

strong {
  color: var(--fg);
  font-weight: 600;
}

/* The site owner's name inside an author list. */
.self {
  color: var(--self);
  font-weight: 600;
}

/* The small uppercase voice: section headings, dates, venues, tags. */
.label {
  font-size: var(--size-label);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* 4. Layout =============================================================== */

.layout {
  display: grid;
  min-height: 100vh;
}

@media (min-width: 60rem) {
  .layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
}

.content {
  min-width: 0;
  padding: 3rem 1.5rem 4.5rem;
  max-width: calc(var(--content-max) + 7rem);
}

@media (min-width: 40rem) {
  .content {
    padding: 3.25rem 3.5rem 5.5rem;
  }
}

/* 5. Sidebar ============================================================== */

.sidebar {
  min-width: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 2.25rem 1.5rem;
}

@media (min-width: 60rem) {
  .sidebar {
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding: 3rem 2rem;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    overflow-y: auto;
  }
}

.sidebar__photo {
  width: 122px;
  height: 122px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  margin-bottom: 1.4rem;
  filter: var(--photo-filter);
}

.sidebar__name {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.018em;
  line-height: 1.22;
}

.sidebar__name a {
  color: inherit;
  border: 0;
}

.sidebar__name a:hover {
  color: var(--accent);
}

.sidebar__pron {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.sidebar__role {
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 1rem;
}

.sidebar__role b {
  display: block;
  color: var(--fg);
  font-weight: 600;
}

.sidebar__group {
  margin-top: 1.5rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.5rem;
  font-size: 0.875rem;
}

/* Link rows: label on the left, a quiet hint right-aligned. */
.sidebar__group a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  color: var(--body);
  border: 0;
}

.sidebar__group a:hover {
  color: var(--accent);
}

.sidebar__group a .hint {
  color: var(--muted);
  font-size: 0.78rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__nav a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

.sidebar__foot {
  margin-top: 1.5rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
}

.sidebar__foot p + p {
  margin-top: 0.2rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.15s ease;
}

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

.theme-toggle svg {
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
}

.theme-toggle .icon-sun {
  display: block;
}

.theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* The label names the theme you would switch TO. Both words are in the
   markup and CSS picks one, so the button is right before JavaScript runs. */
.theme-toggle .t-dark {
  display: none;
}

:root[data-theme="light"] .theme-toggle .t-light {
  display: none;
}

:root[data-theme="light"] .theme-toggle .t-dark {
  display: inline;
}

/* 6. Content ============================================================== */

.section + .section {
  margin-top: 2.75rem;
}

.section > h2 {
  font-size: var(--size-label);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}

.prose {
  max-width: var(--content-max);
}

/* 7. Home page ============================================================ */

.news {
  display: grid;
  gap: 0.85rem;
  max-width: var(--content-max);
}

.news li {
  display: grid;
  gap: 0.1rem 1.2rem;
  font-size: var(--size-small);
}

@media (min-width: 32rem) {
  .news li {
    grid-template-columns: 5.6rem 1fr;
  }
}

.news .date {
  color: var(--muted);
  font-size: 0.82rem;
  padding-top: 0.15rem;
  white-space: nowrap;
}

/* Projects are a horizontal track you can swipe, drag or arrow through.
   It only ever scrolls when the cards do not fit; with two cards on a wide
   screen they simply sit side by side and the arrows stay hidden. */
.projects {
  display: flex;
  gap: 1.25rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 0.9rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.projects:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

/* No scroll-snap here on purpose. The cards are wide enough that the whole
   scroll range can be shorter than a single card, which puts a snap point
   past the end of the track; the browser then clamps to it and fights both
   the arrows and the user. A plain scroller behaves predictably. */
.projects > .project {
  flex: 0 0 min(21rem, 84%);
}

.projects::-webkit-scrollbar {
  height: 6px;
}

.projects::-webkit-scrollbar-track {
  background: transparent;
}

.projects::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

.projects:hover::-webkit-scrollbar-thumb {
  background: var(--line-strong);
}

/* Arrows are revealed by JavaScript only when the track overflows, so a
   mouse user is never shown a control that does nothing. */
.slider-nav {
  display: none;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.projects-wrap.is-scrollable .slider-nav {
  display: flex;
}

.slider-btn {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--raised);
  color: var(--body);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.slider-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.slider-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.slider-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

.project {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.3rem;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 5px;
  transition: border-color 0.2s ease;
}

.project:hover {
  border-color: var(--line-strong);
}

.project h3 {
  font-size: 1rem;
}

.project__period {
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.project ul {
  margin-top: 0.9rem;
  flex: 1 1 auto;
  display: grid;
  align-content: start;
  gap: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.55;
}

.project ul li {
  position: relative;
  padding-left: 0.9rem;
}

.project ul li::before {
  content: "·";
  position: absolute;
  left: 0.15rem;
  color: var(--accent);
  font-weight: 700;
}

.project__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.tag {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0.08rem 0.4rem;
  white-space: nowrap;
}

.awards {
  max-width: var(--content-max);
}

.awards li {
  display: grid;
  gap: 0.1rem 1.5rem;
  padding-block: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.awards li:first-child {
  padding-top: 0;
}

.awards li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

@media (min-width: 34rem) {
  .awards li {
    grid-template-columns: 1fr auto;
    align-items: baseline;
  }
  .awards li .date {
    grid-column: 2;
    grid-row: 1;
  }
  .awards li p {
    grid-column: 1;
  }
}

.awards h3 {
  font-size: 0.975rem;
}

.awards p {
  font-size: var(--size-small);
}

.awards .date {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.service-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
  font-size: var(--size-small);
}

.service-list li {
  position: relative;
  padding-left: 0.9rem;
}

.service-list li::before {
  content: "·";
  position: absolute;
  left: 0.15rem;
  color: var(--accent);
  font-weight: 700;
}

/* 8. Publications ========================================================= */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-bottom: 1.1rem;
  margin-bottom: 2.25rem;
  border-bottom: 1px solid var(--line);
  max-width: var(--content-max);
}

.page-head h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.pub-year {
  max-width: var(--content-max);
}

.pub-year + .pub-year {
  margin-top: 2.5rem;
}

.pub-year > h2 {
  font-size: var(--size-label);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
  font-variant-numeric: tabular-nums;
}

.pub {
  padding-block: 1rem;
  border-top: 1px solid var(--line);
}

.pub:first-child {
  border-top: 0;
  padding-top: 0;
}

.pub__title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.42;
}

.pub__title a {
  color: var(--fg);
  border-bottom-color: transparent;
}

.pub__title a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent-faint);
}

.pub__authors {
  font-size: 0.875rem;
  line-height: 1.55;
  margin-top: 0.22rem;
}

.pub__venue {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* 9. Print ================================================================ */

@media print {
  :root {
    --bg: #fff;
    --panel: #fff;
    --raised: #fff;
    --fg: #000;
    --body: #222;
    --muted: #555;
    --line: #ccc;
    --accent: #000;
    --self: #000;
    --photo-filter: none;
  }

  .layout {
    display: block;
  }

  .sidebar {
    border: 0;
    position: static;
    max-height: none;
    padding: 0 0 1.5rem;
  }

  .theme-toggle {
    display: none;
  }

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

  .project,
  .pub {
    break-inside: avoid;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
