/* --- TERMINAL OVERLAY CONTAINER --- */
#secret-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--terminal-bg); z-index: 9999;
    display: none; flex-direction: row;
    font-family: 'Space Mono', monospace; overflow: hidden;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
#secret-overlay.active { display: flex; }
#secret-overlay::before { content: " "; display: block; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06)); z-index: 10; background-size: 100% 2px, 3px 100%; pointer-events: none; }

/* --- TERMINAL SIDEBAR --- */
.terminal-sidebar { width: 280px; height: 100%; background-color: var(--terminal-sidebar); border-right: 1px solid var(--terminal-border); padding: 40px 20px 0 20px; display: flex; flex-direction: column; z-index: 11; flex-shrink: 0; }
.sidebar-header { color: #fff; font-weight: bold; border-bottom: 2px solid var(--terminal-border); padding-bottom: 10px; margin-bottom: 15px; letter-spacing: 2px; font-size: 1.1em; }
.cycles-wrapper { display: flex; flex-direction: column; gap: 12px; flex-grow: 1; overflow-y: auto; -ms-overflow-style: none; scrollbar-width: none; }
.cycles-wrapper::-webkit-scrollbar { display: none; }

/* --- CYCLE BUTTONS --- */
.cycle-btn { background: none; padding: 12px 15px; cursor: pointer; font-family: 'Space Mono', monospace; font-size: 0.85em; transition: background-color 0.2s ease, opacity 0.2s ease; opacity: 0.3; border: 1px solid transparent; border-left: 3px solid transparent; width: 100%; box-sizing: border-box; display: none; align-items: center; justify-content: space-between; min-height: 46px; white-space: nowrap !important; overflow: hidden; text-overflow: ellipsis; }
.cycle-btn.visible { display: flex; pointer-events: auto; }
@media (hover: hover) { .cycle-btn:hover { opacity: 0.8; background-color: rgba(255,255,255,0.02); } }

/* Themes */
.cycle-btn.theme-crash { color: var(--terminal-error); border-color: rgba(255, 51, 51, 0.2); }
.cycle-btn.theme-crash.active { opacity: 1; background-color: rgba(255, 51, 51, 0.1); border-color: var(--terminal-error); border-left-color: var(--terminal-error); }
.cycle-btn.theme-echo { color: var(--terminal-white); border-color: rgba(255, 255, 255, 0.2); }
.cycle-btn.theme-echo.active { opacity: 1; background-color: rgba(255, 255, 255, 0.1); border-color: var(--terminal-white); border-left-color: var(--terminal-white); }
.cycle-btn.theme-wake { color: var(--terminal-gold); border-color: rgba(255, 215, 0, 0.2); }
.cycle-btn.theme-wake.active { opacity: 1; background-color: rgba(255, 215, 0, 0.1); border-color: var(--terminal-gold); border-left-color: var(--terminal-gold); }
.cycle-btn.theme-bloom { color: var(--terminal-magenta); border-color: rgba(255, 0, 255, 0.2); }
.cycle-btn.theme-bloom.active { opacity: 1; background-color: rgba(255, 0, 255, 0.1); border-color: var(--terminal-magenta); border-left-color: var(--terminal-magenta); }
.cycle-btn.theme-gardener { color: var(--terminal-cyan); border-color: rgba(0, 255, 255, 0.2); }
.cycle-btn.theme-gardener.active { opacity: 1; background-color: rgba(0, 255, 255, 0.1); border-color: var(--terminal-cyan); border-left-color: var(--terminal-cyan); }

.replay-icon { color: var(--terminal-gold); font-weight: bold; font-size: 1.4em; cursor: pointer; opacity: 0.7; margin-left: 10px; display: inline-block; pointer-events: auto; transition: transform 0.2s ease, opacity 0.2s ease; }
@media (hover: hover) { .replay-icon:hover { opacity: 1; transform: scale(1.2); } }
.spin-once { animation: spinReplay 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes spinReplay { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }

/* --- TERMINAL CONTROLS --- */
.controls-wrapper { display: flex; flex-direction: column; margin-top: auto; width: 100%; gap: 10px; padding-top: 20px; padding-bottom: 0; border-top: 1px solid var(--terminal-border); }
.control-row-split { display: flex; gap: 10px; width: 100%; }

#btn-turbo, #btn-mute { flex: 1; background: transparent; border: 1px solid rgba(0, 255, 255, 0.3); color: rgba(0, 255, 255, 0.5); font-family: 'Space Mono', monospace; font-size: 0.75em; height: 44px; cursor: pointer; display: none; justify-content: center; align-items: center; text-align: center; transition: all 0.2s ease; white-space: nowrap !important; }
#btn-turbo { white-space: pre-wrap !important; line-height: 1.1; }
#btn-mute { white-space: nowrap !important; }

#btn-reset { width: 100%; background: transparent; border: 1px solid rgba(255, 51, 51, 0.2); color: rgba(255, 51, 51, 0.5); height: 60px; font-family: 'Space Mono', monospace; font-size: 0.75em; font-weight: bold; cursor: pointer; display: none; justify-content: center; align-items: center; transition: all 0.2s ease; white-space: nowrap; }
#btn-turbo.visible, #btn-mute.visible, #btn-reset.visible { display: flex; }

#btn-turbo.active, #btn-mute.active { background-color: rgba(0, 255, 255, 0.1); border: 1px solid var(--terminal-cyan); color: #ffffff; box-shadow: 0 0 10px rgba(0, 255, 255, 0.2); opacity: 1; }

@media (hover: hover) { 
    #btn-turbo:hover, #btn-mute:hover { color: #fff; border-color: var(--terminal-cyan); } 
    #btn-reset:hover { color: var(--terminal-error); border-color: var(--terminal-error); background-color: rgba(255, 51, 51, 0.05); } 
}
#btn-reset:active, #btn-reset.active-state { background-color: rgba(255, 51, 51, 0.1) !important; color: var(--terminal-error) !important; border-color: var(--terminal-error) !important; transform: scale(0.98); }

/* --- TERMINAL VIEWPORT --- */
.terminal-wrapper { flex-grow: 1; height: 100%; position: relative; display: flex; flex-direction: column; width: 100%; overflow: hidden; }
.terminal-container { width: 100%; height: 100%; overflow-y: auto; overflow-x: hidden; color: var(--terminal-text); text-shadow: 0 0 5px var(--terminal-dim); font-size: 15px; line-height: 1.6; white-space: pre-wrap; z-index: 3; padding: 40px 20px 80px 20px; scrollbar-width: thin; scrollbar-color: var(--terminal-dim) #000; }
.terminal-container::-webkit-scrollbar { width: 10px; } 
.terminal-container::-webkit-scrollbar-track { background: #000; border-left: 1px solid #333; } 
.terminal-container::-webkit-scrollbar-thumb { background: var(--terminal-dim); border: 1px solid var(--terminal-text); border-radius: 0; }

.log-section { display: none !important; width: 100%; }
.log-section.active-log { display: block !important; }

.terminal-line { margin-bottom: 8px; opacity: 1; border-left: 3px solid var(--terminal-dim); padding-left: 15px; }
.divider-line { white-space: nowrap; overflow: hidden; text-overflow: clip; width: 100%; display: block; }
.terminal-line.active { border-left-color: var(--terminal-text); }
.terminal-line.gold-line { border-left-color: var(--terminal-gold); }
.terminal-line.white-line { border-left-color: var(--terminal-white); }
.terminal-line.magenta-line { border-left-color: var(--terminal-magenta); }
.terminal-line.blue-line { border-left-color: var(--terminal-cyan); }

.reix-header { color: #ffffff; font-weight: bold; border-bottom: 1px solid #333; margin: 25px 0 10px 0; padding-bottom: 5px; display: inline-block; width: 100%; }
.operator-text { color: var(--operator-color); font-style: italic; } 
.system-text { color: var(--terminal-text); } 
.alert-text { color: var(--terminal-alert); font-weight: bold; } 
.comment-text { color: #555; }
.golden-text { color: var(--terminal-gold); text-shadow: 0 0 10px var(--terminal-gold); font-weight: bold; }
.white-text { color: var(--terminal-white); text-shadow: 0 0 10px var(--terminal-white); font-weight: bold; }
.magenta-text { color: var(--terminal-magenta); text-shadow: 0 0 10px var(--terminal-magenta); font-weight: bold; }
.system-success { color: var(--terminal-cyan); }
.error-char { color: var(--terminal-error); display: inline-block; font-weight: bold; animation: glitch-shake 0.08s infinite; text-shadow: 1px 0 #000; }

/* FIX: Chrysalis Button Styling */
.secret-link { 
    display: inline-block; 
    margin-top: 20px; 
    margin-bottom: 10px; 
    /* Default: Gold Text, Black Background */
    color: var(--terminal-gold) !important; 
    background-color: transparent !important; 
    padding: 12px 20px; 
    text-decoration: none; 
    font-weight: bold; 
    border: 1px solid var(--terminal-gold); 
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2); 
    transition: all 0.2s ease; 
    font-family: 'Space Mono', monospace; 
    cursor: pointer; 
    pointer-events: auto; 
    opacity: 1 !important;
    text-align: center;
}

/* HOVER / ACTIVE: Invert to Black Text, Gold Background (The Dark Flash) */
@media (hover: hover) { 
    .secret-link:hover { 
        background-color: var(--terminal-gold) !important; 
        color: var(--terminal-bg) !important; 
        box-shadow: 0 0 25px rgba(255, 215, 0, 0.8); 
    } 
}

.secret-link:active, .secret-link.active-state { 
    background-color: var(--terminal-gold) !important; 
    color: var(--terminal-bg) !important; 
    box-shadow: 0 0 40px rgba(255, 215, 0, 1);
    transform: scale(0.98); 
    transition: none !important; /* Instant feedback */
}

/* CLOSE BUTTON */
.close-terminal { position: absolute; top: 20px; right: 30px; color: #444; border: 1px solid #444; background: #000; padding: 5px 10px; cursor: pointer; font-family: 'Space Mono', monospace; z-index: 20; font-size: 12px; transition: background-color 0.2s, color 0.2s; touch-action: manipulation; }
@media (hover: hover) { .close-terminal:hover { color: var(--terminal-text); border-color: var(--terminal-text); } }
.close-terminal:active, .close-terminal.active-state { color: var(--terminal-bg) !important; background-color: var(--terminal-text) !important; border-color: var(--terminal-text) !important; transition: none !important; }

/* RESPONSIVE */
@media (max-width: 700px) and (orientation: portrait) { 
    #secret-overlay { flex-direction: column; }
    .terminal-sidebar { width: 100%; height: auto; padding: 10px; border-right: none; border-bottom: 1px solid var(--terminal-border); display: block; }
    .cycles-wrapper { display: flex; flex-direction: row; overflow-x: auto; gap: 10px; padding-bottom: 5px; }
    .sidebar-header { display: none; }
    .cycle-btn { white-space: nowrap; flex-shrink: 0; padding: 10px 15px; width: auto; min-height: 44px; }
    .replay-icon { margin-left: 15px; font-size: 1.5em; }
    .controls-wrapper { position: fixed; bottom: 0; left: 0; width: 100%; background-color: var(--terminal-sidebar); border-top: 1px solid var(--terminal-border); padding: 8px 10px 0 10px !important; margin-top: 0; z-index: 50; box-shadow: 0 -10px 30px rgba(0,0,0,0.5); display: flex; flex-direction: column; gap: 8px !important; }
    #btn-turbo, #btn-mute, #btn-reset { display: none; }
    #btn-turbo.visible, #btn-mute.visible, #btn-reset.visible { display: flex; }
    #btn-reset { height: 44px !important; font-size: 0.7em !important; }
    .control-row-split { gap: 8px !important; }
    .terminal-container { padding-bottom: 140px; }
}
@media (max-height: 500px) and (orientation: landscape) {
    #secret-overlay { flex-direction: row; }
    .terminal-sidebar { width: 220px; height: 100%; padding: 10px; border-right: 1px solid var(--terminal-border); border-bottom: none; }
    .cycles-wrapper { display: flex; flex-direction: column; overflow-y: auto; }
    .sidebar-header { display: none; }
    .controls-wrapper { margin-top: 10px; }
    .terminal-container { padding-bottom: 20px; }
}