/* Rex - Harald's Dino Friend */
/* Designed for accessibility and engagement */

:root {
    --bg-color: #f5f7fa;
    --chat-bg: #ffffff;
    --rex-color: #4CAF50;
    --rex-bg: #e8f5e9;
    --user-color: #2196F3;
    --user-bg: #e3f2fd;
    --game-color: #FF9800;
    --game-bg: #FFF3E0;
    --text-color: #333333;
    --border-radius: 16px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* App Container - holds chat and game panel side by side */
.app-container {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    max-height: 850px;
}

.container {
    flex: 1;
    min-width: 0;
    max-width: 600px;
    background: var(--chat-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--rex-color);
    color: white;
}

.logo {
    font-size: 32px;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    font-size: 18px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

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

.rex-message {
    align-self: flex-start;
    background: var(--rex-bg);
    border: 2px solid var(--rex-color);
}

.user-message {
    align-self: flex-end;
    background: var(--user-bg);
    border: 2px solid var(--user-color);
}

.message-content {
    word-wrap: break-word;
}

.feedback-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 12px;
}

.feedback-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: white;
    border: 3px solid #ddd;
    border-radius: 12px;
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-btn .btn-icon {
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
}

.feedback-btn .btn-label {
    font-size: 14px;
    font-weight: 600;
}

.feedback-btn:hover {
    transform: scale(1.05);
}

.thumbs-up {
    color: var(--rex-color);
}

.thumbs-up:hover {
    border-color: var(--rex-color);
    background: var(--rex-bg);
}

.thumbs-down {
    color: #f44336;
}

.thumbs-down:hover {
    border-color: #f44336;
    background: #ffebee;
}

.feedback-btn.selected {
    transform: scale(1.1);
}

.thumbs-up.selected {
    border-color: var(--rex-color);
    background: var(--rex-bg);
}

.thumbs-down.selected {
    border-color: #f44336;
    background: #ffebee;
}

/* Input Area */
.input-area {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    background: #fafafa;
    border-top: 1px solid #eee;
}

#message-input {
    flex: 1;
    padding: 14px 18px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    outline: none;
    transition: border-color 0.2s;
}

#message-input:focus {
    border-color: var(--rex-color);
}

.send-btn {
    padding: 14px 24px;
    font-size: 18px;
    font-weight: 600;
    background: var(--rex-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.send-btn:hover {
    background: #43a047;
}

.send-btn:active {
    transform: scale(0.98);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Loading indicator */
.loading {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.loading span {
    width: 8px;
    height: 8px;
    background: var(--rex-color);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }
.loading span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ==================== */
/* Game Panel Styles    */
/* ==================== */

.game-panel {
    width: 450px;
    min-width: 400px;
    background: var(--chat-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

.game-panel.visible {
    display: flex !important;
}

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

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--game-color);
    color: white;
}

.game-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.close-game-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.close-game-btn:hover {
    background: rgba(255,255,255,0.3);
}

.game-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

/* Image Viewer */
.image-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 16px;
}

.image-viewer img {
    max-width: 100%;
    max-height: 500px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    object-fit: contain;
}

.image-viewer .feedback-buttons {
    margin-top: 8px;
}

/* Video Viewer */
.video-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.video-container {
    width: 100%;
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.video-info {
    text-align: center;
    padding: 8px;
}

.video-info h3 {
    font-size: 16px;
    color: var(--text-color);
    margin-bottom: 4px;
    line-height: 1.3;
}

.video-info p {
    font-size: 14px;
    color: #666;
}

.video-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

.video-nav-btn {
    font-size: 24px;
    background: var(--game-bg);
    border: 2px solid var(--game-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-nav-btn:hover:not(:disabled) {
    background: var(--game-color);
    transform: scale(1.1);
}

.video-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.video-counter {
    font-size: 16px;
    font-weight: 600;
    color: var(--game-color);
}

/* Search Results */
.search-results {
    text-align: center;
}

.search-results h3 {
    font-size: 18px;
    color: var(--game-color);
    margin-bottom: 16px;
}

.search-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.search-item {
    background: #fafafa;
    border: 2px solid #ddd;
    border-radius: 12px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.search-item:hover {
    border-color: var(--game-color);
    transform: scale(1.03);
}

.search-item img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

.search-item .search-item-title {
    font-size: 12px;
    margin-top: 6px;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Game Menu */
.game-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-choice {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--game-bg);
    border: 2px solid var(--game-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
}

.game-choice:hover {
    background: var(--game-color);
    color: white;
    transform: scale(1.02);
}

.game-icon {
    font-size: 32px;
}

.game-name {
    font-weight: 600;
}

/* Game Area */
.game-area {
    text-align: center;
}

.game-area h3 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--game-color);
}

.back-to-menu {
    background: none;
    border: none;
    color: var(--game-color);
    font-size: 16px;
    cursor: pointer;
    margin-bottom: 16px;
    padding: 8px;
}

.back-to-menu:hover {
    text-decoration: underline;
}

.game-btn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    background: var(--game-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    margin-top: 16px;
}

.game-btn:hover {
    background: #F57C00;
}

.game-score {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--game-color);
}

/* Match Game */
.match-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.match-card {
    aspect-ratio: 1;
    background: var(--game-bg);
    border: 2px solid var(--game-color);
    border-radius: 8px;
    font-size: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    min-height: 60px;
    position: relative;
}

.match-card .card-back,
.match-card .card-front {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: opacity 0.3s;
    border-radius: 6px;
    object-fit: cover;
}

.match-card .card-back {
    opacity: 1;
}

.match-card .card-front {
    opacity: 0;
}

.match-card.flipped .card-back {
    opacity: 0;
}

.match-card.flipped .card-front {
    opacity: 1;
}

.match-card:hover {
    transform: scale(1.05);
}

.match-card.flipped {
    background: #FFF8E1;
    border-color: var(--game-color);
}

.match-card.matched {
    border-color: var(--rex-color);
    border-width: 3px;
}

.match-card.matched .card-back {
    opacity: 0;
}

.match-card.matched .card-front {
    opacity: 1;
}

/* Roar Game */
.roar-dino {
    font-size: 120px;
    margin: 20px 0;
    transition: transform 0.2s;
}

.roar-dino.roaring {
    transform: scale(1.2);
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: scale(1.2) rotate(0); }
    25% { transform: scale(1.2) rotate(-5deg); }
    75% { transform: scale(1.2) rotate(5deg); }
}

.roar-btn {
    padding: 20px 40px;
    font-size: 24px;
    font-weight: bold;
    background: #E53935;
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.roar-btn:hover {
    background: #C62828;
    transform: scale(1.05);
}

.roar-btn:active {
    transform: scale(0.95);
}

.roar-text {
    font-size: 36px;
    font-weight: bold;
    color: #E53935;
    margin-top: 16px;
    min-height: 50px;
}

/* Color Game */
.creature-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 12px;
}

.creature-btn {
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    background: var(--game-bg);
    border: 2px solid var(--game-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.creature-btn:hover {
    background: var(--game-color);
    color: white;
}

.creature-btn.selected {
    background: var(--game-color);
    color: white;
}

.color-canvas {
    width: 100%;
    max-width: 280px;
    height: 200px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    border-radius: 12px;
    border: 2px dashed #ddd;
}

.color-canvas svg {
    width: 100%;
    height: 100%;
    max-width: 250px;
    max-height: 180px;
}

.color-palette {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.color-btn {
    width: 40px;
    height: 40px;
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: var(--shadow);
}

.color-btn:hover {
    transform: scale(1.15);
}

.color-btn.selected {
    border-color: #333;
    transform: scale(1.15);
}

/* Name Match Game */
.name-match-picture {
    width: 150px;
    height: 150px;
    margin: 16px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    border-radius: 12px;
    border: 3px solid var(--game-color);
}

.name-match-picture img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.name-match-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.name-choice-btn {
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    background: var(--game-bg);
    border: 2px solid var(--game-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.name-choice-btn:hover:not(:disabled) {
    background: var(--game-color);
    color: white;
}

.name-choice-btn.correct {
    background: var(--rex-color);
    border-color: var(--rex-color);
    color: white;
}

.name-choice-btn.wrong {
    background: #ffebee;
    border-color: #f44336;
    color: #f44336;
}

.name-choice-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Counting Game */
.counting-area {
    min-height: 150px;
    padding: 16px;
    margin: 16px 0;
    background: #fafafa;
    border-radius: 12px;
    border: 3px solid var(--game-color);
    text-align: center;
}

.count-question {
    font-size: 18px;
    font-weight: 600;
    color: var(--game-color);
    margin-bottom: 12px;
}

.count-images {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.counting-image {
    width: 50px;
    height: 50px;
    object-fit: contain;
    animation: pop 0.3s ease backwards;
}

@keyframes pop {
    0% { transform: scale(0); opacity: 0; }
    80% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.counting-choices {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.count-choice-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    font-weight: bold;
    background: var(--game-bg);
    border: 3px solid var(--game-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.count-choice-btn:hover:not(:disabled) {
    background: var(--game-color);
    color: white;
    transform: scale(1.1);
}

.count-choice-btn.correct {
    background: var(--rex-color);
    border-color: var(--rex-color);
    color: white;
    transform: scale(1.1);
}

.count-choice-btn.wrong {
    background: #ffebee;
    border-color: #f44336;
    color: #f44336;
}

.count-choice-btn:disabled {
    cursor: not-allowed;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar,
.game-content::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-track,
.game-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-area::-webkit-scrollbar-thumb,
.game-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.chat-area::-webkit-scrollbar-thumb:hover,
.game-content::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Responsive */
@media (max-width: 800px) {
    .app-container {
        flex-direction: column;
        max-width: 600px;
    }

    .game-panel {
        width: 100%;
        max-height: 50vh;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }

    .app-container {
        height: 100vh;
        max-height: none;
        gap: 0;
    }

    .container {
        border-radius: 0;
    }

    .game-panel {
        border-radius: 0;
    }

    .message {
        font-size: 16px;
    }

    #message-input,
    .send-btn {
        font-size: 16px;
    }
}
