/* ============================================
   PIVOTTO - STYLES
   Fixed viewport, no scroll
   ============================================ */

:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --accent-pink: #e94560;
    --accent-gold: #f4a261;
    --text-light: #edf2f4;
    --text-muted: #8d99ae;
    --success: #06d6a0;
    --error: #ef476f;
    
    /* Fixed dialogue height */
    --dialogue-height: 200px;
}

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

html, body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-dark);
    color: var(--text-light);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
}

/* ============================================
   BACKGROUND ANIMATION
   ============================================ */

.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: 
        radial-gradient(ellipse at 20% 80%, rgba(233, 69, 96, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(244, 162, 97, 0.1) 0%, transparent 50%),
        var(--bg-dark);
}

.bg-animation::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    opacity: 0.03;
    pointer-events: none;
}

/* ============================================
   SCREENS - Full viewport, no scroll
   ============================================ */

.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 2rem;
    animation: fadeIn 0.5s ease-out;
    overflow: hidden;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

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

/* ============================================
   TITLE SCREEN
   ============================================ */

.title-screen {
    text-align: center;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.title-logo {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(2.5rem, 8vw, 5rem);
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    animation: glow 3s ease-in-out infinite alternate;
}

@keyframes glow {
    from { filter: drop-shadow(0 0 20px rgba(233, 69, 96, 0.3)); }
    to { filter: drop-shadow(0 0 40px rgba(244, 162, 97, 0.4)); }
}

.title-subtitle {
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-style: italic;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    padding: 0.875rem 2.5rem;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-gold));
    color: white;
    box-shadow: 0 10px 30px rgba(233, 69, 96, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(233, 69, 96, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--accent-pink);
    color: var(--accent-pink);
}

.btn-secondary:hover {
    background: var(--accent-pink);
    color: white;
}

/* ============================================
   FORMS
   ============================================ */

.settings-container,
.upload-container {
    max-width: 500px;
    width: 100%;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.settings-title,
.upload-title,
.character-title {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1.5rem, 4vw, 2rem);
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--accent-gold);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    color: var(--text-light);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent-pink);
}

.form-select option {
    background: var(--bg-dark);
    color: var(--text-light);
}

.api-help {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.api-help a {
    color: var(--accent-gold);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.checkbox-label input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-pink);
}

/* ============================================
   UPLOAD SCREEN
   ============================================ */

.upload-zone {
    border: 3px dashed rgba(255,255,255,0.2);
    border-radius: 20px;
    padding: 3rem 2rem;
    margin: 1.5rem 0;
    transition: all 0.3s;
    cursor: pointer;
    text-align: center;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-pink);
    background: rgba(233, 69, 96, 0.1);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.upload-text {
    color: var(--text-muted);
}

.file-info {
    background: rgba(255,255,255,0.05);
    padding: 0.875rem;
    border-radius: 10px;
    margin: 1rem 0;
    display: none;
}

.file-info.visible {
    display: block;
}

/* ============================================
   CHARACTER SELECTION
   ============================================ */

.character-select {
    max-width: 900px;
    width: 100%;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}

.character-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    overflow-y: auto;
    flex: 1;
    max-height: calc(100vh - 250px);
}

.character-card {
    background: var(--bg-card);
    border-radius: 15px;
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    border: 3px solid transparent;
}

.character-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.character-card.selected {
    border-color: var(--accent-pink);
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.3);
}

.character-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    margin: 0 auto 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    overflow: hidden;
}

.character-avatar .avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.character-type {
    font-size: 0.75rem;
    color: var(--accent-pink);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.character-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   GAME SCREEN - Fixed layout
   ============================================ */

#gameScreen.active {
    padding: 1rem;
}

.game-container {
    width: 100%;
    height: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    flex-shrink: 0;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    margin-right: 1rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-pink), var(--accent-gold));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.score-display {
    font-size: 0.9rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Game Scene - Fixed proportions */
.game-scene {
    flex: 1;
    background: var(--bg-card);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0; /* Important for flex child */
}

/* Background image */
.scene-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: cover;
    background-position: center;
    z-index: 1;
}

.scene-background::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to bottom,
        rgba(22, 33, 62, 0.3) 0%,
        rgba(22, 33, 62, 0.5) 50%,
        rgba(22, 33, 62, 0.95) 85%,
        rgba(22, 33, 62, 1) 100%
    );
}

/* Character Display - Flexible area above dialogue */
.character-display {
    position: relative;
    z-index: 2;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 10px;
    min-height: 0;
}

.character-sprite {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 100%;
}

.sprite-image {
    max-height: 100%;
    max-width: 90%;
    width: auto;
    object-fit: contain;
    animation: float 3s ease-in-out infinite;
}

.sprite-emoji {
    font-size: clamp(4rem, 15vh, 10rem);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Dialogue Box - FIXED HEIGHT */
.dialogue-box {
    position: relative;
    z-index: 10;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(10px);
    padding: 1.25rem 1.5rem;
    height: var(--dialogue-height);
    min-height: var(--dialogue-height);
    max-height: var(--dialogue-height);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
}

.dialogue-box.active {
    display: flex;
}

.speaker-name {
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 0.5rem;
    font-size: 1rem;
    flex-shrink: 0;
}

.dialogue-text {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1rem, 2.5vw, 1.15rem);
    line-height: 1.7;
    flex: 1;
    overflow-y: auto;
}

.dialogue-text .typing-cursor {
    display: inline-block;
    width: 3px;
    height: 1em;
    background: var(--accent-pink);
    margin-left: 2px;
    animation: blink 0.8s infinite;
}

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

.continue-hint {
    text-align: right;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

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

/* Question Container - SAME FIXED HEIGHT as dialogue */
.question-container {
    position: relative;
    z-index: 10;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    padding: 1.25rem 1.5rem;
    height: var(--dialogue-height);
    min-height: var(--dialogue-height);
    max-height: var(--dialogue-height);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
}

.question-container.active {
    display: flex;
}

.question-text {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(0.95rem, 2vw, 1.1rem);
    margin-bottom: 0.75rem;
    color: var(--accent-gold);
    flex-shrink: 0;
}

.answer-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

.answer-btn {
    padding: 0.625rem 1rem;
    background: rgba(255,255,255,0.05);
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-light);
    font-family: 'Outfit', sans-serif;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
}

.answer-btn:hover:not(:disabled) {
    border-color: var(--accent-pink);
    background: rgba(233, 69, 96, 0.1);
}

.answer-btn.correct {
    border-color: var(--success);
    background: rgba(6, 214, 160, 0.2);
}

.answer-btn.incorrect {
    border-color: var(--error);
    background: rgba(239, 71, 111, 0.2);
}

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

/* ============================================
   ENDING SCREEN
   ============================================ */

.ending-container {
    max-width: 600px;
    width: 100%;
    text-align: center;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ending-title {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(2rem, 6vw, 3rem);
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
}

.ending-character {
    margin: 1rem 0;
    height: clamp(120px, 25vh, 200px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ending-sprite-image {
    max-height: 100%;
    width: auto;
}

.ending-sprite-emoji {
    font-size: clamp(5rem, 15vh, 8rem);
}

.ending-message {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    line-height: 1.7;
    color: var(--text-light);
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    background: rgba(255,255,255,0.05);
    border-radius: 15px;
    flex-shrink: 0;
    max-height: 30vh;
    overflow-y: auto;
}

.ending-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.stat {
    text-align: center;
}

.stat-value {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 700;
    color: var(--accent-gold);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 46, 0.95);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

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

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent-pink);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-text {
    color: var(--text-muted);
    font-size: 1.1rem;
    text-align: center;
    white-space: pre-line;
}

/* ============================================
   PRIVACY NOTICE
   ============================================ */

.privacy-notice {
    max-width: 450px;
    margin-top: 1.5rem;
    padding: 0.875rem;
    background: rgba(255,255,255,0.03);
    border-radius: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.privacy-notice a {
    color: var(--accent-gold);
}

/* ============================================
   BUTTON GROUPS
   ============================================ */

.button-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
    flex-shrink: 0;
}

/* ============================================
   FOOTER
   ============================================ */

.footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.footer a {
    color: var(--accent-gold);
    text-decoration: none;
    transition: color 0.3s;
}

.footer a:hover {
    color: var(--accent-pink);
}

/* ============================================
   RESPONSIVE - Maintain fixed layout
   ============================================ */

@media (max-width: 768px) {
    :root {
        --dialogue-height: 180px;
    }
    
    .screen {
        padding: 1rem;
    }

    .character-grid {
        grid-template-columns: repeat(2, 1fr);
        max-height: calc(100vh - 200px);
    }

    .answer-options {
        grid-template-columns: 1fr;
    }

    .ending-stats {
        gap: 1.5rem;
    }
    
    .btn {
        padding: 0.75rem 2rem;
        font-size: 0.9rem;
    }
}

@media (max-height: 600px) {
    :root {
        --dialogue-height: 150px;
    }
    
    .character-grid {
        max-height: calc(100vh - 180px);
    }
    
    .ending-message {
        max-height: 20vh;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --dialogue-height: 120px;
    }
    
    .game-header {
        padding: 0.25rem 0;
    }
    
    .dialogue-box,
    .question-container {
        padding: 0.75rem 1rem;
    }
}
