/* Basic Styles */
body {
    font-family: sans-serif;
    background-color: #121212;
    color: #e0e0e0;
    margin: 0;
}

#app {
    width: 100%;
    max-width: 800px;
    margin: 20px auto;
    position: relative;
}

/* Screen Management */
.screen { display: none; }
.screen.active { display: block; }

/* Cover Selection */
.cover-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    text-align: center;
}
.cover { cursor: pointer; transition: transform 0.2s; }
.cover:hover { transform: scale(1.05); }
.cover img { border-radius: 8px; border: 2px solid #333; width: 100%; height: auto; }
.cover.skeleton { background-color: #2a2a2a; border-radius: 8px; }
.skeleton-img { height: 220px; background-color: #333; border-radius: 8px 8px 0 0; }
.skeleton-text { height: 20px; background-color: #333; margin: 10px; border-radius: 4px; }


/* Story Screen */
#story-content {
    background-color: #1e1e1e;
    padding: 20px;
    border-radius: 8px;
    min-height: 400px;
    margin-bottom: 20px;
    white-space: pre-wrap;
    line-height: 1.6;
}
#story-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Chat Panel --- */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
}
.chat-panel {
    background-color: #2a2a2a;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.chat-header {
    padding: 15px 20px;
    background-color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
}
.chat-header h2 { margin: 0; font-size: 1.1em; }
.close-btn { font-size: 1.5em; background: none; border: none; color: #aaa; cursor: pointer; }

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.message {
    display: flex;
    max-width: 80%;
}
.message p {
    margin: 0;
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.5;
}
.message.bot {
    align-self: flex-start;
}
.message.bot p {
    background-color: #3a3a3a;
    border-bottom-left-radius: 4px;
}
.message.user {
    align-self: flex-end;
}
.message.user p {
    background-color: #6200ea;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-input {
    padding: 15px;
    border-top: 1px solid #444;
}
.chat-input form {
    display: flex;
}
.chat-input input {
    flex-grow: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid #555;
    background-color: #333;
    color: #e0e0e0;
    margin-right: 10px;
}
.chat-input input:focus { outline: none; border-color: #6200ea; }

/* Typing Indicator */
.typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: #888;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}


/* Buttons */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    background-color: #6200ea;
    color: white;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}
button:hover { background-color: #7f39fb; }
button:disabled { background-color: #555; cursor: not-allowed; }

/* Spinner */
.spinner-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 200;
}
.spinner-overlay.active { display: flex; }
.spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid #6200ea;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Alpine Cloak */
[x-cloak] { display: none !important; }