/* ==========================================================================
   Layyin Shifan — Portfolio & Résumé Stylesheet
   Design Philosophy: Calm, editorial, single-column résumé document.
   Restraint: Pure typography, warm off-white / soft charcoal, #F3CBCB blush accent.
   Fluid responsive adaptation from mobile (320px) to widescreen desktop (1920px+).
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties & Color Systems
   -------------------------------------------------------------------------- */
:root {
  /* Requested Accent: #F3CBCB (Soft Blush Rose) */
  --accent-blush: #f3cbcb;
  --accent-blush-soft: rgba(243, 203, 203, 0.2);

  /* Light Theme (Warm Off-White & Soft Charcoal) */
  --bg: #faf8f5;
  --bg-subtle: #f3efe8;
  --text: #262624;
  --text-muted: #66635d;
  --border: #e6e2d8;
  --border-subtle: #eeece5;

  /* In light mode: deep rosewood for link text to meet WCAG AA (>5.5:1 contrast)
     with #F3CBCB used for hover highlights, underlines, borders, and selection */
  --accent: #8e4453;
  --accent-hover: #6e303d;
  --accent-underline: #f3cbcb;
  --focus-ring: #8e4453;
  --selection-bg: #f3cbcb;
  --selection-text: #262624;

  /* Typography */
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Spacing Scale (4px / 8px rhythm) */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;  /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-10: 2.5rem;  /* 40px */
  --space-12: 3rem;    /* 48px */
  --space-16: 4rem;    /* 64px */

  /* Responsive Document Width (Comfortable reading measure on all screens) */
  --doc-width: min(820px, 86vw);
  --header-width: min(1040px, 92vw);
  --header-height: 56px;

  /* Transitions */
  --color-transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

/* Dark Theme (Soft Off-Black, Dimmed Off-White, #F3CBCB Accent) */
[data-theme="dark"] {
  --bg: #161614;
  --bg-subtle: #1e1e1a;
  --text: #eceae5;
  --text-muted: #9c9990;
  --border: #2a2925;
  --border-subtle: #22211e;

  /* In dark mode: #F3CBCB provides exceptional 11.5:1 contrast on #161614 (WCAG AAA) */
  --accent: #f3cbcb;
  --accent-hover: #ffffff;
  --accent-underline: rgba(243, 203, 203, 0.6);
  --focus-ring: #f3cbcb;
  --selection-bg: #f3cbcb;
  --selection-text: #161614;
}

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

html {
  font-size: clamp(16px, 0.94rem + 0.22vw, 18px);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  line-height: 1.68;
  background-color: var(--bg);
  color: var(--text);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: var(--color-transition);
  overflow-x: hidden;
  width: 100%;
}

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

/* --------------------------------------------------------------------------
   Accessibility: Skip Link & Focus Rings
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: -9999px;
  left: 1rem;
  background: var(--text);
  color: var(--bg);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 10000;
  border-radius: 2px;
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

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

/* --------------------------------------------------------------------------
   Typography Hierarchy
   -------------------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--text);
  line-height: 1.25;
}

p {
  color: var(--text);
  margin-bottom: var(--space-4);
}

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

ul {
  list-style: none;
}

/* --------------------------------------------------------------------------
   Links (Restrained, Editorial Underline)
   -------------------------------------------------------------------------- */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
  overflow-wrap: break-word;
  word-break: break-word;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-thickness: 1.5px;
  text-decoration-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Slim Sticky Header (Gracefully spans desktop width)
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: var(--color-transition);
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}

.header-inner {
  max-width: var(--header-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

.header-name {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.header-name:hover {
  color: var(--accent);
  text-decoration: none;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: 0.9375rem;
}

.nav-item {
  color: var(--text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  transition: color 0.15s ease;
}

.nav-item:hover {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
}

/* Accessible Theme Toggle Button (Sun & Moon Icons) */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.theme-toggle svg {
  display: block;
  width: 18px;
  height: 18px;
  transition: transform 0.2s ease;
}

.theme-toggle:hover svg {
  transform: scale(1.08);
}

/* Light mode: show moon (to switch to dark), hide sun */
.theme-toggle .sun-icon {
  display: none;
}
.theme-toggle .moon-icon {
  display: block;
}

/* Dark mode: show sun (to switch to light), hide moon */
[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
  color: var(--accent);
}
[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* --------------------------------------------------------------------------
   Main Document Container (Balanced, fluid desktop & mobile measure)
   -------------------------------------------------------------------------- */
.page-container {
  max-width: var(--doc-width);
  margin: 0 auto;
  padding: clamp(var(--space-8), 6vh, var(--space-16)) var(--space-4) var(--space-16);
  width: 100%;
}

/* --------------------------------------------------------------------------
   Document Top Header (Name, One-Line Role, Plain Links)
   -------------------------------------------------------------------------- */
.doc-header {
  padding-bottom: clamp(var(--space-8), 4vh, var(--space-12));
  border-bottom: 1px solid var(--border);
}

.doc-title {
  font-size: clamp(2.4rem, 4.5vw + 0.5rem, 3.4rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-bottom: var(--space-2);
}

.doc-role {
  font-size: clamp(1.05rem, 1.8vw + 0.2rem, 1.3rem);
  color: var(--text-muted);
  margin-bottom: var(--space-5);
  line-height: 1.45;
}

.doc-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-size: clamp(0.9rem, 0.85rem + 0.2vw, 1rem);
  line-height: 1.6;
}

.doc-links a {
  text-decoration: underline;
  text-underline-offset: 3px;
  display: inline-block;
  padding: 2px 0;
}

.doc-links .sep {
  color: var(--border);
  user-select: none;
}

/* --------------------------------------------------------------------------
   Sections & Hairline Dividers
   -------------------------------------------------------------------------- */
.doc-section {
  padding: clamp(var(--space-8), 4.5vh, var(--space-12)) 0;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: clamp(1.6rem, 2vw + 0.6rem, 2rem);
  font-weight: 500;
  letter-spacing: -0.015em;
  margin-bottom: clamp(var(--space-6), 3vh, var(--space-8));
  color: var(--text);
}

.section-body p {
  font-size: clamp(1rem, 0.95rem + 0.15vw, 1.08rem);
  line-height: 1.72;
}

/* --------------------------------------------------------------------------
   Two-Column Résumé Rhythm (Experience & Projects)
   Left column accommodates dates cleanly without squeezing on desktop.
   -------------------------------------------------------------------------- */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-8), 4vh, var(--space-10));
}

.entry-row {
  display: grid;
  grid-template-columns: minmax(170px, 210px) 1fr;
  column-gap: clamp(var(--space-6), 3vw, var(--space-10));
  align-items: start;
}

.entry-meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding-top: 0.18rem;
}

.entry-date {
  display: block;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  font-weight: 500;
  line-height: 1.4;
}

.entry-location {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.entry-label {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--accent-underline);
  padding-bottom: 1px;
  margin-bottom: var(--space-1);
}

.entry-tech {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.entry-main {
  display: flex;
  flex-direction: column;
}

.entry-title {
  font-size: clamp(1.15rem, 1.1rem + 0.2vw, 1.3rem);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-1);
  line-height: 1.3;
}

.entry-company {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.project-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.project-tag {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-serif);
}

.entry-summary {
  font-size: clamp(0.96rem, 0.92rem + 0.15vw, 1.04rem);
  line-height: 1.68;
  margin-bottom: var(--space-3);
}

.entry-details {
  list-style: disc;
  padding-left: 1.35rem;
  margin-bottom: var(--space-3);
}

.entry-details li {
  font-size: clamp(0.92rem, 0.88rem + 0.15vw, 1rem);
  line-height: 1.65;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.entry-details li:last-child {
  margin-bottom: 0;
}

.entry-links {
  margin-top: var(--space-2);
  font-size: 0.95rem;
}

/* --------------------------------------------------------------------------
   Skills & Definition Groups
   -------------------------------------------------------------------------- */
.skills-block {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-6), 3vh, var(--space-8));
}

.skill-group-title {
  font-size: clamp(1.05rem, 1rem + 0.2vw, 1.18rem);
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--text);
}

.skill-group-text {
  font-size: clamp(0.96rem, 0.92rem + 0.15vw, 1.04rem);
  line-height: 1.7;
  color: var(--text);
}

.skill-sublist {
  list-style: disc;
  padding-left: 1.35rem;
}

.skill-sublist li {
  font-size: clamp(0.92rem, 0.88rem + 0.15vw, 1rem);
  line-height: 1.68;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.skill-sublist li:last-child {
  margin-bottom: 0;
}

.item-date {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   Contact Definition List
   -------------------------------------------------------------------------- */
.contact-intro {
  margin-bottom: var(--space-6);
  font-size: clamp(1rem, 0.95rem + 0.15vw, 1.08rem);
}

.contact-definition-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.contact-def-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: baseline;
  gap: var(--space-4);
  font-size: clamp(0.95rem, 0.9rem + 0.15vw, 1.02rem);
}

.contact-def-row dt {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.contact-def-row dd {
  color: var(--text);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   Document Footer
   -------------------------------------------------------------------------- */
.doc-footer {
  padding-top: clamp(var(--space-8), 4vh, var(--space-12));
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.footer-top a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-color: var(--accent-underline);
}

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

/* --------------------------------------------------------------------------
   Responsive Layout & Screen Size Adjustments
   -------------------------------------------------------------------------- */

/* Large Tablets and Laptops (<= 992px) */
@media (max-width: 992px) {
  .entry-row {
    grid-template-columns: 170px 1fr;
    column-gap: var(--space-6);
  }
}

/* Small Tablets (<= 768px) */
@media (max-width: 768px) {
  .header-nav {
    gap: var(--space-3);
    font-size: 0.85rem;
  }
}

/* Mobile & Phablets (<= 640px) */
@media (max-width: 640px) {
  :root {
    --header-height: 48px;
  }

  .header-nav {
    display: none; /* Keep sticky header clean and focused on mobile */
  }

  .header-inner {
    padding: 0 var(--space-2);
  }

  .page-container {
    padding-top: var(--space-8);
    padding-left: var(--space-3);
    padding-right: var(--space-3);
    padding-bottom: var(--space-12);
  }

  .doc-section {
    padding: var(--space-8) 0;
  }

  /* Two-column collapses to stacked rhythm on mobile */
  .entry-row {
    grid-template-columns: 1fr;
    row-gap: var(--space-2);
  }

  .entry-meta {
    padding-top: 0;
    margin-bottom: var(--space-1);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-3);
  }

  .entry-date {
    margin-bottom: 0;
  }

  .entry-location::before {
    content: "•";
    margin-right: var(--space-2);
    color: var(--border);
  }

  .contact-def-row {
    grid-template-columns: 1fr;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
  }

  .contact-def-row dt {
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
}

/* Extra Small Mobile (<= 375px: iPhone SE, compact Androids) */
@media (max-width: 375px) {
  .page-container {
    padding-left: var(--space-2);
    padding-right: var(--space-2);
  }

  .doc-title {
    font-size: 2rem;
  }

  .doc-links {
    font-size: 0.875rem;
  }

  .entry-details {
    padding-left: 1.1rem;
  }
}

/* --------------------------------------------------------------------------
   Reduced Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  body, a, .theme-toggle, .site-header {
    transition: none !important;
  }
}

/* --------------------------------------------------------------------------
   Print Stylesheet (Clean Résumé Output)
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: #ffffff !important;
    color: #111111 !important;
    font-size: 11pt;
  }

  .site-header,
  .skip-link,
  .footer-top {
    display: none !important;
  }

  .page-container {
    max-width: 100% !important;
    padding: 0 !important;
  }

  .doc-section {
    padding: 1.25rem 0 !important;
    page-break-inside: avoid;
  }

  a {
    color: #111111 !important;
    text-decoration: none !important;
  }

  .entry-row {
    grid-template-columns: 160px 1fr !important;
  }
}
