/* ============================================================
   CHRONOS TERMINAL — LCARS/CRT Theme
   Sci-fi interface: Star Trek LCARS + retro CRT + animated consoles
   Widgets in main area (top/bottom bars), bigger, slower animations
   ============================================================ */

:root {
    --bg: #000000;
    --panel: #111111;
    --amber: #FF9900;
    --green: #00FF41;
    --blue: #6688CC;
    --red: #FF3333;
    --cyan: #00DDFF;
    --purple: #AA55FF;
    --text: #CCCCCC;
    --text-bright: #FFFFFF;
    --scanline: rgba(0, 255, 65, 0.03);
    --glow-amber: 0 0 10px rgba(255, 153, 0, 0.5);
    --glow-green: 0 0 10px rgba(0, 255, 65, 0.5);
    --glow-blue: 0 0 10px rgba(102, 136, 204, 0.5);
    --font-primary: 'Courier New', 'Lucida Console', monospace;
    --font-display: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    --transition: 0.3s ease;
}

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

/* Ultra-thin elegant scrollbar — invisible by default, appears on hover */
* {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
*:hover {
    scrollbar-color: rgba(255, 153, 0, 0.2) transparent;
}
*::-webkit-scrollbar { width: 3px; height: 3px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
    transition: background 0.3s;
}
*:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 153, 0, 0.15);
}
*:hover::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 65, 0.4);
    box-shadow: 0 0 4px rgba(0, 255, 65, 0.3);
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-primary);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    cursor: default;
    user-select: none;
}

/* CRT Scanlines */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(0deg, transparent, transparent 2px, var(--scanline) 2px, var(--scanline) 4px);
    pointer-events: none;
    z-index: 9999;
}

@keyframes crt-flicker {
    0% { opacity: 0.97; } 5% { opacity: 0.95; } 10% { opacity: 0.98; } 100% { opacity: 0.97; }
}
body { animation: crt-flicker 0.15s infinite alternate; }

/* ===== FULL-WIDTH LAYOUT ===== */
.chronos-app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 16px);
    margin: 8px;
    padding: 8px 24px;
    position: relative;
    border: 1px solid rgba(255, 153, 0, 0.25);
    border-radius: 14px;
}

/* ===== ANIMATED BORDER GLOW (pulsing, on .chronos-app only) ===== */
.chronos-app::before {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border: 1px solid rgba(255, 153, 0, 0.15);
    border-radius: 16px;
    pointer-events: none;
    z-index: 100;
    animation: frame-pulse 4s ease-in-out infinite;
}

@keyframes frame-pulse {
    0%, 100% {
        border-color: rgba(255, 153, 0, 0.3);
        box-shadow:
            0 0 12px rgba(255, 153, 0, 0.25),
            0 0 25px rgba(255, 153, 0, 0.1),
            inset 0 0 12px rgba(255, 153, 0, 0.05);
    }
    25% {
        border-color: rgba(0, 221, 255, 0.3);
        box-shadow:
            0 0 12px rgba(0, 221, 255, 0.25),
            0 0 25px rgba(0, 221, 255, 0.1),
            inset 0 0 12px rgba(0, 221, 255, 0.05);
    }
    50% {
        border-color: rgba(0, 255, 65, 0.3);
        box-shadow:
            0 0 12px rgba(0, 255, 65, 0.25),
            0 0 25px rgba(0, 255, 65, 0.1),
            inset 0 0 12px rgba(0, 255, 65, 0.05);
    }
    75% {
        border-color: rgba(170, 85, 255, 0.3);
        box-shadow:
            0 0 12px rgba(170, 85, 255, 0.25),
            0 0 25px rgba(170, 85, 255, 0.1),
            inset 0 0 12px rgba(170, 85, 255, 0.05);
    }
}

/* ===== HEADER ===== */
.header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 8px 0 5px;
    border-bottom: 2px solid var(--amber);
    flex-shrink: 0;
}

.header-pill {
    background: var(--amber);
    color: var(--bg);
    padding: 8px 20px;
    border-radius: 20px 8px 8px 20px;
    font-weight: bold;
    font-size: 1.1em;
    font-family: var(--font-display);
    white-space: nowrap;
}

.header-title {
    font-family: var(--font-display);
    font-size: 1.4em;
    color: var(--amber);
    text-shadow: var(--glow-amber);
    letter-spacing: 3px;
}

.header-version {
    color: var(--blue);
    font-size: 0.9em;
    margin-left: auto;
    font-family: var(--font-display);
}

/* ===== CONSOLE BARS (TOP & BOTTOM) ===== */
.console-bar {
    display: flex;
    gap: 10px;
    padding: 4px 0;
    flex-shrink: 0;
    align-items: stretch;
}

.console-top {
    border-bottom: 1px solid rgba(255, 153, 0, 0.12);
}

.console-bottom {
    border-top: 1px solid rgba(255, 153, 0, 0.12);
}

.console-widget {
    flex: 1;
    background: rgba(17, 17, 17, 0.8);
    border: 1px solid rgba(255, 153, 0, 0.12);
    border-radius: 10px;
    padding: 5px 12px;
    min-width: 0;
}

.widget-label {
    font-family: var(--font-display);
    font-size: 0.65em;
    color: var(--amber);
    letter-spacing: 1.5px;
    margin-bottom: 4px;
    text-transform: uppercase;
    opacity: 0.8;
    text-align: center;
}

.widget-value {
    font-family: var(--font-display);
    font-size: 0.9em;
    color: var(--cyan);
    margin-top: 3px;
    text-align: center;
}

.widget-unit {
    font-size: 0.7em;
    color: var(--text);
    opacity: 0.6;
}

/* -- ECG Monitor -- */
.ecg-monitor {
    width: 100%;
    height: 45px;
}

.ecg-line {
    fill: none;
    stroke: var(--green);
    stroke-width: 1.5;
    filter: drop-shadow(0 0 4px rgba(0, 255, 65, 0.7));
}

/* -- Flux Bars -- */
.flux-bars {
    display: flex;
    gap: 3px;
    justify-content: center;
    align-items: flex-end;
    height: 40px;
    padding: 2px 0;
}

.flux-bar {
    width: 10px;
    background: var(--amber);
    border-radius: 2px;
    animation: flux-dance 3s ease-in-out infinite;   /* SLOWER: was 1.5s */
    opacity: 0.8;
}

.flux-bar:nth-child(1)  { animation-delay: 0.0s; }
.flux-bar:nth-child(2)  { animation-delay: 0.15s; }
.flux-bar:nth-child(3)  { animation-delay: 0.3s; }
.flux-bar:nth-child(4)  { animation-delay: 0.45s; }
.flux-bar:nth-child(5)  { animation-delay: 0.6s; }
.flux-bar:nth-child(6)  { animation-delay: 0.75s; }
.flux-bar:nth-child(7)  { animation-delay: 0.9s; }
.flux-bar:nth-child(8)  { animation-delay: 1.05s; }
.flux-bar:nth-child(9)  { animation-delay: 1.2s; }
.flux-bar:nth-child(10) { animation-delay: 1.35s; }
.flux-bar:nth-child(11) { animation-delay: 1.5s; }
.flux-bar:nth-child(12) { animation-delay: 1.65s; }
.flux-bar:nth-child(13) { animation-delay: 1.8s; }
.flux-bar:nth-child(14) { animation-delay: 1.95s; }
.flux-bar:nth-child(15) { animation-delay: 2.1s; }
.flux-bar:nth-child(16) { animation-delay: 2.25s; }

@keyframes flux-dance {
    0%, 100% { height: 6px; opacity: 0.4; }
    50% { height: 32px; opacity: 1; }
}

/* -- Sine Wave (Neural Link) -- */
.sine-wave { width: 100%; height: 40px; }
.sine-path {
    fill: none;
    stroke: var(--cyan);
    stroke-width: 1.5;
    filter: drop-shadow(0 0 4px rgba(0, 221, 255, 0.6));
}

/* -- Spectrum Analyzer -- */
.spectrum-bars {
    display: flex;
    gap: 3px;
    justify-content: center;
    align-items: flex-end;
    height: 40px;
    padding: 2px 0;
}

.spec-bar {
    width: 8px;
    background: linear-gradient(to top, var(--green), var(--amber), var(--red));
    border-radius: 1px;
    animation: spec-bounce 1.8s ease-in-out infinite;   /* SLOWER: was 0.8s */
}

.spec-bar:nth-child(1)  { animation-delay: 0.00s; }
.spec-bar:nth-child(2)  { animation-delay: 0.07s; }
.spec-bar:nth-child(3)  { animation-delay: 0.14s; }
.spec-bar:nth-child(4)  { animation-delay: 0.21s; }
.spec-bar:nth-child(5)  { animation-delay: 0.28s; }
.spec-bar:nth-child(6)  { animation-delay: 0.35s; }
.spec-bar:nth-child(7)  { animation-delay: 0.42s; }
.spec-bar:nth-child(8)  { animation-delay: 0.49s; }
.spec-bar:nth-child(9)  { animation-delay: 0.56s; }
.spec-bar:nth-child(10) { animation-delay: 0.63s; }
.spec-bar:nth-child(11) { animation-delay: 0.56s; }
.spec-bar:nth-child(12) { animation-delay: 0.49s; }
.spec-bar:nth-child(13) { animation-delay: 0.42s; }
.spec-bar:nth-child(14) { animation-delay: 0.35s; }
.spec-bar:nth-child(15) { animation-delay: 0.28s; }
.spec-bar:nth-child(16) { animation-delay: 0.21s; }
.spec-bar:nth-child(17) { animation-delay: 0.14s; }
.spec-bar:nth-child(18) { animation-delay: 0.07s; }
.spec-bar:nth-child(19) { animation-delay: 0.00s; }
.spec-bar:nth-child(20) { animation-delay: 0.07s; }
.spec-bar:nth-child(21) { animation-delay: 0.14s; }
.spec-bar:nth-child(22) { animation-delay: 0.21s; }
.spec-bar:nth-child(23) { animation-delay: 0.28s; }
.spec-bar:nth-child(24) { animation-delay: 0.35s; }

@keyframes spec-bounce {
    0%, 100% { height: 4px; }
    50% { height: 34px; }
}

/* -- Gauge -- */
.gauge-container { padding: 2px 10px; }
.gauge { width: 100%; height: auto; max-height: 50px; }
.gauge-bg {
    fill: none;
    stroke: rgba(255, 153, 0, 0.15);
    stroke-width: 8;
    stroke-linecap: round;
}
.gauge-fill {
    fill: none;
    stroke: var(--amber);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 142;
    stroke-dashoffset: 35;
    filter: drop-shadow(0 0 4px rgba(255, 153, 0, 0.5));
    animation: gauge-pulse 6s ease-in-out infinite;   /* SLOWER: was 3s */
}

@keyframes gauge-pulse {
    0%, 100% { stroke-dashoffset: 35; }
    50% { stroke-dashoffset: 15; }
}

/* -- DNA Helix -- */
.dna-helix {
    height: 45px;
    position: relative;
    overflow: hidden;
}

.dna-strand {
    position: absolute;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        var(--purple) 2px,
        transparent 4px,
        transparent 14px
    );
    animation: dna-scroll 4s linear infinite;   /* SLOWER: was 2s */
    opacity: 0.6;
}

.dna-strand-2 {
    animation-direction: reverse;
    opacity: 0.4;
    background: repeating-linear-gradient(
        0deg,
        transparent 7px,
        var(--cyan) 9px,
        transparent 11px,
        transparent 14px
    );
}

@keyframes dna-scroll {
    0% { transform: translateY(0); }
    100% { transform: translateY(-14px); }
}

/* -- Temperature Bar -- */
.temp-bar-container {
    width: 100%;
    height: 12px;
    background: rgba(255, 51, 51, 0.1);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 51, 51, 0.2);
}

.temp-bar-fill {
    height: 100%;
    width: 35%;
    background: linear-gradient(90deg, var(--blue), var(--cyan));
    border-radius: 5px;
    animation: temp-fluctuate 8s ease-in-out infinite;   /* SLOWER: was 4s */
}

@keyframes temp-fluctuate {
    0%, 100% { width: 35%; }
    30% { width: 42%; }
    70% { width: 30%; }
}

/* -- Signal Dots -- */
.signal-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 8px 0;
}

.sig-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(0, 221, 255, 0.15);
    border: 1px solid rgba(0, 221, 255, 0.3);
}

.sig-dot.active {
    background: var(--cyan);
    box-shadow: 0 0 8px var(--cyan);
    animation: sig-blink 4s ease-in-out infinite;   /* SLOWER: was 2s */
}

.sig-dot:nth-child(2) { animation-delay: 0.4s; }
.sig-dot:nth-child(3) { animation-delay: 0.8s; }
.sig-dot:nth-child(4) { animation-delay: 1.2s; }

@keyframes sig-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    margin: 2px 0;
    min-height: 0;
}

.phase {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    overflow-y: auto;
}

.phase.active { opacity: 1; visibility: visible; }

.phase-title {
    font-family: var(--font-display);
    font-size: 1.6em;
    color: var(--amber);
    text-shadow: var(--glow-amber);
    letter-spacing: 4px;
    margin-bottom: 4px;
    text-align: center;
}

.phase-subtitle {
    color: var(--text);
    font-size: 0.95em;
    margin-bottom: 15px;
    text-align: center;
}

/* ===== LCARS PANEL ===== */
.lcars-panel {
    background: var(--panel);
    border: 1px solid var(--amber);
    border-radius: 20px 8px 8px 20px;
    padding: 25px 30px 25px 40px;
    position: relative;
    max-width: 500px;
    width: 100%;
}

.lcars-panel::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 12px;
    background: var(--amber);
    border-radius: 20px 0 0 20px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 30px;
    border: 2px solid var(--amber);
    background: transparent;
    color: var(--amber);
    font-family: var(--font-display);
    font-size: 1em;
    letter-spacing: 2px;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
}

.btn:hover { background: var(--amber); color: var(--bg); box-shadow: var(--glow-amber); }
.btn:active { transform: scale(0.97); }
.btn--green { border-color: var(--green); color: var(--green); }
.btn--green:hover { background: var(--green); color: var(--bg); box-shadow: var(--glow-green); }
.btn--blue { border-color: var(--blue); color: var(--blue); }
.btn--blue:hover { background: var(--blue); color: var(--bg); box-shadow: var(--glow-blue); }
.btn--large { padding: 14px 36px; font-size: 1.1em; }
.btn--disabled { opacity: 0.3; pointer-events: none; }

/* ===== PHASE 1: CAMERA ===== */
.camera-container {
    position: relative;
    width: 480px;
    height: 360px;
    border: 2px solid var(--amber);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.camera-container video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

.camera-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 3px solid var(--green);
    border-radius: 8px;
    pointer-events: none;
    animation: scan-pulse 3s ease-in-out infinite;   /* SLOWER: was 2s */
}

@keyframes scan-pulse {
    0%, 100% { border-color: var(--green); box-shadow: inset 0 0 20px rgba(0, 255, 65, 0.1); }
    50% { border-color: var(--amber); box-shadow: inset 0 0 30px rgba(255, 153, 0, 0.15); }
}

.scanning-line {
    position: absolute; left: 0; right: 0;
    height: 3px;
    background: var(--green);
    box-shadow: 0 0 15px var(--green), 0 0 30px var(--green);
    animation: scan-line 3s linear infinite;   /* SLOWER: was 2s */
    display: none;
}
.scanning .scanning-line { display: block; }

@keyframes scan-line {
    0% { top: 0; } 100% { top: 100%; }
}

/* ===== PHASE 2: IDENTITY FORM ===== */
.identity-form {
    margin-bottom: 15px;
}

.form-row {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-family: var(--font-display);
    font-size: 0.8em;
    color: var(--amber);
    letter-spacing: 2px;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.chronos-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--amber);
    color: var(--amber);
    padding: 12px 15px;
    font-family: var(--font-display);
    font-size: 1em;
    border-radius: 6px;
    letter-spacing: 1px;
}

.chronos-input::placeholder { color: rgba(255, 153, 0, 0.3); }
.chronos-input:focus { outline: none; box-shadow: var(--glow-amber); border-color: var(--green); }

.badge-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    color: var(--cyan);
    font-family: var(--font-display);
    font-size: 0.85em;
    letter-spacing: 1px;
}

.spinner-inline {
    width: 18px; height: 18px;
    border: 2px solid var(--panel);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

.badge-status.complete { color: var(--green); }
.badge-status.complete .spinner-inline { display: none; }

.badge-display {
    max-width: 500px;
    width: 100%;
    border: 2px solid var(--green);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--glow-green);
    margin: 10px 0;
}

.badge-display img { width: 100%; height: auto; display: block; }

/* ===== VIRTUAL KEYBOARD (LCARS touch) ===== */
.virtual-keyboard {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 10px;
    background: rgba(17, 17, 17, 0.9);
    border: 1px solid rgba(255, 153, 0, 0.2);
    border-radius: 10px;
    min-height: 0;
}

.kb-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex: 1;
    min-height: 0;
}

.kb-key {
    flex: 1;
    max-width: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 153, 0, 0.06);
    border: 1px solid rgba(255, 153, 0, 0.2);
    border-radius: 8px;
    color: var(--amber);
    font-family: var(--font-display);
    font-size: 1.4em;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.12s;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.kb-key:hover {
    background: rgba(255, 153, 0, 0.15);
    border-color: var(--amber);
}

.kb-key:active, .kb-key.kb-pressed {
    background: var(--amber);
    color: var(--bg);
    transform: scale(0.93);
    box-shadow: 0 0 12px rgba(255, 153, 0, 0.5);
}

.kb-key--action {
    max-width: 110px;
    border-color: rgba(255, 51, 51, 0.3);
    color: var(--red);
    font-size: 1.5em;
}

.kb-key--action:hover {
    background: rgba(255, 51, 51, 0.15);
    border-color: var(--red);
}

.kb-key--action:active {
    background: var(--red);
    color: var(--bg);
    box-shadow: 0 0 12px rgba(255, 51, 51, 0.5);
}

.kb-key--space {
    flex: 3;
    max-width: none;
    border-color: rgba(102, 136, 204, 0.3);
    color: var(--blue);
    font-size: 1.1em;
    letter-spacing: 4px;
}

.kb-key--space:hover {
    background: rgba(102, 136, 204, 0.15);
    border-color: var(--blue);
}

.kb-key--space:active {
    background: var(--blue);
    color: var(--bg);
    box-shadow: 0 0 12px rgba(102, 136, 204, 0.5);
}

.kb-key--enter {
    flex: 2;
    max-width: none;
    border-color: rgba(0, 255, 65, 0.3);
    color: var(--green);
    font-size: 1.1em;
    letter-spacing: 3px;
}

.kb-key--enter:hover {
    background: rgba(0, 255, 65, 0.15);
    border-color: var(--green);
}

.kb-key--enter:active {
    background: var(--green);
    color: var(--bg);
    box-shadow: 0 0 12px rgba(0, 255, 65, 0.5);
}

/* Welcome narration (Phase 2 — after badge + name) */
.welcome-narration {
    color: var(--cyan);
    font-size: 1.1em;
    text-align: center;
    max-width: 700px;
    line-height: 1.8;
    text-shadow: 0 0 8px rgba(0, 221, 255, 0.3);
    margin: 12px 0;
    min-height: 60px;
}

/* ===== PHASE 3: ERA GRID ===== */
.era-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    width: 100%;
    flex: 1;
}

.era-card {
    background: var(--panel);
    border: 2px solid rgba(255, 153, 0, 0.3);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.era-card:hover { border-color: var(--amber); transform: translateY(-3px); box-shadow: var(--glow-amber); }
.era-card.selected { border-color: var(--green); box-shadow: var(--glow-green); }

.era-card-icon {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: 8px;
    margin-bottom: 6px;
    background: #222;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.2em;
    overflow: hidden;
}

.era-card-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

.era-card-name { font-family: var(--font-display); font-size: 0.8em; color: var(--amber); margin-bottom: 2px; }
.era-card-period { font-size: 0.65em; color: var(--text); }

/* ===== PHASE 4: PORTAL ===== */
.phase-title--large {
    font-size: 2.8em;
    letter-spacing: 6px;
    margin-bottom: 10px;
}

#phase4 .phase-subtitle {
    font-size: 1.4em;
    color: var(--cyan);
    text-shadow: 0 0 8px rgba(0, 221, 255, 0.4);
    margin-bottom: 20px;
}

.portal-narration {
    color: var(--text-bright);
    font-size: 1.6em;
    text-align: center;
    max-width: 900px;
    line-height: 2;
    text-shadow: 0 0 12px rgba(0, 221, 255, 0.4);
    flex: 1;
    display: flex;
    align-items: center;
}

.typing-text {
    border-right: 3px solid var(--cyan);
    animation: blink-cursor 1s step-end infinite;
    white-space: pre-wrap;
    padding-right: 4px;
}
@keyframes blink-cursor { 50% { border-color: transparent; } }

/* ===== PHASE 5: AMBIENTAZIONE ===== */
.ambientazione-layout {
    display: flex;
    gap: 20px;
    width: 100%;
    flex: 1;
    overflow-y: auto;
    align-items: flex-start;
}

.ambientazione-layout .ambientazione-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-content: start;
}

.scene-preview-section {
    width: 350px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.scene-preview-box {
    width: 100%;
    aspect-ratio: 1;
    background: var(--panel);
    border: 2px solid rgba(255, 153, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.scene-preview-box img { width: 100%; height: 100%; object-fit: cover; }
.scene-connecting-label {
    color: var(--cyan) !important;
    text-shadow: 0 0 6px rgba(0, 221, 255, 0.4);
    animation: connecting-pulse 2s ease-in-out infinite;
}
@keyframes connecting-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.scene-preview-box .scene-placeholder {
    color: var(--text);
    opacity: 0.3;
    font-family: var(--font-display);
    font-size: 0.8em;
    text-align: center;
    padding: 20px;
    letter-spacing: 1px;
}

.scene-preview-box.loading {
    border-color: var(--cyan);
    animation: scene-loading 2s ease-in-out infinite;
}
@keyframes scene-loading {
    0%, 100% { border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 221, 255, 0.2); }
    50% { border-color: var(--amber); box-shadow: 0 0 10px rgba(255, 153, 0, 0.2); }
}

/* TV Static: CRT scanlines overlay during loading */
.scene-preview-box.loading::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0, 221, 255, 0.03) 2px,
        rgba(0, 221, 255, 0.03) 4px
    );
    z-index: 3;
    pointer-events: none;
    animation: static-flicker 0.15s steps(3) infinite;
}

/* TV Static: Scanning line moving down */
.scene-preview-box.loading::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 3px;
    background: var(--cyan);
    box-shadow: 0 0 15px var(--cyan), 0 0 30px rgba(0, 221, 255, 0.5);
    z-index: 4;
    pointer-events: none;
    animation: scene-scan-line 2.5s linear infinite;
}

@keyframes static-flicker {
    0%, 100% { opacity: 0.7; }
    33% { opacity: 0.3; }
    66% { opacity: 0.9; }
}

@keyframes scene-scan-line {
    0% { top: -3px; }
    100% { top: 100%; }
}

/* TV Static: Noise canvas overlay */
.noise-canvas {
    position: absolute !important;
    top: 0 !important; left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 2;
    pointer-events: none;
    opacity: 0.2;
    image-rendering: pixelated;
}

.scene-preview-box.ready { border-color: var(--green); box-shadow: var(--glow-green); }

/* ===== DEBUG PANEL (always visible in Phase 5) ===== */
.scene-debug-panel {
    width: 100%;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid rgba(0, 221, 255, 0.2);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--font-display);
    font-size: 0.65em;
}

.debug-header {
    color: var(--cyan);
    font-size: 0.9em;
    letter-spacing: 2px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(0, 221, 255, 0.15);
    padding-bottom: 3px;
}

.debug-toggle-hint {
    color: var(--text);
    opacity: 0.3;
    font-size: 0.8em;
}

.debug-row {
    display: flex;
    gap: 6px;
    margin: 2px 0;
    line-height: 1.3;
}

.debug-key {
    color: var(--amber);
    flex-shrink: 0;
    min-width: 50px;
}

.debug-key::after {
    content: ':';
}

.debug-val {
    color: var(--green);
    word-break: break-all;
    opacity: 0.9;
    user-select: text;
    cursor: text;
    -webkit-user-select: text;
}

.debug-val--prompt {
    font-size: 0.95em;
    line-height: 1.4;
}

.debug-row--prompt {
    position: relative;
}

.debug-copy-btn {
    position: absolute;
    top: 0; right: 0;
    background: rgba(0, 221, 255, 0.1);
    border: 1px solid rgba(0, 221, 255, 0.3);
    color: var(--cyan);
    font-size: 1em;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.debug-copy-btn:hover {
    background: rgba(0, 221, 255, 0.25);
    border-color: var(--cyan);
}

.debug-copy-btn.copied {
    background: rgba(0, 255, 65, 0.2);
    border-color: var(--green);
    color: var(--green);
}

/* ===== PHASE 6: EQUIPAGGIAMENTO ===== */
.outfit-layout {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    flex: 1;
}

.outfit-section {
    width: 100%;
}

.selector-group {
    background: var(--panel);
    border: 1px solid rgba(255, 153, 0, 0.2);
    border-radius: 10px;
    padding: 12px 15px;
}

.selector-label {
    font-family: var(--font-display);
    font-size: 0.75em;
    color: var(--amber);
    letter-spacing: 2px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.selector-options { display: flex; flex-direction: column; gap: 4px; }

.selector-option {
    padding: 8px 12px;
    border: 1px solid rgba(255, 153, 0, 0.15);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.85em;
    color: var(--text);
}

.selector-option:hover { border-color: var(--amber); color: var(--amber); }
.selector-option.selected { border-color: var(--green); color: var(--green); background: rgba(0, 255, 65, 0.05); }

/* Sex toggle */
.sex-toggle { display: flex; gap: 8px; margin-bottom: 15px; justify-content: center; }

.sex-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--blue);
    background: transparent;
    color: var(--blue);
    font-family: var(--font-display);
    font-size: 0.9em;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
}

.sex-btn:hover { background: rgba(102, 136, 204, 0.1); }
.sex-btn.selected { background: var(--blue); color: var(--bg); }

.outfit-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

.outfit-card {
    background: var(--panel);
    border: 2px solid rgba(102, 136, 204, 0.3);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.outfit-card:hover { border-color: var(--blue); box-shadow: var(--glow-blue); }
.outfit-card.selected { border-color: var(--green); box-shadow: var(--glow-green); }

.outfit-preview {
    width: 100%; aspect-ratio: 3/4;
    flex: 1;
    min-height: 0;
    background: #1a1a2e;
    border-radius: 8px;
    margin-bottom: 6px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}

.outfit-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.outfit-name { font-family: var(--font-display); color: var(--blue); font-size: 0.8em; }

/* ===== PHASE 6: RESULT ===== */
#generatingState {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.countdown-display {
    font-family: var(--font-display);
    font-size: 3em;
    color: var(--cyan);
    text-shadow: 0 0 30px rgba(0, 221, 255, 0.6);
    margin: 15px 0;
    letter-spacing: 5px;
    text-align: center;
}

.progress-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
}

.progress-bar {
    width: 350px; height: 8px;
    background: var(--panel);
    border: 1px solid var(--amber);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--amber), var(--green));
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-text { color: var(--amber); font-family: var(--font-display); font-size: 0.85em; letter-spacing: 2px; text-align: center; }

/* ===== EMAIL OVERLAY (over Phase 7 during generation) ===== */
.email-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.email-overlay.hidden { display: none !important; }

.email-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    gap: 6px;
    position: relative;
}

.email-overlay-close {
    position: absolute;
    top: -10px; right: -10px;
    background: transparent;
    border: 2px solid var(--amber);
    color: var(--amber);
    font-size: 1.8em;
    width: 40px; height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 10;
    font-family: var(--font-display);
    line-height: 1;
}

.email-overlay-close:hover {
    background: var(--amber);
    color: var(--bg);
    box-shadow: var(--glow-amber);
}

.email-input-display {
    width: 100%;
    max-width: 450px;
    margin-bottom: 8px;
}

.email-hint {
    font-size: 0.75em;
    color: var(--text);
    opacity: 0.6;
    margin: 6px 0;
    font-family: var(--font-display);
}

.email-overlay.sent .virtual-keyboard--email,
.email-overlay.sent .privacy-row,
.email-overlay.sent #emailSendBtn { display: none; }
.email-overlay.sent .email-hint { color: var(--green); opacity: 1; font-size: 1.1em; }

/* Email keyboard — fills remaining space */
.virtual-keyboard--email {
    max-width: 650px;
    flex: 1;
    min-height: 160px;
}

.virtual-keyboard--email .kb-key {
    font-size: 1.1em;
    max-width: none;
}

.kb-key--sym {
    border-color: rgba(0, 221, 255, 0.3) !important;
    color: var(--cyan) !important;
}

.kb-key--sym:hover {
    background: rgba(0, 221, 255, 0.15) !important;
    border-color: var(--cyan) !important;
}

.kb-key--sym:active {
    background: var(--cyan) !important;
    color: var(--bg) !important;
}

.kb-key--numrow {
    border-color: rgba(170, 85, 255, 0.25) !important;
    color: var(--purple) !important;
    font-size: 1em !important;
}

.kb-key--numrow:hover {
    background: rgba(170, 85, 255, 0.15) !important;
}

.kb-key--numrow:active {
    background: var(--purple) !important;
    color: var(--bg) !important;
}

/* Privacy checkbox */
.privacy-row {
    margin: 6px 0;
}

.privacy-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8em;
    color: var(--text);
    font-family: var(--font-display);
    user-select: none;
    -webkit-user-select: none;
}

.privacy-check input[type="checkbox"] {
    display: none;
}

.privacy-box {
    width: 20px; height: 20px;
    border: 2px solid var(--amber);
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.privacy-check input:checked + .privacy-box {
    background: var(--green);
    border-color: var(--green);
}

.privacy-check input:checked + .privacy-box::after {
    content: '\2713';
    color: var(--bg);
    font-size: 0.9em;
    font-weight: bold;
}

.disclaimer-link {
    color: var(--cyan);
    text-decoration: underline;
    cursor: pointer;
}

.disclaimer-link:hover {
    color: var(--green);
}

/* Disclaimer modal */
.disclaimer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.disclaimer-overlay.hidden {
    display: none !important;
}

.disclaimer-modal {
    background: var(--panel);
    border: 2px solid var(--amber);
    border-radius: 12px;
    padding: 25px 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.disclaimer-title {
    font-family: var(--font-display);
    font-size: 1.2em;
    color: var(--amber);
    letter-spacing: 3px;
    margin-bottom: 15px;
    text-align: center;
}

.disclaimer-text {
    font-size: 0.85em;
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 20px;
    white-space: pre-wrap;
    user-select: text;
    -webkit-user-select: text;
}

#resultState {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.result-display {
    max-height: 55vh;
    aspect-ratio: 2/3;
    border: 3px solid var(--green);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 255, 65, 0.3);
    margin: 8px 0;
    animation: result-reveal 1.5s ease-out;
    flex-shrink: 0;
}

@keyframes result-reveal {
    0% { opacity: 0; transform: scale(0.8); filter: brightness(3) blur(10px); }
    50% { filter: brightness(1.5) blur(3px); }
    100% { opacity: 1; transform: scale(1); filter: brightness(1) blur(0); }
}

.result-display img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Final generation debug panel */
.final-debug-panel {
    max-width: 550px;
    margin-bottom: 8px;
}

.result-actions { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }

/* ===== PROMPT PREVIEW ===== */
.prompt-preview {
    position: fixed;
    bottom: 60px; right: 20px;
    background: rgba(17, 17, 17, 0.95);
    border: 1px solid rgba(255, 153, 0, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    max-width: 350px;
    font-size: 0.7em;
    color: var(--text);
    z-index: 100;
    display: none;
}

.prompt-preview.visible { display: block; }
.prompt-preview-label { color: var(--amber); font-family: var(--font-display); font-size: 0.9em; margin-bottom: 4px; }
.prompt-preview-text { color: var(--green); word-break: break-word; line-height: 1.4; }

/* ===== FOOTER ===== */
.footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 0 8px;
    border-top: 2px solid var(--amber);
    flex-shrink: 0;
}

.footer-back {
    background: transparent;
    border: 1px solid var(--amber);
    color: var(--amber);
    padding: 5px 14px;
    border-radius: 6px;
    font-family: var(--font-display);
    font-size: 0.8em;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.footer-back:hover { background: var(--amber); color: var(--bg); box-shadow: var(--glow-amber); }
.footer-back.hidden { display: none; }

.footer-phase { color: var(--amber); font-family: var(--font-display); font-size: 0.85em; letter-spacing: 2px; }

.footer-status { margin-left: auto; color: var(--green); font-size: 0.75em; font-family: var(--font-display); }

.footer-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 5px;
    animation: dot-pulse 3s ease-in-out infinite;   /* SLOWER: was 1.5s */
}

@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== UTILITIES ===== */
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--panel);
    border-top-color: var(--amber);
    border-radius: 50%;
    animation: spin 1.2s linear infinite;   /* SLOWER: was 0.8s */
    margin: 12px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 800px) {
    .chronos-app { margin: 4px; padding: 6px 12px; }
    .console-bar { flex-wrap: wrap; }
    .console-widget { min-width: 45%; }
    .era-grid { grid-template-columns: repeat(3, 1fr); }
    .ambientazione-layout { flex-direction: column; }
    .scene-preview-section { width: 100%; }
    .outfit-layout { flex-direction: column; }
    .outfit-section { width: 100%; }
    .camera-container { width: 300px; height: 225px; }
    .phase-title { font-size: 1.3em; }
}

/* Wide screens: era grid can do more columns */
@media (min-width: 1400px) {
    .era-card-name { font-size: 0.9em; }
    .era-card-period { font-size: 0.75em; }
}
