/* ==========================================================================
   Tharusha Perera · Portfolio
   Minimal academic theme: paper-light by default, dark mode via toggle.
   ========================================================================== */

:root {
  --bg: #faf8f4;
  --bg-elevated: #ffffff;
  --bg-inset: #f2efe8;
  --text: #201d1a;
  --text-muted: #625d55;
  --text-faint: #8b857a;
  --border: #e4ded2;
  --accent: #1e4d8b;
  --accent-strong: #163a6b;
  --accent-tint: #e8eff8;
  --focus-ring: #1e4d8b;
  --shadow: 0 1px 2px rgba(32, 29, 26, 0.04), 0 8px 24px rgba(32, 29, 26, 0.05);
  --radius-s: 6px;
  --radius-m: 10px;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --content-width: 740px;
  --sidebar-width: 300px;
}

:root[data-theme="dark"] {
  --bg: #16161a;
  --bg-elevated: #1d1e23;
  --bg-inset: #202127;
  --text: #ece8e1;
  --text-muted: #a8a29a;
  --text-faint: #7a756d;
  --border: #302f35;
  --accent: #7fb2e8;
  --accent-strong: #a9cef0;
  --accent-tint: #17232f;
  --focus-ring: #7fb2e8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a;
    --bg-elevated: #1d1e23;
    --bg-inset: #202127;
    --text: #ece8e1;
    --text-muted: #a8a29a;
    --text-faint: #7a756d;
    --border: #302f35;
    --accent: #7fb2e8;
    --accent-strong: #a9cef0;
    --accent-tint: #17232f;
    --focus-ring: #7fb2e8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a {
  color: var(--accent);
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}

a:hover,
a:focus-visible {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

p {
  margin: 0 0 1em;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  z-index: 1000;
  border-radius: 0 0 var(--radius-s) 0;
}

.skip-link:focus {
  left: 0;
}

/* ---------- Layout shell ---------- */

.shell {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  flex: 0 0 var(--sidebar-width);
  padding: 56px 32px 40px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 28px;
  flex: 1;
  min-height: 0;
}

.menu-toggle {
  display: none;
}

.identity {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.identity .sidebar-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--text);
}

.identity .role {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.45;
}

.identity .affil {
  color: var(--text-faint);
  font-size: 0.85rem;
  margin: 0;
}

.identity .affil a {
  color: inherit;
}

.contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-elevated);
  transition: all 0.15s ease;
}

.icon-link:hover,
.icon-link:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.icon-link svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.cv-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: #fff !important;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--accent);
  transition: all 0.15s ease;
}

.cv-button:hover,
.cv-button:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.sidebar-nav a {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 7px 0;
  text-decoration: none;
  position: relative;
  padding-left: 16px;
}

.sidebar-nav a::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 1px;
  background: var(--text-faint);
  transition: all 0.15s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--accent);
}

.sidebar-nav a:hover::before,
.sidebar-nav a.active::before {
  width: 10px;
  background: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.theme-toggle svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.sidebar-footer .credit {
  font-size: 0.72rem;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ---------- Main content ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 64px 40px 40px;
}

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

section {
  padding-top: 20px;
  margin-bottom: 76px;
  scroll-margin-top: 24px;
}

.section-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
  display: block;
}

.section-title {
  font-size: 1.7rem;
  margin: 0 0 28px;
}

/* ---------- Hero ---------- */

.hero {
  margin-bottom: 84px;
  padding-top: 0;
}

.hero .kicker {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 14px;
}

.hero h1 {
  font-size: clamp(2rem, 4vw, 2.7rem);
  margin: 0 0 18px;
  letter-spacing: -0.015em;
}

.hero p.lede {
  font-size: 1.12rem;
  color: var(--text-muted);
  max-width: 62ch;
}

.hero .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-top: 32px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.stat b {
  display: block;
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--text);
}

.stat span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.interest-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

/* ---------- Tags / chips ---------- */

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-elevated);
  white-space: nowrap;
}

.tag.accent {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

/* ---------- Publication ---------- */

.publication {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elevated);
  padding: 30px 32px;
  box-shadow: var(--shadow);
}

.publication .venue-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-tint);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 16px;
}

.publication h3 {
  font-size: 1.3rem;
  margin: 0 0 10px;
  line-height: 1.35;
}

.publication .authors {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.publication .authors .me {
  color: var(--text);
  font-weight: 600;
}

.publication .venue-line {
  font-size: 0.88rem;
  color: var(--text-faint);
  font-style: italic;
  margin-bottom: 18px;
}

.result-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 20px 0;
}

.result-pill {
  flex: 1 1 140px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
  padding: 12px 14px;
}

.result-pill b {
  display: block;
  font-family: var(--serif);
  font-size: 1.2rem;
}

.result-pill span {
  font-size: 0.76rem;
  color: var(--text-muted);
}

details.abstract {
  margin: 18px 0 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

details.abstract summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  list-style: none;
}

details.abstract summary::-webkit-details-marker {
  display: none;
}

details.abstract summary::before {
  content: "+ ";
}

details.abstract[open] summary::before {
  content: "\2212 ";
}

details.abstract p {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.publication .pub-links {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pub-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.pub-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Projects ---------- */

.project-group {
  margin-bottom: 40px;
}

.project-group:last-child {
  margin-bottom: 0;
}

.project-group h3 {
  font-size: 1rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  color: var(--text-faint);
  margin: 0 0 16px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.project-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elevated);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.project-card .status {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.project-card h4 {
  font-size: 1.05rem;
  margin: 0;
  line-height: 1.35;
}

.project-card .desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  flex-grow: 1;
}

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

.project-card .links {
  display: flex;
  gap: 12px;
  margin-top: 2px;
}

.project-card .links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
}

.project-card .links a:hover {
  color: var(--accent);
}

.project-card .links svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

/* ---------- Timeline (experience) ---------- */

.timeline-group {
  margin-bottom: 32px;
}

.timeline-group:last-child {
  margin-bottom: 0;
}

.timeline-org {
  font-size: 0.98rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.timeline-org .org-time {
  font-weight: 400;
  color: var(--text-faint);
  font-size: 0.82rem;
  font-family: var(--mono);
  margin-left: 8px;
}

.timeline-list {
  border-left: 1px solid var(--border);
  margin-top: 14px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.timeline-item {
  position: relative;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.timeline-item .role {
  font-weight: 600;
  font-size: 0.95rem;
}

.timeline-item .item-time {
  font-weight: 400;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  margin-left: 6px;
  white-space: nowrap;
}

.timeline-item .role-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 3px;
}

/* ---------- Education ---------- */

.edu-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elevated);
  padding: 24px 26px;
  margin-bottom: 16px;
}

.edu-item:last-child {
  margin-bottom: 0;
}

.edu-item .edu-time {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
}

.edu-item h3 {
  font-size: 1.1rem;
  margin: 6px 0 4px;
}

.edu-item .edu-org {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 10px;
}

.gpa-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 12px 0;
  font-size: 0.86rem;
}

.gpa-row span b {
  color: var(--text);
}

.coursework {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ---------- Skills ---------- */

.skills-table {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.skills-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

.skills-row:last-child {
  border-bottom: none;
}

.skills-row .cat {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-faint);
}

.skills-row .items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Certifications & Awards ---------- */

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.two-col h3 {
  font-size: 1rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  color: var(--text-faint);
  margin: 0 0 14px;
}

.mini-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mini-list li {
  font-size: 0.92rem;
  border-left: 2px solid var(--border);
  padding-left: 12px;
}

.mini-list li b {
  display: block;
  color: var(--text);
}

.mini-list li span {
  color: var(--text-faint);
  font-size: 0.82rem;
}

/* ---------- Updates ---------- */

.updates-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.updates-list li {
  display: flex;
  gap: 20px;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}

.updates-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.updates-date {
  flex: 0 0 100px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
}

.updates-text {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---------- Contact ---------- */

.contact-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elevated);
  padding: 40px;
  text-align: left;
}

.contact-card p.lede {
  color: var(--text-muted);
  max-width: 55ch;
  margin-bottom: 24px;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.contact-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}

.contact-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.contact-links a.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.contact-links a.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

footer.page-footer {
  padding: 24px 0 60px;
  color: var(--text-faint);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* ---------- Reveal-on-scroll ---------- */

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.active {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Responsive ---------- */

body.no-scroll {
  overflow: hidden;
}

@media (max-width: 960px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    height: auto;
    overflow: visible;
    width: 100%;
    padding: 0;
    gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 100;
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 20px;
  }

  .sidebar .identity {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .sidebar .identity .role,
  .sidebar .identity .affil {
    display: none;
  }

  .avatar {
    width: 40px;
    height: 40px;
  }

  .identity .sidebar-name {
    font-size: 1.05rem;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    flex-shrink: 0;
  }

  .menu-toggle svg {
    width: 18px;
    height: 18px;
  }

  .menu-toggle .icon-close {
    display: none;
  }

  .sidebar.menu-open .menu-toggle .icon-open {
    display: none;
  }

  .sidebar.menu-open .menu-toggle .icon-close {
    display: block;
  }

  .sidebar-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    flex-direction: column;
    gap: 20px;
    padding: 4px 20px 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .sidebar.menu-open .sidebar-menu {
    display: flex;
  }

  .sidebar-menu .contact-row {
    justify-content: center;
    padding-top: 4px;
  }

  .sidebar-menu .icon-link {
    width: 42px;
    height: 42px;
  }

  .cv-button-wrap .cv-button {
    width: 100%;
  }

  .sidebar-nav {
    border-top: 1px solid var(--border);
    padding-top: 16px;
  }

  .sidebar-nav a {
    padding: 11px 0;
    font-size: 1rem;
  }

  .sidebar-footer {
    margin-top: 0;
    border-top: 1px solid var(--border);
    padding-top: 16px;
  }

  .sidebar-footer .credit {
    display: block;
  }

  .main {
    padding: 28px 20px 20px;
  }

  .hero {
    margin-bottom: 56px;
  }

  section {
    margin-bottom: 56px;
  }

  .two-col {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .skills-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .updates-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .updates-date {
    flex: 0 0 auto;
  }
}

@media (max-width: 520px) {
  .publication {
    padding: 22px 20px;
  }

  .contact-card {
    padding: 26px 22px;
  }
}
