@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400..700;1,400..700&family=Space+Grotesk:wght@300..700&family=Syne:wght@700;800&display=swap');

/* ----------------------------------------------------
   DESIGN TOKENS & SYSTEM VARIABLES
   ---------------------------------------------------- */
:root {
  /* Colors */
  --bg: #ffffff;
  --text: #000000;
  --text-muted: #737373;
  --border: #e5e5e5;
  --border-heavy: #000000;
  --accent: #000000;
  
  --inverse-bg: #000000;
  --inverse-text: #ffffff;
  
  /* Typography */
  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Grotesk', sans-serif;
  --font-body: 'Instrument Sans', sans-serif;
  
  /* Layout */
  --header-height: 80px;
  --max-width: 1440px;
  --grid-gap: 24px;
  
  /* Transitions */
  --transition-smooth: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  
  /* Scroll timing */
  --scroll-behavior: smooth;
}

/* Dark Mode Overrides */
[data-theme="dark"] {
  --bg: #000000;
  --text: #ffffff;
  --text-muted: #a3a3a3;
  --border: #1a1a1a;
  --border-heavy: #ffffff;
  --accent: #ffffff;
  
  --inverse-bg: #ffffff;
  --inverse-text: #000000;
}

/* ----------------------------------------------------
   CORE RESET & GENERAL STYLES
   ---------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: var(--scroll-behavior);
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.5s cubic-bezier(0.16, 1, 0.3, 1), color 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

body {
  overflow-x: hidden;
  font-size: 1.05rem;
  line-height: 1.6;
}

/* Custom Selection */
::selection {
  background-color: var(--text);
  color: var(--bg);
}

/* Custom Minimalist Monochrome Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
  border-left: 1px solid var(--border);
}
::-webkit-scrollbar-thumb {
  background: var(--text);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ----------------------------------------------------
   TYPOGRAPHY UTILITIES
   ---------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h1 {
  font-size: clamp(1.8rem, 6vw, 4.8rem);
  text-transform: uppercase;
  word-wrap: normal;
  overflow-wrap: normal;
  word-break: normal;
}

h2 {
  font-size: clamp(1.4rem, 5vw, 3.2rem);
  text-transform: uppercase;
  word-wrap: normal;
  overflow-wrap: normal;
  word-break: normal;
}

h3 {
  font-size: clamp(1.1rem, 3vw, 2rem);
  font-family: var(--font-mono);
  font-weight: 600;
  word-wrap: normal;
  overflow-wrap: normal;
  word-break: normal;
}

p {
  color: var(--text-muted);
  max-width: 65ch;
}

.monospace {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
  transition: var(--transition-fast);
}

/* ----------------------------------------------------
   LAYOUT ENGINE: THE GRID CANVAS
   ---------------------------------------------------- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 40px;
}

@media (max-width: 768px) {
  .container {
    padding: 0 20px;
  }
}

/* 1px Architectural Blueprint Border Systems */
.grid-canvas {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.grid-row {
  grid-column: span 12;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  border-bottom: 1px solid var(--border);
}

.border-right {
  border-right: 1px solid var(--border);
}

.border-left {
  border-left: 1px solid var(--border);
}

.border-bottom {
  border-bottom: 1px solid var(--border);
}

.border-top {
  border-top: 1px solid var(--border);
}

/* Responsive Grid Helpers */
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

@media (max-width: 992px) {
  .col-8, .col-6, .col-4, .col-3 {
    grid-column: span 6;
  }
}

@media (max-width: 768px) {
  .col-8, .col-6, .col-4, .col-3 {
    grid-column: span 12;
  }
  .grid-canvas {
    border-left: none;
    border-right: none;
  }
  .border-right {
    border-right: none;
  }
  
  /* Robust horizontal padding symmetry on all stacked columns */
  .grid-row > [class*="col-"] {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  /* Consistent mobile grid column divider logic (no double/missing borders) */
  .grid-row > [class*="col-"]:not(:last-child) {
    border-bottom: 1px solid var(--border) !important;
  }

  /* Prevent inner card double-borders with the parent column dividers */
  .grid-row > [class*="col-"] .project-card,
  .grid-row > [class*="col-"] .card-interactive.matrix-card {
    border-bottom: none !important;
  }

  /* Keep footer PAGES and LEGAL sections side-by-side on mobile with premium layout spacing */
  footer .col-6 {
    padding-bottom: 32px !important;
  }
  
  footer .col-3 {
    grid-column: span 6 !important;
    border-bottom: none !important;
    padding-top: 32px !important;
    padding-bottom: 32px !important;
  }
  
  footer .col-3.border-right {
    border-right: 1px solid var(--border) !important;
  }
}

/* Padding utilities */
.p-clamp {
  padding: clamp(2rem, 5vw, 5rem) clamp(1.5rem, 3vw, 3rem);
}

.py-clamp {
  padding-top: clamp(2rem, 5vw, 5rem);
  padding-bottom: clamp(2rem, 5vw, 5rem);
}

/* ----------------------------------------------------
   HEADER & NAVIGATION
   ---------------------------------------------------- */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  transition: height 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.5s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
}

header.scrolled {
  height: 60px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); /* Avoid hex-rgba compilation bugs in modern rendering */
  backdrop-filter: blur(10px);
}

.header-inner {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.05em;
  text-transform: uppercase;
}

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

.nav-links a {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  position: relative;
  padding: 4px 0;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 1px;
  background-color: var(--text);
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-links a:hover::after,
.nav-links a.active::after {
  width: 100%;
}

.controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* Minimal theme toggler */
.theme-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.theme-btn:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 1.5rem;
}

/* Scroll locking when mobile navigation menu is active */
body.menu-open, html.menu-open {
  overflow: hidden !important;
  height: 100% !important;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: block;
  }
  
  .nav-links {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: calc(100vh - var(--header-height));
    background: var(--bg);
    flex-direction: column;
    padding: 40px;
    gap: 24px;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), top 0.3s cubic-bezier(0.16, 1, 0.3, 1), height 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-top: 1px solid var(--border);
  }
  
  /* Seamless transition when header shrivels to 60px during scrolling */
  header.scrolled .nav-links {
    top: 60px;
    height: calc(100vh - 60px);
  }
  
  .nav-links.active {
    transform: translateX(0);
  }
}

/* ----------------------------------------------------
   INTERACTIVE ELEMENTS & UTILITIES
   ---------------------------------------------------- */

/* Pure Inversion Hover Box Effect */
.card-interactive {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.card-interactive:hover {
  background: var(--inverse-bg);
  color: var(--inverse-text);
  border-color: var(--inverse-bg);
}

.card-interactive:hover p {
  color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .card-interactive:hover p {
  color: rgba(0, 0, 0, 0.7);
}

/* Modernist Button */
.btn-monochrome {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 32px;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--text);
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.btn-monochrome:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text);
}

.btn-monochrome-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 32px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-monochrome-outline:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* ----------------------------------------------------
   PAGE COMPONENTS
   ---------------------------------------------------- */

/* Hero grid element styling */
.hero-wrapper {
  margin-top: var(--header-height);
}

.hero-main-title {
  font-size: clamp(2.0rem, 7.5vw, 4.8rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.03em;
  word-wrap: normal;
  overflow-wrap: normal;
  word-break: normal;
}

@media (min-width: 769px) {
  .hero-main-title br {
    display: none;
  }
}

.matrix-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 300px;
}

.matrix-number {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 24px;
}

.matrix-card-title {
  margin-top: auto;
  margin-bottom: 12px;
}

/* Form Styles */
.form-group {
  margin-bottom: 32px;
  position: relative;
}

.form-input {
  width: 100%;
  padding: 16px 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.1rem;
  outline: none;
  transition: border-color 0.3s ease;
}

.form-label {
  position: absolute;
  top: 16px;
  left: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), color 0.3s ease;
  transform-origin: left top;
}

.form-input:focus ~ .form-label,
.form-input:not(:placeholder-shown) ~ .form-label,
.form-input:-webkit-autofill ~ .form-label {
  transform: translateY(-24px) scale(0.85);
  color: var(--text);
}

.form-input:focus {
  border-bottom-color: var(--text);
}

/* Autofill Premium Aesthetics Override */
.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover, 
.form-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0px 1000px var(--bg) inset !important;
  transition: background-color 5000s ease-in-out 0s;
}

/* Project catalog filtering UI */
.filter-tabs {
  display: flex;
  gap: 16px;
  list-style: none;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .filter-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 24px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    margin-left: -20px;
    margin-right: -20px;
    padding-left: 20px;
    padding-right: 20px;
  }
  .filter-tabs::-webkit-scrollbar {
    display: none; /* Safari & Chrome */
  }
  .filter-tabs li {
    flex-shrink: 0;
  }
}

/* Services Grid for contact page */
.services-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 576px) {
  .services-grid {
    grid-template-columns: 1fr;
  }
}

/* Full-bleed rows for tickers on mobile */
.marquee-row {
  padding-left: 0 !important;
  padding-right: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

.filter-tab-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 20px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: var(--transition-fast);
}

.filter-tab-btn.active, .filter-tab-btn:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.project-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.project-image-box {
  position: relative;
  aspect-ratio: 16/10;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg);
}

.project-image-box svg {
  width: 100%;
  height: 100%;
  stroke: var(--text);
  fill: none;
  opacity: 0.15;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.project-card:hover .project-image-box svg {
  transform: scale(1.05);
  opacity: 0.3;
}

.project-details {
  padding: 24px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.project-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.project-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-transform: uppercase;
}

/* Blog grid and post layouts */
.blog-post-card {
  display: flex;
  flex-direction: column;
  padding: 40px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.blog-post-card:hover {
  background: var(--inverse-bg);
  color: var(--inverse-text);
}

.blog-post-card:hover .monospace {
  color: var(--inverse-text);
}

.blog-post-card:hover p {
  color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .blog-post-card:hover p {
  color: rgba(0, 0, 0, 0.7);
}

.blog-post-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  align-items: center;
}

.blog-content {
  font-size: 1.15rem;
  line-height: 1.8;
}

.blog-content p {
  margin-bottom: 24px;
  max-width: 100%;
}

.blog-content h2, .blog-content h3 {
  margin-top: 48px;
  margin-bottom: 16px;
}

.blog-content pre {
  margin: 32px 0;
  padding: 24px;
  background: var(--border);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-family: monospace;
  font-size: 0.95rem;
}

[data-theme="dark"] .blog-content pre {
  background: #111111;
}

.blog-content code {
  font-family: monospace;
  background: var(--border);
  padding: 2px 6px;
  font-size: 0.9em;
}

[data-theme="dark"] .blog-content code {
  background: #222222;
}

/* ----------------------------------------------------
   FOOTER
   ---------------------------------------------------- */
footer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.footer-link-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footer-link-list a:hover {
  text-decoration: underline;
}

/* ----------------------------------------------------
   SCROLL ENTRY-REVEAL SYSTEM (CSS View Timeline)
   ---------------------------------------------------- */
@supports (animation-range: entry) {
  .scroll-reveal {
    animation: fade-in-up linear both;
    animation-timeline: view();
    animation-range: entry 10% cover 30%;
  }

  @keyframes fade-in-up {
    from {
      opacity: 0;
      transform: translateY(40px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* Progressive enhancement: custom cursor */
.custom-cursor {
  width: 20px;
  height: 20px;
  border: 1px solid #ffffff;
  border-radius: 50%;
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
  mix-blend-mode: difference;
  background-color: transparent;
  display: none; /* Display is toggled in JS for pointers only */
}

@media (pointer: fine) {
  body.custom-cursor-enabled {
    cursor: none;
  }
  body.custom-cursor-enabled a,
  body.custom-cursor-enabled button,
  body.custom-cursor-enabled input,
  body.custom-cursor-enabled textarea,
  body.custom-cursor-enabled select,
  body.custom-cursor-enabled .card-interactive,
  body.custom-cursor-enabled .filter-tab-btn {
    cursor: none;
  }
  body.custom-cursor-enabled .custom-cursor {
    display: block;
    background-color: #ffffff;
  }
}

.custom-cursor.hovering {
  width: 40px;
  height: 40px;
  background-color: transparent;
  border-color: #ffffff;
}
