/* ============================================
   niuhan.net — Artist Portfolio
   MoMA-level minimal gallery aesthetic
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Light theme (default) */
  --color-bg: #ffffff;
  --color-bg-secondary: #fafafa;
  --color-text: #111111;
  --color-text-secondary: #666666;
  --color-text-tertiary: #999999;
  --color-border: #e5e5e5;
  --color-border-light: #f0f0f0;
  --color-overlay: rgba(255, 255, 255, 0.97);
  --color-placeholder: #e8e8e8;
  --color-placeholder-hover: #d8d8d8;
  --color-accent: #111111;
  --color-tag-bg: #f5f5f5;
  --color-tag-text: #555555;
  --color-video-controls: rgba(0, 0, 0, 0.85);
  --color-video-progress: #111111;
  --color-video-buffer: rgba(0, 0, 0, 0.15);
  --color-scrollbar: #d0d0d0;

  /* Typography */
  --font-heading: 'Space Grotesk', 'Syne', sans-serif;
  --font-body: 'Inter', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 2rem;
  --space-xl: 4rem;
  --space-2xl: 6rem;
  --space-3xl: 8rem;

  /* Layout */
  --max-width: 1400px;
  --nav-height: 72px;
  --grid-gap: 2px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-page: 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  --color-bg: #1a1a1a;
  --color-bg-secondary: #222222;
  --color-text: #e5e5e5;
  --color-text-secondary: #999999;
  --color-text-tertiary: #666666;
  --color-border: #2a2a2a;
  --color-border-light: #242424;
  --color-overlay: rgba(26, 26, 26, 0.97);
  --color-placeholder: #242424;
  --color-placeholder-hover: #2e2e2e;
  --color-accent: #e5e5e5;
  --color-tag-bg: #1a1a1a;
  --color-tag-text: #aaaaaa;
  --color-video-controls: rgba(255, 255, 255, 0.9);
  --color-video-progress: #e5e5e5;
  --color-video-buffer: rgba(255, 255, 255, 0.15);
  --color-scrollbar: #333333;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background-color var(--transition-base), color var(--transition-base);
  overflow-x: hidden;
}

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

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-scrollbar); border-radius: 3px; }

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
ul, ol { list-style: none; }

/* ---------- Language Toggle ---------- */
[data-lang="en"] .lang-zh { display: none; }
[data-lang="zh"] .lang-en { display: none; }

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.text-xs { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; }
.text-sm { font-size: 0.8125rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.25rem; }
.text-xl { font-size: 1.75rem; }
.text-2xl { font-size: 2.5rem; }
.text-3xl { font-size: 3.5rem; }
.text-hero { font-size: clamp(3rem, 8vw, 7rem); }

/* ---------- Navigation ---------- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: transparent;
  z-index: 100;
  border-bottom: none;
  transition: background var(--transition-base), border-color var(--transition-base);
}

.nav-logo {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}
.nav-logo:hover { opacity: 0.6; }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.nav-link {
  font-size: 0.9375rem;
  letter-spacing: 0.03em;
  transition: opacity var(--transition-fast);
  position: relative;
  padding: 4px 0;
}
.nav-link:hover { opacity: 0.5; }
.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-text);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.nav-btn {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 2px;
  transition: all var(--transition-fast);
  line-height: 1;
}
.nav-btn:hover {
  background: var(--color-text);
  color: var(--color-bg);
  border-color: var(--color-text);
}

/* Mobile menu close button — hidden by default, shown inside overlay */
.mobile-menu-close {
  display: none;
}

/* Mobile menu */
.nav-mobile-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
}
.nav-mobile-toggle span {
  display: block;
  width: 20px;
  height: 1px;
  background: var(--color-text);
  transition: all var(--transition-fast);
}

/* ---------- Scroll fade under nav ---------- */
.scroll-fade {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + 32px);
  background: linear-gradient(
    to bottom,
    var(--color-bg) 0%,
    var(--color-bg) 50%,
    transparent 100%
  );
  z-index: 50;
  pointer-events: none;
  display: none;
}

/* ---------- Page Sections ---------- */
.page {
  display: none;
  opacity: 0;
  min-height: 100vh;
  padding-top: var(--nav-height);
  transition: opacity var(--transition-page);
}
.page.active {
  display: block;
}
.page.visible {
  opacity: 1;
}

/* Home page: full-bleed hero sits behind the nav */
#page-home {
  padding-top: 0;
}

/* When home is active, make nav blend with the hero image */
.nav.nav-transparent {
  background: transparent;
  border-bottom-color: transparent;
  color: #fff;
}
.nav.nav-transparent .nav-logo,
.nav.nav-transparent .nav-link,
.nav.nav-transparent .nav-btn,
.nav.nav-transparent .nav-mobile-toggle span {
  color: #fff;
}
.nav.nav-transparent .nav-btn {
  border-color: rgba(255,255,255,0.3);
}
.nav.nav-transparent .nav-btn:hover {
  background: #fff;
  color: #111;
  border-color: #fff;
}
.nav.nav-transparent .nav-mobile-toggle span {
  background: #fff;
}
.nav.nav-transparent .nav-link.active::after {
  background: #fff;
}

/* Nav when mobile menu is open — frosted glass to match overlay */
.nav.nav-menu-open,
.nav.nav-menu-open.nav-transparent {
  background: rgba(255, 255, 255, 0.45) !important;
  backdrop-filter: blur(40px) saturate(1.8) !important;
  -webkit-backdrop-filter: blur(40px) saturate(1.8) !important;
  border-bottom-color: transparent !important;
  color: var(--color-text);
}
[data-theme="dark"] .nav.nav-menu-open,
[data-theme="dark"] .nav.nav-menu-open.nav-transparent {
  background: rgba(20, 20, 20, 0.45) !important;
}
.nav.nav-menu-open .nav-logo,
.nav.nav-menu-open .nav-btn,
.nav.nav-menu-open.nav-transparent .nav-logo,
.nav.nav-menu-open.nav-transparent .nav-btn {
  color: var(--color-text);
}
.nav.nav-menu-open .nav-mobile-toggle {
  display: none;
}
.nav.nav-menu-open .nav-mobile-toggle span,
.nav.nav-menu-open.nav-transparent .nav-mobile-toggle span {
  background: var(--color-text);
}
.nav.nav-menu-open .nav-btn,
.nav.nav-menu-open.nav-transparent .nav-btn {
  border-color: var(--color-border);
}

.page-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

/* ---------- Home / Cinematic Hero ---------- */
.hero-cinematic {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 500px;
  overflow: hidden;
}

.hero-cinematic-image {
  position: absolute;
  inset: 0;
}
.hero-cinematic-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.hero-cinematic-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0,0,0,0.7) 0%,
    rgba(0,0,0,0.25) 40%,
    rgba(0,0,0,0.05) 70%,
    transparent 100%
  );
  pointer-events: none;
}

.hero-cinematic-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 clamp(32px, 5vw, 80px) clamp(56px, 10vh, 100px);
  z-index: 2;
}

.hero-cinematic-name {
  font-family: var(--font-heading);
  font-size: clamp(1.75rem, 4vw, 3rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.15;
  color: #fff;
  margin-bottom: 8px;
}

.hero-cinematic-subtitle {
  font-size: clamp(0.75rem, 1.2vw, 0.875rem);
  color: rgba(255,255,255,0.5);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero-cinematic-scroll {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  animation: wdBounce 2.5s ease-in-out infinite;
  opacity: 0.6;
}

/* ---------- Works ---------- */
.works-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.works-title {
  font-size: 2rem;
  font-weight: 400;
}

.works-filters {
  display: flex;
  gap: var(--space-sm);
}

.filter-btn {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
}
.filter-btn.active {
  background: var(--color-text);
  color: var(--color-bg);
  border-color: var(--color-text);
}
.filter-btn:hover:not(.active) {
  border-color: var(--color-text);
}

.works-sub-filters {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.sub-filter {
  padding-bottom: 2px;
  transition: all var(--transition-fast);
  cursor: pointer;
}
.sub-filter.active {
  color: var(--color-text);
  border-bottom: 1px solid var(--color-text);
}
.sub-filter:hover { color: var(--color-text); }

.writing-filter {
  padding-bottom: 2px;
  transition: all var(--transition-fast);
  cursor: pointer;
}
.writing-filter.active {
  color: var(--color-text);
  border-bottom: 1px solid var(--color-text);
}
.writing-filter:hover { color: var(--color-text); }

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-lg) var(--space-md);
}

.work-card {
  cursor: pointer;
  transition: opacity var(--transition-base);
}
.work-card:hover { opacity: 0.85; }
.work-card:hover .work-card-image {
  background: var(--color-placeholder-hover);
}
.work-card:hover .work-card-image img {
  transform: scale(1.03);
}

.work-card-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--color-placeholder);
  margin-bottom: var(--space-sm);
  transition: background var(--transition-base);
  overflow: hidden;
}
.work-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Writing cards: typographic book-cover style */
#writingGrid .work-card-image {
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5rem;
  position: relative;
}
#writingGrid .work-card-image::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid var(--color-border);
  transition: border-color var(--transition-base);
}
#writingGrid .work-card:hover .work-card-image::before {
  border-color: var(--color-text-tertiary);
}
#writingGrid .work-card-image {
  background: var(--color-bg-secondary);
}
/* Writing cards with cover images: no padding/border */
#writingGrid .work-card-image.has-cover {
  padding: 0;
  background: var(--color-bg);
}
#writingGrid .work-card-image.has-cover::before {
  display: none;
}
#writingGrid .work-card-image.has-cover img {
  object-fit: contain;
}
#writingGrid.works-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
/* Typographic title inside writing card cover */
.writing-cover-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1.3;
  color: var(--color-text-secondary);
  letter-spacing: -0.01em;
}

/* Writing card description below card */
.writing-card-author {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.writing-card-desc {
  font-size: 0.8125rem;
  color: var(--color-text-tertiary);
  line-height: 1.5;
  margin-top: var(--space-xs);
}

.writing-card-buy {
  display: inline-block;
  font-size: 0.8125rem;
  color: var(--color-accent, #666);
  text-decoration: none;
  margin-top: var(--space-xs);
  opacity: 0.75;
  transition: opacity 0.2s ease;
}

.writing-card-buy:hover {
  opacity: 1;
  text-decoration: underline;
}

.work-card-meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.work-card-year {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.work-card-tag {
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-tag-text);
  background: var(--color-tag-bg);
  padding: 2px 8px;
  transition: background var(--transition-base), color var(--transition-base);
}

.work-card-title {
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.3;
}

/* ---------- Work Detail Overlay (Mubi-inspired) ---------- */
.work-detail {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #1a1a1a;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-page);
}
.work-detail.open {
  opacity: 1;
  pointer-events: all;
}

/* Back / Close button — always white, top-left */
.work-detail-close {
  position: fixed;
  top: 24px;
  left: 32px;
  z-index: 210;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 18px;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all var(--transition-fast);
}
.work-detail-close:hover {
  background: #fff;
  color: #0a0a0a;
  border-color: #fff;
}

.work-detail-inner {
  max-width: 100%;
  margin: 0;
  padding: 0;
}

/* ── Hero: full-viewport still image with text overlay ── */
.wd-hero {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 600px;
  overflow: hidden;
}

.wd-hero-image {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 40%, #0f3460 100%);
  background-size: cover;
  background-position: center;
}

/* Dark gradient scrim — bottom-heavy for text area */
.wd-hero-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0,0,0,0.85) 0%,
    rgba(0,0,0,0.4) 35%,
    rgba(0,0,0,0.1) 60%,
    transparent 100%
  );
}

/* Text overlay at bottom-left */
.wd-hero-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 clamp(32px, 5vw, 80px) clamp(48px, 8vh, 96px);
  z-index: 2;
}

.wd-hero-title {
  font-family: var(--font-heading);
  font-size: clamp(2.5rem, 6vw, 5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: #fff;
  margin-bottom: clamp(16px, 2vh, 28px);
}

/* Metadata pills */
.wd-hero-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.wd-pill {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.85);
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 2px;
  backdrop-filter: blur(4px);
}

.wd-hero-credits {
  font-size: 0.8125rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.02em;
}

/* Scroll-down hint chevron */
.wd-scroll-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  animation: wdBounce 2s ease-in-out infinite;
}

@keyframes wdBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(6px); }
}

/* ── Below-the-fold body ── */
.wd-body {
  background: #1a1a1a;
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(48px, 8vh, 96px) clamp(24px, 5vw, 80px) clamp(64px, 10vh, 120px);
}

.wd-section {
  margin-bottom: clamp(48px, 6vh, 72px);
}

.wd-section-label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.wd-synopsis {
  font-size: clamp(1rem, 1.5vw, 1.125rem);
  line-height: 1.9;
  color: rgba(255,255,255,0.7);
  max-width: 640px;
}

/* Details grid */
.wd-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 28px 40px;
}

.wd-detail-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  margin-bottom: 6px;
}

.wd-detail-value {
  font-size: 0.9375rem;
  color: rgba(255,255,255,0.8);
}

/* ---------- Custom Video Player ---------- */
.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
  margin-bottom: var(--space-xl);
  overflow: hidden;
  cursor: pointer;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  transition: opacity var(--transition-base);
}
.video-container:hover .video-controls,
.video-container.playing .video-controls-visible {
  opacity: 1;
}

.video-progress-wrapper {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.2);
  cursor: pointer;
  position: relative;
  border-radius: 1.5px;
}

.video-progress-buffer {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255,255,255,0.3);
  border-radius: 1.5px;
}

.video-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: #fff;
  border-radius: 1.5px;
  transition: width 0.1s linear;
}

.video-progress-wrapper:hover {
  height: 5px;
}

.video-bottom-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.video-left-controls,
.video-right-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.video-btn {
  color: #fff;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0;
  display: flex;
  align-items: center;
  transition: opacity var(--transition-fast);
}
.video-btn:hover { opacity: 0.7; }

.video-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.video-time {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.7);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.video-volume-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.video-volume-slider {
  width: 60px;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.3);
  outline: none;
  border-radius: 1.5px;
  cursor: pointer;
}
.video-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.video-play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition-base), transform var(--transition-base);
}
.video-play-overlay svg {
  width: 24px;
  height: 24px;
  fill: #fff;
  margin-left: 3px;
}
.video-container.playing .video-play-overlay {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.2);
}

/* Video coming soon placeholder */
.video-coming-soon {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  border: 1px solid rgba(255,255,255,0.06);
}
.video-coming-soon-text {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
}
.video-coming-soon svg {
  width: 32px;
  height: 32px;
  stroke: rgba(255,255,255,0.15);
  fill: none;
  stroke-width: 1.5;
}

/* ---------- Tools ---------- */
.tools-intro {
  font-size: 1rem;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-xl);
  max-width: 600px;
}

/* Periodic Table of Tools */
.periodic-table {
  margin-top: var(--space-lg);
}

.pt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 180px);
  gap: 16px 8px;
  align-items: start;
}

.pt-series-separator {
  margin-top: var(--space-xl);
  padding-top: var(--space-md);
  border-top: 1px dashed var(--color-border);
}

.pt-series-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--space-sm);
}

.element-card {
  position: relative;
  width: 180px;
  height: 200px;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
}

.element-card:hover {
  border-color: var(--color-text);
  box-shadow: 0 0 0 1px var(--color-text);
}

.element-number {
  position: absolute;
  top: 10px;
  left: 14px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
  line-height: 1;
}

.element-symbol {
  position: absolute;
  top: 44px;
  left: 14px;
  font-family: var(--font-heading);
  font-size: 3.25rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.element-name {
  position: absolute;
  bottom: 36px;
  left: 14px;
  right: 14px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-secondary);
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.element-category {
  position: absolute;
  bottom: 14px;
  left: 14px;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
}

/* Hover image overlay */
.element-hover-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.element-card.has-image:hover .element-hover-img {
  opacity: 1;
}

.element-card.has-image:hover .element-number,
.element-card.has-image:hover .element-symbol,
.element-card.has-image:hover .element-name,
.element-card.has-image:hover .element-category {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* No-image hover: glow effect */
.element-card:not(.has-image):hover {
  background: var(--color-accent);
}

.element-card:not(.has-image):hover .element-number {
  color: var(--color-bg);
  opacity: 0.5;
}

.element-card:not(.has-image):hover .element-symbol {
  color: var(--color-bg);
}

.element-card:not(.has-image):hover .element-name {
  color: var(--color-bg);
  opacity: 0.8;
}

.element-card:not(.has-image):hover .element-category {
  color: var(--color-bg);
  opacity: 0.5;
}

/* Element wrapper + description on hover */
.element-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.element-desc {
  max-width: 180px;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
  letter-spacing: 0.02em;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease;
}

.element-wrapper:hover .element-desc {
  opacity: 1;
  max-height: 120px;
}

/* Category color accents — left border stripe */
.element-card[data-category="plugin"] {
  border-left: 3px solid #4a90d9;
}
.element-card[data-category="app"] {
  border-left: 3px solid #6fcf97;
}
.element-card[data-category="library"] {
  border-left: 3px solid #4ad97a;
}
.element-card[data-category="hardware"] {
  border-left: 3px solid #c9956b;
}
.element-card[data-category="service"] {
  border-left: 3px solid #d9a84a;
}

@media (max-width: 768px) {
  .pt-grid {
    grid-template-columns: repeat(auto-fill, 140px);
  }
  .element-card {
    width: 140px;
    height: 160px;
  }
  .element-symbol {
    font-size: 2.5rem;
    top: 38px;
    left: 10px;
  }
  .element-number {
    top: 8px;
    left: 10px;
  }
  .element-name {
    bottom: 28px;
    left: 10px;
    right: 10px;
    font-size: 0.625rem;
  }
  .element-category {
    bottom: 10px;
    left: 10px;
    font-size: 0.5rem;
  }
  .element-desc {
    max-width: 140px;
    font-size: 0.5625rem;
  }
  .journal-list {
    grid-template-columns: 1fr;
  }
  .journal-entry {
    padding: 18px;
    min-height: 130px;
  }
  .journal-title {
    font-size: 1.1rem;
  }
}

/* ---------- About ---------- */
.about-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3xl);
  align-items: start;
}

.about-photo-wrap {
  width: 100%;
}

.about-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: var(--color-placeholder);
  transition: background var(--transition-base);
}

.about-photo-credit {
  display: block;
  margin-top: var(--space-xs, 0.5rem);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
  opacity: 0.5;
  text-align: right;
}

.about-content { padding-top: var(--space-lg); }

.about-name {
  font-size: 2.5rem;
  font-weight: 400;
  margin-bottom: var(--space-lg);
}

.about-bio {
  font-size: 1rem;
  line-height: 1.9;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

.about-contact {
  font-size: 0.8125rem;
  color: var(--color-text-tertiary);
}
.about-contact a {
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: border-color var(--transition-fast);
}
.about-contact a:hover { border-color: var(--color-text); }

/* ---------- CV ---------- */
.cv-section {
  margin-bottom: var(--space-xl);
}

.cv-section-title {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
}

.cv-entry {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
}

.cv-year {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-text-tertiary);
}

.cv-details h3 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.cv-details h3 a {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.cv-details h3 a:hover {
  opacity: 0.7;
  text-decoration: underline;
}

.cv-details p {
  font-size: 0.8125rem;
  font-weight: 300;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* ---------- Journal ---------- */
.journal-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  align-items: start;
}

.journal-entry {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  min-height: 160px;
  overflow: hidden;
}
.journal-entry:first-child { padding-top: 24px; }

.journal-entry:hover {
  border-color: var(--color-text);
  box-shadow: 0 0 0 1px var(--color-text);
}

.journal-date {
  position: absolute;
  top: 12px;
  right: 14px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 0;
}

.journal-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 8px;
  line-height: 1.3;
  position: relative;
  z-index: 1;
  transition: color 0.3s ease;
}

.journal-excerpt {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-tertiary);
  line-height: 1.6;
  letter-spacing: 0.02em;
  position: relative;
  z-index: 1;
  transition: color 0.3s ease;
}

/* Journal hover image overlay */
.journal-entry-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  z-index: 0;
}

.journal-entry.has-image:hover .journal-entry-img {
  opacity: 1;
}

.journal-entry.has-image:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.1) 60%, transparent 100%);
  z-index: 0;
  pointer-events: none;
}

.journal-entry.has-image:hover .journal-title,
.journal-entry.has-image:hover .journal-excerpt {
  color: #fff;
  z-index: 2;
}

.journal-entry.has-image:hover .journal-date {
  color: rgba(255,255,255,0.7);
  z-index: 2;
}

/* No-image hover: subtle glow like element cards */
.journal-entry:not(.has-image):hover {
  background: var(--color-accent);
}

.journal-entry:not(.has-image):hover .journal-title {
  color: var(--color-bg);
}

.journal-entry:not(.has-image):hover .journal-date,
.journal-entry:not(.has-image):hover .journal-excerpt {
  color: var(--color-bg);
  opacity: 0.6;
}

/* Journal Article Detail */
.journal-article {
  max-width: 720px;
}

.journal-back {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-bottom: var(--space-xl);
  transition: color var(--transition-fast);
}
.journal-back:hover {
  color: var(--color-text);
}

.journal-article-header {
  margin-bottom: var(--space-2xl);
}

.journal-article-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-sm);
}

.journal-article-title {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.3;
}

.journal-article-body {
  font-size: 1rem;
  line-height: 1.85;
  color: var(--color-text-secondary);
}

.journal-article-body p {
  margin-bottom: var(--space-lg);
}

.journal-article-body p:last-child {
  margin-bottom: 0;
}

/* ---------- Footer ---------- */
.footer {
  padding: var(--space-xl) var(--space-lg);
  border-top: 1px solid var(--color-border-light);
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root {
    --nav-height: 60px;
  }

  .nav-links { display: none; }
  .nav-mobile-toggle { display: flex; }

  .nav-links.mobile-open {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    min-height: 100vh;
    min-height: 100dvh; /* dynamic viewport height for mobile Safari */
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(40px) saturate(1.8);
    -webkit-backdrop-filter: blur(40px) saturate(1.8);
    padding: var(--space-2xl);
    padding-top: calc(var(--nav-height) + var(--space-xl));
    gap: var(--space-md);
    z-index: 99;
    animation: mobileMenuIn 0.2s ease-out;
    overflow-y: auto;
  }

  [data-theme="dark"] .nav-links.mobile-open {
    background: rgba(20, 20, 20, 0.45);
  }

  /* Force text color in overlay — overrides nav-transparent white */
  .nav-links.mobile-open,
  .nav-links.mobile-open .nav-link {
    color: var(--color-text) !important;
  }

  .nav-links.mobile-open .mobile-menu-close {
    display: block;
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--color-text);
    opacity: 0.5;
    transition: opacity var(--transition-fast);
    padding: var(--space-sm);
    line-height: 1;
  }
  .nav-links.mobile-open .mobile-menu-close:hover {
    opacity: 1;
  }

  .nav-links.mobile-open .nav-link {
    font-size: 1.75rem;
    font-family: var(--font-heading);
    font-weight: 300;
    letter-spacing: 0.02em;
    padding: var(--space-sm) 0;
    opacity: 0;
    animation: mobileItemIn 0.3s ease-out forwards;
  }
  .nav-links.mobile-open .nav-link:nth-child(1) { animation-delay: 0.05s; }
  .nav-links.mobile-open .nav-link:nth-child(2) { animation-delay: 0.1s; }
  .nav-links.mobile-open .nav-link:nth-child(3) { animation-delay: 0.15s; }
  .nav-links.mobile-open .nav-link:nth-child(4) { animation-delay: 0.2s; }
  .nav-links.mobile-open .nav-link:nth-child(5) { animation-delay: 0.25s; }
  .nav-links.mobile-open .nav-link:nth-child(6) { animation-delay: 0.3s; }

  .nav-links.mobile-open .nav-link.active::after {
    bottom: -2px;
    height: 2px;
    background: var(--color-text) !important;
  }

  @keyframes mobileMenuIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  @keyframes mobileItemIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .hero-cinematic {
    min-height: 100svh; /* use small viewport height on mobile for better fit */
  }

  .works-grid {
    grid-template-columns: 1fr;
  }

  .about-layout {
    grid-template-columns: 1fr;
    gap: var(--space-xl);
  }

  .about-photo-wrap,
  .about-photo {
    max-width: 400px;
  }

  .cv-entry {
    grid-template-columns: 1fr;
    gap: var(--space-xs);
  }

  .page-inner {
    padding: var(--space-lg) var(--space-md);
  }

  .wd-hero {
    min-height: 500px;
  }

  .work-detail-close {
    left: 16px;
    top: 16px;
    padding: 8px 14px;
  }

  .wd-details-grid {
    grid-template-columns: 1fr 1fr;
  }

  .footer {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }
}

@media (max-width: 480px) {
  .works-header {
    flex-direction: column;
  }

  #writingGrid.works-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md) var(--space-sm);
  }

  #writingGrid .work-card-image {
    padding: 1rem;
  }
}

/* Touch devices: always show video controls */
@media (hover: none) {
  .video-controls {
    opacity: 1;
  }
}

/* ---------- Loading / Transition Effects ---------- */
.fade-in {
  animation: fadeIn var(--transition-slow) forwards;
}

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

.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
.stagger-5 { animation-delay: 0.25s; }
.stagger-6 { animation-delay: 0.3s; }
.stagger-7 { animation-delay: 0.35s; }
.stagger-8 { animation-delay: 0.4s; }
.stagger-9 { animation-delay: 0.45s; }

/* ===== Games Periodic Table ===== */
.games-periodic-table {
  margin-top: var(--space-lg);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 280px);
  gap: 20px 12px;
  align-items: start;
}

.game-card {
  position: relative;
  width: 280px;
  height: 320px;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
}

.game-card:hover {
  border-color: var(--color-text);
  box-shadow: 0 0 0 1px var(--color-text);
}

.game-number {
  position: absolute;
  top: 14px;
  left: 18px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
  line-height: 1;
}

.game-symbol {
  position: absolute;
  top: 56px;
  left: 18px;
  font-family: var(--font-heading);
  font-size: 5rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.game-name {
  position: absolute;
  bottom: 44px;
  left: 18px;
  right: 18px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.game-category {
  position: absolute;
  bottom: 18px;
  left: 18px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--color-text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
}

.game-hover-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.game-card.has-image:hover .game-hover-img { opacity: 1; }
.game-card.has-image:hover .game-number,
.game-card.has-image:hover .game-symbol,
.game-card.has-image:hover .game-name,
.game-card.has-image:hover .game-category { opacity: 0; transition: opacity 0.2s ease; }

.game-card:not(.has-image):hover { background: var(--color-accent); }
.game-card:not(.has-image):hover .game-number { color: var(--color-bg); opacity: 0.5; }
.game-card:not(.has-image):hover .game-symbol { color: var(--color-bg); }
.game-card:not(.has-image):hover .game-name { color: var(--color-bg); opacity: 0.8; }
.game-card:not(.has-image):hover .game-category { color: var(--color-bg); opacity: 0.5; }

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.game-desc {
  max-width: 280px;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
  letter-spacing: 0.02em;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease;
}

.game-wrapper:hover .game-desc {
  opacity: 1;
  max-height: 120px;
}

.game-card[data-category="engine"]     { border-left: 3px solid #ff6b6b; }
.game-card[data-category="adventure"]  { border-left: 3px solid #4ecdc4; }
.game-card[data-category="rpg"]        { border-left: 3px solid #a855f7; }
.game-card[data-category="simulation"] { border-left: 3px solid #f59e0b; }

@media (max-width: 768px) {
  .games-grid { grid-template-columns: repeat(auto-fill, 200px); }
  .game-card { width: 200px; height: 240px; }
  .game-symbol { font-size: 3.5rem; top: 46px; left: 14px; }
  .game-number { top: 10px; left: 14px; }
  .game-name { bottom: 34px; left: 14px; right: 14px; font-size: 0.6875rem; }
  .game-category { bottom: 14px; left: 14px; font-size: 0.5625rem; }
  .game-desc { max-width: 200px; font-size: 0.625rem; }
}
