/* ==========================================================
   DIGITALTELOMERE.COM
   Cyberpunk full-bleed scroll narrative through five
   memory sectors of telomeric degradation.
   ========================================================== */

:root {
    --void: #000000;
    --substrate: #0D0221;
    --cyan: #00F0FF;
    --magenta: #FF00E5;
    --green: #39FF14;
    --orange: #FF6B00;
    --ghost: #E0E8FF;
    --decay: #3A3A4A;

    --corruption-level: 0;
    --glitch-direction: 1;

    --font-display: 'Orbitron', 'Inter', sans-serif;
    --font-mono: 'Share Tech Mono', 'Inter', monospace;
    --font-accent: 'Exo 2', 'Inter', sans-serif;
}

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

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

body {
    background: var(--void);
    color: var(--ghost);
    font-family: var(--font-mono);
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    cursor: crosshair;
}

/* ----- Scan line sweep on initial boot ----- */
#scan-line-sweep {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--cyan) 20%,
        var(--cyan) 80%,
        transparent 100%);
    box-shadow: 0 0 12px var(--cyan), 0 0 36px rgba(0, 240, 255, 0.4);
    z-index: 200;
    transform: translateY(-2px);
    animation: sweep 1.5s ease-out 0.6s forwards;
    pointer-events: none;
    opacity: 0;
}

@keyframes sweep {
    0%   { transform: translateY(-2px); opacity: 1; }
    95%  { opacity: 1; }
    100% { transform: translateY(100vh); opacity: 0; }
}

/* ----- Vertical progress bar ----- */
#progress-bar {
    position: fixed;
    top: 0;
    right: 0;
    width: 2px;
    height: 0;
    background: var(--magenta);
    box-shadow: 0 0 8px var(--magenta), 0 0 18px rgba(255, 0, 229, 0.5);
    z-index: 150;
    pointer-events: none;
    transition: height 0.08s linear;
}

/* ----- Global scanline overlay (CRT effect) ----- */
#scanline-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 120;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0) 0px,
        rgba(0, 0, 0, 0) 2px,
        rgba(0, 0, 0, calc(0.18 + var(--corruption-level) * 0.32)) 3px
    );
    mix-blend-mode: multiply;
    opacity: calc(0.6 + var(--corruption-level) * 0.4);
}

#scanline-overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center,
        transparent 40%,
        rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
}

/* ----- Memory stack ----- */
#memory-stack {
    position: relative;
    z-index: 1;
}

.sector {
    position: relative;
    width: 100vw;
    min-height: 100vh;
    padding: 6vh 6vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#sector-00 { background: var(--void); }
#sector-01 { background: radial-gradient(ellipse at top, #050118 0%, var(--void) 70%); min-height: 100vh; }
#sector-02 { background: radial-gradient(ellipse at center, #0a0220 0%, var(--void) 80%); min-height: 150vh; }
#sector-03 { background: linear-gradient(180deg, #0a0220 0%, var(--substrate) 50%, #0a0220 100%); min-height: 150vh; }
#sector-04 { background: var(--void); min-height: 100vh; }

.sector-content {
    position: relative;
    z-index: 5;
    width: 100%;
    max-width: 100%;
}

/* =========================================================
   SECTOR 00 - INITIALIZATION
   ========================================================= */

.hex-rain {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
    opacity: 0;
    animation: rain-fade-in 0.8s ease 2.6s forwards;
    pointer-events: none;
}

@keyframes rain-fade-in {
    to { opacity: 1; }
}

.rain-column {
    position: absolute;
    top: -120%;
    width: 18px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 18px;
    color: var(--cyan);
    text-align: center;
    will-change: transform;
    animation: rain-fall linear infinite;
}

.rain-column span {
    display: block;
    animation: char-flicker 1.6s steps(1) infinite;
}

@keyframes rain-fall {
    from { transform: translateY(0); }
    to   { transform: translateY(220vh); }
}

@keyframes char-flicker {
    0%, 100% { opacity: 0.95; }
    50%      { opacity: 0.55; }
}

.sector-00-content {
    text-align: center;
    margin: auto;
}

.sector-label {
    font-family: var(--font-accent);
    font-weight: 300;
    font-size: clamp(0.75rem, 1.4vw, 1rem);
    letter-spacing: 0.4em;
    color: var(--green);
    text-transform: uppercase;
    margin-bottom: 1.6rem;
    opacity: 0;
    animation: fade-up 0.8s ease 2.4s forwards;
}

.sector-label.warn { color: var(--magenta); }
.sector-label.crit { color: var(--orange); }
.sector-label.calm { color: var(--cyan); }

@keyframes fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.domain-title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(2rem, 8vw, 8rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ghost);
    line-height: 1;
    text-shadow: 0 0 18px rgba(0, 240, 255, 0.6),
                 0 0 36px rgba(0, 240, 255, 0.2);
    word-break: break-word;
    position: relative;
}

.domain-title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(0);
    animation: char-reveal 0.18s ease forwards;
    will-change: opacity, transform;
}

@keyframes char-reveal {
    from { opacity: 0; filter: blur(6px); }
    to   { opacity: 1; filter: blur(0); }
}

.sub-readout {
    margin-top: 2.5rem;
    font-family: var(--font-mono);
    color: var(--decay);
    font-size: clamp(0.75rem, 1vw, 0.95rem);
    letter-spacing: 0.05em;
    opacity: 0;
    animation: fade-up 0.8s ease 3.0s forwards;
}

.readout-line {
    display: block;
    padding: 2px 0;
}

.value-cyan { color: var(--cyan); }

/* =========================================================
   SECTOR HEADERS shared
   ========================================================= */

.sector-header {
    margin-bottom: 4vh;
}

.sector-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 6vw, 5.5rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ghost);
    line-height: 1.05;
    margin-top: 0.6rem;
    word-break: break-word;
}

.sector-title .char {
    display: inline-block;
    will-change: transform, opacity, color;
    transition: color 0.2s steps(1);
}

/* =========================================================
   SECTOR 01 - TELOMERE INTACT (bento grid)
   ========================================================= */

.bento-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, minmax(180px, 1fr));
    gap: 1.4rem;
    width: 100%;
    flex: 1;
    min-height: 60vh;
}

.bento-block {
    border: 1px solid var(--cyan);
    background: rgba(0, 240, 255, 0.02);
    padding: 1.4rem 1.4rem 1.2rem;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: inset 0 0 24px rgba(0, 240, 255, 0.06);
    transition: transform 0.6s ease, opacity 0.6s ease, border-color 0.6s ease;
    opacity: calc(1 - var(--corruption-level) * 0.3);
}

.bento-block::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 8px;
    height: 8px;
    border-top: 1px solid var(--cyan);
    border-left: 1px solid var(--cyan);
}

.bento-block::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-bottom: 1px solid var(--cyan);
    border-right: 1px solid var(--cyan);
}

.block-meta {
    font-family: var(--font-accent);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.25em;
    color: var(--decay);
    text-transform: uppercase;
    margin-bottom: 0.8rem;
}

.block-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.4rem, 3.4vw, 2.6rem);
    letter-spacing: 0.08em;
    color: var(--cyan);
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}

.block-value.small {
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    letter-spacing: 0.18em;
    color: var(--ghost);
}

.block-value.warn { color: var(--magenta); text-shadow: 0 0 8px rgba(255, 0, 229, 0.4); }
.block-value.crit { color: var(--orange); text-shadow: 0 0 8px rgba(255, 107, 0, 0.5); }

.block-bar {
    margin-top: auto;
    height: 4px;
    background: rgba(0, 240, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.block-bar > span {
    display: block;
    height: 100%;
    background: var(--cyan);
    box-shadow: 0 0 10px var(--cyan);
    animation: bar-pulse 2.4s ease-in-out infinite;
}

.block-bar.danger > span {
    background: var(--orange);
    box-shadow: 0 0 10px var(--orange);
}

@keyframes bar-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}

.block-spark {
    margin-top: auto;
    height: 32px;
}

.block-spark svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.block-spark polyline {
    fill: none;
    stroke: var(--cyan);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px var(--cyan));
}

.block-c {
    grid-row: span 2;
}

.block-helix {
    align-items: center;
    justify-content: stretch;
    padding: 1rem;
}

.block-helix svg {
    width: 100%;
    height: 100%;
    flex: 1;
}

.pulse-dots {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.pulse-dots span {
    aspect-ratio: 1 / 1;
    background: var(--cyan);
    box-shadow: 0 0 6px var(--cyan);
    opacity: 0.5;
    animation: dot-pulse 1.6s ease-in-out infinite;
}

.pulse-dots span:nth-child(1) { animation-delay: 0.0s; }
.pulse-dots span:nth-child(2) { animation-delay: 0.1s; }
.pulse-dots span:nth-child(3) { animation-delay: 0.2s; }
.pulse-dots span:nth-child(4) { animation-delay: 0.3s; }
.pulse-dots span:nth-child(5) { animation-delay: 0.4s; }
.pulse-dots span:nth-child(6) { animation-delay: 0.5s; }
.pulse-dots span:nth-child(7) { animation-delay: 0.6s; }
.pulse-dots span:nth-child(8) { animation-delay: 0.7s; }
.pulse-dots span:nth-child(9) { animation-delay: 0.8s; }
.pulse-dots span:nth-child(10) { animation-delay: 0.9s; }
.pulse-dots span:nth-child(11) { animation-delay: 1.0s; }
.pulse-dots span:nth-child(12) { animation-delay: 1.1s; }

@keyframes dot-pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50%      { opacity: 1;   transform: scale(1.0); }
}

.hex-readout {
    margin-top: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--cyan);
    letter-spacing: 0.08em;
    flex: 1;
    overflow: hidden;
    word-break: break-all;
    text-shadow: 0 0 4px rgba(0, 240, 255, 0.3);
}

.cycle-ring {
    position: relative;
    margin-top: auto;
    width: 110px;
    height: 110px;
    align-self: flex-end;
}

.cycle-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-track {
    fill: none;
    stroke: rgba(0, 240, 255, 0.15);
    stroke-width: 2;
}

.ring-progress {
    fill: none;
    stroke: var(--cyan);
    stroke-width: 2;
    stroke-dasharray: 264;
    stroke-dashoffset: 5;
    stroke-linecap: round;
    filter: drop-shadow(0 0 6px var(--cyan));
    animation: ring-shift 4s ease-in-out infinite alternate;
}

@keyframes ring-shift {
    from { stroke-dashoffset: 5; }
    to   { stroke-dashoffset: 35; }
}

.cycle-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--ghost);
    letter-spacing: 0.12em;
}

/* =========================================================
   SECTOR 02 - FIRST CORRUPTION (fractured grid)
   ========================================================= */

.fracture-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(140px, auto);
    gap: 1.2rem;
    margin-bottom: 3rem;
}

.fracture-block {
    border: 1px solid var(--magenta);
    background: rgba(13, 2, 33, 0.6);
    padding: 1.2rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
    box-shadow: inset 0 0 24px rgba(255, 0, 229, 0.08);
}

.fracture-block::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 4px,
        rgba(255, 0, 229, 0.04) 5px,
        transparent 6px
    );
    pointer-events: none;
}

.fb-1 { transform: translate(calc(var(--corruption-level) * -10px), calc(var(--corruption-level) * 4px)); }
.fb-2 { transform: translate(calc(var(--corruption-level) * 14px), calc(var(--corruption-level) * -6px)) rotate(calc(var(--corruption-level) * 0.6deg)); }
.fb-3 { transform: translate(calc(var(--corruption-level) * -6px), calc(var(--corruption-level) * 10px)); }
.fb-4 { transform: translate(calc(var(--corruption-level) * 8px), calc(var(--corruption-level) * 12px)) rotate(calc(var(--corruption-level) * -0.4deg)); }
.fb-5 { transform: translate(calc(var(--corruption-level) * -12px), calc(var(--corruption-level) * -8px)); }
.fb-6 { transform: translate(calc(var(--corruption-level) * 18px), calc(var(--corruption-level) * 6px)) rotate(calc(var(--corruption-level) * 0.8deg)); }

.ghost-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.4rem 3rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--decay);
    letter-spacing: 0.08em;
}

.ghost-row span {
    color: var(--magenta);
    opacity: 0.7;
    text-shadow: 0 0 6px rgba(255, 0, 229, 0.4);
}

/* =========================================================
   SECTOR 03 - CASCADE FAILURE (overlapping panels + bands)
   ========================================================= */

.cascade-stack {
    position: relative;
    min-height: 60vh;
}

.cascade-panel {
    position: absolute;
    border: 1px solid var(--orange);
    background: rgba(13, 2, 33, 0.85);
    padding: 1.2rem 1.4rem;
    box-shadow: 0 0 30px rgba(255, 107, 0, 0.18),
                inset 0 0 24px rgba(255, 107, 0, 0.05);
    transition: transform 0.4s ease;
    backdrop-filter: blur(2px);
    width: clamp(220px, 28vw, 360px);
}

.cp-1 { top: 4%;   left: 2%;   transform: rotate(-2deg); z-index: 5; }
.cp-2 { top: 12%;  left: 36%;  transform: rotate(1.4deg); z-index: 4; }
.cp-3 { top: 22%;  left: 64%;  transform: rotate(-1deg); z-index: 6; }
.cp-4 { top: 50%;  left: 18%;  transform: rotate(2.2deg); z-index: 3; }
.cp-5 { top: 58%;  left: 50%;  transform: rotate(-0.8deg); z-index: 7; width: clamp(260px, 36vw, 460px); }

.cascade-panel::before {
    content: "";
    position: absolute;
    inset: -1px;
    border: 1px solid rgba(255, 0, 229, 0.4);
    transform: translate(3px, 3px);
    pointer-events: none;
}

.band-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 8;
}

.band {
    position: absolute;
    left: -10vw;
    width: 120vw;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(0, 240, 255, 0.18) 30%,
        rgba(255, 0, 229, 0.18) 50%,
        rgba(0, 240, 255, 0.18) 70%,
        transparent 100%);
    mix-blend-mode: screen;
    will-change: transform;
}

.b1 { top: 14%; height: 80px;  animation: band-shift 5s steps(8) infinite; }
.b2 { top: 36%; height: 140px; animation: band-shift 7s steps(10) infinite reverse; opacity: 0.6; }
.b3 { top: 60%; height: 60px;  animation: band-shift 4s steps(6) infinite; opacity: 0.85; }
.b4 { top: 82%; height: 110px; animation: band-shift 6s steps(8) infinite reverse; opacity: 0.7; }

@keyframes band-shift {
    0%   { transform: translateX(-30px); }
    25%  { transform: translateX(40px); }
    50%  { transform: translateX(-60px); }
    75%  { transform: translateX(20px); }
    100% { transform: translateX(-30px); }
}

/* =========================================================
   SECTOR 04 - FINAL TRANSMISSION
   ========================================================= */

.sector-04-content {
    text-align: center;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3rem;
}

.ring-stage {
    position: relative;
    width: min(80vw, 640px);
    height: min(80vw, 640px);
    max-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulse-ring {
    position: absolute;
    inset: 50%;
    width: 220px;
    height: 220px;
    margin: -110px 0 0 -110px;
    border-radius: 50%;
    border: 1px solid var(--cyan);
    box-shadow:
        inset 0 0 20px rgba(0, 240, 255, 0.4),
        0 0 30px rgba(0, 240, 255, 0.4),
        0 0 60px rgba(57, 255, 20, 0.2),
        0 0 120px rgba(255, 0, 229, 0.18),
        0 0 200px rgba(255, 107, 0, 0.12);
    animation: ring-breath 8s ease-in-out infinite;
}

@keyframes ring-breath {
    0%   { transform: scale(0.85); border-color: var(--cyan); box-shadow: 0 0 30px rgba(0, 240, 255, 0.4), 0 0 80px rgba(0, 240, 255, 0.2); }
    25%  { transform: scale(1.0);  border-color: var(--green); box-shadow: 0 0 40px rgba(57, 255, 20, 0.4), 0 0 100px rgba(57, 255, 20, 0.2); }
    50%  { transform: scale(1.15); border-color: var(--magenta); box-shadow: 0 0 50px rgba(255, 0, 229, 0.5), 0 0 120px rgba(255, 0, 229, 0.25); }
    75%  { transform: scale(1.0);  border-color: var(--orange); box-shadow: 0 0 40px rgba(255, 107, 0, 0.5), 0 0 100px rgba(255, 107, 0, 0.25); }
    100% { transform: scale(0.85); border-color: var(--cyan); box-shadow: 0 0 30px rgba(0, 240, 255, 0.4), 0 0 80px rgba(0, 240, 255, 0.2); }
}

.final-title {
    position: relative;
    z-index: 2;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(1.8rem, 5vw, 4rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ghost);
    text-shadow: 0 0 20px rgba(0, 240, 255, 0.6),
                 0 0 40px rgba(255, 0, 229, 0.3);
}

.final-readout {
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--green);
    letter-spacing: 0.18em;
    line-height: 2;
}

.cursor {
    display: inline-block;
    color: var(--green);
    animation: blink 1s steps(1) infinite;
}

@keyframes blink {
    0%, 49%   { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* =========================================================
   GLITCH-TEXT chromatic aberration
   ========================================================= */

.glitch-text {
    position: relative;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    text-align: inherit;
    font-family: inherit;
    font-weight: inherit;
    font-size: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    line-height: inherit;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.glitch-text::before {
    color: var(--magenta);
    clip-path: inset(0 0 60% 0);
    transform: translateX(-3px);
    animation: glitch-shift 3s steps(1) infinite alternate;
    mix-blend-mode: screen;
}

.glitch-text::after {
    color: var(--cyan);
    clip-path: inset(60% 0 0 0);
    transform: translateX(3px);
    animation: glitch-shift 2.5s steps(1) infinite alternate-reverse;
    mix-blend-mode: screen;
}

.glitch-text:hover::before,
.glitch-text:hover::after,
.glitch-text.active::before,
.glitch-text.active::after {
    opacity: 1;
}

@keyframes glitch-shift {
    0%   { transform: translateX(-3px); clip-path: inset(0 0 60% 0); }
    20%  { transform: translateX(2px);  clip-path: inset(10% 0 50% 0); }
    40%  { transform: translateX(-4px); clip-path: inset(40% 0 30% 0); }
    60%  { transform: translateX(3px);  clip-path: inset(20% 0 60% 0); }
    80%  { transform: translateX(-2px); clip-path: inset(0 0 70% 0); }
    100% { transform: translateX(4px);  clip-path: inset(30% 0 40% 0); }
}

/* Heavy-glitch variant always active */
.heavy-glitch::before,
.heavy-glitch::after {
    opacity: 1;
}

/* =========================================================
   SECTOR-DRIVEN EFFECTS via --corruption-level
   ========================================================= */

#sector-02 .sector-title,
#sector-03 .sector-title {
    filter: hue-rotate(calc(var(--corruption-level) * 30deg));
}

#sector-03 .cascade-panel {
    transform-origin: center;
}

/* Particle dissolution accents */
.fracture-block,
.cascade-panel {
    opacity: calc(1 - var(--corruption-level) * 0.05);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 900px) {
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
    }
    .block-c { grid-row: span 2; }
    .fracture-grid { grid-template-columns: repeat(2, 1fr); }
    .cascade-panel {
        position: relative;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        margin-bottom: 1.2rem;
        transform: rotate(0) !important;
    }
    .cascade-stack { display: flex; flex-direction: column; gap: 1rem; }
}

@media (max-width: 560px) {
    .bento-grid { grid-template-columns: 1fr; }
    .fracture-grid { grid-template-columns: 1fr; }
    .sector { padding: 8vh 5vw; }
}
