:root {
    --bg-main: #0B0B0C;
    --bg-card: #1C1C1E;
    --bg-input: #2C2C2E;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A0A5;
    --accent: #D4AF37;
    --error: #FF453A;
    --radius: 12px;
    --transition: all 0.3s ease;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Login Page */
.login-wrap {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--bg-card);
    padding: 3rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-card h1 {
    margin-bottom: 2rem;
    font-size: 2.5rem;
    color: var(--accent);
}

input[type="password"], input[type="text"] {
    width: 100%;
    padding: 1rem;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: white;
    margin-bottom: 1rem;
    font-size: 1rem;
    transition: var(--transition);
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    width: 100%;
    padding: 1rem;
    background: var(--accent);
    color: black;
    border: none;
    border-radius: var(--radius);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(212, 175, 55, 0.3);
}

.error-msg {
    color: var(--error);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* Dashboard */
/* Novel Mode (For Infinite Horizon) */
.novel-mode {
    max-width: 900px !important;
    margin: 0 auto !important;
    padding: 2rem !important;
}

.novel-mode .message {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 1.5rem 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    line-height: 1.8 !important;
    font-size: 1.1rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    border-radius: 0 !important;
    animation: fadeIn 1s ease-in-out;
}

.novel-mode .message.user {
    color: var(--accent) !important;
    font-weight: 700 !important;
    text-align: left !important;
    align-self: flex-start !important;
}

.novel-mode .message.ai {
    color: var(--text-main) !important;
}

.novel-mode .message-name {
    display: block !important;
    margin-bottom: 0.5rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.1em !important;
    font-size: 0.75rem !important;
    opacity: 0.6 !important;
}

/* Infinite Horizon: Continue Button */
.btn-continue {
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
    width: auto;
    padding: 0 1rem;
    text-transform: none;
    letter-spacing: normal;
}

@media (max-width: 768px) {
    .btn-continue span:last-child {
        display: none;
    }
    .btn-continue {
        padding: 0 0.8rem;
        min-width: 40px;
    }
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent);
    text-decoration: none;
}

.logout-btn {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

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

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.story-card:hover {
    transform: translateY(-10px);
    border-color: var(--accent);
}

.story-img {
    width: 100%;
    aspect-ratio: 16/9;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: #000;
}

.story-content {
    padding: 1.5rem;
    flex-grow: 1;
}

.story-content h3 {
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.story-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Chat Interface */
.chat-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    height: calc(100vh - 4rem);
    gap: 1rem;
}

.sidebar {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-img {
    width: 100%;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.sidebar-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--accent);
}

.sidebar-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    overflow-y: auto;
}

.chat-main {
    background: var(--bg-card);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message {
    max-width: 80%;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
}

.message.user {
    align-self: flex-end;
    background: var(--bg-input);
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-bottom-left-radius: 4px;
}

.message-name {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--accent);
}

.chat-input-area {
    padding: 1.5rem;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-form {
    display: flex;
    gap: 1rem;
}

.chat-form input {
    margin-bottom: 0;
}

.chat-form button {
    width: auto;
    padding: 0 2rem;
}

.message-content {
    word-wrap: break-word;
}

.action {
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.8;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 900px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    box-shadow: 0 30px 60px rgba(0,0,0,0.6);
    animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-img {
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: #000;
    height: 100%;
}

.modal-body {
    padding: 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-body h2 {
    color: var(--accent);
    font-size: 2rem;
}

.modal-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.modal-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.modal-footer {
    margin-top: auto;
    padding-top: 2rem;
}

.btn-start {
    display: inline-block;
    padding: 1rem 2.5rem;
    background: var(--accent);
    color: black;
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 700;
    transition: var(--transition);
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(212, 175, 55, 0.3);
}

.close-modal {
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    opacity: 0.5;
    transition: var(--transition);
}

.close-modal:hover {
    opacity: 1;
}

/* Responsive / Mobile-Accurate Layout */
@media (max-width: 768px) {
    .mobile-only-header {
        display: flex !important;
    }

    .container {
        padding: 0.5rem;
    }

    .chat-container {
        grid-template-columns: 1fr;
        height: calc(100vh - 1rem);
        margin: 0;
    }

    .chat-messages {
        padding: 0.8rem 0.5rem;
        gap: 0.8rem;
    }

    .message {
        padding: 0.8rem 1rem;
        max-width: 100%;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .chat-input-area {
        padding: 0.8rem;
    }

    .chat-form textarea {
        padding: 0.8rem;
    }

    .header {
        margin-bottom: 1.5rem;
        flex-direction: column;
        gap: 0.8rem;
        text-align: center;
    }

    .header-controls {
        display: flex;
        flex-direction: column;
        gap: 0.8rem;
        width: 100%;
        align-items: center;
    }

    .session-btns {
        display: flex;
        gap: 1rem;
        justify-content: center;
    }

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-of-type(1) { animation-delay: 0.2s; }
.typing-dot:nth-of-type(2) { animation-delay: 0.4s; }
.typing-dot:nth-of-type(3) { animation-delay: 0.6s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

.mobile-info-fab {
        display: flex !important;
        position: absolute;
        bottom: 5.5rem;
        right: 0.8rem;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--accent);
        color: var(--bg-main);
        border: none;
        font-size: 1.1rem;
        font-weight: 700;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0,0,0,0.4);
        z-index: 100;
    }

    .story-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Modal Mobile */
    .modal-content {
        grid-template-columns: 1fr;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-img {
        height: 250px;
    }

    .modal-body {
        padding: 1.5rem;
    }

    .modal-body h2 {
        font-size: 1.5rem;
    }

    .sidebar {
        display: none; /* Hide sidebar on mobile to maximize chat space */
    }

    .chat-form button {
        padding: 0 1rem;
    }

    /* Settings Mobile */
    #settings-panel form {
        grid-template-columns: 1fr;
    }

    .mobile-info-btn {
        display: inline-block !important;
        background: var(--bg-card);
        border: 1px solid var(--accent);
        color: var(--accent);
        padding: 0.4rem 0.8rem;
        border-radius: 6px;
        font-weight: 700;
        font-size: 0.8rem;
        margin-right: 0.8rem;
        cursor: pointer;
    }

    .mobile-close {
        display: block !important;
        position: absolute;
        top: 1rem;
        right: 1rem;
        font-size: 1.5rem;
        color: white;
        cursor: pointer;
        z-index: 2001;
        background: rgba(0,0,0,0.5);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }

    .sidebar {
        background: var(--bg-main) !important;
        padding: 2rem !important;
        overflow-y: auto !important;
    }
}

.mobile-close {
    display: none;
}

.mobile-info-fab {
    display: none;
}
/* AI Thought Cloaking - TEMPORARILY DISABLED FOR TESTING
thought {
    display: none !important;
} */
/* Command Menu */
.command-menu {
    position: absolute;
    bottom: 100%;
    left: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.5rem;
    display: none;
    flex-direction: column;
    min-width: 200px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    margin-bottom: 0.5rem;
}

.command-item {
    padding: 0.8rem 1rem;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transition: var(--transition);
}

.command-item:hover {
    background: rgba(212, 175, 55, 0.1);
}

.command-item .key {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--accent);
}

/* Export/Import Modal */
.export-modal-body {
    padding: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
}

.code-container {
    background: #000;
    padding: 1rem;
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    margin: 1rem 0;
    white-space: pre-wrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.import-textarea {
    width: 100%;
    height: 300px;
    background: #000;
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 1rem;
    font-family: inherit;
    resize: none;
    margin: 1rem 0;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    border-color: white;
    color: white;
}


@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 0.8; }
    100% { opacity: 0.4; }
}
