/* datatelomere.com — Research Instrument */
:root {
    --bg-primary: #0f1117;
    --bg-panel: #1a1d23;
    --border: #2a2d35;
    --text-primary: #e5e7eb;
    --text-secondary: #6b7280;
    --accent-teal: #4fd1c5;
    --accent-amber: #f59e0b;
    --accent-coral: #ef4444;
    --accent-blue: #38bdf8;
    --warm-noise: #92400e;

    --degradation: 0;
    --grid-line: rgba(229, 231, 235, calc(0.04 - var(--degradation) * 0.03));
    --letter-spacing: calc(0.04em + var(--degradation) * 0.08em);
}

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

html {
    scroll-behavior: smooth;
    background: var(--bg-primary);
}

body {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.6;
    letter-spacing: var(--letter-spacing);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

.num {
    font-family: 'JetBrains Mono', monospace;
    font-feature-settings: 'tnum' 1;
    font-variant-numeric: tabular-nums;
}

/* Background grid overlay */
.grid-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: 48px 48px;
    transition: background-image 200ms linear;
}

/* SVG noise overlay (procedural via CSS) */
.noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: calc(var(--degradation) * 0.18);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.6 0 0 0 0 0.3 0 0 0 0 0.05 0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    mix-blend-mode: overlay;
}

/* Masthead */
.masthead {
    position: fixed;
    top: 24px;
    left: 32px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.masthead-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-secondary);
}

.masthead-meta {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: rgba(107, 114, 128, 0.55);
}

/* Progress rail */
.progress-rail {
    position: fixed;
    top: 0;
    right: 24px;
    height: 100vh;
    width: 60px;
    z-index: 10;
    pointer-events: none;
}

.rail-track {
    position: absolute;
    top: 12vh;
    bottom: 12vh;
    right: 30px;
    width: 2px;
    background: var(--border);
}

.rail-fill {
    position: absolute;
    top: 12vh;
    right: 30px;
    width: 2px;
    height: 0;
    background: var(--accent-teal);
    box-shadow: 0 0 8px rgba(79, 209, 197, 0.6);
    transition: background 200ms;
}

.rail-tick {
    position: absolute;
    right: 0;
    width: 60px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.rail-tick::after {
    content: '';
    width: 12px;
    height: 1px;
    background: var(--text-secondary);
}

.rail-tick span {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-secondary);
}

/* Layout */
main {
    position: relative;
    z-index: 2;
    padding: 0 64px;
    max-width: 1600px;
    margin: 0 auto;
}

.region {
    min-height: 100vh;
    padding: 96px 0 64px;
    position: relative;
}

.region-degraded {
    min-height: 200vh;
}

.region-entropy {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 120px 0;
}

.region-label {
    margin-bottom: 48px;
    max-width: 720px;
}

.label-num {
    display: inline-block;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--accent-teal);
    margin-bottom: 16px;
    padding: 4px 10px;
    border: 1px solid currentColor;
}

.region-headline {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.region-sub {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 560px;
}

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    margin-bottom: 48px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    grid-column: span 4;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: filter 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-color 400ms ease;
    will-change: filter;
}

.panel-wide { grid-column: span 8; min-height: 260px; }
.panel-tall { grid-column: span 4; grid-row: span 2; min-height: 380px; }
.panel-mid { grid-column: span 4; }

.grid-shifted .panel:nth-child(2) { grid-column: span 4; }
.grid-shifted .panel:nth-child(3) { grid-column: span 5; }
.grid-shifted .panel:nth-child(4) { grid-column: span 3; }
.grid-shifted .panel:nth-child(5) { grid-column: span 4; }

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 23, 0.4);
}

.panel-title {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.panel-status {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent-teal);
    padding: 2px 6px;
    border: 1px solid rgba(79, 209, 197, 0.3);
}

.panel-status.warn { color: var(--accent-amber); border-color: rgba(245, 158, 11, 0.4); }
.panel-status.err { color: var(--accent-coral); border-color: rgba(239, 68, 68, 0.5); }

.panel-body {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
}

.panel-foot {
    display: flex;
    gap: 20px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    margin-top: 12px;
    flex-wrap: wrap;
}

.foot-pair {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

.foot-pair em {
    color: var(--accent-teal);
    font-style: normal;
    font-size: 11px;
}

.foot-pair b {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 13px;
}

/* SVG charts */
.line-chart, .area-chart, .scatter {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 120px;
}

.grid-lines-svg line {
    stroke: var(--border);
    stroke-width: 1;
    stroke-dasharray: 2 4;
    opacity: 0.5;
}

.line-stroke {
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px rgba(79, 209, 197, 0.4));
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1800ms ease-out;
}

.line-stroke.in-view { stroke-dashoffset: 0; }

.line-stroke-secondary {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 2200ms ease-out 200ms;
}

.line-stroke-secondary.in-view { stroke-dashoffset: 0; }

/* Gauge */
.gauge-body {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.radial-gauge {
    width: 140px;
    height: 140px;
    margin: 0 auto;
}

.gauge-arc {
    transition: stroke-dashoffset 1800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gauge-readout {
    margin-top: -90px;
    margin-bottom: 60px;
    pointer-events: none;
}

.gauge-num {
    font-size: clamp(2rem, 4vw, 2.6rem);
    font-weight: 700;
    color: var(--accent-teal);
}

.gauge-unit {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.gauge-caption {
    display: block;
    font-size: 9px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* Heat grid */
.heat-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 2px;
    flex: 1;
}

.heat-cell {
    background: var(--accent-teal);
    border-radius: 1px;
    transition: opacity 600ms;
}

/* Ticker */
.ticker-body {
    justify-content: center;
    gap: 12px;
}

.big-num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    color: var(--accent-teal);
    line-height: 1;
    letter-spacing: 0.02em;
    text-shadow: 0 0 24px rgba(79, 209, 197, 0.3);
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.big-unit {
    font-size: 0.4em;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.16em;
}

.ticker-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

/* Scatter */
.scatter circle {
    transition: filter 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    filter: blur(6px);
}

.scatter.in-view circle { filter: blur(0); }

/* Telomere bands */
.telomere-band {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 32px 0;
    margin: 0 -64px;
}

.telomere-band span {
    display: block;
    height: 12px;
    background: var(--accent-teal);
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(79, 209, 197, 0.4);
}

.telomere-band.band-1 span {
    width: 56px;
    opacity: 0.85;
}

.telomere-band.band-1 span:nth-child(odd) {
    background: var(--accent-blue);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.telomere-band.band-2 span {
    background: var(--accent-amber);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.telomere-band.band-2 span:nth-child(1) { width: 56px; opacity: 0.9; }
.telomere-band.band-2 span:nth-child(2) { width: 48px; opacity: 0.78; }
.telomere-band.band-2 span:nth-child(3) { width: 40px; opacity: 0.66; }
.telomere-band.band-2 span:nth-child(4) { width: 32px; opacity: 0.55; }
.telomere-band.band-2 span:nth-child(5) { width: 24px; opacity: 0.42; }
.telomere-band.band-2 span:nth-child(6) { width: 18px; opacity: 0.3; }
.telomere-band.band-2 span:nth-child(7) { width: 12px; opacity: 0.18; }

/* Scanlines + jitter (degraded) */
.scanlines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: repeating-linear-gradient(
        0deg,
        transparent 0,
        transparent 3px,
        rgba(229, 231, 235, 0.04) 3px,
        rgba(229, 231, 235, 0.04) 4px
    );
    mix-blend-mode: overlay;
    opacity: calc(0.4 + var(--degradation) * 0.6);
}

.line-stroke.jitter {
    filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.4));
    animation: jitter 0.6s steps(8) infinite;
}

.line-stroke.jitter-2 {
    animation: jitter 0.5s steps(6) infinite reverse;
}

@keyframes jitter {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(0.5px); }
    50% { transform: translateY(-0.5px); }
    75% { transform: translateY(0.3px); }
}

/* Number cascade */
.number-cascade {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    flex: 1;
    align-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--accent-amber);
    letter-spacing: 0.06em;
}

.number-cascade .cell {
    text-align: right;
    padding: 4px 6px;
    background: rgba(245, 158, 11, 0.04);
    border-left: 1px solid rgba(245, 158, 11, 0.3);
    transition: opacity 300ms;
}

.number-cascade .cell.dim { color: var(--text-secondary); border-color: var(--border); background: transparent; }

/* Bar stack */
.bar-stack {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 80px;
    margin-top: 16px;
}

.bar-stack .bar {
    flex: 1;
    background: linear-gradient(to top, var(--accent-amber), rgba(245, 158, 11, 0.3));
    border-radius: 1px 1px 0 0;
    transition: height 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Entropy region */
.entropy-label {
    text-align: center;
    margin-bottom: 64px;
}

.entropy-label .label-num {
    color: var(--accent-coral);
}

.entropy-field {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.entropy-field .particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--accent-coral);
    opacity: 0.3;
    animation: flicker 1.4s infinite;
}

.entropy-field .particle.teal { background: var(--accent-teal); }
.entropy-field .particle.amber { background: var(--accent-amber); }

@keyframes flicker {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

.telomere-circle {
    position: relative;
    width: 80vmin;
    height: 80vmin;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.telomere-glow {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at center,
        rgba(79, 209, 197, 0.15) 0%,
        rgba(79, 209, 197, 0.08) 30%,
        rgba(15, 17, 23, 0) 70%);
    animation: pulse 4s ease-in-out infinite;
    filter: blur(12px);
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; transform: scale(0.96); }
    50% { opacity: 1; transform: scale(1.04); }
}

.telomere-meta {
    position: relative;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.24em;
    color: var(--accent-teal);
    z-index: 3;
    text-shadow: 0 0 12px rgba(79, 209, 197, 0.6);
}

/* Footer */
.instrument-footer {
    display: flex;
    justify-content: space-between;
    padding: 32px 0;
    border-top: 1px solid var(--border);
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* Blur-focus state */
.panel.blur-far { filter: blur(6px); }
.panel.blur-mid { filter: blur(3px); }
.panel.blur-near { filter: blur(0); }

/* Degradation effects on borders */
.region-degraded .panel {
    border-color: color-mix(in srgb, var(--border) calc((1 - var(--degradation)) * 100%), var(--warm-noise));
}

.region-degraded .panel-status,
.region-degraded .gauge-num,
.region-degraded .big-num {
    color: var(--accent-amber);
}

/* Responsive */
@media (max-width: 900px) {
    main { padding: 0 24px; }
    .panel, .panel-wide, .panel-tall, .panel-mid { grid-column: span 12; }
    .progress-rail { display: none; }
    .telomere-band { margin: 0 -24px; }
}
