/* Global Theme Variables */
:root {
  --bg-color: #f5f5f5;
  --container-bg: #ffffff;
  --text-primary: #2c3e50;
  --text-secondary: #34495e;
  --text-muted: #666;
  --border-color: #eee;
  --link-color: #3498db;
}
[data-theme="dark"] {
  --bg-color: #1a1a1a;
  --container-bg: #2d2d2d;
  --text-primary: #e0e0e0;
  --text-secondary: #d0d0d0;
  --text-muted: #b8b8b8;
  --border-color: #404040;
  --link-color: #5dade2;
}
/* Base Layout */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg-color);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease;
}
main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 0;
}
.container {
  background-color: var(--container-bg);
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem;
  transition: background-color 0.3s ease;
}
/* Header */
header {
  background-color: transparent;
  color: var(--text-primary);
  padding: 0.5rem 0;
  text-align: left;
  width: 100%;
  border-bottom: 1px solid var(--border-color);
}
.header-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header-right { display: flex; gap: 1rem; align-items: center; }
.menu-wrapper { position: relative; }
.menu-button {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 5px;
  font-size: 1rem;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  touch-action: manipulation;
}
.menu-button:hover { background-color: var(--border-color); }
.menu-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  min-width: 150px;
  z-index: 2000; /* ensure dropdown is above other header elements on mobile */
  /* Visibility-based toggle for iOS reliability */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease, visibility 0s .15s;
}
.menu-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity .15s ease, transform .15s ease, visibility 0s;
}
.menu-dropdown a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background-color 0.3s ease, color 0.3s ease;
}
.menu-dropdown a:hover { background-color: var(--border-color); }
.menu-dropdown a:first-child { border-radius: 5px 5px 0 0; }
.menu-dropdown a:last-child { border-radius: 0 0 5px 5px; }
header h1 { margin: 0; font-size: 1.2rem; font-weight: 500; }
header h1 a { position: relative; text-decoration: none; color: inherit; }
header h1 a:after { content: ''; position: absolute; width: 100%; height: 1px; bottom: -2px; left: 0; background-color: var(--link-color); transform: scaleX(0); transform-origin: bottom right; transition: transform 0.2s ease-out; }
header h1 a:hover:after { transform: scaleX(1); transform-origin: bottom left; }
nav a { color: var(--text-primary); text-decoration: none; font-size: 0.95rem; padding: 0.5rem 1rem; border-radius: 5px; transition: background-color 0.3s ease, color 0.3s ease; }
nav a:hover { background-color: var(--border-color); }
/* Theme Toggle */
.theme-toggle-wrapper { position: relative; display: inline-block; }
.theme-toggle { 
  --toggle-width: 60px;
  --slider-size: 24px;
  --padding: 3px;
  position: relative; 
  width: var(--toggle-width); 
  height: 30px; 
  background-color: var(--border-color); 
  border-radius: 15px; 
  cursor: pointer; 
  transition: background-color 0.3s ease; 
  border: none; 
  padding: 0; 
}
.theme-toggle:hover { opacity: 0.8; }
.theme-toggle-slider { 
  position: absolute; 
  top: var(--padding); 
  left: var(--padding); 
  width: var(--slider-size); 
  height: var(--slider-size); 
  background-color: #fff; 
  border-radius: 50%; 
  transition: transform 0.3s ease; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  box-shadow: 0 2px 4px rgba(0,0,0,0.2); 
}
.theme-toggle-slider i { font-size: 0.75rem; color: #2c3e50; }
[data-theme="dark"] .theme-toggle { background-color: var(--link-color); }
[data-theme="dark"] .theme-toggle-slider { transform: translateX(calc(var(--toggle-width) - var(--slider-size) - (var(--padding) * 2))); }
[data-theme="dark"] .theme-toggle-slider i { color: #f39c12; }
/* Footer */
footer { background-color: transparent; color: var(--text-muted); padding: 0.75rem 0; text-align: center; margin-top: auto; width: 100%; border-top: 1px solid var(--border-color); font-size: 0.9rem; }
.footer-content { display: flex; justify-content: space-between; align-items: center; max-width: 800px; margin: 0 auto; padding: 0 1rem; }
.footer-right { display: flex; flex-direction: column; align-items: flex-end; }
.footer-links { display: flex; gap: 1.5rem; align-items: center; margin-bottom: 0.5rem; }
.footer-links a { color: var(--text-muted); text-decoration: none; font-size: 1.1rem; transition: color 0.3s ease; }
.footer-links a:hover { color: var(--text-primary); }
.footer-email a:hover { text-decoration: underline; }
/* Skip Link */
.skip-link { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip-link:focus { position: static; width: auto; height: auto; padding: 0.5rem 0.75rem; background: var(--container-bg); border: 1px solid var(--border-color); border-radius: 5px; margin: 0.5rem; }
/* Footer Specific */
.footer-copyright { margin-top: 0.5rem; font-size: 0.9rem; color: var(--text-muted); }
.footer-email-link { color: var(--text-muted); text-decoration: none; }
.footer-email-link:hover { text-decoration: underline; }
/* Section Description */
.section-description { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 1.5rem; font-style: italic; }
/* Site Logo */
.site-logo { font-size: 1.2rem; font-weight: 500; }
.site-logo a { position: relative; text-decoration: none; color: inherit; }
.site-logo a:after { content: ''; position: absolute; width: 100%; height: 1px; bottom: -2px; left: 0; background-color: var(--link-color); transform: scaleX(0); transform-origin: bottom right; transition: transform 0.2s ease-out; }
.site-logo a:hover:after { transform: scaleX(1); transform-origin: bottom left; }
/* Books Page Shared Elements */
.book-item { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; gap: 1.5rem; align-items: flex-start; }
.book-item:last-child { border-bottom: none; }
.book-cover { flex-shrink: 0; width: 120px; }
.book-cover a { display: block; transition: transform 0.3s ease, opacity 0.3s ease; }
.book-cover a:hover { transform: translateY(-4px); opacity: 0.9; }
.book-cover img { width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.book-details { flex: 1; }
.book-title { color: var(--text-primary); font-size: 1.1rem; font-weight: 500; margin-bottom: 0.25rem; margin-top: 0; }
.book-author { color: var(--text-muted); font-size: 0.9rem; font-style: italic; margin-bottom: 0.5rem; }
.book-notes { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.6; }
/* Misc */
.intro { font-size: 1.1rem; color: var(--text-primary); max-width: 600px; margin: 2rem auto; text-align: center; }
.experience, .education { margin: 2rem 0; text-align: left; }
.experience h2, .education h2 { color: var(--text-primary); font-size: 1.5rem; margin-bottom: 1.5rem; font-weight: 500; }
.experience-item, .education-item { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); }
.experience-item:last-child, .education-item:last-child { border-bottom: none; }
.experience-header h4, .education-header h4 { color: var(--text-primary); margin: 0 0 0.25rem 0; font-size: 1.1rem; font-weight: 500; }
.company, .university { display: block; color: var(--text-muted); margin-bottom: 0.25rem; }
.company a, .university a { color: var(--link-color); text-decoration: none; }
.company a:hover, .university a:hover { text-decoration: underline; }
.duration { color: var(--text-muted); font-size: 0.9rem; }
.activities { color: var(--text-muted); font-size: 0.9rem; margin: 0.5rem 0 0 0; font-style: italic; }

/* Horizontal timeline (wrapping serpentine line) */
.timeline-section { margin: 2.5rem 0; }
.timeline { position: relative; }
.timeline-items {
  --tl-cols: 3;
  --tl-col-gap: 2.5rem;
  --tl-row-gap: 2rem;
  display: grid;
  grid-template-columns: repeat(var(--tl-cols), minmax(220px, 1fr));
  column-gap: var(--tl-col-gap);
  row-gap: var(--tl-row-gap);
  align-items: start;
}
.timeline-item { position: relative; text-align: left; }
.timeline-dot {
  position: absolute;
  top: 0.3rem;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 14px;
  background: var(--container-bg);
  border: 2px solid var(--link-color);
  border-radius: 50%;
  z-index: 2;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.18);
}
.tl-card {
  position: relative;
  margin-top: 2rem; /* space below dot */
  background: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem 0.9rem 0.95rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  transition: box-shadow 0.2s ease, transform 0.12s ease;
}
.tl-card:hover { box-shadow: 0 8px 22px rgba(0,0,0,0.12); transform: translateY(-2px); }
.tl-title { margin: 0 0 0.4rem; font-size: 0.95rem; line-height: 1.35; color: var(--text-primary); font-weight: 600; }
.tl-title a { color: var(--link-color); text-decoration: none; }
.tl-title a:hover { text-decoration: underline; }
.tl-meta { font-size: 0.75rem; font-weight: 500; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.4rem; }
.tl-desc { margin: 0; font-size: 0.8rem; line-height: 1.4; color: var(--text-secondary); }

/* Dark mode tweaks */
[data-theme="dark"] .timeline-items::before { background: var(--border-color); }
[data-theme="dark"] .timeline-dot { background: var(--container-bg); box-shadow: 0 0 0 3px rgba(93,173,226,0.25); }
[data-theme="dark"] .tl-card { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
[data-theme="dark"] .tl-card:hover { box-shadow: 0 10px 28px rgba(0,0,0,0.55); }

/* Serpentine connectors for 3-column desktop layout */
/* Odd rows (items 6n+1 to 6n+3): left-to-right */
.timeline-item:nth-child(6n+1)::after,
.timeline-item:nth-child(6n+2)::after {
  content: "";
  position: absolute;
  top: 0.9rem;
  left: 50%;
  height: 2px;
  width: calc(50% + var(--tl-col-gap));
  background: var(--border-color);
  z-index: 0;
}
/* Odd row, last column: vertical drop to next row */
.timeline-item:nth-child(6n+3)::after {
  content: "";
  position: absolute;
  top: 0.9rem;
  right: calc(-1 * (var(--tl-col-gap) / 2));
  width: 2px;
  height: calc(var(--tl-row-gap) + 1.6rem);
  background: var(--border-color);
  z-index: 0;
}
/* Even rows (items 6n+4 to 6n+6): right-to-left */
.timeline-item:nth-child(6n+5)::after,
.timeline-item:nth-child(6n+6)::after {
  content: "";
  position: absolute;
  top: 0.9rem;
  right: 50%;
  height: 2px;
  width: calc(50% + var(--tl-col-gap));
  background: var(--border-color);
  z-index: 0;
}
/* Even row, first column: vertical up from previous row and horizontal lead-in */
.timeline-item:nth-child(6n+4)::after {
  content: "";
  position: absolute;
  top: calc(-1 * (var(--tl-row-gap) + 1.6rem) + 0.9rem);
  left: calc(-1 * (var(--tl-col-gap) / 2));
  width: 2px;
  height: calc(var(--tl-row-gap) + 1.6rem);
  background: var(--border-color);
  z-index: 0;
}
.timeline-item:nth-child(6n+4)::before {
  content: "";
  position: absolute;
  top: 0.9rem;
  left: calc(-1 * (var(--tl-col-gap) + 50%));
  width: calc(50% + var(--tl-col-gap));
  height: 2px;
  background: var(--border-color);
  z-index: 0;
}
/* Do not draw connectors past the last item */
.timeline-item:last-child::after,
.timeline-item:last-child::before { content: none; }

/* Responsive: stack vertically on narrow screens */
@media (max-width: 760px) {
  .timeline-items { display: block; }
  .timeline-item { max-width: none; }
  .timeline-item::after,
  .timeline-item::before { content: none !important; }
  .timeline-dot { position: absolute; left: 0; transform: none; top: 0.4rem; }
  .tl-card { margin-top: 0; padding-left: 2.2rem; }
  .timeline-item { padding-left: 0.2rem; }
  .timeline-item::before {
    content: "";
    position: absolute;
    left: 0.35rem;
    top: 0.4rem;
    bottom: -1.4rem;
    width: 2px;
    background: var(--border-color);
    z-index: 0;
  }
  .timeline-item:last-child::before { bottom: 0.6rem; }
  .timeline-dot { left: 0; }
}

/* Vertical two-lane roadmap (Experience | Education) */
.roadmap-section { margin: 2rem 0; text-align: left; }
.roadmap {
  position: relative;
  display: grid;
  grid-template-columns: 1fr; /* content only, no rail */
  gap: 2rem 2rem;
  align-items: start;
}
.rail {
  display: none; /* hide vertical rail */
}
.lane { display: grid; gap: 1.5rem; }
.lane-experience { grid-column: 1; }
.lane-education  { grid-column: 1; }
.lane-title { margin: 0; color: var(--text-muted); font-weight: 600; letter-spacing: 0.2px; }
.lane-title i { margin-right: 0.5rem; color: var(--link-color); }
.node { position: relative; }
.node .dot {
  position: absolute;
  top: 0.6rem;
  width: 12px; height: 12px;
  background: var(--container-bg);
  border: 2px solid var(--link-color);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15); /* subtle glow */
  left: -7px;
  right: auto;
}
.rm-card {
  background: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.rm-title { margin: 0 0 0.25rem; font-size: 1.05rem; color: var(--text-primary); }
.rm-title a { color: var(--link-color); text-decoration: none; }
.rm-title a:hover { text-decoration: underline; }
.rm-meta  { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 0.5rem; }
.rm-desc  { margin: 0; color: var(--text-secondary); }
.rm-points { margin: 0; padding-left: 1rem; }

/* Slightly tighter spacing on small screens */
@media (max-width: 720px) {
  .roadmap { gap: 1.25rem 1.25rem; }
  .lane-title { margin-top: 0.25rem; }
}
