/* ============================================
   DESIGN SYSTEM — Victor Rios Portfolio
   ============================================ */

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

:root {
  --bg: #ffffff;
  --surface: #f8f8f8;
  --surface-2: #f0f0f0;
  --border: #e0e0e0;
  --border-hi: #cccccc;
  --text: #1a1a1a;
  --text-dim: #888888;
  --accent: #000000;
  --font: 'JetBrains Mono', monospace;
}

html {
  scroll-behavior: smooth;
  scrollbar-color: var(--border-hi) var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(56px + env(safe-area-inset-top, 0px) + 12px);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

img {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* --- Typography --- */
h1 {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
}

h2 {
  font-size: 24px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 40px;
}

h2 .prompt-symbol {
  color: var(--text-dim);
  margin-right: 8px;
}

h3 {
  font-size: 16px;
  font-weight: 500;
  color: var(--accent);
}

p {
  color: var(--text);
  line-height: 1.7;
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 max(40px, env(safe-area-inset-left, 0px)) 0 max(40px, env(safe-area-inset-right, 0px));
}

section {
  padding: 120px 0;
}

/* --- Light background grain (GPU-friendly vs huge fixed text layer) --- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.04;
  background-image: radial-gradient(var(--accent) 0.45px, transparent 0.55px);
  background-size: 12px 12px;
}

/* ============================================
   NAV
   ============================================ */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  contain: layout style;
}

.nav.visible {
  transform: translateY(0);
  opacity: 1;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 max(40px, env(safe-area-inset-left, 0px)) 0 max(40px, env(safe-area-inset-right, 0px));
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nav-logo {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.nav-links {
  display: flex;
  gap: 32px;
  list-style: none;
  flex-shrink: 0;
}

.nav-links a {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  transition: color 0.2s;
  padding-bottom: 2px;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
}

.nav-links a:hover::after,
.nav-links a.active::after {
  transform: scaleX(1);
}

/* ============================================
   HERO
   ============================================ */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  padding: 80px 0;
  padding-top: max(80px, env(safe-area-inset-top, 0px));
  padding-bottom: max(80px, env(safe-area-inset-bottom, 0px));
  position: relative;
  z-index: 1;
}

.hero-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  align-items: center;
  width: 100%;
}

.hero-terminal {
  width: 100%;
}

.hero-ascii {
  display: flex;
  justify-content: center;
  align-items: center;
}

.hero-ascii pre {
  font-size: 5px;
  line-height: 5.5px;
  letter-spacing: 1px;
  color: var(--text-dim);
  white-space: pre;
  margin: 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s ease 0.5s, transform 0.8s ease 0.5s;
}

.hero-ascii pre.loaded {
  opacity: 1;
  transform: translateY(0);
}

/* Terminal Component */
.terminal {
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.terminal-dot {
  width: 7px;
  height: 7px;
  border: 1px solid #ccc;
}

.terminal-title {
  margin-left: 6px;
  color: var(--text-dim);
  font-size: 10px;
}

.terminal-body {
  padding: 20px 20px;
}

.line {
  margin-bottom: 5px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.5;
}

.prompt {
  color: var(--text-dim);
}

.command {
  color: var(--accent);
}

.output {
  color: var(--text-dim);
}

.highlight {
  color: var(--accent);
  font-weight: 700;
}

.spacer {
  height: 14px;
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .nav {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(255, 255, 255, 0.98);
  }

  .cursor {
    animation: none;
    opacity: 1;
  }

  .reveal,
  .reveal-left,
  .reveal-scale,
  .stagger > * {
    transition-duration: 0.01ms !important;
  }
}

/* Hero tagline */
.hero-tagline {
  margin-top: 32px;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ============================================
   ASCII DIVIDERS
   ============================================ */
.ascii-divider {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  opacity: 0.3;
  padding: 0 max(40px, env(safe-area-inset-left, 0px)) 0 max(40px, env(safe-area-inset-right, 0px));
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  letter-spacing: 2px;
  user-select: none;
  white-space: nowrap;
  scrollbar-width: none;
}

.ascii-divider::-webkit-scrollbar {
  display: none;
}

/* ============================================
   ABOUT
   ============================================ */
#about {
  position: relative;
  z-index: 1;
}

.about-content {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 60px;
  align-items: start;
}

.about-text p {
  font-size: 14px;
  color: var(--text);
  line-height: 1.8;
  margin-bottom: 24px;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.skill-tag {
  padding: 6px 14px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: border-color 0.2s, color 0.2s;
}

.skill-tag:hover {
  border-color: var(--border-hi);
  color: var(--text);
}

.about-stats {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stat-item {
  border: 1px solid var(--border);
  padding: 20px;
  background: var(--surface);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
  display: block;
}

/* ============================================
   PROJECTS
   ============================================ */
#projects {
  position: relative;
  z-index: 1;
}

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: all 0.2s;
  background: transparent;
}

.filter-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
}

.filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0, 0, 0, 0.03);
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.project-card {
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
  opacity: 1;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hi);
}

.project-card.hidden {
  display: none;
}

.project-thumb {
  position: relative;
  height: 150px;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.project-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.project-thumb-placeholder {
  color: var(--text-dim);
  font-size: 9px;
  line-height: 9px;
  letter-spacing: 1px;
  white-space: pre;
  opacity: 0.5;
}

.project-ascii-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  opacity: 0;
  transition: opacity 0.3s ease;
  overflow: hidden;
}

.project-card:hover .project-ascii-overlay {
  opacity: 1;
}

.project-ascii-overlay pre {
  font-size: 5px;
  line-height: 5.5px;
  letter-spacing: 1px;
  color: var(--text-dim);
  white-space: pre;
  margin: 0;
}

.project-info {
  padding: 20px;
}

.project-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 8px;
}

.project-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.project-tag {
  padding: 3px 8px;
  border: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.project-links {
  display: flex;
  gap: 16px;
}

.project-link {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s;
  letter-spacing: 0.3px;
}

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

/* ============================================
   GALLERY
   ============================================ */
#arts {
  position: relative;
  z-index: 1;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.gallery-item {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  transition: border-color 0.2s;
}

.gallery-item:hover {
  border-color: var(--border-hi);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s;
}

.gallery-item:hover img {
  opacity: 0.1;
}

.gallery-ascii-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  padding: 8px;
  overflow: hidden;
}

.gallery-item:hover .gallery-ascii-overlay {
  opacity: 1;
}

.gallery-ascii-overlay pre {
  font-size: 5px;
  line-height: 5.5px;
  letter-spacing: 1px;
  color: var(--text-dim);
  white-space: pre;
  margin: 0;
}

.gallery-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 10px;
  gap: 12px;
}

.gallery-placeholder pre {
  font-size: 7px;
  line-height: 8px;
  letter-spacing: 1px;
  color: var(--text-dim);
  opacity: 0.5;
  white-space: pre;
  margin: 0;
}

.gallery-placeholder span {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 10px;
}

/* Lightbox Dialog */
.lightbox {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  max-width: min(90vw, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 24px));
  max-height: min(90vh, calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px));
  max-height: min(90dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px));
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.lightbox img {
  max-width: min(85vw, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 32px));
  max-height: min(85vh, calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 48px));
  max-height: min(85dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 48px));
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 14px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  z-index: 10;
}

.lightbox-close:hover {
  color: var(--accent);
}

/* ============================================
   CONTACT / FOOTER
   ============================================ */
#contact {
  position: relative;
  z-index: 1;
  padding-bottom: max(80px, calc(80px + env(safe-area-inset-bottom, 0px)));
}

.contact-content {
  text-align: center;
}

.contact-links {
  display: flex;
  gap: 40px;
  justify-content: center;
  margin-top: 40px;
}

.contact-link {
  font-size: 13px;
  color: var(--text-dim);
  transition: color 0.2s;
  position: relative;
  letter-spacing: 0.5px;
}

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

.footer-ascii {
  text-align: center;
  color: var(--text-dim);
  font-size: 10px;
  opacity: 0.2;
  margin-top: 80px;
  letter-spacing: 2px;
  user-select: none;
}

.footer-note {
  text-align: center;
  margin-top: 24px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.4;
}

/* ============================================
   SCROLL REVEAL ANIMATIONS
   ============================================ */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-left {
  opacity: 0;
  transform: translateX(-20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-scale {
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal-scale.visible {
  opacity: 1;
  transform: scale(1);
}

/* Stagger children */
.stagger > * {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.stagger > *.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================
   TYPEWRITER
   ============================================ */
.typewriter .line {
  opacity: 0;
  transition: opacity 0.1s;
}

.typewriter .line.typed {
  opacity: 1;
}

.typewriter .line .command {
  overflow: hidden;
  display: inline;
}

/* ============================================
   GLITCH TEXT HOVER (social links)
   ============================================ */
.glitch-hover {
  position: relative;
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Tablet */
@media (max-width: 1024px) {
  .container {
    padding: 0 max(24px, env(safe-area-inset-left, 0px)) 0 max(24px, env(safe-area-inset-right, 0px));
  }

  .nav-inner {
    padding: 0 max(24px, env(safe-area-inset-left, 0px)) 0 max(24px, env(safe-area-inset-right, 0px));
  }

  h1 {
    font-size: 36px;
  }

  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .about-content {
    grid-template-columns: 1fr;
    gap: 40px;
  }

  .about-stats {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .stat-item {
    flex: 1;
    min-width: 140px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  section {
    padding: 80px 0;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 20px;
    margin-bottom: 32px;
  }

  .hero-inner {
    grid-template-columns: 1fr;
    gap: 40px;
    text-align: center;
  }

  .hero-terminal {
    text-align: left;
    width: 100%;
    max-width: 100%;
  }

  .hero-terminal .terminal {
    max-width: 100%;
  }

  .hero-tagline {
    text-align: center;
  }

  .hero-ascii {
    order: -1;
    width: 100%;
    justify-content: center;
  }

  .hero-ascii pre {
    font-size: clamp(4.25px, 2.4vmin, 5.5px);
    line-height: 1.1;
    letter-spacing: clamp(0, 0.2vmin, 1px);
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

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

  .gallery-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .nav-inner {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .nav-links {
    gap: 16px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: min(100%, calc(100vw - 56px - 24px));
    padding-bottom: 4px;
    margin-bottom: -4px;
  }

  .nav-links::-webkit-scrollbar {
    display: none;
  }

  .nav-links li {
    flex-shrink: 0;
  }

  .nav-links a {
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 2px;
  }

  .contact-links {
    flex-direction: column;
    gap: 20px;
    align-items: center;
  }

  .contact-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
  }

  .filter-bar {
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 8px;
    margin-bottom: 48px;
    margin-right: calc(-1 * max(24px, env(safe-area-inset-right, 0px)));
    padding-right: max(24px, env(safe-area-inset-right, 0px));
  }

  .filter-bar::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    padding: 10px 14px;
    font-size: 10px;
    flex-shrink: 0;
    min-height: 44px;
    box-sizing: border-box;
  }

  .ascii-divider {
    font-size: 9px;
    letter-spacing: 1px;
    padding: 0 max(24px, env(safe-area-inset-left, 0px)) 0 max(24px, env(safe-area-inset-right, 0px));
  }

  .project-thumb {
    height: min(180px, 42vw);
  }
}

/* Small mobile — e.g. iPhone SE, narrow portrait */
@media (max-width: 480px) {
  .container {
    padding: 0 max(16px, env(safe-area-inset-left, 0px)) 0 max(16px, env(safe-area-inset-right, 0px));
  }

  .terminal-body {
    padding: 14px 16px;
    font-size: 12px;
  }

  .line {
    font-size: 12px;
  }

  .hero-ascii pre {
    font-size: clamp(4px, 2.15vmin, 5px);
    line-height: 1.1;
    letter-spacing: clamp(0, 0.18vmin, 0.75px);
  }

  .nav-inner {
    padding: 0 max(16px, env(safe-area-inset-left, 0px)) 0 max(16px, env(safe-area-inset-right, 0px));
  }

  .nav-links {
    gap: 12px;
    max-width: min(100%, calc(100vw - 48px - 16px));
  }

  .nav-links a {
    font-size: 10px;
    letter-spacing: 0.5px;
  }

  .filter-bar {
    margin-right: calc(-1 * max(16px, env(safe-area-inset-right, 0px)));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
}

/* Viewports wider than phone: avoid tall hero + keep filter row closer to project grid */
@media (min-width: 769px) {
  .hero {
    min-height: 100vh;
    padding: 80px 0;
  }

  .filter-bar {
    margin-bottom: 28px;
  }
}

/* Touch devices: show project ASCII while pressing thumb (hover is unreliable) */
@media (hover: none) and (pointer: coarse) {
  .project-thumb:active .project-ascii-overlay {
    opacity: 1;
  }

  .project-thumb .project-ascii-overlay {
    transition: opacity 0.25s ease;
  }
}

/* Isolate layout for hero grid + thumbs (lighter style recalc on scroll) */
.hero-inner,
.project-thumb {
  contain: layout;
}
