/* Interactive narrative — show, don't tell */

.page-home {
    --realm-cs: #2c4a6e;
    --realm-words: #5a4a3a;
    --realm-world: #3d5240;
    --realm-path: #1a1a1a;
}

.page-home #main-content {
    position: relative;
    z-index: 2;
}

#story-bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.55;
}

#story-fragments {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.story-fragment {
    position: absolute;
    font-size: 0.72rem;
    opacity: 0;
    white-space: nowrap;
    will-change: transform, opacity;
    transition: opacity 0.4s ease;
    color: rgba(26, 26, 26, 0.35);
    user-select: none;
}

.story-fragment.mono { font-family: var(--font-mono); }
.story-fragment.serif { font-family: var(--font-serif); font-style: italic; }

.story-fragment.visible {
    opacity: var(--peak, 0.22);
}

/* Signal tuner hero */
.story-tuner-wrap {
    position: relative;
    max-width: 580px;
    margin: 0 auto 1.25rem;
}

.tuner-chassis {
    border: 1px solid rgba(26, 26, 26, 0.12);
    border-radius: 8px;
    padding: 0.75rem 0.85rem 0.85rem;
    background: linear-gradient(180deg, rgba(26,26,26,0.03) 0%, transparent 100%);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.4),
        0 4px 24px rgba(26,26,26,0.06);
}

.tuner-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    opacity: 0.55;
}

.tuner-label {
    flex-shrink: 0;
}

.tuner-signal-meter {
    flex: 1;
    height: 4px;
    background: rgba(26, 26, 26, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.tuner-signal-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--realm-words), var(--realm-cs));
    border-radius: 2px;
    transition: width 0.12s ease-out;
    box-shadow: 0 0 8px rgba(44, 74, 110, 0.3);
}

body.story-tuner-locked .tuner-signal-fill {
    background: var(--tuner-lock-color, #2c4a6e);
    box-shadow: 0 0 10px color-mix(in srgb, var(--tuner-lock-color, #2c4a6e) 50%, transparent);
}

.tuner-freq {
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    min-width: 3.5em;
    text-align: right;
    transition: color 0.2s;
}

body.story-tuner-locked .tuner-freq {
    color: var(--tuner-lock-color, #2c4a6e);
    opacity: 1;
}

.tuner-unit {
    opacity: 0.6;
    flex-shrink: 0;
}

.tuner-screen {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(26, 26, 26, 0.1);
    background: #eeede8;
}

#tuner-canvas {
    width: 100%;
    height: 220px;
    display: block;
    cursor: ew-resize;
    touch-action: none;
}

.tuner-scanline {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(26, 26, 26, 0.02) 2px,
        rgba(26, 26, 26, 0.02) 4px
    );
    animation: scanDrift 8s linear infinite;
}

@keyframes scanDrift {
    from { transform: translateY(0); }
    to { transform: translateY(4px); }
}

.tuner-lock-ring {
    position: absolute;
    inset: 8px;
    border: 1px solid transparent;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, border-color 0.3s;
}

body.story-tuner-locked .tuner-lock-ring {
    opacity: 0.35;
    border-color: var(--tuner-lock-color, #2c4a6e);
    box-shadow: inset 0 0 30px color-mix(in srgb, var(--tuner-lock-color, #2c4a6e) 8%, transparent);
}

.story-tuner-readout {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    margin: 0.85rem 0 1.1rem;
    min-height: 1.2em;
    opacity: 0.55;
    transition: opacity 0.3s, color 0.3s, letter-spacing 0.3s;
}

.story-tuner-readout.locked {
    opacity: 1;
    letter-spacing: 0.22em;
    animation: readoutPulse 2s ease-in-out infinite;
}

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

.story-tuner-control {
    position: relative;
    height: 44px;
    margin: 0 12px;
    cursor: ew-resize;
    touch-action: none;
    outline: none;
}

.story-tuner-control:focus-visible .tuner-knob {
    box-shadow: 0 0 0 2px rgba(44, 74, 110, 0.35);
}

.tuner-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    transform: translateY(-50%);
    background: linear-gradient(
        90deg,
        var(--realm-cs) 0%,
        var(--realm-words) 33%,
        var(--realm-world) 66%,
        var(--realm-path) 100%
    );
    opacity: 0.2;
    border-radius: 2px;
}

.tuner-stations {
    position: absolute;
    inset: 0;
}

.tuner-station {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(26, 26, 26, 0.15);
    background: var(--color-paper, #f5f4ef);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    line-height: 1;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    opacity: 0.45;
    transition: opacity 0.25s ease, border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
    color: inherit;
    padding: 0;
    z-index: 2;
}

.tuner-station:hover {
    opacity: 0.85;
}

.tuner-station.near {
    opacity: 0.75;
    border-color: var(--station-color);
}

.tuner-station.active {
    opacity: 1;
    border-color: var(--station-color);
    background: color-mix(in srgb, var(--station-color) 12%, var(--color-paper, #f5f4ef));
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--station-color) 40%, transparent),
        0 0 10px color-mix(in srgb, var(--station-color) 18%, transparent);
}

.tuner-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    transform: translate(-50%, -50%);
    background: #1a1a1a;
    border-radius: 50%;
    z-index: 3;
    pointer-events: none;
    transition: background 0.3s, box-shadow 0.3s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(26, 26, 26, 0.25);
}

.story-tuner-control:active .tuner-knob {
    transform: translate(-50%, -50%) scale(1.15);
}

body.story-tuner-locked .tuner-knob {
    background: var(--tuner-lock-color, #2c4a6e);
    box-shadow: 0 0 12px color-mix(in srgb, var(--tuner-lock-color, #2c4a6e) 40%, transparent);
}

.story-realm-section {
    max-width: 640px;
    margin: 0 auto 1.5rem;
    position: relative;
    z-index: 3;
}

.story-realm-tabs {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 0.45rem;
    margin: 0 0 0.65rem;
    flex-wrap: wrap;
    position: relative;
    z-index: 4;
}

.story-realm-tab {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    box-sizing: border-box;
    height: 2rem;
    min-width: 5.75rem;
    padding: 0 0.75rem;
    border: 1px solid rgba(26, 26, 26, 0.12);
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    line-height: 1;
    letter-spacing: 0.04em;
    border-radius: 999px;
    cursor: pointer;
    pointer-events: auto;
    opacity: 0.35;
    transition: opacity 0.25s ease, border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
    color: inherit;
    white-space: nowrap;
}

.story-realm-tab:hover {
    opacity: 0.85;
}

.story-realm-tab.active {
    opacity: 1;
    border-color: var(--tab-color, rgba(26,26,26,0.45));
    background: color-mix(in srgb, var(--tab-color, #1a1a1a) 8%, transparent);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--tab-color, #1a1a1a) 35%, transparent),
        0 2px 10px color-mix(in srgb, var(--tab-color, #1a1a1a) 10%, transparent);
}

/* Scrambling name */
.story-name-wrap {
    text-align: center;
    margin-bottom: 1rem;
    position: relative;
}

.story-name {
    font-size: clamp(1.6rem, 5vw, 2.25rem);
    font-weight: 700;
    min-height: 2.8rem;
    letter-spacing: 0.02em;
    transition: font-family 0.25s ease, opacity 0.25s ease, letter-spacing 0.3s ease;
    position: relative;
    display: inline-block;
}

.story-name.scrambling {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    letter-spacing: 0.08em;
}

.story-name.glitch {
    animation: nameGlitch 0.35s steps(2) 2;
}

@keyframes nameGlitch {
    0% { transform: translate(0); text-shadow: none; }
    25% { transform: translate(-2px, 1px); text-shadow: 2px 0 rgba(44,74,110,0.4); }
    50% { transform: translate(2px, -1px); text-shadow: -2px 0 rgba(90,74,58,0.4); }
    75% { transform: translate(-1px, -1px); text-shadow: 1px 1px rgba(61,82,64,0.3); }
    100% { transform: translate(0); text-shadow: none; }
}

/* Content panels — only the active panel affects layout height */
#story-panels {
    position: relative;
    margin: 0;
}

.story-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    transform: translateY(4px);
    transition:
        opacity 0.3s ease,
        transform 0.3s ease,
        visibility 0.3s ease;
    pointer-events: none;
    filter: blur(2px);
    margin: 0;
}

.story-panel.active {
    position: relative;
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    filter: none;
}

/* Consistent list rhythm inside panels */
.content .story-panel ul {
    margin: 0 0 0.85rem;
    padding-left: 1.2rem;
    list-style: disc;
    list-style-position: outside;
    font-size: inherit;
    line-height: 1.55;
}

.content .story-panel p {
    margin: 0 0 0.6rem;
    line-height: 1.55;
    font-size: inherit;
}

.content .story-panel p + ul {
    margin-top: 0.15rem;
}

.content .story-panel ul li {
    margin: 0 0 0.45rem;
    padding: 0;
    line-height: 1.55;
    animation: none !important;
}

.content .story-panel .interactive-item {
    padding: 0;
    margin-left: 0;
    margin-bottom: 0.45rem;
    border-radius: 0;
}

.content .story-panel .interactive-item:hover {
    background: none;
    box-shadow: none;
    transform: none;
}

.content .story-panel ul li:last-child {
    margin-bottom: 0;
}

.content .story-panel a {
    border-bottom-width: 1px;
    line-height: inherit;
    vertical-align: baseline;
}

.content .story-panel .obfuscated-link span {
    line-height: inherit;
    vertical-align: baseline;
}

.story-panel.active li {
    animation: panelItemIn 0.35s ease backwards !important;
    animation-delay: calc(var(--li-index, 0) * 0.03s + 0.08s) !important;
}

@keyframes panelItemIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.story-panel-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    line-height: 1;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    opacity: 0.45;
    margin: 0 0 0.85rem;
    min-height: 0.65rem;
}

.story-panel[data-realm="cs"] .story-panel-label { color: var(--realm-cs); }
.story-panel[data-realm="words"] .story-panel-label { color: var(--realm-words); }
.story-panel[data-realm="world"] .story-panel-label { color: var(--realm-world); }
.story-panel[data-realm="path"] .story-panel-label { color: var(--realm-path); }

body.story-has-focus .story-fragment:not(.realm-match) { opacity: 0.06 !important; }

body.story-unlocking #main-content {
    animation: unlockReveal 1.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes unlockReveal {
    0% { opacity: 0; filter: blur(12px) brightness(1.4); transform: scale(1.02); }
    60% { filter: blur(2px) brightness(1.05); }
    100% { opacity: 1; filter: blur(0) brightness(1); transform: scale(1); }
}

body.story-unlocking::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(245,244,239,0) 0%, rgba(245,244,239,0.9) 70%);
    pointer-events: none;
    z-index: 9999;
    animation: unlockFlash 1s ease-out forwards;
}

@keyframes unlockFlash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

.maze-title {
    font-size: 1rem;
    letter-spacing: 0.35em;
    opacity: 0.45;
    animation: mazePulse 3s ease-in-out infinite;
}

@keyframes mazePulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.55; }
}

.maze-instructions {
    opacity: 0.22;
    font-family: var(--font-mono);
    letter-spacing: 0.3em;
}

#maze-container {
    width: min(380px, 100%);
    margin: 0 auto;
}

#lock-screen {
    padding: 1rem;
    box-sizing: border-box;
}

@media (max-width: 600px) {
    #story-bg-canvas,
    #story-fragments {
        display: none;
    }

    .story-tuner-wrap {
        margin-bottom: 1rem;
    }

    .tuner-chassis {
        padding: 0.55rem 0.6rem 0.65rem;
        border-radius: 6px;
    }

    .tuner-header {
        gap: 0.45rem;
        font-size: 0.58rem;
    }

    #tuner-canvas {
        height: 150px;
    }

    .story-tuner-readout {
        font-size: 0.62rem;
        letter-spacing: 0.1em;
        margin: 0.6rem 0 0.75rem;
    }

    .story-tuner-control {
        margin: 0;
        height: 48px;
    }

    .tuner-station {
        width: 2.35rem;
        height: 2.35rem;
        font-size: 0.62rem;
    }

    .tuner-knob {
        width: 18px;
        height: 18px;
    }

    .story-realm-tabs {
        gap: 0.35rem;
    }

    .story-realm-tab {
        flex: 1 1 calc(50% - 0.2rem);
        min-width: 0;
        height: 2.25rem;
        padding: 0 0.45rem;
        font-size: 0.6rem;
        letter-spacing: 0.02em;
    }

    .story-name-wrap {
        margin-bottom: 0.75rem;
    }

    .story-name {
        min-height: 2.2rem;
    }

    .story-realm-section {
        margin-bottom: 1rem;
    }

    .content .story-panel ul {
        padding-left: 1rem;
    }

    .story-panel-label {
        letter-spacing: 0.1em;
        margin-bottom: 0.65rem;
    }

    .maze-title {
        letter-spacing: 0.2em;
        font-size: 0.9rem;
    }

    .maze-instructions {
        letter-spacing: 0.15em;
        font-size: 0.85rem;
    }

    .auto-solve-btn {
        font-size: 0.62rem;
        padding: 0.45rem 0.75rem;
        text-align: center;
        max-width: 100%;
    }

    #maze-container {
        width: min(340px, calc(100vw - 2rem));
    }
}

@media (prefers-reduced-motion: reduce) {
    .story-fragment { display: none; }
    #story-bg-canvas { display: none; }
    #story-panels { min-height: 0 !important; }
    .story-panel {
        position: relative;
        visibility: visible;
        opacity: 1;
        transform: none;
        filter: none;
        pointer-events: auto;
    }
    body.story-unlocking #main-content,
    body.story-unlocking::after { animation: none; }
}
