/* scriptgrapher.com - Maximalist Glitch-Opera Dashboard */
:root {
    --abyss-slate: #0e1a2b;
    --midnight-glass: #14243d;
    --console-depth: #1a2e4a;
    --twilight-steel: #4a6fa5;
    --pale-script: #d8e8f4;
    --muted-console: #8bacc8;
    --glacial-code: #7eb8da;
    --violet-corruption: #c4a6d4;
    --frozen-output: #b4d4e7;
    --deep-console: #2c4a6e;
    --white-burst: #f0f6fc;
    --signal-green: #6ec4a7;
    --signal-amber: #d4a86c;
    --dark-violet: #1a1a2e;
    --scroll-progress: 0;
    --glitch-intensity: 0;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background: var(--abyss-slate);
    background: linear-gradient(170deg, #0e1a2b 0%, #14243d 40%, #1a2e4a 100%);
    color: var(--pale-script);
    font-family: "Libre Baskerville", Georgia, serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scan Lines Overlay */
#scan-lines {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(0deg, transparent 0px, transparent 2px, rgba(14, 26, 43, 0.15) 2px, rgba(14, 26, 43, 0.15) 4px);
    animation: scanPulse 12s ease-in-out infinite;
}

@keyframes scanPulse {
    0%, 100% { opacity: 0.08; }
    50% { opacity: 0.15; }
}

/* Glitch Flash */
#glitch-flash {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 999;
    background: linear-gradient(90deg, transparent 0%, rgba(196, 166, 212, 0.15) 48%, rgba(126, 184, 218, 0.15) 52%, transparent 100%);
    opacity: 0;
    transition: opacity 0.1s;
}

#glitch-flash.active { opacity: 1; }

/* Data Rain */
#data-rain {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

.rain-column {
    position: absolute;
    top: 0;
    width: 20px;
    height: 100%;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.7rem;
    color: var(--twilight-steel);
    opacity: 0.3;
    mask-image: linear-gradient(to bottom, transparent 0%, white 20%, white 80%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, white 20%, white 80%, transparent 100%);
    overflow: hidden;
    writing-mode: vertical-rl;
    animation: rainFall var(--rain-speed, 4s) linear infinite;
}

@keyframes rainFall {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(100%); }
}

/* Grid Dots */
#grid-dots {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 3;
}

.grid-dot {
    position: absolute;
    width: 3px; height: 3px;
    border-radius: 50%;
    background: var(--twilight-steel);
    animation: dotPulse 6s ease-in-out infinite;
    animation-delay: var(--dot-delay, 0s);
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.1; }
    50% { opacity: 0.25; }
}

/* Instrument Panel - Fixed Header */
#instrument-panel {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    z-index: 100;
    background: linear-gradient(180deg, var(--abyss-slate) 0%, rgba(14, 26, 43, 0.95) 100%);
    border-bottom: 1px solid var(--twilight-steel);
    padding: 4px;
}

.instrument-row {
    display: grid;
    grid-template-columns: 1fr 2.4fr 1fr 1fr;
    gap: 4px;
    margin-bottom: 4px;
}

.instrument-row:last-child {
    grid-template-columns: 2fr 1fr 1.5fr;
    margin-bottom: 0;
}

/* Panel Base Styles */
.panel {
    position: relative;
    border: 1px solid var(--twilight-steel);
    background: var(--midnight-glass);
    overflow: hidden;
    transition: background 0.6s ease, transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.panel::before {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 2px;
    z-index: 2;
}

.panel::after {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: radial-gradient(ellipse at 30% 20%, rgba(126, 184, 218, 0.08) 0%, transparent 70%);
    pointer-events: none;
    transition: background-position 0.3s;
}

.script-panel::before { background: var(--glacial-code); }
.output-panel::before { background: var(--frozen-output); }
.status-panel::before { background: var(--deep-console); }
.glitch-panel::before { background: var(--violet-corruption); }

.panel-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-bottom: 1px solid rgba(74, 111, 165, 0.3);
}

.status-indicator {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--twilight-steel);
    flex-shrink: 0;
}

.status-indicator.active {
    background: var(--signal-green);
    box-shadow: 0 0 6px var(--signal-green);
    animation: indicatorGlow 2s ease-in-out infinite;
}

.status-indicator.loading {
    background: var(--signal-amber);
    box-shadow: 0 0 6px var(--signal-amber);
    animation: indicatorBlink 1.5s ease-in-out infinite;
}

.status-indicator.glitch {
    background: var(--violet-corruption);
    box-shadow: 0 0 6px var(--violet-corruption);
    animation: indicatorGlitch 3s steps(4) infinite;
}

@keyframes indicatorGlow {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

@keyframes indicatorBlink {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

@keyframes indicatorGlitch {
    0% { opacity: 1; }
    25% { opacity: 0.2; }
    50% { opacity: 0.9; }
    75% { opacity: 0.4; }
    100% { opacity: 1; }
}

.panel-label {
    font-family: "IBM Plex Sans", sans-serif;
    font-weight: 500;
    font-size: 0.65rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--twilight-steel);
}

.panel-timestamp {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.6rem;
    color: var(--muted-console);
    margin-left: auto;
}

.panel-content {
    padding: 8px 10px;
    position: relative;
}

/* Typography */
.site-title {
    position: relative;
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 4rem);
    letter-spacing: -0.03em;
    line-height: 0.9;
    text-align: center;
}

.title-layer {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}

.layer-glacial {
    color: var(--glacial-code);
    animation: chromaticDrift1 8s ease-in-out infinite;
}

.layer-violet {
    color: var(--violet-corruption);
    animation: chromaticDrift2 8s ease-in-out infinite;
}

.layer-pale {
    color: var(--pale-script);
    animation: chromaticDrift3 8s ease-in-out infinite;
}

@keyframes chromaticDrift1 {
    0%, 100% { transform: translate(calc(-50% + 1px), calc(-50% - 1px)); }
    33% { transform: translate(calc(-50% - 1px), calc(-50% + 0.5px)); }
    66% { transform: translate(calc(-50% + 0.5px), calc(-50% + 1px)); }
}

@keyframes chromaticDrift2 {
    0%, 100% { transform: translate(calc(-50% - 1px), calc(-50% + 1px)); }
    33% { transform: translate(calc(-50% + 1px), calc(-50% - 0.5px)); }
    66% { transform: translate(calc(-50% - 0.5px), calc(-50% - 1px)); }
}

@keyframes chromaticDrift3 {
    0%, 100% { transform: translate(-50%, -50%); }
    33% { transform: translate(calc(-50% + 0.3px), calc(-50% + 0.3px)); }
    66% { transform: translate(calc(-50% - 0.3px), calc(-50% - 0.3px)); }
}

.title-content {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-title {
    font-family: "Libre Baskerville", serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(1.4rem, 2.2vw, 2.6rem);
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: var(--pale-script);
    text-shadow: 0 0 12px rgba(126, 184, 218, 0.3);
    margin-bottom: 16px;
}

.heading-text {
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 5rem);
    letter-spacing: -0.03em;
    line-height: 0.9;
    color: var(--pale-script);
}

.narrative-text {
    font-family: "Libre Baskerville", serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.15rem);
    letter-spacing: 0.015em;
    line-height: 1.72;
    color: var(--pale-script);
    margin-bottom: 12px;
}

.narrative-text:last-child { margin-bottom: 0; }

.italic-text { font-style: italic; }

.code-text {
    font-family: "IBM Plex Mono", monospace;
    font-weight: 400;
    font-size: clamp(0.8rem, 0.95vw, 1rem);
    letter-spacing: 0.04em;
    line-height: 1.55;
    color: var(--glacial-code);
}

.code-text.micro {
    font-size: 0.75rem;
    color: var(--muted-console);
}

.muted { color: var(--muted-console); }
.accent-glacial { color: var(--glacial-code); }
.accent-violet { color: var(--violet-corruption); }

/* Cursor Blink */
.cursor-blink {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--glacial-code);
    vertical-align: text-bottom;
    animation: cursorBlink 530ms steps(1) infinite;
}

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

/* Background Characters */
.bg-char {
    position: absolute;
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(8rem, 20vw, 18rem);
    color: rgba(74, 111, 165, 0.06);
    pointer-events: none;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
    z-index: 0;
}

.glitch-char {
    color: rgba(196, 166, 212, 0.08);
}

/* Displaced Characters */
.displaced-char {
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-style: italic;
    font-size: 2rem;
    color: var(--twilight-steel);
    opacity: 0.4;
    display: inline-block;
    transition: transform 0.3s, opacity 0.3s;
}

.displaced-char.large {
    font-size: clamp(3rem, 5vw, 5rem);
    opacity: 0.3;
}

.displaced-chars-grid {
    display: flex;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

.glitch-chars {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* Symbol Stream */
.symbol-stream {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 1.2rem;
    color: var(--twilight-steel);
    opacity: 0.6;
}

.symbol-stream span {
    animation: symbolFloat 4s ease-in-out infinite;
    animation-delay: var(--sym-delay, 0s);
}

@keyframes symbolFloat {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 0.8; }
}

/* Glitch Block */
.glitch-block {
    width: 100%;
    height: 60px;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 3px,
        rgba(196, 166, 212, 0.1) 3px,
        rgba(196, 166, 212, 0.1) 4px
    );
    position: relative;
    overflow: hidden;
}

.glitch-block::after {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(126, 184, 218, 0.1) 50%, transparent 100%);
    animation: glitchSweep 3s linear infinite;
}

@keyframes glitchSweep {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Main Content */
#script-console {
    padding-top: 140px;
}

.chapter {
    min-height: 100vh;
    padding: 20px 12px;
}

/* Dashboard Grids */
.dashboard-grid {
    display: grid;
    gap: 6px;
    max-width: 1400px;
    margin: 0 auto;
}

.grid-chapter-1 {
    grid-template-columns: 1.2fr 1fr 1fr 0.8fr;
    grid-template-rows: auto auto;
}

.grid-chapter-1 .panel:nth-child(1) { grid-column: 1 / 3; }

.grid-chapter-2 {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto auto auto;
}

.grid-chapter-2 .large-panel {
    grid-column: 1;
    grid-row: 1 / 4;
}

.grid-chapter-3 {
    grid-template-columns: 1.5fr 1fr 1fr;
    grid-template-rows: auto auto;
}

.grid-chapter-3 .panel:nth-child(1) { grid-column: 1 / 3; }

.grid-chapter-4 {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 20px;
}

.grid-chapter-5 {
    grid-template-columns: 1fr 1fr 2fr 1fr 1fr;
    gap: 8px;
    align-items: start;
}

/* Stagger Reveal */
.stagger-reveal {
    opacity: 0;
    background: var(--abyss-slate);
    transition: opacity 0.4s ease, background 0.6s ease;
    transition-delay: calc(var(--stagger, 0) * 80ms);
}

.stagger-reveal.revealed {
    opacity: 1;
    background: var(--midnight-glass);
}

/* Glitch Zone (Chapter 3) */
.glitch-zone {
    position: relative;
}

.glitch-zone .dashboard-grid {
    transition: transform 0.3s;
}

.glitch-affected {
    transition: transform 0.1s steps(2), filter 0.3s;
}

.glitch-zone.active .glitch-affected {
    animation: panelGlitch 0.3s steps(3) infinite;
}

@keyframes panelGlitch {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-2px, 1px) rotate(0.3deg); }
    50% { transform: translate(1px, -1px) rotate(-0.2deg); }
    75% { transform: translate(2px, 0px) rotate(0.5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

.glitch-title {
    position: relative;
    display: inline-block;
}

.glitch-text-layer {
    display: block;
}

.glitch-text-layer.layer-1 {
    color: var(--glacial-code);
    position: absolute;
    top: 0; left: 0;
    clip-path: inset(0 0 60% 0);
    animation: glitchLayer1 4s steps(2) infinite;
}

.glitch-text-layer.layer-2 {
    color: var(--violet-corruption);
    position: absolute;
    top: 0; left: 0;
    clip-path: inset(40% 0 20% 0);
    animation: glitchLayer2 4s steps(3) infinite;
}

.glitch-text-layer.layer-3 {
    color: var(--pale-script);
}

@keyframes glitchLayer1 {
    0%, 80%, 100% { transform: translate(0, 0); }
    85% { transform: translate(-4px, 2px); }
    90% { transform: translate(6px, -1px); }
}

@keyframes glitchLayer2 {
    0%, 70%, 100% { transform: translate(0, 0); }
    75% { transform: translate(3px, -2px); }
    80% { transform: translate(-5px, 1px); }
}

/* Scramble Text */
.scramble-text {
    font-family: "IBM Plex Mono", monospace;
    font-size: clamp(1.5rem, 3vw, 3rem);
    letter-spacing: 0.2em;
    color: var(--violet-corruption);
    text-align: center;
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
}

.scramble-text span {
    display: inline-block;
    transition: transform 0.2s, opacity 0.2s;
}

/* Output Section (Chapter 4) */
.output-result {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.output-result.visible {
    opacity: 1;
    transform: translateY(0);
}

.output-typography-1 {
    padding: 24px;
}

.output-typography-2 { padding: 16px; }

.code-block {
    font-family: "IBM Plex Mono", monospace;
    font-size: clamp(0.8rem, 0.95vw, 1rem);
    letter-spacing: 0.04em;
    line-height: 1.55;
    color: var(--glacial-code);
    white-space: pre;
    overflow-x: auto;
}

.output-typography-3 { padding: 16px; }

.concrete-poetry {
    position: relative;
    height: 300px;
    width: 100%;
}

.concrete-word {
    position: absolute;
    left: var(--x);
    top: var(--y);
    font-family: "IBM Plex Mono", monospace;
    font-size: calc(var(--size) * 1rem);
    color: var(--glacial-code);
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
}

.concrete-word:hover {
    opacity: 1;
    transform: scale(1.1);
    color: var(--white-burst);
}

.output-typography-4 { padding: 24px; }

.display-quote {
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(1.8rem, 3vw, 3.5rem);
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--pale-script);
}

/* Coda Zone (Chapter 5) */
.coda-zone .dashboard-grid {
    min-height: 60vh;
    align-items: center;
}

.coda-dim {
    opacity: 0.3;
    transition: opacity 2s ease;
}

.coda-dim .panel-content {
    opacity: 0.5;
}

.coda-center {
    background: var(--midnight-glass);
    border-color: var(--glacial-code);
}

.final-sentence {
    font-family: "Libre Baskerville", serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 1.4vw, 1.4rem);
    line-height: 1.72;
    color: var(--pale-script);
    text-align: center;
    padding: 20px;
}

.final-cursor {
    display: block;
    margin: 12px auto 0;
}

.fading-text {
    opacity: 0.4;
}

/* Connection Lines SVG */
.connection-svg {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 4;
}

.connection-svg line {
    stroke: var(--twilight-steel);
    stroke-width: 0.5;
    opacity: 0.2;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawLine 3s ease-out forwards;
}

@keyframes drawLine {
    to { stroke-dashoffset: 0; }
}

/* Typewriter effect */
.typewriter-cursor::after {
    content: "|";
    animation: cursorBlink 530ms steps(1) infinite;
}

/* Panel Overlap Effects */
.satellite-panel {
    position: relative;
    z-index: 1;
}

.large-panel {
    z-index: 2;
}

/* Magnetic Text */
.magnetic-text-container {
    position: relative;
}

.magnetic-text {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

.magnetic-text.assembled {
    opacity: 1;
    transform: translateY(0);
}

/* Error Log Panel */
.error-log-panel .panel-content {
    border-left: 2px solid var(--violet-corruption);
    margin-left: 4px;
    padding-left: 12px;
}

/* Panel hover effects */
.panel:hover {
    background: var(--console-depth);
    z-index: 10;
}

/* Nav highlight */
#panel-nav .code-text {
    cursor: default;
    transition: color 0.3s;
}

/* Responsive */
@media (max-width: 900px) {
    .instrument-row {
        grid-template-columns: 1fr 1fr;
    }
    .instrument-row:last-child {
        grid-template-columns: 1fr 1fr;
    }
    .grid-chapter-1 {
        grid-template-columns: 1fr 1fr;
    }
    .grid-chapter-2 {
        grid-template-columns: 1fr;
    }
    .grid-chapter-2 .large-panel {
        grid-column: 1;
        grid-row: auto;
    }
    .grid-chapter-3 {
        grid-template-columns: 1fr;
    }
    .grid-chapter-3 .panel:nth-child(1) {
        grid-column: 1;
    }
    .grid-chapter-4 {
        grid-template-columns: 1fr;
    }
    .grid-chapter-5 {
        grid-template-columns: 1fr 1fr;
    }
    .grid-chapter-5 .coda-center {
        grid-column: 1 / -1;
    }
}

@media (max-width: 600px) {
    .instrument-row,
    .instrument-row:last-child {
        grid-template-columns: 1fr;
    }
    #instrument-panel {
        max-height: 40vh;
        overflow-y: auto;
    }
    .grid-chapter-1,
    .grid-chapter-5 {
        grid-template-columns: 1fr;
    }
    .grid-chapter-1 .panel:nth-child(1) {
        grid-column: 1;
    }
}
