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

body {
    font-family: 'Georgia', serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    line-height: 1.6;
    position: relative;
    overflow-x: hidden;
}

/* Animated Background Particles */
body::before {
    content: '';
    position: fixed;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    animation: particleFloat 20s ease-in-out infinite;
    z-index: 0;
}

@keyframes particleFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.05); }
}

/* Container */
.container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 900px;
    width: 100%;
    overflow: hidden;
    animation: fadeIn 0.5s ease-in;
    position: relative;
    z-index: 1;
}

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

/* Scene Background Layer */
.scene-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1s ease-in-out;
    pointer-events: none;
    z-index: 0;
}

.scene-background.active {
    opacity: 0.3;
}

/* Scene Illustrations */
.scene-illustration {
    width: 100%;
    height: 250px;
    background-size: cover;
    background-position: center;
    position: relative;
    border-radius: 15px;
    margin-bottom: 25px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: sceneReveal 1s ease-out;
}

@keyframes sceneReveal {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.illustration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.4) 100%);
    animation: overlayPulse 3s ease-in-out infinite;
}

@keyframes overlayPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Scene-specific backgrounds using CSS gradients and patterns */
.scene-forest {
    background: linear-gradient(180deg, #2d5016 0%, #1a3a0f 50%, #0d1f08 100%);
    position: relative;
}

.scene-forest::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 30% 40%, rgba(76, 175, 80, 0.3) 0%, transparent 30%),
        radial-gradient(circle at 70% 60%, rgba(56, 142, 60, 0.2) 0%, transparent 40%);
    animation: forestSway 8s ease-in-out infinite;
}

@keyframes forestSway {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(10px); }
}

.scene-stream {
    background: linear-gradient(180deg, #4fc3f7 0%, #29b6f6 50%, #0288d1 100%);
    position: relative;
}

.scene-stream::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
    animation: waterFlow 3s linear infinite;
}

@keyframes waterFlow {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.scene-dark {
    background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1e 50%, #000000 100%);
    position: relative;
}

.scene-dark::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(138, 43, 226, 0.2) 0%, transparent 50%);
    animation: darkPulse 4s ease-in-out infinite;
}

@keyframes darkPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

.scene-cavern {
    background: linear-gradient(180deg, #37474f 0%, #263238 50%, #102027 100%);
    position: relative;
}

.scene-cavern::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(255, 215, 0, 0.3) 0%, transparent 30%),
        radial-gradient(circle at 80% 20%, rgba(255, 215, 0, 0.2) 0%, transparent 40%);
    animation: crystalShimmer 5s ease-in-out infinite;
}

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

.scene-ending {
    background: linear-gradient(135deg, #ffd700 0%, #ff6b6b 50%, #a770ef 100%);
    position: relative;
}

.scene-ending::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    animation: endingGlow 2s ease-in-out infinite;
}

@keyframes endingGlow {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
    font-style: italic;
}

/* Main Content */
main {
    padding: 40px;
    position: relative;
    z-index: 1;
}

#story-content {
    margin-bottom: 30px;
    position: relative;
}

#story-title {
    color: #667eea;
    font-size: 2em;
    margin-bottom: 20px;
    border-bottom: 3px solid #667eea;
    padding-bottom: 10px;
    animation: titleSlide 0.8s ease-out;
}

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

#story-text {
    font-size: 1.1em;
    color: #333;
    margin-bottom: 20px;
    text-align: justify;
    line-height: 1.8;
    min-height: 60px;
}

/* Typing Effect Cursor */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background-color: #667eea;
    margin-left: 2px;
    animation: blink 0.7s infinite;
    vertical-align: text-bottom;
    opacity: 0;
}

.typing-cursor.active {
    opacity: 1;
}

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

/* Text Animation Classes */
.text-typing {
    overflow: hidden;
    border-right: 2px solid #667eea;
    white-space: nowrap;
    animation: typing 2s steps(40, end);
}

.text-fade-in {
    animation: textFadeIn 1s ease-in;
}

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

/* Dramatic Scene Transitions */
.dramatic-entrance {
    animation: dramaticEntrance 1.5s ease-out;
}

@keyframes dramaticEntrance {
    0% {
        opacity: 0;
        transform: scale(0.8) rotateX(90deg);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.05) rotateX(45deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotateX(0deg);
    }
}

.shake-animation {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.flash-animation {
    animation: flash 0.5s ease-in-out;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; background-color: rgba(255, 255, 255, 0.9); }
}

/* Choices */
#choices-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

.choice-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 25px;
    font-size: 1.1em;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    position: relative;
    overflow: hidden;
}

.choice-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.choice-btn:hover::before {
    width: 300px;
    height: 300px;
}

.choice-btn:nth-child(1) { animation: choiceSlideIn 0.5s ease-out 0.1s backwards; }
.choice-btn:nth-child(2) { animation: choiceSlideIn 0.5s ease-out 0.2s backwards; }
.choice-btn:nth-child(3) { animation: choiceSlideIn 0.5s ease-out 0.3s backwards; }
.choice-btn:nth-child(4) { animation: choiceSlideIn 0.5s ease-out 0.4s backwards; }

@keyframes choiceSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50px) rotateY(-90deg);
    }
    to {
        opacity: 1;
        transform: translateX(0) rotateY(0deg);
    }
}

.choice-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.choice-btn:active {
    transform: translateY(-1px) scale(0.98);
    animation: buttonPress 0.2s ease-out;
}

@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(0.98); }
}

/* Controls */
#controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.control-btn {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.control-btn:hover:not(:disabled) {
    background: #667eea;
    color: white;
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progress Bar */
#progress-bar {
    height: 8px;
    background: #e0e0e0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.5s ease;
}

/* Footer */
footer {
    background: #f5f5f5;
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 0.9em;
}

#decision-count {
    font-weight: bold;
    color: #667eea;
}

/* Ending Styles */
.ending {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
    animation: endingGlow 2s ease-in-out infinite;
}

@keyframes endingGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(240, 147, 251, 0.5);
    }
    50% {
        box-shadow: 0 0 30px rgba(240, 147, 251, 0.8);
    }
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.4s ease;
}

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

.modal-content h2 {
    color: #667eea;
    margin-bottom: 30px;
    text-align: center;
    font-size: 2em;
}

.character-preview {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: #f4c7ab;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.avatar-face {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
}

.avatar-face::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 30px;
    background: #2c1810;
    border-radius: 50% 50% 0 0;
}

.avatar-face::after {
    content: '👤';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 60px;
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: bold;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1em;
    transition: border 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.color-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.color-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
}

.color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

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

.start-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}

/* Character Info Panel */
.character-panel {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 3px solid #667eea;
}

.character-mini-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #f4c7ab;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.mini-avatar-face {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
}

.mini-avatar-face::after {
    content: '👤';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 30px;
}

.character-info {
    flex-grow: 1;
}

.character-info h3 {
    margin: 0 0 5px 0;
    color: #667eea;
    font-size: 1.3em;
}

.character-class-display,
.character-trait-display {
    margin: 2px 0;
    color: #666;
    font-size: 0.9em;
}

.customize-btn {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.customize-btn:hover {
    background: #764ba2;
    transform: translateY(-2px);
}

/* Audio Controls */
.audio-controls {
    display: flex;
    gap: 10px;
}

.audio-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(102, 126, 234, 0.2);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s ease;
}

.audio-btn:hover {
    background: rgba(102, 126, 234, 0.4);
    transform: scale(1.1);
}

.audio-btn.muted {
    opacity: 0.4;
}

/* Dialogue System */
.dialogue-box {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(50, 50, 80, 0.95) 100%);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: dialogueSlide 0.5s ease-out;
}

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

.dialogue-box.hidden {
    display: none;
}

.dialogue-character {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.dialogue-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid white;
}

.dialogue-speaker {
    color: #ffd700;
    font-weight: bold;
    font-size: 1.2em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.dialogue-content {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.dialogue-text {
    color: white;
    font-size: 1.1em;
    line-height: 1.6;
    margin-bottom: 15px;
    font-style: italic;
}

.dialogue-continue {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.dialogue-continue:hover {
    background: #764ba2;
    transform: translateX(5px);
}

/* Endings Display */
.endings-display {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 15px;
    padding: 25px;
    margin: 30px 0;
    border: 2px solid #667eea;
}

.endings-display.hidden {
    display: none;
}

.endings-display h3 {
    color: #667eea;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.5em;
}

#endings-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.ending-card {
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    transition: all 0.3s ease;
}

.ending-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.ending-card.locked {
    opacity: 0.4;
    filter: grayscale(100%);
}

.ending-card .ending-icon {
    font-size: 2em;
    margin-bottom: 10px;
}

.ending-card .ending-name {
    font-weight: bold;
    color: #667eea;
    margin-bottom: 5px;
}

.ending-card .ending-description {
    font-size: 0.85em;
    color: #666;
}

/* Achievement Badge */
.achievement-badge {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    z-index: 3000;
    animation: achievementPop 0.6s ease-out forwards;
}

@keyframes achievementPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2) rotate(10deg);
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

.achievement-badge h2 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2em;
}

.achievement-badge p {
    color: #666;
    font-size: 1.2em;
}

/* Notification Toast */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #667eea;
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 2000;
}

.notification.show {
    transform: translateX(0);
}

/* Class-specific styling */
.class-warrior {
    border-left: 5px solid #ff4444;
}

.class-mage {
    border-left: 5px solid #4444ff;
}

.class-rogue {
    border-left: 5px solid #44ff44;
}

.class-ranger {
    border-left: 5px solid #ff8844;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }
    
    main {
        padding: 20px;
    }
    
    #story-title {
        font-size: 1.5em;
    }
    
    #story-text {
        font-size: 1em;
    }
    
    .choice-btn {
        font-size: 1em;
        padding: 12px 20px;
    }

    .character-panel {
        flex-wrap: wrap;
        justify-content: center;
    }

    .audio-controls {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }

    .modal-content {
        padding: 20px;
    }

    .notification {
        right: 10px;
        left: 10px;
        top: 10px;
    }

    #endings-list {
        grid-template-columns: 1fr;
    }

    .dialogue-box {
        padding: 15px;
    }

    .scene-illustration {
        height: 180px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    #controls {
        flex-direction: column;
    }
    
    .control-btn {
        width: 100%;
    }

    .character-panel {
        padding: 15px;
    }

    .character-mini-avatar {
        width: 50px;
        height: 50px;
    }

    .achievement-badge {
        padding: 20px;
        width: 90%;
    }

    .achievement-badge h2 {
        font-size: 1.5em;
    }

    .scene-illustration {
        height: 150px;
    }

    main {
        padding: 15px;
    }
}

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

.loading-spinner {
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}