/* ===== Design Tokens ===== */
:root {
  --color-bg: #fff;
  --color-text: #333;
  --color-text-muted: #555;
  --color-text-light: #ccc;
  --color-surface: #fff;
  --color-header: #000;
  --color-header-text: #fff;
  --color-tag-bg: #f5f5f5;
  --color-border: rgba(0, 0, 0, 0.1);
  --color-shadow: rgba(0, 0, 0, 0.1);
  --color-gallery-bg: #1a1a1a;
  --color-gallery-card: #222;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-pill: 15px;
  --shadow-card: 0 2px 10px var(--color-shadow);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  font-family: var(--font-sans);
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

main {
  flex: 1 0 auto;
}

/* ===== Header ===== */
header {
  background-color: var(--color-header);
  color: var(--color-header-text);
  padding: 2rem 0;
  text-align: center;
}

.header-title {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.header-subtitle {
  color: var(--color-text-light);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

header nav {
  margin-top: 1rem;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}

header nav a {
  color: var(--color-header-text);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: color var(--transition-normal);
}

header nav a:hover {
  color: var(--color-text-light);
}

header nav a i {
  flex: 0 0 auto;
}

/* ===== Buttons ===== */
.view-cv-btn,
.download-cv-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-header);
  color: var(--color-header-text);
  padding: 0.8rem 1.5rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 1rem;
  transition: background-color var(--transition-normal), transform var(--transition-fast);
}

.view-cv-btn:hover,
.download-cv-btn:hover {
  background: #333;
  transform: translateY(-2px);
}

header nav .view-cv-btn {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  background: transparent;
}

header nav .view-cv-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--color-header-text);
}

/* ===== Layout ===== */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

/* ===== Welcome Section ===== */
.welcome {
  text-align: center;
  max-width: 800px;
  margin: 2rem auto;
}

.welcome h2 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
}

.divider {
  height: 1px;
  background: var(--color-border);
  margin: 3rem 0 2rem;
}

/* ===== Projects Grid ===== */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 2rem;
  margin: 2rem 0;
}

.project-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.project-card-link:hover {
  text-decoration: none;
  color: inherit;
}

.project-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-fast);
}

.project-card:hover {
  transform: translateY(-5px);
}

.project-card img {
  width: 100%;
  height: 250px;
  object-fit: cover;
}

.project-info {
  padding: 1.5rem;
}

.project-tags {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.tag {
  background: var(--color-tag-bg);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
}

/* ===== Category Dividers ===== */
.cat-divider {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 0.25rem;
  font: 600 0.95rem/1.4 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.cat-divider::after {
  content: "";
  height: 1px;
  flex: 1 1 auto;
  background: currentColor;
  opacity: 0.25;
}

.cat-note {
  grid-column: 1 / -1;
  margin: 0.5rem 0 1.5rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.775rem;
  line-height: 1.35;
  color: var(--color-text-muted);
  background: rgba(0, 0, 0, 0.045);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.cat-note::before {
  content: "\2139\FE0E";
  font-weight: 600;
  opacity: 0.6;
  line-height: 1;
}

/* ===== Contact Section ===== */
.contact-section {
  text-align: center;
  margin: 3rem 0;
}

.contact-info {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  max-width: 810px;
  margin: 2rem auto;
}

.contact-info a {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 1rem 0;
  color: var(--color-text);
  text-decoration: none;
  gap: 0.5rem;
}

.contact-info a i {
  margin-right: 0.5rem;
}

/* ===== Footer ===== */
footer {
  background: var(--color-header);
  color: var(--color-header-text);
  text-align: center;
  padding: 1rem;
  margin-top: auto;
}

/* ===== CV Page ===== */
.cv-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-md);
}

.cv-header {
  text-align: center;
  margin-bottom: 2rem;
}

.cv-section {
  margin-bottom: 2rem;
  text-align: left;
}

.cv-section h2 {
  color: var(--color-text);
  border-bottom: 2px solid var(--color-header);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.experience-item {
  margin-bottom: 1.5rem;
}

.experience-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.cv-section ul {
  margin-left: 0;
  padding-left: 1.2em;
}

.cv-section ul li {
  margin-bottom: 0.5em;
}

.small-skills {
  font-size: 0.9em;
}

.small-subtitle {
  font-size: 0.7em;
}

/* ===== Gallery Page ===== */
.gallery-container {
  position: relative;
  flex: 1;
  width: 100%;
  background: var(--color-gallery-bg);
  overflow: hidden;
}

.carousel-wrapper {
  width: 100%;
  overflow: hidden;
  background: #111;
  margin-bottom: 2.5rem;
}

.carousel {
  display: flex;
  gap: 2.5rem;
  animation: scroll-carousel 40s linear infinite;
  will-change: transform;
  align-items: center;
}

.carousel li {
  list-style: none;
  flex: 0 0 auto;
  width: 320px;
  height: 200px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  background: var(--color-gallery-card);
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@keyframes scroll-carousel {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ===== Photo Grid ===== */
.grid-wrapper {
  width: 100%;
  max-width: 100vw;
  padding: 0 2vw 2vw;
  margin: 0 auto;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  gap: 3rem;
  list-style: none;
  justify-items: center;
  align-items: start;
}

.gallery-item {
  display: flex;
  justify-content: center;
  align-items: center;
}

.gallery-item figure {
  min-width: 25vw;
  height: 70vh;
  cursor: pointer;
  width: 100%;
  max-width: none;
  aspect-ratio: 1 / 1.5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  background: var(--color-gallery-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.gallery-item figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-fast);
}

.photo-grid .gallery-item,
.photo-grid .gallery-item figure {
  width: 100%;
  max-width: none;
  min-width: 0;
  aspect-ratio: 1 / 1.5;
}

.photo-grid .gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  cursor: pointer;
}

.photo-grid .gallery-item img:hover {
  transform: scale(0.85);
  background: #111;
  object-fit: contain;
  transition: transform 0.9s, background 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  max-width: 90%;
  max-height: 90vh;
  position: relative;
}

.modal-content img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

.close-modal {
  position: absolute;
  top: -40px;
  right: 0;
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
}

/* ===== Loading Overlay ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: #111;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  z-index: 2000;
  flex-direction: column;
}

#loading-overlay > * {
  position: relative;
  z-index: 2;
}

#loading-count {
  margin-top: 1rem;
}

#force-open-gallery {
  margin-top: 2rem;
  padding: 0.7rem 2rem;
  font-size: 1.5rem;
  border-radius: var(--radius-md);
  border: none;
  background: #333;
  color: #fff;
  cursor: pointer;
  min-height: 44px;
}

.gallery-container + footer {
  z-index: 10;
}

/* ===== Responsive: Tablet & Below ===== */
@media (max-width: 1200px) {
  .photo-grid {
    gap: 1.5rem;
  }
}

@media (max-width: 1024px) {
  header nav a {
    font-size: 0.95rem;
  }

  .gallery-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2rem 0;
  }

  .gallery-item figure {
    min-width: unset;
    width: 90%;
    aspect-ratio: 1 / 1.5;
    max-height: 60vh;
  }

  .carousel li,
  .gallery-item figure {
    max-width: 240px;
    max-height: 240px;
  }

  .photo-grid {
    grid-template-columns: repeat(4, minmax(90px, 1fr));
    gap: 1.5rem;
  }
}

@media (max-width: 900px) {
  .carousel li {
    width: 180px;
    height: 110px;
  }

  .photo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .projects-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  header nav a {
    flex: 0 0 48%;
    justify-content: center;
  }

  header nav a:last-child:nth-child(odd) {
    margin-left: auto;
    margin-right: auto;
  }

  .cv-section ul,
  .cv-section ul li {
    text-align: left;
    width: 100%;
  }
}

@media (max-width: 600px) {
  .photo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }

  .carousel li,
  .gallery-item figure,
  .gallery-item {
    max-height: 180px;
  }
}

/* ===== Accessibility: Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .carousel {
    animation: none;
  }

  .project-card:hover {
    transform: none;
  }

  .photo-grid .gallery-item img:hover {
    transform: none;
    transition: none;
  }
}

/* ===== Dark Mode (cat-note) ===== */
@media (prefers-color-scheme: dark) {
  .cat-note {
    color: #d0d0d0;
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.12);
  }
}
