:root[data-theme=dark] {
  --bg: #0f0f0f;
  --bg-surface: #1a1a1a;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #2e9cdb;
  --border: #2a2a2a;
}

:root[data-theme=light] {
  --bg: #f5f5f5;
  --bg-surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #1a87c8;
  --border: #e0e0e0;
}

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

body {
  font-family: "Segoe UI", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 60px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.navbar__logo a {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}
.navbar__links {
  display: flex;
  gap: 1.5rem;
  flex: 1;
}
.navbar__links a {
  font-size: 0.95rem;
  color: var(--text-muted);
  transition: color 0.2s;
}
.navbar__links a:hover {
  color: var(--text);
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  color: var(--text);
  transition: border-color 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle__icon { display: none; }

/* ── Hero ── */
.hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  flex: 1;
  padding: 3rem 4rem;
  background: var(--bg);
}
.hero__avatar { flex-shrink: 0; }
.hero__avatar img {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
}
.hero__content { max-width: 600px; }
.hero__title {
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 700;
  margin-bottom: 0.75rem;
  line-height: 1.2;
}
.hero__title.typing::after {
  content: "|";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: blink 0.7s step-end infinite;
}
.hero__sub {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}
.hero__actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Button ── */
.btn {
  display: inline-block;
  padding: 0.65rem 1.75rem;
  background-color: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-weight: 600;
  border: 2px solid var(--accent);
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn--outline {
  background-color: transparent;
  color: var(--accent);
}
.btn--outline:hover {
  background-color: var(--accent);
  color: #fff;
  opacity: 1;
}

/* ── CV layout ── */
.cv-page { overflow: hidden; }

.cv-layout {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.cv-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
}
.cv-sidebar__header {
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.cv-sidebar__header h1 {
  font-size: 1rem;
  font-weight: 700;
}
.cv-sidebar__nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.5rem;
  flex: 1;
}
.cv-sidebar__item {
  background: none;
  border: none;
  border-left: 3px solid transparent;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.cv-sidebar__item svg { flex-shrink: 0; }
.cv-sidebar__item:hover {
  background: var(--bg);
  color: var(--text);
}
.cv-sidebar__item.active {
  border-left-color: var(--accent);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}
.cv-sidebar__footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.cv-detail {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 3rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.cv-detail__loading {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cv-detail__panel {
  width: 100%;
  max-width: 960px;
  padding-bottom: 4rem;
}

/* ── CV Cards ── */
.cv__cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.cv__cards-row .cv__card {
  flex: 1 1 340px;
  margin-bottom: 0;
}
.cv__card {
  display: flex;
  gap: 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.cv__card--edu {
  flex-direction: column;
  gap: 0.5rem;
}
.cv__card-edu-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.cv__card-edu-body { flex: 1; }
.cv__card-edu-footer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}
.cv__card-logo--bottom {
  padding-top: 0;
  width: 60%;
}
.cv__card-logo--bottom img {
  width: 100%;
  max-height: 120px;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
  padding: 0.5rem;
}
.cv__card-main { flex: 1; }
.cv__card-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.2rem;
}
.cv__card-date {
  color: var(--accent);
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
  white-space: nowrap;
}
.cv__card-company {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.cv__card-thesis {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0.4rem 0 0.75rem;
}
.cv__card-papers-label {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0;
  color: var(--text);
}
.cv__card-papers {
  display: flex;
  flex-direction: column;
  margin: 0.4rem 0 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.cv__card-cert-image {
  width: 100%;
  margin-bottom: 0.5rem;
}
.cv__card-cert-image img {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 6px;
}
.cv__card-cert-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.cv__card-cert-actions-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.cv__card-software {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cv__card-software .cv__card-tags { margin-top: 0; }
.cv__card-tags {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  width: fit-content;
}
.cv__card-side {
  flex-shrink: 0;
  width: 160px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}
.cv__card-logo { width: 100%; }
.cv__card-logo img {
  width: 100%;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
  padding: 0.5rem;
}
.cv__card-location {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-bottom: 1.1rem;
}
.cv__card-location img {
  vertical-align: middle;
  margin-right: 3px;
}

/* ── Key Projects grid ── */
.cv__projects {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  padding: 0.5rem 0;
}
.cv__project-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  transition: border-color 0.2s, transform 0.2s;
  text-decoration: none;
}
.cv__project-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cv__project-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: var(--border);
}
.cv__project-item span {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0 0.75rem 0.75rem;
}
.cv__project-item-title {
  font-weight: 600;
  color: var(--text);
}
.cv__project-item-desc {
  font-size: 0.78rem;
  line-height: 1.4;
}

/* ── Projects page ── */
.projects-page { overflow: hidden; }

.projects-layout {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.projects-sidebar {
  width: 260px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 1rem 0;
}
.projects-sidebar__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.projects-sidebar__item img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--border);
}
.projects-sidebar__item span {
  font-size: 0.9rem;
  line-height: 1.3;
}
.projects-sidebar__item:hover {
  background: var(--bg);
  color: var(--text);
}
.projects-sidebar__item.active {
  border-left-color: var(--accent);
  background: var(--bg);
  color: var(--text);
}

.projects-detail {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}
.projects-detail__empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.projects-detail__content {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 860px;
  margin: 0 auto;
  padding-bottom: 4rem;
}
.projects-detail__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.projects-detail__title-row h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0;
}
.projects-detail__image img {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.projects-detail__desc {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}
.projects-detail__desc p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.8;
  margin-bottom: 0.75rem;
}
.projects-detail__desc p:last-child { margin-bottom: 0; }

/* ── Tool icons ── */
.tool-item {
  display: flex;
  align-items: center;
  gap: 0;
  overflow: hidden;
  max-width: 28px;
  transition: max-width 0.25s ease;
}
.tool-item:hover {
  max-width: 160px;
  gap: 0.4rem;
}
img.tool-icon {
  width: 28px !important;
  height: 28px !important;
  object-fit: contain;
  object-position: center;
  border-radius: 4px;
  flex-shrink: 0;
}
.tool-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease 0.05s;
}
.tool-item:hover .tool-label { opacity: 1; }

/* ── 3D model modal ── */
.model-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.model-modal[hidden] { display: none; }
.model-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}
.model-modal__box {
  position: relative;
  z-index: 1;
  width: 80vw;
  height: 75vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.model-modal__box canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.model-modal__layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.model-modal__tree-panel {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.model-modal__tree-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.model-modal__tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.model-modal__tree label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-modal__tree label:hover { color: var(--text); }
.model-modal__tree label input {
  cursor: pointer;
  width: 12px;
  height: 12px;
}
.model-modal__tree .tree-group { padding-left: 0.6rem; }
.model-modal__viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.model-modal__viewport canvas {
  flex: 1;
  width: 100% !important;
  display: block;
}
.model-modal__controls {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 2;
  font-size: 0.7rem;
  color: #666;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.model-modal__controls-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.model-modal__sep {
  color: #aaa;
  margin: 0 0.4rem;
  font-weight: 300;
}
.model-modal__label {
  font-weight: 600;
  margin-right: 0.15rem;
}
.model-modal__bg-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 2px solid #333;
  cursor: pointer;
  vertical-align: middle;
}
.model-modal__bg-swatch.active { border-color: var(--accent); }
.model-modal__bg-swatch:hover { opacity: 0.8; }
.model-modal__bg-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  color: #333;
}
.model-modal__bg-btn:hover { border-color: #888; }
.model-modal__context-menu {
  position: absolute;
  z-index: 10;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.model-modal__context-menu[hidden] { display: none; }
.model-modal__context-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 0.4rem 0.75rem;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}
.model-modal__context-menu button:hover { background: var(--bg); }
.model-modal__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.model-modal__close:hover { border-color: var(--accent); }

/* ── PDF modal ── */
.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pdf-modal[hidden] { display: none; }
.pdf-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}
.pdf-modal__box {
  position: relative;
  z-index: 1;
  width: 70vw;
  height: 85vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pdf-modal__box iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
}
.pdf-modal__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pdf-modal__close:hover { border-color: var(--accent); }

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    padding: 2rem 1.5rem;
    gap: 1.5rem;
    text-align: center;
  }
  .hero__avatar img { width: 120px; height: 120px; }
  .hero__actions { justify-content: center; }
  .navbar { padding: 0 1rem; gap: 1rem; }
  .navbar__links { gap: 0.75rem; }
  .navbar__links a { font-size: 0.85rem; }
  .cv-page { overflow: auto; }
  .projects-page { overflow: auto; }
  .cv-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 60px);
  }
  .cv-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .cv-sidebar__nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
  }
  .cv-sidebar__item {
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }
  .cv-sidebar__item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }
  .cv-sidebar__footer { padding: 0.75rem 1rem; }
  .cv-detail { padding: 1.5rem 1rem; }
  .cv__card { flex-direction: column; }
  .cv__card-side { width: 100%; flex-direction: row; align-items: center; }
  .cv__card-logo { width: 80px; }
  .cv__projects { grid-template-columns: repeat(2, 1fr); }
  .projects-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 60px);
  }
  .projects-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
  }
  .projects-detail { padding: 1.5rem 1rem; }
  .model-modal__box { width: 95vw; height: 80vh; }
  .model-modal__layout { flex-direction: column; }
  .model-modal__tree-panel {
    width: 100%;
    max-height: 120px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 480px) {
  .cv__projects { grid-template-columns: 1fr; }
  .hero__title { font-size: 1.5rem; }
}
