/* =============================================================================
   caostar.com — Portfolio
   ========================================================================== */

/* --- 1. Reset + Body ---------------------------------------------------- */

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

html {
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

body {
  background: #000;
  color: #eee;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: #4fc3f7; text-decoration: none; transition: opacity 0.15s; }
a:hover { opacity: 0.8; }

img { max-width: 100%; height: auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

/* Skip link for accessibility */
.skip-link {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: 9999;
  padding: 8px 16px;
  background: #4fc3f7;
  color: #000;
  border-radius: 0 0 6px 6px;
  font-size: 11px;
  font-weight: 600;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
  opacity: 1;
}

/* --- 2. Background Effects ---------------------------------------------- */

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 0;
  pointer-events: none;
}

#grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.035;
}

#grain-overlay::before {
  content: '';
  position: absolute;
  inset: -200%;
  width: 400%;
  height: 400%;
  filter: url(#grain);
  opacity: 0.5;
}

#grain-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
}

#content {
  position: relative;
  z-index: 2;
}

/* --- Nav (Hamburger) ---------------------------------------------------- */

#nav {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
}

.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: border-color 0.2s;
  touch-action: manipulation;
}

.nav-toggle:hover,
.nav-toggle:focus-visible,
.nav-toggle[aria-expanded="true"] {
  border-color: rgba(79, 195, 247, 0.3);
}

.nav-toggle:focus-visible {
  outline: 2px solid rgba(79, 195, 247, 0.5);
  outline-offset: 2px;
}

.nav-bar {
  display: block;
  width: 100%;
  height: 1.5px;
  background: #aaa;
  border-radius: 1px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.nav-toggle[aria-expanded="true"] .nav-bar:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-bar:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}

.nav-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 6px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.nav-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-menu a {
  display: block;
  padding: 12px 18px;
  font-size: 12px;
  color: #bbb;
  letter-spacing: 0.5px;
  transition: background 0.15s, color 0.15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-menu a:hover,
.nav-menu a:focus-visible {
  background: rgba(79, 195, 247, 0.08);
  color: #4fc3f7;
  opacity: 1;
}

.nav-menu a:focus-visible {
  outline: 2px solid rgba(79, 195, 247, 0.5);
  outline-offset: -2px;
}

/* --- 3. Hero ------------------------------------------------------------ */

#hero {
  text-align: center;
  padding: 20px 24px 12px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
}

.site-title {
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 400;
  letter-spacing: clamp(4px, 1.5vw, 8px);
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 60px rgba(79, 195, 247, 0.15), 0 0 120px rgba(79, 195, 247, 0.05);
}

.site-tagline {
  margin-top: 12px;
  margin-bottom: 0;
  font-size: clamp(9px, 2vw, 11px);
  color: #555;
  letter-spacing: clamp(2px, 0.5vw, 3px);
  text-transform: uppercase;
}

/* --- 4. Projects Grid --------------------------------------------------- */

.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* --- 5. Project Card ---------------------------------------------------- */

.project-card {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.project-card:hover {
  transform: translateY(-4px);
  border-color: rgba(79, 195, 247, 0.25);
  box-shadow: 0 8px 32px rgba(79, 195, 247, 0.06);
}

/* --- 6. Card Media + Hover Preview -------------------------------------- */

.card-media {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111;
}

.card-thumbnail,
.card-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-thumbnail {
  transition: transform 0.4s ease;
}

.card-media:hover .card-thumbnail {
  transform: scale(1.04);
}

.card-preview {
  opacity: 0;
  transition: opacity 0.35s ease;
}

.card-media:hover .card-preview,
.card-media.previewing .card-preview {
  opacity: 1;
}

.card-media-link {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-media-link:hover { opacity: 1; }

/* --- 7. Card Body ------------------------------------------------------- */

.card-body {
  padding: 16px 20px 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: #eee;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card-summary {
  font-size: 11px;
  color: #888;
  line-height: 1.6;
  margin-bottom: 14px;
}

.card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tag {
  font-size: 9px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(79, 195, 247, 0.06);
  border: 1px solid rgba(79, 195, 247, 0.15);
  color: #4fc3f7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- 8. Card Buttons ---------------------------------------------------- */

.card-actions {
  display: flex;
  gap: 8px;
}

.card-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #ccc;
  touch-action: manipulation;
}

.card-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #eee;
  opacity: 1;
}

.card-btn-launch {
  background: rgba(79, 195, 247, 0.1);
  border-color: rgba(79, 195, 247, 0.25);
  color: #4fc3f7;
}

.card-btn-launch:hover {
  background: rgba(79, 195, 247, 0.2);
  color: #4fc3f7;
}

/* Focus styles */
.card-btn:focus-visible,
.post-card:focus-visible {
  outline: 2px solid rgba(79, 195, 247, 0.5);
  outline-offset: 2px;
}

/* --- 9. Blog Posts Section ---------------------------------------------- */

.section-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1200px;
  margin: 48px auto 0;
  padding: 0 24px;
}

.divider-line {
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.divider-label {
  font-size: 9px;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 3px;
}

.section-link {
  text-align: center;
  font-size: 12px;
  font-weight: 400;
  color: #666;
  letter-spacing: 1px;
  padding: 20px 24px 32px;
}

.section-link a {
  color: #4fc3f7;
  border-bottom: 1px solid rgba(79, 195, 247, 0.2);
  padding-bottom: 1px;
}

.section-link a:hover {
  border-bottom-color: #4fc3f7;
  opacity: 1;
}

.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.post-card {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.post-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.15);
  opacity: 1;
}

.post-image {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #0a0a0a;
}

.post-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.post-card:hover .post-image img {
  transform: scale(1.03);
}

.post-body {
  padding: 14px 16px 16px;
}

.post-date {
  display: block;
  font-size: 9px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.post-title {
  font-size: 13px;
  font-weight: 500;
  color: #ddd;
  line-height: 1.4;
  margin-bottom: 8px;
}

.post-excerpt {
  font-size: 10px;
  color: #666;
  line-height: 1.5;
}

.posts-fallback {
  text-align: center;
  padding: 24px;
  color: #444;
  font-size: 11px;
}

.posts-loader {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 0;
}

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.posts-loader-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 3px;
  border-radius: 50%;
  background: #4fc3f7;
  animation: dotPulse 1.2s ease-in-out infinite;
}

.posts-loader-dots span:nth-child(2) { animation-delay: 0.15s; }
.posts-loader-dots span:nth-child(3) { animation-delay: 0.3s; }

/* --- 10. Footer --------------------------------------------------------- */

#site-footer {
  padding: 60px 24px 32px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 10px;
  color: #333;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  margin-top: 48px;
}

/* --- 11. Animations ----------------------------------------------------- */

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

.reveal {
  opacity: 0;
}

.reveal.visible {
  animation: fadeInUp 0.5s ease forwards;
  animation-delay: var(--delay, 0s);
}

/* --- 12. Scrollbar ------------------------------------------------------ */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* --- 13. Responsive ----------------------------------------------------- */

/* Tablet */
@media (max-width: 900px) {
  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile */
@media (max-width: 700px) {
  #hero { padding: 20px 16px 12px; padding-top: calc(20px + env(safe-area-inset-top, 0px)); }

  .projects-grid {
    grid-template-columns: 1fr;
    padding: 0 16px;
  }

  .posts-grid {
    grid-template-columns: 1fr;
    padding: 0 16px;
    gap: 16px;
  }

  .section-divider { padding: 0 16px; margin-top: 36px; }
  .section-link { padding: 16px 16px 24px; }

  .card-body { padding: 14px 16px 18px; }
  .card-actions { flex-direction: column; }
  .card-btn { width: 100%; justify-content: center; font-size: 12px; }

  .card-title { font-size: 15px; }
  .card-summary { font-size: 12px; }
  .tag { font-size: 10px; padding: 4px 10px; }

  .post-body { padding: 12px 14px 14px; }
  .post-title { font-size: 14px; }
  .post-excerpt { font-size: 11px; }
  .post-date { font-size: 10px; }

  .nav-menu a { font-size: 13px; padding: 14px 20px; }

  /* Disable hover effects on touch — use .previewing class only */
  .project-card:hover { transform: none; }
  .card-media:hover .card-thumbnail { transform: none; }
  .card-media:hover .card-preview { opacity: 0; }
  .card-media.previewing .card-preview { opacity: 1; }
  .post-card:hover { transform: none; }
  .post-card:hover .post-image img { transform: none; }

  #site-footer { margin-top: 36px; padding-top: 40px; }
}

/* Small mobile */
@media (max-width: 360px) {
  #hero { padding: 20px 12px 10px; padding-top: calc(20px + env(safe-area-inset-top, 0px)); }
  .projects-grid { padding: 0 12px; }
  .posts-grid { padding: 0 12px; }
  .section-divider { padding: 0 12px; }
  .section-link { padding: 14px 12px 20px; }
  .card-body { padding: 12px 14px 16px; }
}

/* Landscape phone */
@media (max-width: 700px) and (max-height: 500px) {
  #hero { padding-top: 20px; padding-bottom: 10px; }
}

/* --- 14. Reduced Motion ------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; }
  #bg-canvas { display: none; }
}
