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

:root {
    --black: #000000;
    --white: #ffffff;
    --gray-dark: #1a1a1a;
    --gray: #333333;
    --gray-light: #666666;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    background: var(--black);
    color: var(--white);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--black);
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* App screen needs scrolling content */
#app-screen {
    position: fixed !important;
    overflow-y: auto;
    height: 100vh;
    top: 0;
    left: 0;
}

#app-screen > * {
    flex-shrink: 0;
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

#loading-screen > * {
    display: block;
}

.terminal-loader {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.cursor {
    animation: blink 1s step-end infinite;
}

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

.loading-text {
    font-size: 0.875rem;
    color: var(--gray-light);
    letter-spacing: 2px;
}

.bypass-btn {
    margin-top: 2rem;
    background: transparent;
    border: 1px solid var(--white);
    color: var(--white);
    padding: 1rem 2rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    display: inline-block;
}

.bypass-btn:hover {
    background: var(--white);
    color: var(--black);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
}

/* ===== LOGIN SCREEN ===== */
#login-screen {
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.logo-container {
    text-align: center;
    margin-bottom: 3rem;
}

.title {
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    font-weight: 700;
    letter-spacing: 4px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    position: relative;
}

.glitch {
    position: relative;
    animation: glitch 3s infinite;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.glitch::before {
    color: var(--white);
    animation: glitch-offset-1 3s infinite linear alternate-reverse;
    clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
    transform: translate(-2px, -1px);
}

.glitch::after {
    color: var(--gray-light);
    animation: glitch-offset-2 2s infinite linear alternate-reverse;
    clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
    transform: translate(2px, 1px);
}

@keyframes glitch-offset-1 {
    0% { transform: translate(-2px, -1px); }
    25% { transform: translate(2px, 1px); }
    50% { transform: translate(-1px, 2px); }
    75% { transform: translate(1px, -2px); }
    100% { transform: translate(-2px, 1px); }
}

@keyframes glitch-offset-2 {
    0% { transform: translate(2px, 1px); }
    25% { transform: translate(-2px, -1px); }
    50% { transform: translate(1px, -2px); }
    75% { transform: translate(-1px, 2px); }
    100% { transform: translate(2px, -1px); }
}

.subtitle {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-light);
    letter-spacing: 2px;
}

.login-container {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.terminal-btn {
    background: transparent;
    border: 1px solid var(--white);
    color: var(--white);
    padding: 1rem 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
}

.terminal-btn:hover {
    background: var(--white);
    color: var(--black);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.terminal-btn:active {
    transform: scale(0.98);
}

.btn-icon {
    font-weight: 700;
}

.warning-text {
    margin-top: 1.5rem;
    font-size: 0.75rem;
    color: var(--gray-light);
    text-align: center;
    letter-spacing: 1px;
}

/* ===== APP HEADER ===== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--gray);
    background: var(--black);
    position: sticky;
    top: 0;
    z-index: 100;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border: 1px solid var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 1px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--gray-light);
    color: var(--gray-light);
    padding: 0.5rem 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.625rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    border-color: var(--white);
    color: var(--white);
}

/* ===== 3D STAIRCASE VISUALIZATION ===== */
.staircase-container {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--gray);
}

.staircase-header {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.direction-indicator {
    font-size: 0.625rem;
    letter-spacing: 3px;
    color: var(--gray-light);
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-dark);
    background: var(--gray-dark);
    transition: all 0.5s ease;
}

.direction-indicator.positive {
    color: var(--white);
    border-color: var(--white);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.direction-indicator.negative {
    color: #8b4545;
    border-color: #8b4545;
    box-shadow: 0 0 10px rgba(139, 69, 69, 0.3);
}

.staircase-viewport {
    position: relative;
    width: 100%;
    height: 300px;
    background: var(--black);
    border: 1px solid var(--gray);
    overflow: hidden;
    margin-bottom: 1rem;
}

.staircase-viewport canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    outline: none;
}

/* Loading overlay for 3D scene */
.staircase-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--black);
    z-index: 10;
}

.staircase-loading::after {
    content: 'INITIALIZING_3D_VIEW...';
    font-size: 0.625rem;
    color: var(--gray-light);
    letter-spacing: 2px;
    animation: blink 1.5s infinite;
}

.position-display {
    text-align: center;
    padding: 0.75rem;
    border: 1px solid var(--gray);
    background: var(--gray-dark);
    margin-bottom: 0.75rem;
}

.position-label {
    color: var(--gray-light);
    font-size: 0.625rem;
    letter-spacing: 2px;
}

.position-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 0.25rem;
    letter-spacing: 3px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.625rem;
    color: var(--gray-light);
    letter-spacing: 1px;
}

.stat {
    flex: 1;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid var(--gray-dark);
}

.stat span:last-child {
    color: var(--white);
    font-weight: 700;
}

/* ===== AI SECTION ===== */
.ai-section {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--gray);
}

.ai-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    letter-spacing: 2px;
}

.ai-indicator {
    width: 8px;
    height: 8px;
    background: var(--white);
    border-radius: 50%;
    animation: blink 1.5s ease-in-out infinite;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.confession-input {
    width: 100%;
    min-height: 100px;
    background: var(--gray-dark);
    border: 1px solid var(--gray);
    color: var(--white);
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    resize: vertical;
    transition: border-color 0.2s ease;
}

.confession-input::placeholder {
    color: var(--gray-light);
}

.confession-input:focus {
    outline: none;
    border-color: var(--white);
}

.submit-btn {
    width: 100%;
}

.analysis-result {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid var(--gray);
    background: var(--gray-dark);
    animation: slideIn 0.3s ease-out;
    max-height: 300px;
    overflow-y: auto;
}

.analysis-result::-webkit-scrollbar {
    width: 6px;
}

.analysis-result::-webkit-scrollbar-track {
    background: var(--gray-dark);
    border: 1px solid var(--gray);
}

.analysis-result::-webkit-scrollbar-thumb {
    background: var(--gray-light);
    border-radius: 3px;
}

.analysis-result::-webkit-scrollbar-thumb:hover {
    background: var(--white);
}

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

.result-header {
    font-size: 0.625rem;
    letter-spacing: 2px;
    color: var(--gray-light);
    margin-bottom: 0.75rem;
}

.result-content {
    font-size: 0.875rem;
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

.result-movement {
    font-size: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray);
}

.movement-up {
    color: var(--white);
}

.movement-down {
    color: #8b4545;
}

.hidden {
    display: none;
}

/* ===== HISTORY SECTION ===== */
.history-section {
    padding: 1.5rem 1rem;
    padding-bottom: 3rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--gray-dark);
    border: 1px solid var(--gray);
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--gray-light);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--white);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    letter-spacing: 2px;
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--gray-light);
    font-family: var(--font-mono);
    font-size: 0.625rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s ease;
}

.text-btn:hover {
    color: var(--white);
}


.history-item {
    padding: 0.75rem;
    border: 1px solid var(--gray-dark);
    background: var(--gray-dark);
    font-size: 0.75rem;
    line-height: 1.6;
}

.history-date {
    font-size: 0.625rem;
    color: var(--gray-light);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.history-text {
    color: var(--white);
}

.history-movement {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--gray-dark);
    font-size: 0.625rem;
    letter-spacing: 1px;
}

/* ===== UTILITIES ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

/* ===== SCANLINE EFFECT ===== */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
    .staircase-viewport {
        height: 400px;
    }

    .app-header {
        max-width: 800px;
        margin: 0 auto;
        width: 100%;
    }

    .staircase-container,
    .ai-section,
    .history-section {
        max-width: 800px;
        margin: 0 auto;
        width: 100%;
    }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (hover: none) {
    .terminal-btn:active {
        background: var(--white);
        color: var(--black);
    }

    .text-btn:active {
        color: var(--white);
    }
}

/* ===== SAFE AREA FOR NOTCH ===== */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .history-section {
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }
}
