/* RESET & VARIABLES */
:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --surface-light: #2c2c2c;
    --primary-color: #3b82f6;
    /* Architecture Blue */
    --accent-color: #f59e0b;
    /* Safety Orange */
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --border-color: #333;
    --radius-lg: 16px;
    --radius-md: 8px;
    --transition: all 0.3s ease;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-family);
    overflow: hidden;
    /* Prevent body scroll, handle inside containers if needed */
    height: 100vh;
    width: 100vw;
}

/* UTILITIES */
.hidden {
    display: none !important;
}

.btn {
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: var(--transition);
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #3a3a3a;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-text {
    font-size: 1.2rem;
    display: block;
}

.btn-sub {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    opacity: 0.8;
    margin-top: 4px;
}

.btn-lg {
    padding: 2rem;
    min-width: 250px;
    flex-direction: column;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.btn-full {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    margin-top: 1rem;
}

/* LAYOUT & SCREENS */
.app-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    /* Default flex for centering */
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 0;
    background: var(--bg-color);
    /* Ensure opaque background */
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

/* HOMEPAGE */
#home-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    /* Fallback background */
    background: #121212;
}

/* VIDEO BACKGROUND */
#bg-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2;
}

.hero-content {
    z-index: 3;
    background: rgba(40, 40, 40, 0.3);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    padding: 3rem;
    border-radius: var(--radius-lg);
    max-width: 90%;
    width: 700px;
    margin: 0 auto;
    animation: fadeIn 1s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.logo {
    font-size: 3rem;
    /* Responsive adjustment for mobile baseline */
    margin-bottom: 0.5rem;
    letter-spacing: -2px;
    background: linear-gradient(to right, #fff, #bbb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    /* Helps legibility on video */
}

.tagline {
    font-size: 1.1rem;
    color: #e0e0e0;
    /* Brighter for glass */
    margin-bottom: 3rem;
}

.action-buttons {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* FORMS & CARDS */
.card {
    background: var(--surface-color);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    margin: auto;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    position: relative;
}

.btn-back {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-back:hover {
    color: var(--text-main);
    text-decoration: underline;
}

h2 {
    margin-bottom: 0.5rem;
    font-size: 2rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 1rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: white;
    font-family: inherit;
    font-size: 1rem;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    border-color: transparent;
}

/* CUSTOM FILE UPLOAD */
.file-upload-group input[type="file"] {
    display: none;
}

.file-label {
    background: var(--surface-light);
    border: 2px dashed var(--border-color);
    padding: 1.5rem;
    text-align: center;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-label:hover {
    border-color: var(--primary-color);
    background: #333;
}

/* UPLOAD FEEDBACK */
.upload-feedback {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--surface-light);
    border: 1px solid var(--primary-color);
    /* Indicates success/selection */
    border-radius: var(--radius-md);
    margin-top: 0;
    /* Since label hides, this replaces it */
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1;
    overflow: hidden;
}

.uploaded-icon {
    font-size: 1.2rem;
}

#selected-filename {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* max-width controlled by flex */
    font-weight: 500;
    color: var(--text-main);
}

#btn-remove-image {
    background: transparent;
    border: 1px solid var(--border-color);
    color: #ef4444;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-left: 1rem;
    white-space: nowrap;
}

#btn-remove-image:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* RADIO GROUP */
.radio-group {
    display: flex;
    gap: 1rem;
}

.radio-label {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.radio-label input {
    position: absolute;
    opacity: 0;
}

.radio-label span {
    display: block;
    padding: 0.8rem;
    text-align: center;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.radio-label input:checked+span {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* GIVE SELECTION GRID */
.category-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.8rem;
    margin-top: 1.5rem;
}

.cat-btn {
    padding: 1rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
    text-align: left;
}

.cat-btn:hover {
    border-color: var(--primary-color);
    transform: translateX(5px);
}

/* WAITING SCREEN */
#waiting-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.loader-content {
    max-width: 400px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid var(--surface-light);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 2rem auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#waiting-text {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

#waiting-subtext {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* SESSION UI */
#session-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.session-header {
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--surface-color);
    flex-shrink: 0;
}

.timer-display {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#session-topic {
    border-left: 1px solid var(--border-color);
    padding-left: 1rem;
    margin-left: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.session-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Mobile first: text below image */
    overflow: hidden;
}

/* WORK AREA (IMAGE + CANVAS) */
.work-area {
    flex: 2;
    position: relative;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 20px;
}

.canvas-wrapper {
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    max-height: 100%;
}

#session-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

#drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
    /* Important for drawing on touch */
}

/* TOOLS */
.tools-dock {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.9);
    backdrop-filter: blur(10px);
    padding: 0.8rem;
    border-radius: 50px;
    display: flex;
    gap: 1rem;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.tool-btn.active,
.tool-btn:hover {
    background: var(--surface-light);
}

.color-picker {
    display: flex;
    gap: 5px;
    border-left: 1px solid #555;
    padding-left: 10px;
    border-right: 1px solid #555;
    padding-right: 10px;
}

.color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
}

.color-dot.active {
    border-color: white;
    transform: scale(1.2);
}

/* CHAT PANEL */
.chat-panel {
    flex: 1;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.chat-header {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.safety-badge {
    font-size: 0.7rem;
    background: #22c55e;
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.message {
    max-width: 80%;
    padding: 0.8rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
}

.message.received {
    background: var(--surface-light);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.message.sent {
    background: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.system-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.chat-input-area {
    padding: 1rem;
    background: var(--surface-light);
    display: flex;
    gap: 0.5rem;
}

#chat-input {
    padding: 0.8rem;
    border: none;
    background: var(--bg-color);
    border-radius: 30px;
}

.btn-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-disclaimer {
    font-size: 0.7rem;
    color: #666;
    text-align: center;
    padding: 4px;
}

/* RESPONSIVE & MOBILE OPTIMIZATIONS */

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior: none;
}

/* Allow scrolling on form screens, lock session screen */
.screen {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#session-screen,
#home-screen {
    overflow: hidden;
}

/* Mobile Button Adjustments */
@media (max-width: 480px) {
    .btn-lg {
        min-width: 100%;
        /* Full width on small phones */
        padding: 1.5rem;
    }

    .logo {
        font-size: 2.5rem;
        /* Smaller logo */
    }

    .card {
        padding: 1.5rem;
        width: 95%;
    }
}

/* RESPONSIVE LAYOUTS */
@media (min-width: 768px) {
    .app-container {
        max-width: 100%;
    }

    #home-screen {
        padding: 0;
    }

    .hero-content {
        padding: 4rem;
    }

    .logo {
        font-size: 5rem;
    }

    .action-buttons {
        flex-direction: row;
    }

    /* Session: Horizontal Layout */
    .session-workspace {
        flex-direction: row;
    }

    .work-area {
        flex: 3;
        padding: 40px;
        order: 1;
    }

    .chat-panel {
        flex: 1;
        border-top: none;
        border-left: 1px solid var(--border-color);
        min-height: auto;
        max-width: 350px;
        order: 2;
    }
}

/* MOBILE SESSION LAYOUT (Default / < 768px) */
@media (max-width: 767px) {
    .session-workspace {
        flex-direction: column;
    }

    .work-area {
        flex: 1;
        /* Takes available space */
        padding: 10px;
        min-height: 50vh;
        /* Ensure canvas has space */
    }

    .chat-panel {
        height: 35vh;
        /* Fixed height for chat on mobile */
        min-height: 200px;
        flex: none;
        /* Don't grow, stick to height */
    }

    .tools-dock {
        bottom: 10px;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .tool-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

/* Allow home screen to scroll on small devices if content is tall */
@media (max-height: 700px) {
    #home-screen {
        overflow-y: auto;
    }
}

.footer {
    padding: 1rem;
    color: var(--text-muted);
    align-items: center;
    text-align: center;
    font-size: 0.8rem;
    margin-top: 2rem;
    /* adequate spacing instead of absolute pos */
    width: 100%;
}