/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent-maroon: #800000;
    --color-correct: #228B22;
    --color-close: #FFA500;
    --color-wrong: #4a4a5a;
    --color-neutral: #2d2d44;
    --font-display: 'Playfair Display', serif;
    --font-body: 'Lora', serif;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
    border-bottom: 2px solid var(--accent-maroon);
}

h1 {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 5px;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--accent-maroon);
    letter-spacing: 3px;
    text-transform: uppercase;
    font-weight: 500;
}

/* Sections */
section {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

h2, h3 {
    font-family: var(--font-display);
    margin-bottom: 15px;
}

h2 {
    font-size: 1.8rem;
}

h3 {
    font-size: 1.3rem;
    color: var(--text-secondary);
}

/* Case Thumbnail */
.case-thumbnail {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 20px;
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

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

/* Case Section */
.case-section {
    border-left: 4px solid var(--accent-maroon);
}

.case-title {
    color: var(--text-primary);
}

.case-description {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 5px;
    font-style: italic;
}

/* Hint Section */
.hint-section {
    background: rgba(128, 0, 0, 0.2);
    border: 1px solid var(--accent-maroon);
}

.hint-list {
    list-style: none;
    padding-left: 0;
}

.hint-list li {
    padding: 10px 15px;
    margin: 8px 0;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    border-left: 3px solid var(--accent-maroon);
    animation: fadeIn 0.5s ease-in;
}

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

/* Guess Section */
.guess-section {
    background: var(--bg-secondary);
}

.guesses-remaining {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.guesses-remaining span {
    color: var(--color-close);
    font-weight: bold;
    font-size: 1.3rem;
}

.input-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    font-weight: 500;
}

.input-group input {
    padding: 12px 15px;
    border: 2px solid var(--color-neutral);
    border-radius: 5px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent-maroon);
    box-shadow: 0 0 10px rgba(128, 0, 0, 0.3);
}

.input-group input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.input-group input.correct {
    background: var(--color-correct);
    border-color: var(--color-correct);
    color: white;
}

.input-group input.close {
    background: var(--color-close);
    border-color: var(--color-close);
    color: black;
}

#submit-btn {
    width: 100%;
    padding: 15px;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, var(--accent-maroon), #a00000);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(128, 0, 0, 0.4);
}

#submit-btn:disabled {
    background: var(--color-neutral);
    cursor: not-allowed;
    transform: none;
}

/* History Section */
.history-section {
    background: var(--bg-primary);
}

.history-header {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 5px;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.history-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

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

.history-cell {
    padding: 12px 8px;
    border-radius: 5px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--color-neutral);
    color: var(--text-primary);
    word-wrap: break-word;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-cell.correct {
    background: var(--color-correct);
    color: white;
}

.history-cell.close {
    background: var(--color-close);
    color: black;
}

.history-cell.wrong {
    background: var(--color-wrong);
    color: var(--text-secondary);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--accent-maroon);
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
}

.solution-reveal {
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: left;
}

.solution-reveal h4 {
    color: var(--accent-maroon);
    margin-bottom: 10px;
}

.solution-reveal p {
    margin: 8px 0;
}

.modal-btn {
    padding: 12px 30px;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: white;
    background: var(--accent-maroon);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-btn:hover {
    background: #a00000;
    transform: scale(1.05);
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 999;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-neutral);
    border-top: 4px solid var(--accent-maroon);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .input-grid {
        grid-template-columns: 1fr;
    }

    .history-header,
    .history-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-header span:nth-child(3),
    .history-header span:nth-child(4) {
        display: none;
    }

    .container {
        padding: 10px;
    }

    section {
        padding: 15px;
    }

    .story-selection-content {
        padding: 20px;
    }

    .story-selection-content h1 {
        font-size: 2.2rem;
    }

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

    .chat-message.user {
        margin-left: 10%;
    }

    .chat-message.assistant {
        margin-right: 10%;
    }
}

/* Empty State */
.history-grid:empty::after {
    content: "No accusations yet. Make your first guess above!";
    display: block;
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-style: italic;
}

/* Story Selection Screen */
.story-selection {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.story-selection-content {
    text-align: center;
    padding: 40px;
    max-width: 800px;
}

.story-selection-content h1 {
    font-family: var(--font-display);
    font-size: 3.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.story-selection-content h2 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    margin: 30px 0 20px;
    color: var(--text-secondary);
}

.story-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.story-card {
    background: var(--bg-card);
    border: 2px solid var(--color-neutral);
    border-radius: 15px;
    padding: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.story-card:hover {
    border-color: var(--accent-maroon);
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(128, 0, 0, 0.3);
}

.story-card h3 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 15px;
}

.story-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Chatbot Section */
.chatbot-section {
    background: var(--bg-secondary);
    border: 1px solid var(--color-neutral);
}

.chatbot-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.chatbot-messages {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 15px;
    max-height: 300px;
    min-height: 100px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.chatbot-messages:empty::after {
    content: "No messages yet. Ask me anything about the case!";
    color: var(--text-secondary);
    font-style: italic;
    display: block;
    text-align: center;
    padding: 30px;
}

.chat-message {
    margin: 10px 0;
    padding: 12px 15px;
    border-radius: 10px;
    animation: fadeIn 0.3s ease;
}

.chat-message.user {
    background: var(--accent-maroon);
    color: white;
    margin-left: 20%;
    text-align: right;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    background: var(--bg-card);
    color: var(--text-primary);
    margin-right: 20%;
    border-bottom-left-radius: 4px;
}

.chat-message.loading {
    background: var(--bg-card);
    color: var(--text-secondary);
    margin-right: 20%;
    font-style: italic;
}

.chatbot-form {
    display: flex;
    gap: 10px;
}

.chatbot-form input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid var(--color-neutral);
    border-radius: 5px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.chatbot-form input:focus {
    outline: none;
    border-color: var(--accent-maroon);
}

.chatbot-form button {
    padding: 12px 25px;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, var(--accent-maroon), #a00000);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chatbot-form button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(128, 0, 0, 0.4);
}

.chatbot-form button:disabled {
    background: var(--color-neutral);
    cursor: not-allowed;
}

/* Scrollbar for chatbot */
.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--accent-maroon);
    border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a00000;
}
