:root {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --accent-color: #8e44ad;
    --user-msg-bg: #2c3e50;
    --ai-msg-bg: #1a1a1a; /* Blend with bg or slightly lighter */
    --input-bg: #2c2c2c;
    --font-main: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-serif: 'Georgia', 'Times New Roman', serif;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Start Screen */
#start-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    animation: fadeIn 1s ease;
}

#start-screen h1 {
    font-family: var(--font-serif);
    font-size: 3rem;
    margin-bottom: 1rem;
    font-weight: normal;
    letter-spacing: 2px;
}

#start-screen p {
    font-size: 1.2rem;
    color: #aaa;
    margin-bottom: 3rem;
}

.start-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
}

#start-btn, #start-history-btn {
    padding: 15px 40px;
    font-size: 1.1rem;
    background: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 2px;
}

#start-btn:hover, #start-history-btn:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

/* Chat Screen */
#chat-screen {
    max-width: 800px; /* Limit width for reading comfort */
    margin: 0 auto;
    position: relative;
    width: 100%; /* Ensure full width on mobile/resize */
}

#progress-container {
    width: 100%;
    height: 3px;
    background-color: transparent;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    visibility: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--accent-color);
    transition: width 0.1s linear;
}

#progress-text {
    position: absolute;
    top: 10px;
    width: 100%;
    text-align: center;
    color: var(--accent-color);
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    padding-bottom: 100px; /* Space for input */
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

.message {
    margin-bottom: 1.5rem;
    line-height: 1.6;
    opacity: 0;
    animation: slideUp 0.5s forwards;
    display: flex;
    flex-direction: column;
    position: relative; /* For positioning delete button */
}

.message:hover .delete-msg-btn {
    opacity: 1;
}

.message.user {
    align-items: flex-end;
}

.message.model {
    align-items: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 15px 20px;
    border-radius: 8px;
    position: relative;
}

.message.user .message-content {
    background-color: var(--user-msg-bg);
    border-bottom-right-radius: 2px;
}

.message.model .message-content {
    background-color: transparent; /* Minimalist, just text for AI? Or subtle bg */
    padding-left: 0;
    font-family: var(--font-serif);
    font-size: 1.1rem;
}

/* Delete Message Button */
.delete-msg-btn {
    position: absolute;
    top: -10px;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: #333;
    border: 1px solid #555;
    color: #aaa;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    z-index: 10;
}

.message.user .delete-msg-btn {
    right: 0;
}

.message.model .delete-msg-btn {
    left: -25px;
    top: 5px;
}

.delete-msg-btn:hover {
    color: #ff4444;
    border-color: #ff4444;
}

/* Cursor effect for streaming */
.cursor::after {
    content: '|';
    animation: blink 1s infinite;
}

#input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    background: linear-gradient(to top, var(--bg-color) 80%, transparent);
    display: flex;
    gap: 10px;
    box-sizing: border-box;
    align-items: flex-end;
}

textarea {
    flex: 1;
    background: var(--input-bg);
    border: none;
    color: white;
    padding: 15px;
    border-radius: 4px;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 150px;
    overflow-y: hidden; /* Hide scrollbar */
}

/* Bold text styling */
strong {
    font-weight: 700;
    color: #fff; /* Ensure high contrast */
}

#send-btn {
    padding: 15px 25px;
    background: var(--text-color);
    color: var(--bg-color);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#support-btn, #history-btn {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 15px;
    transition: color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#support-btn:hover, #history-btn:hover {
    color: var(--accent-color);
}

/* Donation Modal & History Modal Common */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: var(--input-bg);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    border: 1px solid #444;
}

/* History Modal Specifics */
.history-content {
    max-width: 700px; /* Wider for reading chat */
    height: 80%;
    display: flex;
    flex-direction: column;
    text-align: left; /* Align text left for list/chat */
}

.history-content h3 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    flex-shrink: 0;
}

#history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
}

.history-item {
    background: #222;
    padding: 15px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    background: #333;
}

.history-info {
    flex: 1;
    overflow: hidden;
}

.delete-session-btn {
    background: transparent;
    border: none;
    color: #555;
    cursor: pointer;
    padding: 5px 10px;
    font-size: 1.2rem;
    margin-left: 10px;
    transition: color 0.2s;
}

.delete-session-btn:hover {
    color: #ff4444;
}

.history-date {
    font-size: 0.85rem;
    color: var(--accent-color);
    margin-bottom: 5px;
}

.history-preview {
    font-size: 0.95rem;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#history-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.3s;
}

#history-details.hidden {
    display: none;
}

.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#back-to-history, #continue-chat-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    padding: 5px 0;
    font-size: 1rem;
}

#continue-chat-btn {
    border: 1px solid var(--accent-color);
    padding: 5px 15px;
    border-radius: 4px;
    transition: all 0.3s;
}

#continue-chat-btn:hover {
    background: var(--accent-color);
    color: white;
}

#history-chat-view {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    scrollbar-width: thin;
}

/* Close Button */
#close-modal, #close-history {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
}

#close-modal:hover, #close-history:hover {
    color: white;
}

.modal-content h3 {
    margin-top: 0;
    color: var(--accent-color);
    font-family: var(--font-serif);
}

.qr-container {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.qr-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.qr-item img {
    width: 150px;
    height: 150px;
    object-fit: contain;
    background: white; /* QR codes often need white bg */
    padding: 5px;
    border-radius: 4px;
}

.qr-item span {
    font-size: 0.9rem;
    color: #aaa;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

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