/**
 * Shared Styles for "The Void is Crimson"
 * Common CSS across all acts
 *
 * Act-specific customizations should be defined in:
 * - act1-custom.css (Red theme)
 * - act2-custom.css (Red→Blue transition)
 * - act3-custom.css (Blue theme)
 */

/* ===== CSS CUSTOM PROPERTIES (VARIABLES) ===== */
/* These will be overridden in act-specific files */
:root {
    /* Colors - Override per act */
    --primary-color: #8b0000;
    --primary-light: #ff4444;
    --primary-glow: rgba(255, 0, 0, 0.5);
    --secondary-color: #4d0000;
    --accent-color: #ff9999;

    /* Spacing */
    --container-max-width: 800px;
    --container-padding: 60px 20px;
    --section-gap: 40px;
    --paragraph-gap: 18px;

    /* Typography */
    --font-body: Calibri, sans-serif;
    --font-title: 'Cormorant Garamond', serif;
    --font-code: 'Courier New', Courier, monospace;

    --font-size-body: 14pt;
    --font-size-title: 28pt;
    --font-size-subtitle: 16pt;
    --font-size-section: 20pt;
    --font-size-end: 18pt;

    --line-height-body: 1.6;

    /* Effects */
    --progress-bar-height: 3px;
    --drop-cap-size: 3.5em;

    /* Animations */
    --transition-standard: 0.3s ease;
    --fade-duration: 1s;
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    color: #e8e8e8;
    background: linear-gradient(180deg, #0a0a0a 0%, #1a0a0a 50%, #0a0a0a 100%);
    position: relative;
    overflow-x: hidden;
}

::selection {
    background: var(--primary-color);
    color: white;
}

/* ===== THREE.JS CANVAS ===== */
#three-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0;
    transition: opacity 1.5s ease;
    pointer-events: none;
}

#three-background.active {
    opacity: 1;
}

/* ===== STARFIELD BACKGROUND (Disabled to remove stray pixel dots) ===== */
/* body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(2px 2px at 20% 30%, white, transparent),
        radial-gradient(2px 2px at 60% 70%, white, transparent),
        radial-gradient(1px 1px at 50% 50%, white, transparent),
        radial-gradient(1px 1px at 80% 10%, white, transparent),
        radial-gradient(2px 2px at 90% 60%, white, transparent),
        radial-gradient(1px 1px at 33% 80%, white, transparent),
        radial-gradient(1px 1px at 15% 60%, white, transparent);
    background-size: 200% 200%;
    background-position: 0% 0%;
    opacity: 0.3;
    animation: stars 200s linear infinite;
    pointer-events: none;
    z-index: 0;
} */

@keyframes stars {
    from { background-position: 0% 0%; }
    to { background-position: 100% 100%; }
}

/* ===== READING PROGRESS BAR ===== */
#progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: var(--progress-bar-height);
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-light));
    box-shadow: 0 0 10px var(--primary-light);
    z-index: 1000;
    transition: width 0.1s;
}

/* ===== CONTAINER ===== */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: var(--container-padding);
    position: relative;
    z-index: 1;
}

article {
    /* Glassmorphism moved here so it only affects story content */
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 40px;
    border-radius: 8px;
    border-left: 1px solid rgba(139, 0, 0, 0.1);
    border-right: 1px solid rgba(139, 0, 0, 0.1);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

/* ===== TYPOGRAPHY ===== */

/* Main Title */
h1 {
    font-size: clamp(24pt, 7vw, var(--font-size-title));
    text-align: center;
    margin-bottom: 15px;
    color: #ffffff;
    text-shadow: 0 0 20px var(--primary-glow), 0 0 5px #000;
    letter-spacing: 2px;
    animation: fadeIn 2s ease-in both;
}

/* Subtitle */
.subtitle {
    text-align: center;
    font-style: italic;
    margin-bottom: var(--section-gap);
    color: #eee; /* Lightened for contrast */
    text-shadow: 0 0 5px #000;
    font-size: var(--font-size-subtitle);
    animation: fadeIn 2s ease-in 0.5s both;
}

/* Section Headings */
h2 {
    font-size: clamp(18pt, 5vw, var(--font-size-section));
    margin: 50px 0 30px 0;
    color: var(--primary-light);
    text-shadow: 0 0 15px var(--primary-glow), 0 0 5px #000;
    letter-spacing: 3px;
    animation: slideIn var(--fade-duration) ease-out both;
}

/* Paragraphs */
p {
    margin-bottom: var(--paragraph-gap);
    text-align: left;
    color: #f0f0f0; /* Slightly brighter for better contrast */
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8), 1px 1px 2px rgba(0, 0, 0, 1);
    line-height: 1.7; /* Better readability */
    animation: fadeInText var(--fade-duration) ease-out both;
}

/* Drop Cap */
h2 + p::first-letter {
    font-size: var(--drop-cap-size);
    line-height: 0.9;
    float: left;
    margin: 0.1em 0.1em 0 0;
    color: var(--primary-light);
    text-shadow: 0 0 10px var(--primary-glow);
}

/* Emphasis */
em {
    font-style: italic;
    color: var(--accent-color);
    transition: all var(--transition-standard);
    cursor: default;
}

p em:hover {
    color: var(--primary-light);
    text-shadow: 0 0 8px var(--primary-glow);
}

/* Horizontal Rules */
hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
    margin: var(--section-gap) 0;
    box-shadow: 0 0 10px var(--primary-glow);
}

/* End Marker */
.end {
    text-align: center;
    font-weight: bold;
    margin-top: 60px;
    font-size: var(--font-size-end);
    color: var(--primary-color);
    text-shadow: 0 0 15px var(--primary-glow);
    letter-spacing: 4px;
}

/* ===== SPECIAL CONTENT BLOCKS ===== */

/* Journal Entries */
.journal-entry {
    border-left: 2px solid var(--secondary-color);
    padding-left: 20px;
    margin: 30px 0;
    font-family: var(--font-code);
    color: #ccc;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.5);
}

.journal-entry p {
    margin-bottom: 12px;
}

.journal-entry strong {
    color: var(--primary-light);
}

/* Poem Fragments */
.poem-fragment {
    border-left: 2px solid var(--secondary-color);
    padding-left: 20px;
    margin: 30px 0;
    font-family: var(--font-code);
    font-style: italic;
    color: #ccc;
    background: rgba(255, 255, 255, 0.02);
}

/* Memory Echoes (ACT III specific, but structured here) */
.memory-echo {
    border-left: 2px solid #6699cc;
    padding-left: 20px;
    margin: 30px 0;
    font-style: italic;
    color: #aabbdd;
    background: rgba(100, 150, 200, 0.05);
}

/* ===== TRIGGER ZONES (for Three.js scenes) ===== */
.trigger-void,
.trigger-frequency,
.trigger-entities,
.trigger-pattern,
.trigger-weave,
.trigger-akari,
.trigger-nine,
.trigger-kelly,
.trigger-scavenger,
.trigger-grief {
    position: relative;
}

/* ===== ACCESSIBILITY ===== */

/* Skip to content link for keyboard navigation */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    font-weight: bold;
    border-radius: 0 0 4px 0;
}

.skip-to-content:focus {
    top: 0;
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInText {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Pulse animation for titles (used in index.html) */
@keyframes pulse {
    0%, 100% {
        text-shadow: 0 0 10px var(--primary-glow), 0 0 20px var(--primary-glow);
    }
    50% {
        text-shadow: 0 0 15px var(--primary-glow), 0 0 30px var(--primary-glow);
    }
}

/* ===== AUTO-NAVIGATION FADE ===== */
body.fade-out-to-next {
    transition: opacity 1.5s ease-in-out;
    opacity: 0;
}

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

/* Mobile phones (portrait and landscape) */
@media (max-width: 768px) {
    body {
        font-size: 13pt; /* Slightly larger for better mobile readability */
        line-height: 1.7; /* More spacing for easier reading */
    }

    h1 {
        font-size: 24pt;
        letter-spacing: 1px;
        margin-bottom: 10px;
    }

    h2 {
        font-size: 18pt;
        letter-spacing: 2px;
        margin: 40px 0 20px 0;
    }

    .subtitle {
        font-size: 14pt;
        margin-bottom: 30px;
    }

    .container {
        padding: 30px 15px; /* More compact on mobile */
    }

    h2 + p::first-letter {
        font-size: 2.5em; /* Smaller drop cap on mobile */
    }

    /* Better spacing for mobile */
    p {
        margin-bottom: 20px; /* Slightly more spacing */
    }

    /* Make journal entries and poems more readable on mobile */
    .journal-entry,
    .poem-fragment,
    .memory-echo {
        padding-left: 15px;
        margin: 20px 0;
        font-size: 12pt;
    }

    /* Ensure text doesn't overflow on small screens */
    body {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Reduce animation complexity on mobile - only target content animations,
       not horror effects which have their own carefully timed durations */
    h1, h2, p, .subtitle {
        animation-duration: 0.5s !important;
    }
}

/* Extra small phones */
@media (max-width: 480px) {
    body {
        font-size: 12pt;
    }

    h1 {
        font-size: 20pt;
    }

    h2 {
        font-size: 16pt;
    }

    .subtitle {
        font-size: 13pt;
    }

    .container {
        padding: 20px 10px;
    }

    h2 + p::first-letter {
        font-size: 2em;
    }

    .end {
        font-size: 16pt;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        padding: 20px 15px;
    }

    h1 {
        font-size: 22pt;
        margin-bottom: 8px;
    }

    h2 {
        margin: 30px 0 15px 0;
    }
}

/* ===== HORROR EFFECTS ENGINE ===== */

/* Vignette overlay — darkens screen edges for dread */
#horror-vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: radial-gradient(ellipse at center,
        transparent 30%,
        rgba(0, 0, 0, 0.25) 55%,
        rgba(0, 0, 0, 0.65) 75%,
        rgba(0, 0, 0, 0.92) 100%
    );
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Glitch scan-line overlay — visible horizontal distortion bands */
.horror-glitch-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    background:
        repeating-linear-gradient(
            0deg,
            transparent 0px,
            rgba(139, 0, 0, 0.12) 1px,
            transparent 3px,
            rgba(0, 0, 0, 0.15) 4px,
            transparent 6px
        ),
        linear-gradient(
            180deg,
            transparent 0%,
            rgba(139, 0, 0, 0.08) 15%,
            transparent 30%,
            rgba(0, 0, 139, 0.06) 50%,
            transparent 65%,
            rgba(139, 0, 0, 0.10) 85%,
            transparent 100%
        );
    animation: horror-glitch-scan 0.3s linear forwards;
}

@keyframes horror-glitch-scan {
    0%   { transform: translateY(-100%) scaleY(1.03); opacity: 1; }
    50%  { opacity: 0.8; }
    100% { transform: translateY(100%) scaleY(0.97); opacity: 0; }
}

/* Red tint flash — accompanies glitch */
.horror-red-tint {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9997;
    background: radial-gradient(ellipse at center,
        rgba(139, 0, 0, 0.08) 0%,
        rgba(80, 0, 0, 0.15) 60%,
        rgba(40, 0, 0, 0.2) 100%
    );
    animation: horror-red-pulse 0.35s ease-out forwards;
}

@keyframes horror-red-pulse {
    0%   { opacity: 0; }
    30%  { opacity: 1; }
    100% { opacity: 0; }
}

/* Color wash — brief red/blue shift across the whole screen */
.horror-color-wash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9996;
    background: linear-gradient(
        135deg,
        rgba(139, 0, 0, 0.1) 0%,
        transparent 40%,
        rgba(0, 0, 100, 0.08) 100%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Screen flicker — rapid brightness changes */
.horror-flicker {
    filter: brightness(0.7) contrast(1.1) !important;
}

/* Text bleed — dramatic red shadow that pulses on paragraphs.
   Uses animation-name override only to avoid clobbering fadeInText fill-mode
   which would reset opacity to 0 and make text disappear. */
.horror-text-bleed {
    animation-name: horror-bleed !important;
    animation-duration: 4s !important;
    animation-timing-function: ease-in-out !important;
    animation-fill-mode: both !important;
}

@keyframes horror-bleed {
    0%   { text-shadow: none; color: inherit; opacity: 1; }
    20%  { text-shadow: 0 0 10px rgba(139, 0, 0, 0.7), 0 0 25px rgba(139, 0, 0, 0.4), 0 0 50px rgba(80, 0, 0, 0.2); opacity: 1; }
    50%  { text-shadow: 0 0 15px rgba(139, 0, 0, 0.5), 0 0 35px rgba(80, 0, 0, 0.3); color: #ff9999; opacity: 1; }
    80%  { text-shadow: 0 0 8px rgba(139, 0, 0, 0.3); opacity: 1; }
    100% { text-shadow: none; color: inherit; opacity: 1; }
}

/* Whisper text — hidden messages revealed on hover */
.horror-whisper {
    position: relative;
    cursor: default;
}

.horror-whisper::after {
    content: attr(data-whisper);
    position: absolute;
    top: -1.8em;
    left: 0;
    font-size: 0.7em;
    color: rgba(139, 0, 0, 0);
    font-style: italic;
    white-space: nowrap;
    transition: color 0.6s ease, text-shadow 0.6s ease;
    pointer-events: none;
    font-family: 'Cormorant Garamond', serif;
    letter-spacing: 2px;
}

.horror-whisper-visible::after,
.horror-whisper:hover::after {
    color: rgba(200, 50, 50, 0.7);
    text-shadow: 0 0 8px rgba(139, 0, 0, 0.5);
}

/* Cursor trail dots */
.horror-cursor-dot {
    position: fixed;
    width: 4px;
    height: 4px;
    background: rgba(180, 0, 0, 0.8);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9997;
    box-shadow: 0 0 6px rgba(139, 0, 0, 0.6);
    animation: horror-dot-fade 1.5s ease-out forwards;
}

@keyframes horror-dot-fade {
    0%   { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.2); }
}

/* Horror trigger paragraphs — glow on hover */
.horror-trigger {
    transition: text-shadow 0.5s ease;
}

.horror-trigger:hover {
    text-shadow: 0 0 4px rgba(139, 0, 0, 0.25), 0 0 15px rgba(139, 0, 0, 0.1);
}

/* Audio prompt overlay */
#horror-audio-prompt {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: none;
}

.horror-audio-prompt-inner {
    background: rgba(10, 5, 5, 0.95);
    border: 1px solid rgba(139, 0, 0, 0.5);
    border-radius: 6px;
    padding: 16px 22px;
    text-align: center;
    box-shadow: 0 0 30px rgba(139, 0, 0, 0.2), inset 0 0 20px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    cursor: pointer;
    animation: prompt-glow 2s ease-in-out infinite;
}

@keyframes prompt-glow {
    0%, 100% { box-shadow: 0 0 30px rgba(139, 0, 0, 0.2), inset 0 0 20px rgba(0, 0, 0, 0.5); }
    50% { box-shadow: 0 0 40px rgba(139, 0, 0, 0.35), inset 0 0 20px rgba(0, 0, 0, 0.5); }
}

.horror-audio-icon {
    font-size: 24px;
    color: rgba(180, 30, 30, 0.8);
    margin-bottom: 6px;
}

.horror-audio-text {
    font-family: 'Cormorant Garamond', serif;
    color: #ddd;
    font-size: 14px;
    letter-spacing: 1px;
}

.horror-audio-sub {
    font-size: 11px;
    color: #777;
    margin-top: 4px;
}

/* Film grain overlay — subtle texture */
#horror-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9995;
    opacity: 0.4;
    image-rendering: pixelated;
    mix-blend-mode: overlay;
}

/* Chromatic aberration / RGB split overlay */
.horror-chromatic {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9994;
    opacity: 0;
    transition: opacity 0.15s ease;
    background:
        linear-gradient(90deg,
            rgba(255, 0, 0, 0.03) 0%,
            transparent 33%,
            transparent 66%,
            rgba(0, 0, 255, 0.03) 100%
        );
    mix-blend-mode: screen;
}

.horror-chromatic-active {
    opacity: 1;
    animation: horror-chromatic-shift 0.3s ease-out;
}

@keyframes horror-chromatic-shift {
    0%   { transform: translateX(-2px); filter: blur(0px); }
    25%  { transform: translateX(3px); filter: blur(0.5px); }
    50%  { transform: translateX(-1px); filter: blur(0px); }
    75%  { transform: translateX(2px); filter: blur(0.3px); }
    100% { transform: translateX(0); filter: blur(0px); }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* Print Styles */
@media print {
    body::before,
    #three-background,
    #progress-bar {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    h1, h2, em {
        color: black;
        text-shadow: none;
    }
}

/* ===== NEW SUBTLE HORROR EFFECTS ===== */

/* Peripheral shadow — fleeting dark shape in periphery */
#horror-peripheral-shadow {
    position: fixed;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.4) 0%, transparent 70%);
    pointer-events: none;
    z-index: 9993;
    opacity: 0;
    transition: opacity 0.8s ease;
    filter: blur(40px);
}

/* Twitching word — subtle vibration */
.horror-twitch-word {
    display: inline-block;
    animation: horror-word-vibrate 0.15s linear infinite;
    color: var(--primary-light);
    text-shadow: 0 0 5px var(--primary-glow);
}

/* Panic state typography for emotional distress */
.horror-panic {
    letter-spacing: -1px;
    font-style: italic;
    line-height: 1.2;
}

@keyframes horror-word-vibrate {
    0%   { transform: translate(0, 0); }
    25%  { transform: translate(0.5px, -0.5px); }
    50%  { transform: translate(-0.5px, 0.5px); }
    75%  { transform: translate(0.5px, 0.5px); }
    100% { transform: translate(0, 0); }
}

/* Narrative Pause — Forces the reader to scroll through empty space, building tension */
.narrative-pause {
    height: 35vh;
    width: 100%;
    margin: 0;
    padding: 0;
    pointer-events: none;
}

/* Optional breathing animation — can be applied manually to specific blocks */
.horror-breathe {
    animation: horror-breathe-anim 8s ease-in-out infinite;
}

@keyframes horror-breathe-anim {
    0%, 100% { transform: scale(1) translateY(0); }
    50% { transform: scale(1.002) translateY(0.5px); }
}
