@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600&family=Crimson+Text:wght@400;600&family=IM+Fell+English:ital@0;1&family=Special+Elite&display=swap');

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

:root {
    --projects-nav-height: 2rem;
    --bg-deck: #19140d;
    --bg-deck-deep: #0f0b07;
    --panel-wood: rgba(28, 22, 16, 0.78);
    --panel-wood-light: rgba(40, 31, 21, 0.72);
    --ink-light: #f1e6d6;
    --ink-muted: #cbb79a;
    --accent-brass: #d6b26d;
    --accent-burgundy: #8f3a2d;
    --accent-sage: #6f7a4f;
    --paper: #f6e7c8;
    --paper-deep: #e8d0a1;
    --paper-line: rgba(120, 96, 62, 0.18);
    --font-body: 'Crimson Text', 'IM Fell English', serif;
    --font-display: 'Special Elite', 'IM Fell English', serif;
    --font-notes: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
}

body {
    font-family: var(--font-body);
    background:
        radial-gradient(circle at top left, rgba(88, 63, 34, 0.45), transparent 45%),
        radial-gradient(circle at 80% 20%, rgba(120, 84, 41, 0.35), transparent 50%),
        linear-gradient(135deg, var(--bg-deck) 0%, var(--bg-deck-deep) 100%);
    color: var(--ink-light);
    height: 100vh;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 120px 120px, 180px 180px;
    opacity: 0.35;
    pointer-events: none;
    z-index: 0;
}

.projects-nav {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: var(--projects-nav-height);
    padding: 0 1rem;
    border-bottom: 1px solid rgba(214, 178, 109, 0.18);
    background: rgba(15, 11, 7, 0.72);
}

.projects-nav a {
    color: var(--ink-muted);
    font-size: 0.85rem;
    text-decoration: none;
    letter-spacing: 0.03em;
    transition: color 0.2s ease;
}

.projects-nav a:hover,
.projects-nav a:focus-visible {
    color: var(--accent-brass);
}

.screen,
.game-container,
.welcome-container,
.suspects-panel,
.chat-panel,
.clues-panel {
    position: relative;
    z-index: 1;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    height: calc(100vh - var(--projects-nav-height));
}

.screen.active {
    display: flex;
}

/* Welcome Screen */
#welcome-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1f1710 0%, #120d08 100%);
}

.welcome-container {
    max-width: 800px;
    padding: 3rem;
    background: var(--panel-wood);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(214, 178, 109, 0.25);
    text-align: center;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.welcome-container h1 {
    font-family: var(--font-display);
    font-size: 3rem;
    margin-bottom: 2rem;
    color: var(--accent-brass);
    text-shadow: 0 0 20px rgba(214, 178, 109, 0.4);
}

.intro-text {
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 2rem;
    text-align: left;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 1rem;
    color: var(--ink-muted);
}

.intro-text::-webkit-scrollbar {
    width: 8px;
}

.intro-text::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.intro-text::-webkit-scrollbar-thumb {
    background: rgba(214, 178, 109, 0.5);
    border-radius: 4px;
}

/* Markdown styling within intro text */
.intro-text p {
    margin: 0 0 1rem 0;
}

.intro-text h1, .intro-text h2, .intro-text h3 {
    color: #ff6b6b;
    margin: 1.5rem 0 1rem 0;
}

.intro-text h1 {
    font-size: 2rem;
}

.intro-text h2 {
    font-size: 1.5rem;
}

.intro-text h3 {
    font-size: 1.2rem;
}

.intro-text strong {
    color: var(--accent-brass);
    font-weight: 700;
}

.intro-text ul {
    margin: 1rem 0;
    padding-left: 2rem;
}

.intro-text li {
    margin: 0.5rem 0;
}

/* Buttons */
.btn-primary {
    background: var(--accent-burgundy);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    background: #a14839;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(143, 58, 45, 0.4);
}

/* Game Screen */
#game-screen {
    padding: 1rem;
}

.game-container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 416px auto;
    grid-template-areas: "chat clues suspects";
    gap: 1rem;
    height: 100%;
    max-height: 100%;
    padding: 0;
    width: 100%;
}

/* Suspects Panel */
.suspects-panel {
    grid-area: suspects;
    background: var(--panel-wood);
    border-radius: 10px;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(214, 178, 109, 0.2);
    overflow-y: auto;
    max-height: 100%;
    width: fit-content;
    min-width: 0;
}

.suspects-panel h2 {
    font-family: var(--font-display);
    color: var(--accent-brass);
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
}

.suspects-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.suspect-card {
    background: rgba(28, 22, 16, 0.6);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.suspect-card:hover {
    border-color: rgba(214, 178, 109, 0.6);
    background: rgba(50, 38, 24, 0.7);
    transform: translateX(5px);
}

.suspect-card.active {
    border-color: var(--accent-brass);
    background: rgba(214, 178, 109, 0.15);
}

.suspect-card img {
    width: 90px;
    height: 135px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0;
}

/* Suspect name removed from card UI */

/* Chat Panel */
.chat-panel {
    grid-area: chat;
    background: var(--panel-wood-light);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(214, 178, 109, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative; /* For loading spinner positioning */
    max-height: 100%;
    min-height: 0;
    width: 100%; /* Take full horizontal space */
    min-width: 0; /* Allow shrinking if needed */
}

.chat-header {
    background: rgba(143, 58, 45, 0.25);
    padding: 1.5rem;
    border-bottom: 1px solid rgba(214, 178, 109, 0.2);
    flex-shrink: 0; /* Don't let header shrink */
}

.chat-header h2 {
    font-family: var(--font-display);
    color: var(--accent-brass);
    font-size: 1.3rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0; /* Important for flexbox to work properly */
    min-width: 0; /* Allow horizontal flexibility */
    width: 100%; /* Take full width */
    justify-content: flex-start; /* Align messages to top */
}

/* When only system message present, center it vertically */
.chat-messages:has(.system-message:only-child) {
    justify-content: center;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(214, 178, 109, 0.3);
    border-radius: 4px;
}

.message {
    max-width: 80%;
    padding: 1rem;
    border-radius: 10px;
    line-height: 1.6;
}

/* Markdown styling within messages */
.message p {
    margin: 0 0 0.5rem 0;
}

.message p:last-child {
    margin-bottom: 0;
}

.message h1, .message h2, .message h3 {
    margin: 0.5rem 0;
    color: var(--accent-brass);
}

.message h1 {
    font-size: 1.3rem;
}

.message h2 {
    font-size: 1.2rem;
}

.message h3 {
    font-size: 1.1rem;
}

.message strong {
    color: #e6d2aa;
    font-weight: 700;
}

.message em {
    font-style: italic;
    color: #e0e0e0;
}

.message code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.8rem;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message pre code {
    background: none;
    padding: 0;
}

.message ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message li {
    margin: 0.25rem 0;
}

.message a {
    color: #6495ed;
    text-decoration: underline;
}

.message a:hover {
    color: #8ab4f8;
}

.message.user {
    align-self: flex-end;
    background: rgba(111, 122, 79, 0.35);
    border: 1px solid rgba(111, 122, 79, 0.6);
}

.message.suspect {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(214, 178, 109, 0.15);
}

.message.system-message {
    align-self: center;
    background: rgba(143, 58, 45, 0.2);
    border: 1px solid rgba(143, 58, 45, 0.4);
    max-width: 90%;
    text-align: center;
    font-style: italic;
}

.message.clue-revealed {
    align-self: center;
    background: rgba(111, 122, 79, 0.25);
    border: 1px solid rgba(111, 122, 79, 0.5);
    max-width: 90%;
    font-weight: 600;
}

.message.clue-revealed .clue-title {
    margin-bottom: 0.35rem;
}

.message.clue-revealed .clue-body {
    font-weight: 400;
}

.message.pulse-highlight {
    animation: pulse-highlight 1s ease-in-out infinite;
}

@keyframes pulse-highlight {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.6);
    }
    70% {
        box-shadow: 0 0 0 12px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

.chat-input-container {
    display: flex;
    gap: 0.5rem;
    padding: 1.5rem;
    background: rgba(15, 11, 7, 0.65);
    border-top: 1px solid rgba(214, 178, 109, 0.2);
    flex-shrink: 0; /* Don't let input shrink */
}

#chat-input {
    flex: 1;
    background: rgba(255, 245, 230, 0.08);
    border: 1px solid rgba(214, 178, 109, 0.3);
    color: var(--ink-light);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

#chat-input:focus {
    border-color: var(--accent-brass);
    background: rgba(255, 245, 230, 0.15);
}

.btn-send {
    background: var(--accent-burgundy);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-send:hover:not(:disabled) {
    background: #a14839;
    transform: translateY(-2px);
}

/* Clues Panel */
.clues-panel {
    grid-area: clues;
    background:
        repeating-linear-gradient(
            0deg,
            var(--paper-line),
            var(--paper-line) 1px,
            transparent 1px,
            transparent 28px
        ),
        linear-gradient(135deg, var(--paper) 0%, var(--paper-deep) 100%);
    border-radius: 12px;
    padding: 1.5rem;
    border: 2px solid rgba(159, 122, 62, 0.6);
    overflow-y: auto;
    max-height: 100%;
    width: 416px;
    min-width: 416px;
    color: #2b2216;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.clues-panel h2 {
    font-family: var(--font-display);
    color: #5b3a1a;
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
}

.notes-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.notes-header-text {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.notes-header h2 {
    margin-bottom: 0;
}

.notes-suspect-photo {
    width: 150px;
    height: 225px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid rgba(159, 122, 62, 0.6);
    box-shadow: 0 6px 14px rgba(43, 34, 22, 0.2);
}

.notes-suspect-photo.is-hidden {
    display: none;
}

.notes-suspect-bio {
    font-family: var(--font-notes);
    font-size: 1.225rem;
    color: #3e2d1c;
}

.btn-notes-reset {
    width: calc(100% - 2.4rem);
    margin: 0 1.2rem 1.2rem;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(159, 122, 62, 0.6);
    background: rgba(255, 255, 255, 0.6);
    color: #3e2d1c;
    font-family: var(--font-display);
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: sticky;
    bottom: 1.2rem;
}

.btn-notes-reset:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(43, 34, 22, 0.2);
}

.btn-notes-reset.is-hidden {
    display: none;
}

.case-summary {
    font-family: var(--font-notes);
    font-size: 1.225rem;
    color: #2b2216;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.case-summary p {
    margin: 0;
}

.clues-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.clue-section {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.clue-list {
    list-style: disc;
    padding-left: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clue-list-item {
    padding: 0.2rem 0;
}

.clue-section-bio {
    font-family: var(--font-notes);
    font-size: 1.225rem;
    color: #3e2d1c;
    margin-top: -0.2rem;
}

.clue-section-title {
    font-family: var(--font-display);
    color: #6a4420;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

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

.clue-list-item .clue-text {
    font-family: var(--font-notes);
    font-size: 1.225rem;
    line-height: 1.6;
    color: #2b2216;
}

/* Markdown styling within clues */
.clue-text p {
    margin: 0 0 0.5rem 0;
}

.clue-text p:last-child {
    margin-bottom: 0;
}

.clue-text strong {
    color: #5b3a1a;
    font-weight: 700;
}

.clue-text em {
    font-style: italic;
}

.clue-text code {
    background: rgba(43, 34, 22, 0.12);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Special Elite', 'Courier New', monospace;
    font-size: 0.85em;
}

.no-clues {
    text-align: center;
    color: #6a5b44;
    font-style: italic;
    padding: 2rem;
}

/* Modal */
.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;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #1f1710 0%, #120d08 100%);
    padding: 3rem;
    border-radius: 15px;
    max-width: 600px;
    text-align: center;
    border: 2px solid var(--accent-brass);
    box-shadow: 0 0 30px rgba(214, 178, 109, 0.45);
}

.modal-content h2 {
    font-family: var(--font-display);
    color: var(--accent-brass);
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
}

.modal-content p {
    font-size: 1.2rem;
    line-height: 1.8;
    margin-bottom: 2rem;
}

/* Loading Indicator - Inside Chat Window */
.loading-indicator {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

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

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #ff6b6b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Disabled state for input form while loading */
#chat-input:disabled,
.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Responsive Design */
@media (max-width: 1400px) {
    .game-container {
        grid-template-columns: minmax(0, 1fr) 364px auto;
        grid-template-areas: "chat clues suspects";
    }
    
    .suspects-panel {
        width: fit-content;
        min-width: 0;
    }
    
    .clues-panel {
        width: 364px;
        min-width: 364px;
    }
}

@media (max-width: 1200px) {
    .game-container {
        grid-template-columns: minmax(0, 1fr) 338px auto;
        grid-template-areas: "chat clues suspects";
    }
    
    .suspects-panel {
        width: fit-content;
        min-width: 0;
        padding: 1rem;
    }
    
    .clues-panel {
        width: 338px;
        min-width: 338px;
    }
}

@media (max-width: 768px) {
    .game-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "suspects"
            "chat"
            "clues";
    }
    
    .suspects-panel {
        max-height: 150px;
        width: 100%;
        min-width: 100%;
    }
    
    .suspects-list {
        flex-direction: row;
        overflow-x: auto;
    }
    
    .suspect-card img {
        width: 90px;
        height: 135px;
    }
    
    .clues-panel {
        max-height: 200px;
        width: 100%;
        min-width: 100%;
    }
}
