/* ==========================================================================
   synclayer.dev — Live Operations Console
   Tokens from DESIGN.md. No border-radius. No gradients. No shadows.
   TODO(font): swap JetBrains Mono for Berkeley Mono when operator licenses it.
   ========================================================================== */

/* Fonts via Google Fonts (see index.html <link>). TODO(font): swap to Berkeley Mono if licensed. */

:root,
html[data-theme="dark"] {
  --bg: #0e0f0c;
  --surface: #15160f;
  --ink: #ede8db;
  --ink-muted: #8a867b;
  --grid: #1e1f18;
  --wire: #3a3833;
  --amber: #e8a33d;
  --green: #7fb069;
  --red: #d14b3c;
  --grain-opacity: 0.035;

  color-scheme: dark;
}

html[data-theme="paper"] {
  --bg: #f3efe6;
  --surface: #ebe6d9;
  --ink: #1a1815;
  --ink-muted: #6b6659;
  --grid: #e2ddce;
  --wire: #c7bfac;
  --amber: #b8771e;
  --green: #4e7e3c;
  --red: #a83a2d;
  --grain-opacity: 0.025;

  color-scheme: light;
}

:root {
  --fs-xs: 0.6875rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.5rem;
  --fs-serif-sm: 1.25rem;
  --fs-serif-lg: clamp(2rem, 4vw, 3.25rem);

  --sp-0: 2px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-8: 48px;
  --sp-10: 64px;
  --sp-12: 96px;

  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
}

/* --- reset --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.45;
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}
body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, p { margin: 0; }

/* --- graph-paper substrate (always visible) --- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px;
  pointer-events: none;
  opacity: 0.5;
}

/* fine grain noise */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

/* all content above the substrate */
main, header, footer, .skip { position: relative; z-index: 1; }

/* --- skip link --- */
.skip {
  position: absolute;
  left: var(--sp-4);
  top: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  color: var(--amber);
  background: var(--bg);
  border: 1px solid var(--amber);
  font-size: var(--fs-xs);
  transform: translateY(-200%);
  transition: transform 120ms ease-out;
  z-index: 100;
}
.skip:focus { transform: translateY(0); outline: 1px solid var(--amber); outline-offset: 2px; }

/* --- focus ring universal --- */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 1px solid var(--amber);
  outline-offset: 2px;
}

/* ==========================================================================
   VIEWPORT 1 — Console
   ========================================================================== */
.console {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "wordmark cluster"
    "map      map"
    "log      serifline";
  padding: var(--sp-5) var(--sp-6);
  gap: var(--sp-4);
  overflow: hidden;
}

.wordmark {
  grid-area: wordmark;
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  align-self: start;
}

.cluster {
  grid-area: cluster;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--sp-4);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
}
.cluster .build { font-variant-numeric: tabular-nums; }
.cluster .sep { opacity: 0.5; }
.theme-toggle {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.theme-toggle:hover { color: var(--ink); }

.map-shell {
  grid-area: map;
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  align-self: center;
  justify-self: center;
}
.signal-map {
  display: block;
  width: 100%;
  height: auto;
}
.map-hover {
  position: absolute;
  left: 50%;
  bottom: -28px;
  transform: translateX(-50%);
  font-size: var(--fs-sm);
  color: var(--ink);
  opacity: 0;
  transition: opacity 120ms ease-out;
  pointer-events: none;
  white-space: nowrap;
}
.map-hover.is-visible { opacity: 1; }

.log-shell {
  grid-area: log;
  width: 320px;
  max-width: 100%;
  align-self: end;
}
.log-shell .log-label {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
}
.log {
  font-size: var(--fs-xs);
  line-height: 1.55;
  color: var(--ink);
  height: 220px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  /* fade old rows out at the top so they don't clip harshly */
  -webkit-mask-image: linear-gradient(to top, #000 72%, transparent 100%);
          mask-image: linear-gradient(to top, #000 72%, transparent 100%);
}
.log-row {
  flex: 0 0 auto;          /* critical: stop flex from shrinking row height */
  min-height: 1.55em;
  animation: fadein 180ms ease-out;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-ts { color: var(--ink-muted); }
.log-host { color: var(--ink); }
.log-sep { color: var(--ink-muted); opacity: 0.5; }
.log-event { color: var(--ink); }
.log-row--alert .log-event { color: var(--red); }
.log-metric { color: var(--ink-muted); }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { from { opacity: 1; } to { opacity: 0; } }
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.serifline {
  grid-area: serifline;
  align-self: end;
  justify-self: end;
  font-family: var(--font-serif);
  font-size: var(--fs-serif-lg);
  color: var(--ink);
  font-style: italic;
  line-height: 1.1;
  max-width: 560px;
  text-align: right;
}

.chevron {
  position: absolute;
  left: 50%;
  bottom: var(--sp-4);
  transform: translateX(-50%);
  font-size: var(--fs-md);
  color: var(--amber);
  opacity: 0.3;
  animation: chevron-pulse 4s ease-in-out infinite;
  pointer-events: none;
  user-select: none;
}
@keyframes chevron-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

/* ==========================================================================
   Signal-map nodes / wires / packets
   ========================================================================== */
.signal-map .wire {
  stroke: var(--wire);
  stroke-width: 1;
  transition: stroke 160ms ease-out;
}
.signal-map .wire--planned { stroke-opacity: 0.4; }
.signal-map .wire--offline { stroke: var(--red); stroke-opacity: 0.4; stroke-dasharray: 4 4; }
.signal-map .wire--active { stroke: var(--amber); stroke-opacity: 0.9; }

.signal-map .packet {
  fill: var(--amber);
}

.signal-map .node-hit { fill: transparent; }

.signal-map .node-dot {
  transition: transform 160ms ease-out;
  transform-origin: center;
  transform-box: fill-box;
}
.signal-map .node-dot--center { fill: var(--ink); }
.signal-map .node-dot--online { fill: var(--green); }
.signal-map .node-dot--planned { fill: transparent; stroke: var(--ink-muted); stroke-width: 1; }
.signal-map .node-dot--offline { fill: var(--red); fill-opacity: 0.6; }
.signal-map .node-dot--pulse {
  animation: node-pulse 600ms ease-out;
}
@keyframes node-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.8); }
  100% { transform: scale(1); }
}

.signal-map .node-label {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}
.signal-map .node-label--italic { font-style: italic; fill: var(--ink-muted); }

.signal-map a:hover .node-label,
.signal-map a:focus .node-label { fill: var(--amber); }
.signal-map a:hover .wire, .signal-map a:focus .wire { stroke: var(--amber); }

/* ==========================================================================
   VIEWPORT 2 — Channels
   ========================================================================== */
.channels {
  padding: var(--sp-12) var(--sp-6) var(--sp-10);
  max-width: 1100px;
  margin: 0 auto;
}
.section-label {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--sp-6);
}
.ch-list { display: flex; flex-direction: column; }

.ch-row {
  display: grid;
  grid-template-columns: 16px minmax(220px, auto) 16px 1fr 16px auto;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink-muted) 20%, transparent);
  font-size: var(--fs-base);
  color: var(--ink);
  transition: background 120ms ease-out;
}
.ch-row:hover { background: color-mix(in srgb, var(--ink-muted) 8%, transparent); }
.ch-row--pulse { border-bottom-color: var(--amber); }

.ch-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 0;
  align-self: center;
}
.ch-dot--online { background: var(--green); }
.ch-dot--planned { background: transparent; border: 1px solid var(--ink-muted); }
.ch-dot--offline { background: var(--red); opacity: 0.6; }

.ch-host { color: var(--ink); }
.ch-sep { color: var(--ink-muted); opacity: 0.4; }
.ch-desc { color: var(--ink-muted); font-size: var(--fs-sm); }
.ch-status { color: var(--ink-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; text-align: right; }

/* ==========================================================================
   VIEWPORT 3 — Transmissions + contact
   ========================================================================== */
.transmissions {
  padding: var(--sp-12) var(--sp-6) var(--sp-10);
  max-width: 1100px;
  margin: 0 auto;
}
.tx-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--sp-5);
  align-items: start;
}
.tx-lead {
  grid-column: 1 / span 8;
  font-family: var(--font-serif);
  font-size: var(--fs-serif-lg);
  line-height: 1.15;
  color: var(--ink);
}
.tx-sat-a {
  grid-column: 9 / span 4;
  grid-row: 2;
  font-size: var(--fs-base);
  color: var(--ink-muted);
  margin-top: var(--sp-8);
}
.tx-sat-b {
  grid-column: 7 / span 6;
  grid-row: 3;
  font-size: var(--fs-base);
  color: var(--ink-muted);
  margin-top: var(--sp-6);
  text-align: right;
}

.contact {
  margin-top: var(--sp-10);
  text-align: center;
}
.contact-link {
  font-family: var(--font-serif);
  font-size: var(--fs-serif-sm);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.contact-link::after {
  content: "▌";
  color: var(--amber);
  font-family: var(--font-mono);
  animation: blink 1s step-end infinite;
  display: inline-block;
  transform: translateY(-1px);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  padding: var(--sp-6);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  border-top: 1px solid color-mix(in srgb, var(--ink-muted) 15%, transparent);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .map-shell { max-width: 900px; }
  .tx-lead { grid-column: 1 / span 10; }
  .tx-sat-a { grid-column: 1 / span 6; grid-row: 2; margin-top: var(--sp-6); text-align: left; }
  .tx-sat-b { grid-column: 7 / span 6; grid-row: 2; margin-top: var(--sp-6); }
}

@media (max-width: 720px) {
  .console {
    padding: var(--sp-4);
    grid-template-columns: 1fr;
    grid-template-areas:
      "wordmark"
      "cluster"
      "map"
      "serifline"
      "log";
    min-height: auto;
    padding-bottom: var(--sp-10);
  }
  .cluster { justify-content: flex-start; flex-wrap: wrap; }
  .cluster .build { display: none; }
  .serifline { justify-self: start; text-align: left; max-width: 100%; }
  .log-shell { width: 100%; }
  .log { max-height: 180px; }
  .chevron { display: none; }

  .channels, .transmissions { padding: var(--sp-10) var(--sp-4); }
  .section-label { margin-bottom: var(--sp-4); }
  .ch-row {
    grid-template-columns: 16px 1fr auto;
    gap: var(--sp-2);
    padding: var(--sp-3) 0;
  }
  .ch-row .ch-sep { display: none; }
  .ch-desc { grid-column: 1 / -1; font-size: var(--fs-xs); padding-left: 24px; color: var(--ink-muted); }

  .tx-grid { grid-template-columns: 1fr; gap: var(--sp-6); }
  .tx-lead, .tx-sat-a, .tx-sat-b { grid-column: 1; grid-row: auto; margin-top: 0; text-align: left; }
  .tx-lead { font-size: clamp(1.6rem, 5vw, 2.2rem); }
}

@media (max-width: 480px) {
  .console { padding: var(--sp-3); }
  .log { max-height: 140px; font-size: 10px; }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .signal-map .packet { display: none; }
  .chevron { animation: none; opacity: 0.3; }
  .contact-link::after { animation: none; opacity: 0.8; }
}
