:root {
  --bg: #fafafa;
  --bg-secondary: #f3f4f6;
  --surface: #fff;
  --text: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;
  --text-body: #374151;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-selection: rgba(99, 102, 241, 0.15);
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --quote-border: #d0d0d0;
  --orb-purple: rgba(236, 200, 255, 0.25);
  --orb-purple-edge: rgba(200, 180, 255, 0.12);
  --orb-blue: rgba(200, 230, 255, 0.2);
  --orb-blue-edge: rgba(180, 220, 255, 0.1);
  --orb-rose: rgba(255, 200, 210, 0.18);
  --orb-rose-edge: rgba(255, 180, 200, 0.08);
  --font-serif: 'Newsreader', Georgia, serif;
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Dark palette — system preference when no manual theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* Feynman-style neutrals: canvas #171717, elevated UI #262626 */
    --bg: #171717;
    --bg-secondary: #262626;
    --surface: #262626;
    --text: #ffffff;
    --text-secondary: #a3a3a3;
    --text-tertiary: #737373;
    --text-body: #d4d4d4;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-selection: rgba(129, 140, 248, 0.22);
    --border: #404040;
    --border-light: #2a2a2a;
    --quote-border: #404040;
    --orb-purple: rgba(120, 120, 140, 0.08);
    --orb-purple-edge: rgba(90, 90, 110, 0.04);
    --orb-blue: rgba(100, 120, 150, 0.07);
    --orb-blue-edge: rgba(70, 90, 120, 0.035);
    --orb-rose: rgba(130, 110, 115, 0.06);
    --orb-rose-edge: rgba(100, 85, 90, 0.03);
  }
}

:root[data-theme="dark"] {
  --bg: #171717;
  --bg-secondary: #262626;
  --surface: #262626;
  --text: #ffffff;
  --text-secondary: #a3a3a3;
  --text-tertiary: #737373;
  --text-body: #d4d4d4;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-selection: rgba(129, 140, 248, 0.22);
  --border: #404040;
  --border-light: #2a2a2a;
  --quote-border: #404040;
  --orb-purple: rgba(120, 120, 140, 0.08);
  --orb-purple-edge: rgba(90, 90, 110, 0.04);
  --orb-blue: rgba(100, 120, 150, 0.07);
  --orb-blue-edge: rgba(70, 90, 120, 0.035);
  --orb-rose: rgba(130, 110, 115, 0.06);
  --orb-rose-edge: rgba(100, 85, 90, 0.03);
}

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

html {
  color-scheme: light dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

/* Theme toggle — moon when light UI, sun when dark UI */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.2s var(--ease);
}

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

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle svg {
  display: block;
}

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

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

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

/* Detached from social row: viewport chrome, not a “link” */
.theme-toggle--fixed {
  position: fixed;
  top: max(1.1rem, env(safe-area-inset-top, 0px));
  right: max(1.1rem, env(safe-area-inset-right, 0px));
  z-index: 2;
  padding: 0.4rem;
  border-radius: 8px;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.theme-toggle--fixed:hover {
  background-color: var(--border-light);
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  font-weight: 400;
  position: relative;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  top: -10%;
  right: -15%;
  width: 60vw;
  height: 60vw;
  max-width: 700px;
  max-height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--orb-purple) 0%, var(--orb-purple-edge) 40%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -5%;
  left: -10%;
  width: 50vw;
  height: 50vw;
  max-width: 600px;
  max-height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--orb-blue) 0%, var(--orb-blue-edge) 40%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.gradient-orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.gradient-orb--rose {
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  width: 50vw;
  height: 50vw;
  max-width: 550px;
  max-height: 550px;
  background: radial-gradient(circle, var(--orb-rose) 0%, var(--orb-rose-edge) 40%, transparent 70%);
}

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

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s var(--ease);
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* --- Animations --- */

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

.animate-in {
  animation: fadeUp 0.6s var(--ease) both;
}

/* --- Layout --- */

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 4rem 1.5rem 4rem;
  position: relative;
  z-index: 1;
}

/* --- Header --- */

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.name {
  font-family: var(--font-serif);
  font-size: 2.1rem;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

.social {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-shrink: 0;
  padding-top: 0.4rem;
}

.social a {
  color: var(--text-tertiary);
  display: flex;
  transition: color 0.2s var(--ease);
}

.social a:hover {
  color: var(--text);
  text-decoration: none;
}

.bio {
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.65;
  color: var(--text-body);
  white-space: pre-line;
}

.aside-bio {
  position: absolute;
  top: 4.5rem;
  left: calc(100% + 2.5rem);
  width: 180px;
  padding-left: 1rem;
  border-left: 1px solid var(--border-light);
}

.about-list {
  list-style: none;
}

.about-list li {
  font-size: 0.68rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-tertiary);
  padding-left: 0.75rem;
  position: relative;
}

.about-list li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--border);
}

.about-list li + li {
  margin-top: 0.35rem;
}

@media (max-width: 1280px) {
  .aside-bio {
    display: none;
  }
}

.bio[contenteditable="true"] {
  outline: none;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  background: var(--surface);
}

/* --- Bio Edit --- */

.bio-edit-bar {
  display: none;
  margin-top: 0.35rem;
}

.bio-edit-bar.visible {
  display: flex;
  gap: 0.5rem;
}

.bio-edit-btn {
  font-family: var(--font-serif);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.bio-edit-btn:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
}

.bio-edit-btn--save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.bio-edit-btn--save:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* --- Quote --- */

.quote {
  border-left: 1.5px solid var(--quote-border);
  padding: 0 0 0 1.25rem;
  margin: 2.5rem 0;
  background: none;
  border-radius: 0;
}

.quote p {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.8;
  color: var(--text-body);
  letter-spacing: 0.01em;
}

.quote p + p {
  margin-top: 0.6rem;
}

.quote cite {
  display: block;
  margin-top: 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-style: normal;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

/* --- Section --- */

.section {
  margin-top: 2.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.section-header .section-title {
  margin-bottom: 0;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 0.8rem;
}

/* --- Products --- */

.product-list {
  list-style: none;
}

.product-list li {
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text-secondary);
  padding: 0.35rem 0;
}

.product-list li + li {
  border-top: none;
}

.product-list a {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 0.9rem;
}

/* --- Articles --- */

.article-list {
  list-style: none;
}

.article-list li {
  padding: 0.4rem 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.article-list li + li {
  border-top: 1px solid var(--border-light);
}

.article-list a {
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.5;
  flex: 1;
}

.article-date {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-tertiary);
  flex-shrink: 0;
  white-space: nowrap;
}

/* --- Timeline --- */

.timeline {
  display: flex;
  flex-direction: column;
}

.timeline-year {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  padding: 1.2rem 0 0.4rem;
}

.timeline-year:first-child {
  padding-top: 0;
}

.timeline-item {
  display: flex;
  gap: 1.25rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border-light);
  position: relative;
}

.timeline-year + .timeline-item {
  padding-top: 0.5rem;
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-date {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 5.5rem;
  padding-top: 0.15rem;
  letter-spacing: 0.01em;
}

.timeline-content {
  flex: 1;
}

.timeline-text {
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-secondary);
}

.timeline-link {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  transition: color 0.15s var(--ease);
}

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

.timeline-delete {
  position: absolute;
  top: 0.9rem;
  right: 0;
  background: none;
  border: none;
  color: var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.2rem;
  display: none;
  transition: color 0.15s var(--ease);
}

.timeline-delete:hover {
  color: #e55;
}

.admin-active .timeline-delete {
  display: block;
}

/* --- Admin Panel --- */

.admin-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.15rem 0.45rem;
  transition: all 0.15s var(--ease);
  display: none;
}

.admin-toggle:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
}

.admin-toggle.visible {
  display: inline-flex;
}

.admin-panel {
  display: none;
  margin-bottom: 1rem;
  padding: 0.85rem;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.admin-panel.open {
  display: block;
}

.admin-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.admin-input {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s var(--ease);
}

.admin-input:focus {
  border-color: var(--accent);
}

.admin-input:first-child {
  flex: 1;
  min-width: 160px;
}

.admin-input:nth-child(2) {
  flex: 2;
  min-width: 180px;
}

.admin-input--date {
  width: 130px;
}

.admin-btn {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s var(--ease);
}

.admin-btn:hover {
  background: var(--accent-hover);
}

.admin-hint {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

/* --- Responsive --- */

@media (max-width: 640px) {
  .container {
    padding: 2.5rem 1.25rem 3rem;
  }

  .name {
    font-size: 1.7rem;
  }

  .header-top {
    flex-direction: column;
    gap: 0.5rem;
  }

  .social {
    padding-top: 0;
  }

  .quote {
    margin: 2rem 0;
    padding-left: 1rem;
  }

  .quote p {
    font-size: 0.9rem;
  }

  .section {
    margin-top: 2rem;
  }

  .timeline-item {
    flex-direction: column;
    gap: 0.2rem;
  }

  .timeline-date {
    min-width: auto;
  }

  .article-list li {
    flex-direction: column;
    gap: 0.15rem;
  }

  .admin-add {
    flex-direction: column;
  }

  .admin-input--date {
    width: 100%;
  }
}
