/* ====================================================================
   panayotislambis.com — brutalist, platform-native, monochrome
   2026 cutting-edge: OKLCH, container queries, :has(), @scope,
   scroll-driven animations, view transitions, anchor positioning.
   ==================================================================== */

@layer reset, tokens, base, layout, components, utilities;

/* ---------- RESET ---------------------------------------------------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
  img, video { display: block; max-width: 100%; height: auto; }
  button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
  a { color: inherit; text-decoration: none; }
  ul, ol { list-style: none; }
  :focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
}

/* ---------- TOKENS --------------------------------------------------- */
@layer tokens {
  :root {
    /* Typography — variable fonts via @font-face below */
    --font-display: "Söhne Breit", "Inter Tight", system-ui, sans-serif;
    --font-body:    "Söhne", "Inter", system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, monospace;

    /* Type scale — responsive, fluid via clamp() */
    --fs-mono:    clamp(0.72rem, 0.7rem + 0.1vw, 0.78rem);
    --fs-body:    clamp(0.95rem, 0.9rem + 0.2vw, 1.05rem);
    --fs-lead:    clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
    --fs-h3:      clamp(1.5rem, 1.3rem + 1vw, 2.2rem);
    --fs-h2:      clamp(2.5rem, 2rem + 2vw, 4rem);
    --fs-h1:      clamp(3.5rem, 2.5rem + 6vw, 9rem);
    --fs-mega:    clamp(5rem, 3rem + 12vw, 16rem);

    /* Color — OKLCH for perceptual consistency.
       Defaults to dark scheme (black canvas, light type), respects user pref. */
    --ink:        oklch(96% 0 0);
    --paper:      oklch(8% 0 0);
    --paper-2:    oklch(12% 0 0);
    --paper-3:    oklch(18% 0 0);
    --rule:       oklch(30% 0 0);
    --muted:      oklch(60% 0 0);
    --accent:     oklch(70% 0.18 25);   /* sodium-vapor red, sparingly used */
    --selection:  oklch(70% 0.18 95 / 0.4);

    /* Spatial */
    --gutter:     clamp(1rem, 0.5rem + 2vw, 2.5rem);
    --rail:       clamp(0.6rem, 0.4rem + 1vw, 1.2rem);
    --col:        minmax(0, 1fr);

    /* Motion */
    --ease:       cubic-bezier(0.2, 0.6, 0.2, 1);
    --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
    --t-fast:     180ms;
    --t-med:      420ms;
    --t-slow:     900ms;
  }

  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
      --ink:    oklch(10% 0 0);
      --paper:  oklch(98% 0 0);
      --paper-2:oklch(94% 0 0);
      --paper-3:oklch(90% 0 0);
      --rule:   oklch(80% 0 0);
      --muted:  oklch(45% 0 0);
    }
  }

  ::selection { background: var(--selection); color: var(--ink); }
}

/* ---------- BASE ----------------------------------------------------- */
@layer base {
  html {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--fs-body);
    line-height: 1.5;
    color-scheme: dark light;
  }

  body {
    min-height: 100dvh;
    overflow-x: clip;
    background: var(--paper);
  }

  h1, h2, h3, h4, h5 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 0.92;
    letter-spacing: -0.03em;
    text-wrap: balance;
  }
  h1 { font-size: var(--fs-h1); }
  h2 { font-size: var(--fs-h2); }
  h3 { font-size: var(--fs-h3); font-weight: 600; }

  p { text-wrap: pretty; max-width: 60ch; }
  em { font-style: italic; }

  /* Mono labels — lift small UI text */
  .mono, [data-mono] {
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  /* Anchor states */
  a { transition: color var(--t-fast) var(--ease); }
  a:hover { color: var(--accent); }

  /* View transitions — site-wide */
  @view-transition { navigation: auto; }

  ::view-transition-old(root) {
    animation: fade-out var(--t-med) var(--ease) both;
  }
  ::view-transition-new(root) {
    animation: fade-in var(--t-med) var(--ease) both;
  }
  @keyframes fade-out { to { opacity: 0; } }
  @keyframes fade-in  { from { opacity: 0; } }

  /* 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;
    }
  }
}

/* ---------- LAYOUT --------------------------------------------------- */
@layer layout {
  /* The grid — 12-col modular, gutter via token */
  .grid {
    display: grid;
    grid-template-columns: repeat(12, var(--col));
    gap: var(--rail) var(--gutter);
  }

  .container {
    width: 100%;
    padding-inline: var(--gutter);
  }

  /* Page rails — top header / bottom footer with rules */
  .frame {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100dvh;
  }

  /* Top bar */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: var(--rail) var(--gutter);
    border-bottom: 1px solid var(--rule);
    background: color-mix(in oklch, var(--paper) 88%, transparent);
    backdrop-filter: blur(12px);
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .topbar nav { display: flex; gap: var(--gutter); justify-content: center; }
  .topbar nav a[aria-current="page"] { color: var(--accent); }
  .topbar .right { justify-self: end; display: flex; gap: 1rem; align-items: center; }

  .lang-switch {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
  }
  .lang-switch button {
    font: inherit;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    transition: color var(--t-fast) var(--ease);
  }
  .lang-switch button[aria-pressed="true"] { color: var(--ink); }
  .lang-switch span { color: var(--rule); }

  /* Footer */
  .botbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: var(--rail) var(--gutter);
    border-top: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
  }
  .botbar .right { justify-self: end; }

  /* Page sections */
  section { padding-block: clamp(3rem, 2rem + 4vw, 8rem); }
  section + section { border-top: 1px solid var(--rule); }
}

/* ---------- COMPONENTS ----------------------------------------------- */
@layer components {

  /* HERO — massive type, project counter, scrolling marquee */
  .hero {
    padding: var(--gutter);
    min-height: 88dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: var(--gutter);
    position: relative;
  }

  .hero h1 {
    font-size: var(--fs-mega);
    line-height: 0.82;
    letter-spacing: -0.04em;
    margin-block: auto;
  }

  .hero .meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gutter);
    align-items: end;
    color: var(--muted);
  }

  /* WORK INDEX — list of projects, full-bleed rows that swap photo on hover */
  .work-index { padding-inline: var(--gutter); }
  .work-row {
    display: grid;
    grid-template-columns: 4ch minmax(0, 1fr) 1fr 1fr 8ch;
    align-items: end;
    gap: var(--gutter);
    padding-block: clamp(1.5rem, 1rem + 2vw, 3rem);
    border-bottom: 1px solid var(--rule);
    color: var(--ink);
    position: relative;
    transition: padding-inline var(--t-med) var(--ease);
  }
  .work-row:first-of-type { border-top: 1px solid var(--rule); }
  .work-row:hover { padding-inline-start: 1.5rem; }
  .work-row .num {
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    color: var(--muted);
    align-self: start;
    padding-top: 0.6rem;
  }
  .work-row .title {
    font-family: var(--font-display);
    font-size: var(--fs-h2);
    font-weight: 700;
    line-height: 0.92;
    letter-spacing: -0.03em;
  }
  .work-row .meta {
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    line-height: 1.5;
  }
  .work-row .arrow {
    font-family: var(--font-mono);
    color: var(--muted);
    text-align: end;
    transition: transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  }
  .work-row:hover .arrow {
    color: var(--ink);
    transform: translateX(0.4rem);
  }
  .work-row:hover .title {
    color: var(--accent);
  }

  /* Hover preview — fixed thumb that follows hover */
  .hover-preview {
    position: fixed;
    inset: auto;
    pointer-events: none;
    width: clamp(280px, 22vw, 420px);
    aspect-ratio: 4 / 5;
    background: var(--paper-3);
    border: 1px solid var(--rule);
    z-index: 20;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
    transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
    overflow: hidden;
  }
  .hover-preview img {
    width: 100%; height: 100%; object-fit: cover;
  }
  .hover-preview.is-active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  @media (max-width: 768px) {
    .hover-preview { display: none; }
  }

  /* CASE STUDY — project page */
  .case-head {
    padding: var(--gutter);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gutter);
    align-items: end;
    border-bottom: 1px solid var(--rule);
    min-height: 70dvh;
  }
  .case-head h1 {
    font-size: var(--fs-mega);
    line-height: 0.82;
  }
  .case-head dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.5rem;
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }
  .case-head dt { color: var(--muted); }
  .case-head dd { color: var(--ink); }

  .case-gallery {
    display: grid;
    grid-template-columns: repeat(12, var(--col));
    gap: var(--rail);
    padding: var(--rail);
  }
  .case-gallery figure { position: relative; overflow: clip; }
  .case-gallery figure img {
    width: 100%; height: 100%; object-fit: cover;
    transition: scale var(--t-slow) var(--ease-out);
  }
  .case-gallery figure:hover img { scale: 1.02; }
  /* Asymmetric brutalist tile sizes */
  .case-gallery figure:nth-child(6n+1) { grid-column: span 8; aspect-ratio: 16/9; }
  .case-gallery figure:nth-child(6n+2) { grid-column: span 4; aspect-ratio: 4/5; }
  .case-gallery figure:nth-child(6n+3) { grid-column: span 5; aspect-ratio: 1/1; }
  .case-gallery figure:nth-child(6n+4) { grid-column: span 7; aspect-ratio: 16/10; }
  .case-gallery figure:nth-child(6n+5) { grid-column: span 12; aspect-ratio: 21/9; }
  .case-gallery figure:nth-child(6n+6) { grid-column: span 6; aspect-ratio: 4/5; }

  @media (max-width: 768px) {
    .case-gallery figure { grid-column: 1 / -1 !important; aspect-ratio: 4/5 !important; }
  }

  /* ABOUT */
  .about {
    padding: var(--gutter);
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: clamp(2rem, 1rem + 4vw, 6rem);
  }
  .about h2 {
    font-size: var(--fs-h2);
    grid-column: 1;
  }
  .about .body {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    font-size: var(--fs-lead);
    line-height: 1.5;
    max-width: 60ch;
  }
  @media (max-width: 768px) {
    .about { grid-template-columns: 1fr; }
    .about h2, .about .body { grid-column: 1; }
  }

  /* CONTACT */
  .contact {
    padding: var(--gutter);
    min-height: 70dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
  }
  .contact h2 { font-size: var(--fs-h1); margin-block: auto; }
  .contact .channels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
  }
  .contact .channels a { color: var(--ink); display: block; padding-block: 0.5rem; border-top: 1px solid var(--rule); }
  .contact .channels a:hover { color: var(--accent); }

  /* MARQUEE — slow horizontal credits ticker (CSS scroll-driven) */
  .marquee {
    overflow: clip;
    border-block: 1px solid var(--rule);
    padding-block: 1.2rem;
  }
  .marquee-track {
    display: inline-flex;
    gap: 4rem;
    white-space: nowrap;
    animation: marquee 60s linear infinite;
    font-family: var(--font-display);
    font-size: var(--fs-h3);
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  .marquee-track span { color: var(--muted); }
  .marquee-track span::after { content: " ◆ "; color: var(--rule); margin-inline: 1.5rem; }
  @keyframes marquee {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
  }
}

/* ---------- MOBILE ---------------------------------------------------- */
@layer components {
  @media (max-width: 768px) {
    .topbar {
      grid-template-columns: 1fr auto;
      grid-template-rows: auto auto;
      gap: 0.5rem 1rem;
      padding: 0.7rem var(--gutter);
      font-size: 0.66rem;
    }
    .topbar > a:first-child { grid-column: 1; grid-row: 1; }
    .topbar .right          { grid-column: 2; grid-row: 1; justify-self: end; }
    .topbar nav             { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; gap: 1.2rem; }

    .hero { padding: var(--gutter); min-height: 80dvh; }
    .hero .meta { grid-template-columns: 1fr; gap: 0.4rem; }
    .hero .meta > div:last-child { text-align: start; }

    .work-row {
      grid-template-columns: 3ch 1fr;
      grid-template-areas:
        "num title"
        ".   meta1"
        ".   meta2"
        ".   arrow";
      gap: 0.4rem 1rem;
      padding-block: 1.4rem;
      align-items: start;
    }
    .work-row .num   { grid-area: num; padding-top: 0.3rem; }
    .work-row .title { grid-area: title; font-size: clamp(1.8rem, 8vw, 2.6rem); line-height: 0.95; }
    .work-row > .meta:nth-of-type(1) { grid-area: meta1; }
    .work-row > .meta:nth-of-type(2) { grid-area: meta2; }
    .work-row .arrow { grid-area: arrow; text-align: start; }
    .work-row:hover  { padding-inline-start: 0.5rem; }

    .marquee-track { font-size: 1.6rem; }
    section { padding-block: clamp(2rem, 4vw + 1rem, 4rem); }

    .case-head { grid-template-columns: 1fr; gap: 2rem; min-height: 50dvh; padding-block: 3rem; }

    section ul[style*="grid-template-columns"] { font-size: clamp(1.2rem, 5vw, 1.8rem) !important; }

    .contact h2 { font-size: clamp(2.5rem, 12vw, 5rem); }
    .contact .channels { grid-template-columns: 1fr; }

    .botbar {
      grid-template-columns: 1fr;
      grid-template-rows: auto auto auto;
      gap: 0.3rem;
      text-align: center;
      padding-block: 1rem;
    }
    .botbar .right { justify-self: center; }
  }

  @media (max-width: 420px) {
    .topbar nav { gap: 0.9rem; font-size: 0.62rem; }
    .work-row .title { font-size: clamp(1.5rem, 9vw, 2.2rem); }
  }
}

/* ---------- UTILITIES ------------------------------------------------ */
@layer utilities {
  [hidden] { display: none !important; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
  }
  /* i18n visibility — body[data-lang] picks which children show */
  body[data-lang="en"] [data-lang]:not([data-lang="en"]),
  body[data-lang="el"] [data-lang]:not([data-lang="el"]) {
    display: none;
  }
}
