/*
 * css/styles.css — all styling for withinquantum.
 *
 * Sections (search for the capitalised names):
 *   TOKENS        colors, fonts, sizes. Most visual changes happen here.
 *   BASE          page reset, no-scroll rule, focus style
 *   ART           gradient scenes, grid, dots, grain
 *   LAYOUT        top bar, two columns
 *   TOOL LIST     left column rows and pager
 *   STAGE         right column: start caption and tool panel
 *   MOTIFS        the per-tool graphics (see js/motifs.js)
 *   RESPONSIVE    short screens, tablets, phones
 *   MOTION        reduced-motion rules
 *   DEBUG         ?debug=1 outlines and panel
 */

/* ============================================================ TOKENS */
:root {
  /* colors */
  --bg: #0A0B0F;            /* page background */
  --text: #F4F5F7;          /* main text */
  --text-soft: #C9CDD6;     /* descriptions */
  --text-muted: #A1A6B3;    /* small labels */
  --line: rgba(255, 255, 255, 0.16);
  --line-soft: rgba(255, 255, 255, 0.10);
  --glass: rgba(10, 11, 15, 0.62);   /* tool panel background */
  --row-active: rgba(255, 255, 255, 0.09);

  /* fonts */
  --font-sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* layout */
  --pad: 48px;                               /* outer margin */
  --topbar-h: 88px;
  --left-w: clamp(340px, 33vw, 480px);       /* width of the tool list column */
  --gap: clamp(32px, 4vw, 72px);             /* space between the two columns */
  --row-h: 76px;                             /* height of one tool row */
  --panel-h: 320px;                          /* height of the tool panel */
  --radius: 20px;
  --motif-size: clamp(180px, 36vh, 360px);

  /* texture strength (0 = off) */
  --grain: 0.35;
  --grid-alpha: 0.045;
  --dots-alpha: 0.5;

  /* motion */
  --fade: 900ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ============================================================ BASE */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;           /* the site never scrolls; see docs/DESIGN.md */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
button { font: inherit; color: inherit; }
p, h1, h2, ul { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

/* ============================================================ ART */
.poster {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.art { position: absolute; inset: 0; pointer-events: none; }

.scenes { position: absolute; inset: 0; }

.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--fade) ease;
}
.scene.is-active { opacity: 1; }

.scene__drift {
  position: absolute;
  inset: 0;
  animation: wq-drift 14s ease-in-out infinite;
}

/* Three soft color blobs per scene. --c is set per blob by js/app.js. */
.blob {
  position: absolute;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--c) 0%, rgba(10, 11, 15, 0) 68%);
  filter: blur(28px);
}
.blob--1 { left: 44%; top: -14%; width: 53vw; }
.blob--2 { left: 68%; top: 16%;  width: 47vw; }
.blob--3 { left: 52%; top: 40%;  width: 43vw; }

.texture { position: absolute; inset: 0; width: 100%; height: 100%; }

.texture--grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, var(--grid-alpha)) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, var(--grid-alpha)) 1px, transparent 1px);
  background-size: 48px 48px;
}

.texture--dots {
  left: 40%;
  width: 60%;
  opacity: var(--dots-alpha);
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.22) 1px, transparent 1.4px);
  background-size: 8px 8px;
  -webkit-mask-image: radial-gradient(ellipse at 55% 40%, #000 0%, transparent 60%);
  mask-image: radial-gradient(ellipse at 55% 40%, #000 0%, transparent 60%);
}

.texture--grain { mix-blend-mode: overlay; opacity: var(--grain); }

/* ============================================================ LAYOUT */
.layout {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  padding:
    env(safe-area-inset-top, 0px)
    calc(var(--pad) + env(safe-area-inset-right, 0px))
    calc(40px + env(safe-area-inset-bottom, 0px))
    calc(var(--pad) + env(safe-area-inset-left, 0px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  text-decoration: none;
}
.brand__mark { width: 30px; height: 30px; }
.brand__name { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }

.gh-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(10, 11, 15, 0.35);
  font-family: var(--font-mono);
  font-size: 13px;
  text-decoration: none;
  transition: border-color 200ms ease, background 200ms ease;
}
.gh-pill:hover { border-color: rgba(255, 255, 255, 0.6); background: rgba(10, 11, 15, 0.55); }
.gh-pill svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}

.main {
  min-height: 0;
  padding-top: 24px;
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr);
  gap: var(--gap);
}

/* ============================================================ TOOL LIST */
.index {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.index__headline {
  font-size: clamp(34px, 3.2vw, 46px);
  line-height: 1.04;
  font-weight: 600;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.index__head {
  margin-top: clamp(24px, 4.5vh, 44px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.index__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tool-list { --row-h: 76px; }

.tool-row {
  width: 100%;
  height: var(--row-h);
  padding: 0 16px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 14px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  cursor: pointer;
  transition: background 300ms ease;
}
.tool-row:hover { background: rgba(255, 255, 255, 0.05); }
.tool-row.is-active { background: var(--row-active); }

.tool-row__num {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.tool-row__text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tool-row__name { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.tool-row__short {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-row__arrow {
  width: 18px; height: 18px;
  fill: none; stroke: var(--text); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0.4;
  transition: opacity 200ms ease, transform 300ms var(--ease-out);
}
.tool-row:hover .tool-row__arrow,
.tool-row.is-active .tool-row__arrow { opacity: 1; transform: translateX(3px); }

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.pager__btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  transition: border-color 200ms ease;
}
.pager__btn:hover { border-color: rgba(255, 255, 255, 0.6); }
.pager__label { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.index__foot {
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================ STAGE */
.stage { position: relative; min-height: 0; }

.motifs {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: calc(var(--panel-h) + 16px);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.motif {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 700ms ease, transform var(--fade) var(--ease-out);
}
.motif.is-active { opacity: 1; transform: scale(1); }

.home-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
}
.home-caption__count {
  font-size: clamp(80px, 8.4vw, 120px);
  line-height: 0.85;
  font-weight: 700;
  letter-spacing: -0.06em;
}
.home-caption__suffix {
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-left: 6px;
}
.home-caption__prompt {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
}

.detail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: var(--panel-h);
  max-height: 100%;
  overflow: auto;
  padding: 32px;
  border-radius: var(--radius);
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 40px;
  animation: wq-panel-in 500ms var(--ease-out);
}

.detail__back { display: none; }

.detail__main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.detail__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.detail__name {
  font-size: clamp(56px, 5.8vw, 84px);
  line-height: 0.9;
  font-weight: 700;
  letter-spacing: -0.05em;
}
.detail__tagline {
  font-size: 21px;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.detail__desc {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-soft);
  max-width: 60ch;
}

.detail__side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.detail__stats { display: flex; gap: 32px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__value { font-size: 44px; font-weight: 700; letter-spacing: -0.04em; line-height: 1; }
.stat__label { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.detail__facts { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--font-mono);
  font-size: 12px;
}

.detail__links { margin-top: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  height: 48px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: transform 200ms var(--ease-out), background 200ms ease;
}
.btn:hover { transform: translateY(-1px); }
.btn--primary { background: var(--text); color: var(--bg); }
.btn--ghost { background: transparent; color: var(--text); }
.btn--ghost:hover { background: rgba(255, 255, 255, 0.08); }

/* ============================================================ MOTIFS */
/* pulse */
.m-pulse { position: relative; width: var(--motif-size); height: var(--motif-size); }
.m-pulse__ring {
  position: absolute;
  inset: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  animation: wq-pulse 3s ease-out infinite;
}
.m-pulse__ring:nth-child(2) { animation-delay: 1s; }
.m-pulse__ring:nth-child(3) { animation-delay: 2s; }
.m-pulse__core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 27.5%;
  height: 27.5%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--text);
  display: grid;
  place-items: center;
}
.m-pulse__core svg { width: 42%; height: 42%; }

/* phasors */
.m-phasors { width: var(--motif-size); height: var(--motif-size); overflow: visible; }
.m-phasors text { fill: rgba(255, 255, 255, 0.6); font-family: var(--font-mono); font-size: 12px; }

/* tiles */
.m-tiles { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.m-tiles__row { display: flex; gap: calc(var(--motif-size) * 0.033); }
.m-tiles__tile {
  width: calc(var(--motif-size) * 0.19);
  height: calc(var(--motif-size) * 0.206);  /* 74px at full size */
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: calc(var(--motif-size) * 0.04);
  font-size: calc(var(--motif-size) * 0.122);
  font-weight: 600;
  line-height: 1;
}
.m-tiles__tried {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(244, 245, 247, 0.75);
}
.m-tiles__tried s { margin: 0 4px; }

/* monogram (fallback) */
.m-mono { position: relative; width: var(--motif-size); height: var(--motif-size); display: grid; place-items: center; }
.m-mono__ring { position: absolute; inset: 8%; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, 0.55); }
.m-mono__orbit { position: absolute; inset: 0; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, 0.2); animation: wq-spin 24s linear infinite; }
.m-mono__dot { position: absolute; top: -7px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; box-shadow: 0 0 24px 4px rgba(255, 255, 255, 0.25); }
.m-mono__text { font-size: calc(var(--motif-size) * 0.3); font-weight: 700; letter-spacing: -0.06em; }

/* ============================================================ RESPONSIVE */
/* Laptops up to 1300px wide: give the button column more room */
@media (max-width: 1300px) and (min-width: 861px) {
  .detail { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .chip { padding: 6px 10px; font-size: 11px; }
  .detail__facts { gap: 6px; }
}

/* Short laptop screens */
@media (max-height: 760px) and (min-width: 861px) {
  :root { --topbar-h: 72px; --panel-h: 280px; }
  .tool-list { --row-h: 64px; }
  .detail { padding: 24px 28px; gap: 28px; }
  .detail__name { font-size: clamp(48px, 5vw, 68px); }
  .detail__tagline { font-size: 18px; }
  .stat__value { font-size: 36px; }
}

/* Tablets and small laptops */
@media (max-width: 1100px) and (min-width: 861px) {
  :root { --pad: 32px; --left-w: 320px; --gap: 32px; }
  .detail { padding: 24px; gap: 24px; }
  .detail__name { font-size: clamp(44px, 5vw, 60px); }
  .detail__tagline { font-size: 18px; }
  .stat__value { font-size: 34px; }
  .detail { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .btn { padding: 0 16px; font-size: 14px; }
}

/* Phones: list fills the screen; a tool opens as a full-screen sheet.
   On very small phones the sheet may scroll as a last resort so no text is cut off. */
@media (max-width: 860px) {
  :root { --pad: 20px; --topbar-h: 68px; --motif-size: clamp(110px, 24vh, 240px); }
  .tool-list { --row-h: 68px; }

  .blob--1 { left: 20%; top: -18%; width: 110vw; }
  .blob--2 { left: 55%; top: 30%; width: 90vw; }
  .blob--3 { left: -10%; top: 55%; width: 90vw; }
  .texture--dots { left: 0; width: 100%; }

  .layout { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  .main { grid-template-columns: 1fr; padding-top: 8px; }
  .index__headline { font-size: clamp(28px, 8vw, 36px); }
  .brand__name { font-size: 16px; }
  .gh-pill { padding: 0 12px; }

  .stage {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: none;
    flex-direction: column;
    gap: 12px;
    padding:
      calc(16px + env(safe-area-inset-top, 0px))
      var(--pad)
      calc(20px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 11, 15, 0.35);
    overflow-y: auto;
  }
  .poster.is-tool .stage { display: flex; }

  .motifs { position: relative; inset: auto; flex: 0 0 auto; height: calc(var(--motif-size) + 24px); order: 1; }
  .home-caption { display: none; }

  .detail {
    position: relative;
    order: 2;
    min-height: 0;
    max-height: none;
    overflow: visible;
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 24px 20px;
  }
  .detail__back {
    display: inline-flex;
    align-items: center;
    height: 44px;
    padding: 0 16px;
    justify-self: start;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    font-family: var(--font-mono);
    font-size: 13px;
    cursor: pointer;
  }
  .detail__name { font-size: 52px; }
  .detail__tagline { font-size: 19px; }
  .detail__links { margin-top: 0; }
  .btn { flex: 1 1 auto; justify-content: center; }
  .detail__facts { gap: 6px; }
  .chip { padding: 5px 10px; font-size: 11px; }
  .detail__side { gap: 14px; }
  .detail { gap: 16px; }
}
@media (max-width: 860px) and (max-height: 760px) {
  :root { --motif-size: clamp(90px, 16vh, 200px); }
  .stage { gap: 8px; }
  .detail { gap: 14px; padding: 18px; }
  .detail__main { gap: 8px; }
  .detail__side { gap: 14px; }
  .detail__name { font-size: 42px; }
  .detail__tagline { font-size: 17px; }
  .detail__desc { font-size: 14px; line-height: 1.5; }
  .stat__value { font-size: 30px; }
  .detail__stats { gap: 24px; }
  .btn { height: 44px; }
}

/* ============================================================ MOTION */
@keyframes wq-drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(18px, -14px); }
}
@keyframes wq-pulse {
  0% { transform: scale(0.55); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}
@keyframes wq-spin { to { transform: rotate(360deg); } }
@keyframes wq-panel-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================ DEBUG (?debug=1) */
.debug .index, .debug .stage, .debug .motifs, .debug .detail, .debug .tool-row {
  outline: 1px dashed rgba(255, 200, 0, 0.6);
  outline-offset: -1px;
}
.debug-panel {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 100;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 200, 0, 0.6);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: #FFE9A8;
}
.debug-panel .debug-msg { color: #FFC4C4; }

.noscript {
  position: fixed;
  inset: auto 20px 20px 20px;
  z-index: 10;
  font-family: var(--font-sans);
  color: var(--text);
}
