/* Fantasy RPG Styles */
:root {
    --fantasy-gold: #DAA520;
    --fantasy-brown: #8B4513;
    --fantasy-dark: #2F1B14;
    --fantasy-light: #F4E4BC;
    --fantasy-green: #228B22;
    --fantasy-blue: #4682B4;
    --fantasy-red: #DC143C;
    --purple-dark: #4A148C;
    --purple-medium: #7B1FA2;
    --purple-light: #9C27B0;
    --yellow-bright: #FFD700;
}

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

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255, 165, 0, 0.8) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(0, 255, 255, 0.6) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 0, 0, 0.7) 0%, transparent 30%),
        radial-gradient(circle at 90% 90%, rgba(255, 255, 0, 0.5) 0%, transparent 40%),
        radial-gradient(circle at 10% 10%, rgba(255, 165, 0, 0.6) 0%, transparent 35%),
        radial-gradient(circle at 70% 80%, rgba(0, 255, 255, 0.4) 0%, transparent 45%),
        radial-gradient(circle at 30% 90%, rgba(255, 0, 0, 0.5) 0%, transparent 40%),
        radial-gradient(circle at 60% 10%, rgba(255, 255, 0, 0.6) 0%, transparent 35%),
        linear-gradient(135deg, #4A148C 0%, #7B1FA2 25%, #8E24AA 50%, #9C27B0 75%, #AB47BC 100%);
    color: var(--fantasy-light);
    overflow: hidden;
    height: 100vh;
    animation: magicalShimmer 8s ease-in-out infinite alternate;
}

/* ============================================
   HOME PAGE STYLES
   ============================================ */

#homePage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: 
        linear-gradient(135deg, 
            #2D0A4E 0%, 
            #4A148C 15%, 
            #6A1B9A 30%, 
            #7B1FA2 45%, 
            #8E24AA 60%, 
            #9C27B0 75%, 
            #AB47BC 90%, 
            #BA68C8 100%);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
    padding-top: 20px;
}

#homePage.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Animated Yellow Dots Background */
.floating-dots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

.floating-dots::before,
.floating-dots::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--yellow-bright);
    border-radius: 50%;
    opacity: 0.15;
    box-shadow:
        /* Row 1 */
        calc(10vw) calc(10vh) 0 0 rgba(255, 215, 0, 0.2),
        calc(25vw) calc(8vh) 0 0 rgba(255, 215, 0, 0.15),
        calc(45vw) calc(12vh) 0 0 #eeff00,
        calc(65vw) calc(7vh) 0 0 rgba(255, 215, 0, 0.12),
        calc(80vw) calc(15vh) 0 0 rgba(255, 215, 0, 0.2),
        calc(92vw) calc(9vh) 0 0 rgba(255, 215, 0, 0.14),
        /* Row 2 */
        calc(5vw) calc(25vh) 0 0 rgba(255, 215, 0, 0.16),
        calc(18vw) calc(30vh) 0 0 rgba(255, 215, 0, 0.19),
        calc(35vw) calc(28vh) 0 0 rgba(255, 215, 0, 0.13),
        calc(55vw) calc(32vh) 0 0 rgba(255, 215, 0, 0.17),
        calc(72vw) calc(27vh) 0 0 rgba(255, 215, 0, 0.15),
        calc(88vw) calc(33vh) 0 0 rgba(255, 215, 0, 0.18),
        /* Row 3 */
        calc(12vw) calc(45vh) 0 0 rgba(255, 215, 0, 0.14),
        calc(28vw) calc(48vh) 0 0 rgba(255, 215, 0, 0.16),
        calc(42vw) calc(43vh) 0 0 rgba(255, 215, 0, 0.19),
        calc(60vw) calc(47vh) 0 0 rgba(255, 215, 0, 0.12),
        calc(78vw) calc(44vh) 0 0 rgba(255, 215, 0, 0.17),
        calc(95vw) calc(49vh) 0 0 rgba(255, 215, 0, 0.15),
        /* Row 4 */
        calc(8vw) calc(65vh) 0 0 rgba(255, 215, 0, 0.18),
        calc(22vw) calc(68vh) 0 0 rgba(255, 215, 0, 0.13),
        calc(38vw) calc(63vh) 0 0 rgba(255, 215, 0, 0.16),
        calc(52vw) calc(67vh) 0 0 rgba(255, 215, 0, 0.2),
        calc(68vw) calc(64vh) 0 0 rgba(255, 215, 0, 0.14),
        calc(85vw) calc(69vh) 0 0 rgba(255, 215, 0, 0.17),
        /* Row 5 */
        calc(15vw) calc(82vh) 0 0 rgba(255, 215, 0, 0.15),
        calc(32vw) calc(85vh) 0 0 rgba(255, 215, 0, 0.19),
        calc(48vw) calc(88vh) 0 0 rgba(255, 215, 0, 0.12),
        calc(63vw) calc(83vh) 0 0 rgba(255, 215, 0, 0.16),
        calc(75vw) calc(87vh) 0 0 rgba(255, 215, 0, 0.18),
        calc(90vw) calc(84vh) 0 0 rgba(255, 215, 0, 0.14);
}

.floating-dots::after {
    opacity: 0.12;
}

/* Home Container */
.home-container {
    position: relative;
    z-index: 2;
    max-width: 1400px;
    width: 95%;
    padding: 40px 20px;
}

/* Header */
.home-header {
    text-align: center;
    margin-bottom: 50px;
    animation: fadeInDown 1s ease-out;
    position: relative;
    z-index: 10;
    width: 100%;
}

.game-title {
    font-size: 4em;
    font-weight: bold;
    color: var(--yellow-bright);
    text-shadow: 
        0 0 20px rgba(255, 215, 0, 0.8),
        0 0 40px rgba(255, 215, 0, 0.5),
        3px 3px 8px rgba(0, 0, 0, 0.8);
    margin-bottom: 10px;
    letter-spacing: 2px;
    display: block;
    visibility: visible;
    opacity: 1;
    position: relative;
    z-index: 10;
}

.game-subtitle {
    font-size: 1.5em;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.8);
    font-style: italic;
}

/* Scenario Layout */
.scenario-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    animation: fadeInUp 1s ease-out 0.3s backwards;
}

/* Main Preview Area (Left - Bigger) */
.scenario-preview {
    background: 
        radial-gradient(circle at 20% 20%, rgba(255, 215, 0, 0.1) 0%, transparent 50%),
        linear-gradient(145deg, rgba(74, 20, 140, 0.4) 0%, rgba(123, 31, 162, 0.4) 100%);
    border: 3px solid var(--yellow-bright);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(255, 215, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
}

.scenario-preview:hover {
    transform: translateY(-5px);
    box-shadow: 
        0 25px 70px rgba(0, 0, 0, 0.7),
        0 0 60px rgba(255, 215, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.preview-content {
    display: flex;
    flex-direction: column;
    gap: 25px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#previewMap {
    width: 100%;
    height: 400px;
    object-fit: cover;
    border-radius: 15px;
    border: 2px solid rgba(255, 215, 0, 0.5);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
}

#previewMap:hover {
    transform: scale(1.02);
}

.preview-info {
    text-align: center;
}

#previewTitle {
    font-size: 2.5em;
    color: var(--yellow-bright);
    margin-bottom: 15px;
    text-shadow: 
        0 0 15px rgba(255, 215, 0, 0.6),
        2px 2px 6px rgba(0, 0, 0, 0.8);
}

#previewDescription {
    font-size: 1.2em;
    line-height: 1.8;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 25px;
    padding: 0 20px;
}

.start-btn {
    padding: 18px 45px;
    font-size: 1.3em;
    background: linear-gradient(135deg, var(--yellow-bright) 0%, #FFA500 100%);
    color: var(--purple-dark);
    border: 3px solid var(--yellow-bright);
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 8px 20px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(255, 215, 0, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 
        0 12px 30px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(255, 215, 0, 0.6);
    background: linear-gradient(135deg, #FFA500 0%, var(--yellow-bright) 100%);
}

.start-btn:active {
    transform: translateY(-1px) scale(1.02);
}

/* Scenario Selector (Right) */
.scenario-selector {
    background: 
        radial-gradient(circle at 80% 20%, rgba(255, 215, 0, 0.08) 0%, transparent 60%),
        linear-gradient(145deg, rgba(74, 20, 140, 0.3) 0%, rgba(123, 31, 162, 0.3) 100%);
    border: 3px solid rgba(255, 215, 0, 0.6);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 
        0 15px 40px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    position: relative;
}

/* Difficulty Progression Arrow */
.scenario-selector::after {
    content: '↓';
    position: absolute;
    right: -50px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3em;
    color: rgba(255, 215, 0, 0.6);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.scenario-selector::before {
    content: '';
    position: absolute;
    right: -40px;
    top: 80px;
    bottom: 80px;
    width: 3px;
    background: linear-gradient(to bottom, 
        rgba(76, 175, 80, 0.6) 0%,
        rgba(255, 152, 0, 0.6) 33%,
        rgba(244, 67, 54, 0.6) 66%,
        rgba(156, 39, 176, 0.6) 100%);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.difficulty-label {
    position: absolute;
    right: -130px;
    font-size: 0.9em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.difficulty-label.easier {
    top: 90px;
    color: rgba(76, 175, 80, 1);
}

.difficulty-label.harder {
    bottom: 90px;
    color: rgba(244, 67, 54, 1);
}

.scenario-selector h3 {
    font-size: 1.8em;
    color: var(--yellow-bright);
    text-align: center;
    margin-bottom: 25px;
    text-shadow: 
        0 0 10px rgba(255, 215, 0, 0.5),
        2px 2px 4px rgba(0, 0, 0, 0.8);
}

.scenario-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.scenario-card {
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.05) 0%, transparent 70%),
        linear-gradient(135deg, rgba(123, 31, 162, 0.4) 0%, rgba(74, 20, 140, 0.4) 100%);
    border: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.scenario-card.locked {
    background: 
        linear-gradient(135deg, rgba(80, 80, 80, 0.4) 0%, rgba(50, 50, 50, 0.4) 100%);
    border: 2px solid rgba(128, 128, 128, 0.3);
    cursor: not-allowed;
    opacity: 0.6;
}

.scenario-card.locked:hover {
    transform: none;
    border-color: rgba(128, 128, 128, 0.3);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    background: 
        linear-gradient(135deg, rgba(80, 80, 80, 0.4) 0%, rgba(50, 50, 50, 0.4) 100%);
}

.scenario-card.locked .scenario-icon {
    filter: grayscale(100%) opacity(0.5);
}

.scenario-card.locked .scenario-details h4 {
    color: #999;
}

.coming-soon-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, #FF6B6B 0%, #C92A2A 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

.scenario-card:hover {
    transform: translateX(5px);
    border-color: var(--yellow-bright);
    box-shadow: 
        0 8px 25px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(255, 215, 0, 0.3);
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.1) 0%, transparent 70%),
        linear-gradient(135deg, rgba(123, 31, 162, 0.5) 0%, rgba(74, 20, 140, 0.5) 100%);
}

.scenario-card.active {
    border-color: var(--yellow-bright);
    border-width: 3px;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.5),
        0 0 30px rgba(255, 215, 0, 0.5),
        inset 0 0 20px rgba(255, 215, 0, 0.1);
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.15) 0%, transparent 70%),
        linear-gradient(135deg, rgba(156, 39, 176, 0.6) 0%, rgba(123, 31, 162, 0.6) 100%);
}

.scenario-icon {
    font-size: 3em;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

.scenario-details {
    flex: 1;
}

.scenario-details h4 {
    font-size: 1.3em;
    color: var(--yellow-bright);
    margin-bottom: 5px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

/* Hide difficulty badges - using progression arrow instead */
.difficulty {
    display: none;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Responsive Design for Home Page */
@media (max-width: 1600px) {
    .home-container {
        padding: 30px 15px;
    }
    
    .game-title {
        font-size: 3.5em;
    }
}

@media (max-width: 1024px) {
    .scenario-layout {
        grid-template-columns: 1fr;
    }
    
    .game-title {
        font-size: 3em;
    }
    
    #previewMap {
        height: 300px;
    }
    
    .scenario-selector::after,
    .scenario-selector::before,
    .difficulty-label {
        display: none;
    }
}

@media (max-width: 768px) {
    .game-title {
        font-size: 2.5em;
    }
    
    .game-subtitle {
        font-size: 1.2em;
    }
    
    #previewTitle {
        font-size: 2em;
    }
    
    #previewDescription {
        font-size: 1em;
    }
    
    .scenario-card {
        padding: 15px;
    }
    
    .scenario-icon {
        font-size: 2.5em;
    }
}

/* Small screens with low height (like Chromebooks 1518x853) */
@media (max-height: 900px) {
    .home-container {
        padding: 20px 15px;
    }
    
    .home-header {
        margin-bottom: 30px;
    }
    
    .game-title {
        font-size: 3em !important;
        margin-bottom: 5px;
    }
    
    .game-subtitle {
        font-size: 1.3em;
    }
}

/* ============================================
   END HOME PAGE STYLES
   ============================================ */

#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Main Game Canvas */
#gameCanvas {
    border: 4px solid var(--fantasy-gold);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(218, 165, 32, 0.5);
    background: #000;
}

/* Interface Styling */
.interface {
    position: absolute;
    z-index: 10;
    transition: all 0.3s ease-in-out;
}

.interface.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
    display: none !important;
}

/* ============================================
   NEW DIALOGUE INTERFACE - REVAMPED
   ============================================ */

#dialogueInterface {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15;
    visibility: visible;
}

#dialogueInterface:not(.hidden) {
    display: flex !important;
    visibility: visible !important;
}

#dialogueInterface.hidden {
    display: none !important;
    visibility: hidden;
    opacity: 0;
}

#dialogueBox {
    width: 95vw;
    height: 90vh;
    max-width: 1400px;
    max-height: 900px;
    background: 
        radial-gradient(circle at 10% 20%, rgba(255, 215, 0, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(138, 43, 226, 0.12) 0%, transparent 50%),
        linear-gradient(145deg, rgba(74, 20, 140, 0.97) 0%, rgba(123, 31, 162, 0.97) 25%, rgba(156, 39, 176, 0.97) 75%, rgba(171, 71, 188, 0.97) 100%);
    border: 4px solid var(--fantasy-gold);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.8),
        0 10px 30px rgba(218, 165, 32, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 1600px) {
    #dialogueBox {
        max-width: 95vw;
        padding: 25px;
    }
}

@media (max-height: 900px) {
    #dialogueBox {
        height: 82vh;
        max-height: 82vh;
        padding: 20px;
    }
    
    #dialogueInterface {
        align-items: flex-start;
        padding-top: 20px;
        padding-bottom: 20px;
    }
}

/* Small screens (like Chromebooks with 1518x853) */
@media (max-width: 1600px) and (max-height: 900px) {
    #dialogueBox {
        width: 92vw;
        height: 80vh;
        max-width: 95vw;
        max-height: 80vh;
        padding: 15px;
        border-radius: 15px;
    }
    
    #dialogueInterface {
        align-items: flex-start;
        padding-top: 15px;
        padding-bottom: 15px;
    }
    
    .dialogue-columns {
        gap: 20px;
        padding: 0 10px;
    }
    
    .character-sprite {
        max-width: 180px;
        max-height: 180px;
    }
    
    .word-bubble {
        min-height: 200px;
        max-height: 300px;
        padding: 15px;
    }
    
    /* Ensure spell book is visible and fits on small screens */
    .open-book-canvas {
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px !important;
        box-sizing: border-box;
    }
    
    .canvas-frame-embedded {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    #drawingCanvas {
        width: 100% !important;
        max-width: 100% !important;
        height: 200px !important;
        box-sizing: border-box;
    }
    
    .canvas-frame-embedded canvas {
        width: 100% !important;
        max-width: 100% !important;
        height: 200px !important;
        box-sizing: border-box;
    }
    
    .embedded-combat-log {
        max-height: 80px !important;
        min-height: 50px !important;
        font-size: 0.85em !important;
        padding: 10px !important;
    }
    
    .canvas-title-embedded {
        font-size: 1em !important;
        margin: 3px 0 !important;
    }
    
    .drawing-tools-embedded,
    .canvas-actions-embedded {
        gap: 8px !important;
    }
    
    .tool-btn-embedded,
    .cast-btn-embedded,
    .cancel-btn-embedded {
        padding: 8px 12px !important;
        font-size: 0.9em !important;
    }
}

#dialogueBox::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle, rgba(255, 215, 0, 0.08) 0%, transparent 70%),
        radial-gradient(circle at 70% 30%, rgba(138, 43, 226, 0.06) 0%, transparent 50%);
    animation: magicalGlow 5s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

@keyframes magicalGlow {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 0.3;
    }
    100% {
        transform: rotate(5deg) scale(1.05);
        opacity: 0.5;
    }
}

/* Close Button */
.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--fantasy-red) 0%, #8B0000 100%);
    color: white;
    border: 2px solid var(--fantasy-red);
    border-radius: 50%;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(220, 20, 60, 0.4);
}

.close-btn:hover {
    background: linear-gradient(135deg, #FF1744, #D50000);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 6px 20px rgba(220, 20, 60, 0.6);
}

/* Three Column Layout (Player, Book, NPC) */
.dialogue-columns {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 60px;
    height: 100%;
    align-items: center;
    padding: 0 20px;
}

/* Character Column */
.character-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    height: 100%;
    justify-content: center;
    position: relative;
}

.left-side {
    align-items: flex-end;
}

.right-side {
    align-items: flex-start;
}

/* Character Sprite Container */
.character-sprite-container {
    flex-shrink: 0;
}

.character-sprite {
    max-width: 280px;
    max-height: 280px;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.5));
    animation: characterIdle 3s ease-in-out infinite;
}

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

.character-sprite:hover {
    animation: characterBounce 0.6s ease;
}

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

/* Word Bubble */
.word-bubble {
    position: relative;
    width: 100%;
    max-width: 500px;
    min-height: 350px;
    max-height: 450px;
    background: 
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 60%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 248, 248, 0.98) 100%);
    border: 4px solid var(--fantasy-dark);
    border-radius: 30px;
    padding: 25px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.6),
        inset 0 2px 10px rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    animation: bubblePop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bubblePop {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Bubble Tails */
.bubble-tail {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

.bubble-tail-left {
    bottom: 80px;
    left: -25px;
    border-width: 20px 25px 20px 0;
    border-color: transparent var(--fantasy-dark) transparent transparent;
}

.bubble-tail-left::after {
    content: '';
    position: absolute;
    left: 5px;
    top: -16px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 16px 22px 16px 0;
    border-color: transparent rgba(255, 255, 255, 0.95) transparent transparent;
}

.bubble-tail-right {
    bottom: 80px;
    right: -25px;
    border-width: 20px 0 20px 25px;
    border-color: transparent transparent transparent var(--fantasy-dark);
}

.bubble-tail-right::after {
    content: '';
    position: absolute;
    right: 5px;
    top: -16px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 16px 0 16px 22px;
    border-color: transparent transparent transparent rgba(248, 240, 220, 0.95);
}

/* Bubble Content */
.bubble-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 15px;
}

/* NPC Name Header */
.npc-name-header {
    font-size: 1.6em;
    font-weight: bold;
    color: var(--fantasy-gold);
    text-align: center;
    padding: 12px;
    background: linear-gradient(135deg, rgba(218, 165, 32, 0.2) 0%, rgba(184, 134, 11, 0.2) 100%);
    border-radius: 15px;
    border: 2px solid var(--fantasy-gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

/* Scrollable Conversation Areas */
.conversation-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: 
        radial-gradient(circle at 30% 30%, rgba(218, 165, 32, 0.08) 0%, transparent 70%),
        linear-gradient(135deg, rgba(244, 228, 188, 0.3) 0%, rgba(255, 255, 255, 0.2) 100%);
    border-radius: 15px;
    border: 2px solid rgba(218, 165, 32, 0.3);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.1);
    color: var(--fantasy-dark);
    line-height: 1.6;
    font-size: 1.05em;
}

/* Message Styling Inside Bubbles */
.bubble-message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 12px;
    animation: messageSlideIn 0.4s ease-out;
    word-wrap: break-word;
}

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

.player-bubble .bubble-message {
    background: linear-gradient(135deg, rgba(70, 130, 180, 0.15) 0%, rgba(100, 149, 237, 0.15) 100%);
    border-left: 4px solid var(--fantasy-blue);
    color: #1a1a1a;
}

.npc-bubble .bubble-message {
    background: linear-gradient(135deg, rgba(218, 165, 32, 0.15) 0%, rgba(255, 215, 0, 0.12) 100%);
    border-left: 4px solid var(--fantasy-gold);
    color: #2a2a2a;
    font-weight: 500;
}

/* Text Input Container */
.text-input-container {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

#playerInput {
    flex: 1;
    padding: 15px 18px;
    border: 3px solid rgba(218, 165, 32, 0.5);
    border-radius: 15px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 248, 248, 0.95) 100%);
    color: var(--fantasy-dark);
    font-size: 1.05em;
    font-family: inherit;
    box-shadow: 
        inset 0 2px 6px rgba(0, 0, 0, 0.08),
        0 2px 12px rgba(218, 165, 32, 0.2);
    transition: all 0.3s ease;
}

#playerInput::placeholder {
    color: rgba(47, 27, 20, 0.5);
    font-style: italic;
}

#playerInput:focus {
    outline: none;
    border-color: var(--fantasy-gold);
    box-shadow: 
        inset 0 2px 6px rgba(0, 0, 0, 0.08),
        0 0 20px rgba(218, 165, 32, 0.5),
        0 0 40px rgba(218, 165, 32, 0.3);
    background: linear-gradient(135deg, rgba(255, 255, 255, 1) 0%, rgba(255, 250, 240, 1) 100%);
}

.send-btn {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--fantasy-gold) 0%, #B8860B 100%);
    color: white;
    border: 2px solid var(--fantasy-gold);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(218, 165, 32, 0.4);
    flex-shrink: 0;
}

.send-btn:hover {
    background: linear-gradient(135deg, #FFD700, #DAA520);
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 20px rgba(218, 165, 32, 0.6);
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 15px;
    justify-content: center;
    align-items: center;
}

.typing-indicator span {
    width: 10px;
    height: 10px;
    background: var(--fantasy-gold);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* ============================================
   BATTLE BOOK (CENTER ELEMENT)
   ============================================ */

.battle-book-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 200px;
}

.battle-book {
    position: relative;
    width: 180px;
    height: 240px;
    perspective: 1000px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.battle-book:hover {
    transform: scale(1.05);
}

.book-cover {
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(135deg, 
            var(--fantasy-brown) 0%, 
            #654321 30%, 
            var(--fantasy-brown) 60%, 
            #8B4513 100%);
    border: 4px solid var(--fantasy-gold);
    border-radius: 8px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.8),
        inset 0 2px 10px rgba(0, 0, 0, 0.5),
        inset 0 -2px 10px rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    position: relative;
    animation: bookFloat 3s ease-in-out infinite;
}

@keyframes bookFloat {
    0%, 100% {
        transform: translateY(0px) rotateY(-2deg);
    }
    50% {
        transform: translateY(-10px) rotateY(2deg);
    }
}

.book-spine {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 15px;
    background: linear-gradient(90deg, 
        rgba(0, 0, 0, 0.4) 0%, 
        rgba(0, 0, 0, 0.1) 50%, 
        rgba(255, 255, 255, 0.1) 100%);
    border-right: 2px solid rgba(218, 165, 32, 0.5);
    border-radius: 8px 0 0 8px;
}

.book-icon {
    font-size: 4em;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.7));
    animation: bookGlow 2s ease-in-out infinite alternate;
}

@keyframes bookGlow {
    from {
        filter: drop-shadow(0 4px 12px rgba(255, 215, 0, 0.3));
    }
    to {
        filter: drop-shadow(0 4px 20px rgba(255, 215, 0, 0.7));
    }
}

.book-title {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--fantasy-gold);
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    letter-spacing: 1px;
}

/* Book Opening Animation */
@keyframes bookOpen {
    0% {
        transform: rotateY(0deg) scale(1);
    }
    50% {
        transform: rotateY(90deg) scale(1.2);
    }
    100% {
        transform: rotateY(0deg) scale(1);
    }
}

.battle-book.opening {
    pointer-events: none;
}

.battle-book.opening .book-cover {
    animation: none;
}

/* ============================================
   EMBEDDED OPEN BOOK CANVAS
   ============================================ */

.open-book-canvas {
    width: 450px;
    max-width: 100%;
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.12) 0%, transparent 60%),
        linear-gradient(135deg, rgba(139, 69, 19, 0.95) 0%, rgba(160, 82, 45, 0.95) 50%, rgba(139, 69, 19, 0.95) 100%);
    border: 4px solid var(--fantasy-gold);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 
        0 15px 50px rgba(0, 0, 0, 0.8),
        0 5px 25px rgba(218, 165, 32, 0.4),
        inset 0 2px 10px rgba(255, 255, 255, 0.1);
    animation: bookExpand 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

@keyframes bookExpand {
    from {
        opacity: 0;
        transform: scale(0.3) rotateY(90deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotateY(0deg);
    }
}

.open-book-canvas.hidden {
    display: none !important;
    visibility: hidden;
    opacity: 0;
}

.open-book-canvas:not(.hidden) {
    display: flex !important;
    visibility: visible !important;
    opacity: 1;
}

/* Embedded Combat Log - IMPROVED VERSION */
.embedded-combat-log {
    max-height: 180px;
    min-height: 120px;
    overflow-y: auto;
    padding: 15px 18px;
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.15) 0%, transparent 60%),
        linear-gradient(135deg, rgba(0, 0, 0, 0.85) 0%, rgba(74, 20, 140, 0.75) 50%, rgba(0, 0, 0, 0.85) 100%);
    border-radius: 12px;
    border: 3px solid var(--fantasy-gold);
    text-align: left;
    box-shadow: 
        0 8px 20px rgba(0, 0, 0, 0.6),
        inset 0 2px 4px rgba(255, 215, 0, 0.2);
    scroll-behavior: smooth;
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.5),
        0 2px 15px rgba(255, 215, 0, 0.3);
    font-size: 0.95em;
    color: #FFE4B5;
}

.canvas-title-embedded {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--fantasy-gold);
    text-align: center;
    text-shadow: 
        0 0 10px rgba(255, 215, 0, 0.6),
        2px 2px 4px rgba(0, 0, 0, 0.9);
    margin: 5px 0;
}

/* Embedded Canvas Frame */
.canvas-frame-embedded {
    position: relative;
    display: inline-block;
    padding: 10px;
    background: 
        linear-gradient(45deg, var(--fantasy-brown) 0%, var(--fantasy-gold) 50%, var(--fantasy-brown) 100%);
    border-radius: 12px;
    box-shadow: 
        0 8px 30px rgba(0, 0, 0, 0.7),
        inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

.canvas-frame-embedded::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    pointer-events: none;
}

.canvas-frame-embedded canvas {
    display: block;
    border: 2px solid var(--fantasy-dark);
    border-radius: 8px;
    background: 
        linear-gradient(135deg, #FFFEF7 0%, #F4E4C1 100%);
    cursor: crosshair;
    box-shadow: 
        inset 0 0 15px rgba(0, 0, 0, 0.08),
        0 4px 12px rgba(0, 0, 0, 0.5);
}

/* Embedded Drawing Tools */
.drawing-tools-embedded {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.tool-btn-embedded {
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(200, 200, 200, 0.2) 100%);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.tool-btn-embedded:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(220, 220, 220, 0.3) 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

/* Embedded Action Buttons */
.canvas-actions-embedded {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.cast-btn-embedded {
    flex: 1;
    padding: 12px 30px;
    background: linear-gradient(135deg, var(--fantasy-gold) 0%, #FFD700 100%);
    color: var(--fantasy-dark);
    border: 3px solid var(--fantasy-gold);
    border-radius: 15px;
    font-size: 1.3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 6px 20px rgba(255, 215, 0, 0.5),
        0 0 30px rgba(255, 215, 0, 0.3),
        inset 0 2px 5px rgba(255, 255, 255, 0.5);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.cast-btn-embedded:hover {
    background: linear-gradient(135deg, #FFD700, #FFA500 100%);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 
        0 10px 30px rgba(255, 215, 0, 0.7),
        0 0 50px rgba(255, 215, 0, 0.5),
        inset 0 2px 5px rgba(255, 255, 255, 0.5);
}

.cast-btn-embedded:active {
    transform: translateY(-1px) scale(1.02);
}

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

.cancel-btn-embedded {
    padding: 12px 20px;
    background: linear-gradient(135deg, rgba(100, 100, 100, 0.6) 0%, rgba(80, 80, 80, 0.6) 100%);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 15px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.cancel-btn-embedded:hover {
    background: linear-gradient(135deg, rgba(120, 120, 120, 0.7) 0%, rgba(100, 100, 100, 0.7) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

/* Spell/Attack Button (on Book) */
.book-spell-btn {
    position: absolute;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 30px;
    background: linear-gradient(135deg, var(--fantasy-red) 0%, #8B0000 100%);
    color: white;
    border: 3px solid var(--fantasy-gold);
    border-radius: 20px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 
        0 8px 25px rgba(220, 20, 60, 0.5),
        0 0 30px rgba(255, 215, 0, 0.3);
    animation: spellButtonPulse 2s infinite;
    z-index: 5;
    white-space: nowrap;
}

@keyframes spellButtonPulse {
    0%, 100% {
        box-shadow: 
            0 8px 25px rgba(220, 20, 60, 0.5),
            0 0 30px rgba(255, 215, 0, 0.3);
    }
    50% {
        box-shadow: 
            0 12px 35px rgba(220, 20, 60, 0.7),
            0 0 50px rgba(255, 215, 0, 0.5);
    }
}

.book-spell-btn:hover {
    background: linear-gradient(135deg, #FF1744, #D50000);
    transform: translateX(-50%) translateY(-8px) scale(1.08);
    box-shadow: 
        0 15px 40px rgba(220, 20, 60, 0.7),
        0 0 60px rgba(255, 215, 0, 0.6);
}

.book-spell-btn:active {
    transform: translateX(-50%) translateY(-4px) scale(1.03);
}

/* ============================================
   NPC HEALTH BAR
   ============================================ */

/* Player Health Bar (matches NPC) */
.player-health-bar {
    width: 100%;
    max-width: 300px;
    margin-bottom: 10px;
    animation: healthBarSlideIn 0.5s ease-out;
}

/* NPC Health Bar */
.npc-health-bar {
    width: 100%;
    max-width: 300px;
    margin-bottom: 10px;
    animation: healthBarSlideIn 0.5s ease-out;
}

.npc-health-bar.hidden,
.player-health-bar.hidden,
.battle-book.hidden {
    display: none;
}

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

.health-bar-label {
    text-align: center;
    margin-bottom: 5px;
}

#npcHealthText {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--fantasy-gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.health-bar-container {
    width: 100%;
    height: 24px;
    background: 
        linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(40, 0, 0, 0.6) 100%);
    border: 3px solid var(--fantasy-gold);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.6),
        0 4px 15px rgba(0, 0, 0, 0.5);
    position: relative;
}

.health-bar-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, transparent 100%);
    pointer-events: none;
}

.health-bar-fill {
    height: 100%;
    background: linear-gradient(135deg, 
        #DC143C 0%, 
        #FF4444 25%, 
        #FF6B6B 50%, 
        #FF4444 75%, 
        #DC143C 100%);
    transition: width 0.6s ease, background 0.3s ease;
    box-shadow: 
        0 0 15px rgba(220, 20, 60, 0.6),
        inset 0 2px 8px rgba(255, 255, 255, 0.3);
    position: relative;
    animation: healthPulse 2s ease-in-out infinite;
}

@keyframes healthPulse {
    0%, 100% {
        box-shadow: 
            0 0 15px rgba(220, 20, 60, 0.6),
            inset 0 2px 8px rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 
            0 0 25px rgba(220, 20, 60, 0.9),
            inset 0 2px 8px rgba(255, 255, 255, 0.3);
    }
}

/* Health bar color changes based on health percentage */
.health-bar-fill.low-health {
    background: linear-gradient(135deg, 
        #8B0000 0%, 
        #DC143C 50%, 
        #8B0000 100%);
}

.health-bar-fill.medium-health {
    background: linear-gradient(135deg, 
        #FFA500 0%, 
        #FFD700 50%, 
        #FFA500 100%);
}

.health-bar-fill.high-health {
    background: linear-gradient(135deg, 
        #228B22 0%, 
        #32CD32 50%, 
        #228B22 100%);
}

/* Player health bar uses blue instead of red */
.health-bar-player {
    background: linear-gradient(135deg, 
        #4682B4 0%, 
        #5B9BD5 25%, 
        #87CEEB 50%, 
        #5B9BD5 75%, 
        #4682B4 100%) !important;
    box-shadow: 
        0 0 15px rgba(70, 130, 180, 0.6),
        inset 0 2px 8px rgba(255, 255, 255, 0.3) !important;
}

@keyframes playerHealthPulse {
    0%, 100% {
        box-shadow: 
            0 0 15px rgba(70, 130, 180, 0.6),
            inset 0 2px 8px rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 
            0 0 25px rgba(70, 130, 180, 0.9),
            inset 0 2px 8px rgba(255, 255, 255, 0.3);
    }
}

.health-bar-player {
    animation: playerHealthPulse 2s ease-in-out infinite !important;
}

.btn-icon {
    font-size: 1.4em;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.btn-text {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

button {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--fantasy-gold) 0%, var(--fantasy-brown) 100%);
    color: var(--fantasy-light);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: all 0.2s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(0);
}

.combat-button {
    background: linear-gradient(135deg, var(--fantasy-red) 0%, #8B0000 100%);
    animation: pulseGlow 2s infinite;
}

/* ============================================
   COMBAT CANVAS OVERLAY - REVAMPED
   ============================================ */

.combat-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    transform: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

/* Dark Backdrop */
.combat-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    animation: backdropFadeIn 0.3s ease-out;
}

@keyframes backdropFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Canvas Container */
.combat-canvas-container {
    position: relative;
    z-index: 2;
    background: 
        radial-gradient(circle at 20% 30%, rgba(255, 215, 0, 0.15) 0%, transparent 60%),
        radial-gradient(circle at 80% 70%, rgba(220, 20, 60, 0.12) 0%, transparent 60%),
        linear-gradient(145deg, rgba(139, 0, 0, 0.95) 0%, rgba(178, 34, 34, 0.95) 25%, rgba(220, 20, 60, 0.95) 50%, rgba(255, 69, 0, 0.9) 100%);
    border: 4px solid var(--fantasy-gold);
    border-radius: 25px;
    padding: 30px;
    box-shadow: 
        0 25px 80px rgba(0, 0, 0, 0.9),
        0 10px 40px rgba(220, 20, 60, 0.5),
        0 0 60px rgba(255, 215, 0, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.1);
    text-align: center;
    backdrop-filter: blur(10px);
    max-width: 90vw;
    max-height: 90vh;
    animation: canvasSlideIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes canvasSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.combat-canvas-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle, rgba(220, 20, 60, 0.1) 0%, transparent 70%),
        radial-gradient(circle at 70% 30%, rgba(255, 215, 0, 0.08) 0%, transparent 60%);
    animation: combatGlow 3s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

@keyframes combatGlow {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 0.3;
    }
    100% {
        transform: rotate(-3deg) scale(1.02);
        opacity: 0.6;
    }
}

/* Canvas Close Button */
.canvas-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(200, 200, 200, 0.2) 100%);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

.canvas-close-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(220, 220, 220, 0.3) 100%);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.8);
}

/* Canvas Title */
.canvas-title {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--fantasy-gold);
    margin-bottom: 20px;
    text-shadow: 
        0 0 15px rgba(255, 215, 0, 0.6),
        2px 2px 6px rgba(0, 0, 0, 0.9);
    animation: titleGlow 2s ease-in-out infinite alternate;
}

@keyframes titleGlow {
    from {
        text-shadow: 
            0 0 15px rgba(255, 215, 0, 0.6),
            2px 2px 6px rgba(0, 0, 0, 0.9);
    }
    to {
        text-shadow: 
            0 0 25px rgba(255, 215, 0, 0.9),
            0 0 40px rgba(255, 215, 0, 0.5),
            2px 2px 6px rgba(0, 0, 0, 0.9);
    }
}

/* Canvas Frame (Fantasy Border) */
.canvas-frame {
    position: relative;
    display: inline-block;
    padding: 15px;
    background: 
        linear-gradient(45deg, var(--fantasy-brown) 0%, var(--fantasy-gold) 50%, var(--fantasy-brown) 100%);
    border-radius: 15px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.8),
        inset 0 2px 10px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
}

.canvas-frame::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    pointer-events: none;
}

#drawingCanvas {
    display: block;
    border: 3px solid var(--fantasy-dark);
    border-radius: 8px;
    background: 
        linear-gradient(135deg, #FFFEF7 0%, #F4E4C1 100%);
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><text x='0' y='24' font-size='24'>🪄</text></svg>") 4 4, url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path d='M12 2 L12 10 M12 14 L12 22 M2 12 L10 12 M14 12 L22 12' stroke='black' stroke-width='2' fill='none'/><circle cx='12' cy='12' r='2' fill='black'/></svg>") 12 12, crosshair;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.08),
        0 5px 15px rgba(0, 0, 0, 0.5);
}

/* Drawing Tools */
.drawing-tools {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.tool-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(200, 200, 200, 0.2) 100%);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.tool-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(220, 220, 220, 0.3) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

/* Canvas Actions */
.canvas-actions {
    margin-bottom: 15px;
}

.cast-btn {
    padding: 18px 50px;
    background: linear-gradient(135deg, var(--fantasy-gold) 0%, #FFD700 100%);
    color: var(--fantasy-dark);
    border: 3px solid var(--fantasy-gold);
    border-radius: 20px;
    font-size: 1.6em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 8px 30px rgba(255, 215, 0, 0.5),
        0 0 40px rgba(255, 215, 0, 0.4),
        inset 0 2px 5px rgba(255, 255, 255, 0.5);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
    animation: castButtonPulse 2s infinite;
}

@keyframes castButtonPulse {
    0%, 100% {
        box-shadow: 
            0 8px 30px rgba(255, 215, 0, 0.5),
            0 0 40px rgba(255, 215, 0, 0.4),
            inset 0 2px 5px rgba(255, 255, 255, 0.5);
        transform: scale(1);
    }
    50% {
        box-shadow: 
            0 12px 40px rgba(255, 215, 0, 0.7),
            0 0 60px rgba(255, 215, 0, 0.6),
            inset 0 2px 5px rgba(255, 255, 255, 0.5);
        transform: scale(1.05);
    }
}

.cast-btn:hover {
    background: linear-gradient(135deg, #FFD700, #FFA500 100%);
    transform: translateY(-5px) scale(1.08);
    box-shadow: 
        0 15px 50px rgba(255, 215, 0, 0.8),
        0 0 80px rgba(255, 215, 0, 0.6),
        inset 0 2px 5px rgba(255, 255, 255, 0.5);
}

.cast-btn:active {
    transform: translateY(-2px) scale(1.03);
}

.cast-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    animation: none;
}

/* Top Combat Log (Above Canvas) */
.top-combat-log {
    max-height: 150px;
    min-height: 80px;
    overflow-y: auto;
    padding: 15px 20px;
    margin-bottom: 20px;
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 215, 0, 0.15) 0%, transparent 60%),
        linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(74, 20, 140, 0.7) 50%, rgba(0, 0, 0, 0.8) 100%);
    border-radius: 15px;
    border: 3px solid var(--fantasy-gold);
    text-align: left;
    box-shadow: 
        inset 0 2px 10px rgba(0, 0, 0, 0.5),
        0 4px 20px rgba(255, 215, 0, 0.4);
    backdrop-filter: blur(8px);
    font-size: 1.05em;
    animation: logSlideDown 0.5s ease-out;
}

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

.combat-message {
    margin-bottom: 12px;
    padding: 12px 15px;
    border-radius: 10px;
    background: rgba(220, 20, 60, 0.3);
    border-left: 4px solid var(--fantasy-red);
    animation: fadeIn 0.5s ease-in;
    color: #FFF8DC;
    font-size: 1.1em;
    font-weight: 500;
    line-height: 1.5;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    letter-spacing: 0.3px;
}

/* Loading Screen */
#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #4A148C 0%, #7B1FA2 25%, #8E24AA 50%, #9C27B0 75%, #AB47BC 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.5s ease-out;
}

#loadingScreen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    color: var(--fantasy-gold);
}

.loading-content h2 {
    font-size: 2em;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(218, 165, 32, 0.3);
    border-top: 4px solid var(--fantasy-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* Game UI Overlay */
#gameUI {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 5;
}

#gameUI.hidden {
    opacity: 0;
}

/* Tutorial Instructions */
.tutorial-instructions {
    position: fixed;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    border: 4px solid var(--fantasy-gold);
    border-radius: 20px;
    padding: 20px 60px 20px 40px;
    font-size: 24px;
    font-weight: 900;
    color: white;
    text-align: center;
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.8),
        0 0 10px rgba(255, 215, 0, 0.6);
    box-shadow: 
        0 0 30px rgba(218, 165, 32, 0.8),
        inset 0 0 20px rgba(255, 215, 0, 0.3),
        0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    max-width: 90%;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.tutorial-instructions.hidden {
    display: none !important;
}

.tutorial-content {
    flex: 1;
}

.collapse-tutorial-btn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: var(--fantasy-gold);
    border: 2px solid white;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 28px;
    font-weight: bold;
    color: black;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.collapse-tutorial-btn:hover {
    background: var(--yellow-bright);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.5);
}

.collapse-tutorial-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Expand Tutorial Button (collapsed state) */
.expand-tutorial-btn {
    position: fixed;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    border: 3px solid var(--fantasy-gold);
    border-radius: 15px;
    padding: 12px 25px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: 
        0 0 20px rgba(218, 165, 32, 0.6),
        0 4px 10px rgba(0, 0, 0, 0.4);
}

.expand-tutorial-btn:hover {
    background: rgba(0, 0, 0, 1);
    transform: translateX(-50%) scale(1.05);
    box-shadow: 
        0 0 30px rgba(218, 165, 32, 0.9),
        0 4px 15px rgba(0, 0, 0, 0.5);
}

.expand-tutorial-btn:active {
    transform: translateX(-50%) scale(0.95);
}

.expand-tutorial-btn.hidden {
    display: none;
}

#playerStats {
    background: 
        radial-gradient(circle at 20% 30%, rgba(255, 215, 0, 0.15) 0%, transparent 70%),
        radial-gradient(circle at 80% 70%, rgba(220, 20, 60, 0.1) 0%, transparent 60%),
        linear-gradient(135deg, rgba(74, 20, 140, 0.9) 0%, rgba(123, 31, 162, 0.9) 50%, rgba(156, 39, 176, 0.85) 100%);
    border: 2px solid var(--fantasy-gold);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 15px;
    font-weight: bold;
    min-width: 140px;
    box-shadow: 
        0 8px 25px rgba(0, 0, 0, 0.4),
        0 2px 10px rgba(218, 165, 32, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    color: #FFF8DC;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
}

#playerStats div {
    margin-bottom: 8px;
    font-size: 1.1em;
    position: relative;
}

#playerStats div:last-child {
    margin-bottom: 0;
}

#gameInstructions {
    background: 
        radial-gradient(circle at 30% 20%, rgba(138, 43, 226, 0.12) 0%, transparent 60%),
        radial-gradient(circle at 70% 80%, rgba(255, 215, 0, 0.08) 0%, transparent 50%),
        linear-gradient(135deg, rgba(74, 20, 140, 0.85) 0%, rgba(123, 31, 162, 0.85) 25%, rgba(142, 36, 170, 0.85) 75%, rgba(156, 39, 176, 0.8) 100%);
    border: 2px solid rgba(218, 165, 32, 0.6);
    border-radius: 12px;
    padding: 15px;
    font-size: 0.95em;
    max-width: 280px;
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(218, 165, 32, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px);
    color: #F0E68C;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
}

#gameInstructions::before {
    content: '';
    position: absolute;
    top: -20%;
    left: -20%;
    width: 140%;
    height: 140%;
    background: 
        radial-gradient(circle, rgba(255, 215, 0, 0.05) 0%, transparent 70%);
    animation: softGlow 6s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

@keyframes softGlow {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 0.2;
    }
    100% {
        transform: rotate(3deg) scale(1.02);
        opacity: 0.4;
    }
}

/* API key UI removed - now handled via config.js */

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

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

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 10px rgba(220, 20, 60, 0.3); }
    50% { box-shadow: 0 0 20px rgba(220, 20, 60, 0.6); }
}

@keyframes magicalShimmer {
    0% {
        filter: brightness(1) hue-rotate(0deg);
    }
    25% {
        filter: brightness(1.1) hue-rotate(5deg);
    }
    50% {
        filter: brightness(1.05) hue-rotate(-3deg);
    }
    75% {
        filter: brightness(1.08) hue-rotate(7deg);
    }
    100% {
        filter: brightness(1) hue-rotate(0deg);
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--fantasy-gold);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #B8860B;
}

/* Tutorial Guide Interface Styles */
#tutorialGuideInterface {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    max-width: 800px;
    max-height: 80vh;
}

#tutorialGuideBox {
    background: 
        radial-gradient(circle at 15% 25%, rgba(255, 215, 0, 0.12) 0%, transparent 60%),
        radial-gradient(circle at 85% 75%, rgba(138, 43, 226, 0.12) 0%, transparent 60%),
        radial-gradient(circle at 50% 50%, rgba(220, 20, 60, 0.08) 0%, transparent 50%),
        linear-gradient(145deg, rgba(74, 20, 140, 0.95) 0%, rgba(123, 31, 162, 0.95) 25%, rgba(142, 36, 170, 0.95) 50%, rgba(156, 39, 176, 0.95) 75%, rgba(171, 71, 188, 0.95) 100%);
    border: 3px solid var(--fantasy-gold);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 
        0 15px 40px rgba(0, 0, 0, 0.8),
        0 5px 20px rgba(218, 165, 32, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    text-align: center;
    backdrop-filter: blur(12px);
    position: relative;
    overflow: hidden;
}

#tutorialGuideBox::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle, rgba(255, 215, 0, 0.08) 0%, transparent 70%),
        radial-gradient(circle at 60% 40%, rgba(138, 43, 226, 0.06) 0%, transparent 60%);
    animation: tutorialGlow 5s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

@keyframes tutorialGlow {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 0.4;
    }
    100% {
        transform: rotate(4deg) scale(1.03);
        opacity: 0.7;
    }
}

#tutorialGuideHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--fantasy-gold);
    padding-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

#tutorialGuideHeader h3 {
    color: var(--fantasy-gold);
    font-size: 1.5em;
    font-weight: bold;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#closeTutorialGuideButton {
    background: linear-gradient(135deg, var(--fantasy-red) 0%, #8B0000 100%);
    color: white;
    border: 2px solid var(--fantasy-red);
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#closeTutorialGuideButton:hover {
    background: linear-gradient(135deg, #DC143C, #B22222);
    transform: scale(1.1);
}

#tutorialGuideContent {
    max-height: 60vh;
    overflow: auto;
    border: 2px solid var(--fantasy-brown);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
}

#tutorialGuideImage {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    display: block;
    margin: 0 auto;
}

#showTutorialGuideButton {
    margin-left: 15px;
    padding: 5px 12px;
    background: linear-gradient(135deg, var(--fantasy-blue) 0%, #4169E1 100%);
    color: white;
    border: 2px solid var(--fantasy-blue);
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 12px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    transition: all 0.3s ease;
}

#showTutorialGuideButton:hover {
    background: linear-gradient(135deg, #4169E1, #6495ED);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Tutorial Mode Toggle */
#tutorialModeToggle {
    display: flex;
    gap: 5px;
    background: rgba(0, 0, 0, 0.3);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--fantasy-brown);
}

.mode-button {
    padding: 6px 12px;
    background: transparent;
    color: var(--fantasy-light);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.mode-button.active {
    background: linear-gradient(135deg, var(--fantasy-gold) 0%, #B8860B 100%);
    color: #000;
    text-shadow: none;
}

.mode-button:not(.active):hover {
    background: rgba(218, 165, 32, 0.2);
    color: var(--fantasy-gold);
}

/* Guide Content Areas */
.guide-content {
    transition: opacity 0.3s ease;
}

.guide-content.hidden {
    display: none;
}

.guide-content.active {
    display: block;
}

/* Tutorial Chat Area */
#tutorialChatArea {
    height: 60vh;
    display: flex;
    flex-direction: column;
    text-align: left;
}

#tutorialConversationHistory {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: 
        radial-gradient(circle at 25% 25%, rgba(255, 215, 0, 0.08) 0%, transparent 60%),
        radial-gradient(circle at 75% 75%, rgba(138, 43, 226, 0.08) 0%, transparent 60%),
        linear-gradient(135deg, rgba(0, 0, 0, 0.5) 0%, rgba(74, 20, 140, 0.4) 50%, rgba(0, 0, 0, 0.5) 100%);
    border: 2px solid rgba(218, 165, 32, 0.4);
    border-radius: 12px;
    margin-bottom: 15px;
    max-height: 45vh;
    box-shadow: 
        inset 0 2px 10px rgba(0, 0, 0, 0.4),
        0 2px 15px rgba(218, 165, 32, 0.2);
    backdrop-filter: blur(6px);
}

#tutorialInputArea {
    display: flex;
    gap: 10px;
    align-items: center;
}

#tutorialPlayerInput {
    flex: 1;
    padding: 15px;
    background: 
        radial-gradient(circle at 30% 20%, rgba(255, 215, 0, 0.1) 0%, transparent 60%),
        linear-gradient(135deg, rgba(244, 228, 188, 0.9) 0%, rgba(255, 240, 200, 0.85) 100%);
    border: 2px solid rgba(218, 165, 32, 0.6);
    border-radius: 10px;
    color: var(--fantasy-dark);
    font-size: 15px;
    font-family: 'Georgia', serif;
    box-shadow: 
        inset 0 2px 5px rgba(0, 0, 0, 0.1),
        0 2px 10px rgba(218, 165, 32, 0.2);
    transition: all 0.3s ease;
}

#tutorialPlayerInput:focus {
    outline: none;
    border-color: var(--fantasy-gold);
    box-shadow: 
        inset 0 2px 5px rgba(0, 0, 0, 0.1),
        0 0 20px rgba(218, 165, 32, 0.5),
        0 0 40px rgba(218, 165, 32, 0.2);
    background: 
        radial-gradient(circle at 30% 20%, rgba(255, 215, 0, 0.15) 0%, transparent 60%),
        linear-gradient(135deg, rgba(255, 248, 220, 0.95) 0%, rgba(255, 240, 200, 0.9) 100%);
}

#tutorialSendButton {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--fantasy-green) 0%, #006400 100%);
    color: white;
    border: 2px solid var(--fantasy-green);
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

#tutorialSendButton:hover {
    background: linear-gradient(135deg, #32CD32, var(--fantasy-green));
    transform: translateY(-1px);
}

.tutorial-message {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
    animation: fadeIn 0.5s ease-in;
}

.tutorial-message.player {
    background: linear-gradient(135deg, rgba(70, 130, 180, 0.8) 0%, rgba(100, 149, 237, 0.8) 100%);
    color: white;
    margin-left: auto;
    text-align: right;
    border: 1px solid var(--fantasy-blue);
}

.tutorial-message.guide {
    background: linear-gradient(135deg, rgba(218, 165, 32, 0.8) 0%, rgba(184, 134, 11, 0.8) 100%);
    color: #000;
    margin-right: auto;
    text-align: left;
    border: 1px solid var(--fantasy-gold);
    font-weight: bold;
}

/* ============================================
   RESPONSIVE DESIGN - REVAMPED
   ============================================ */

@media (max-width: 1024px) {
    /* Dialogue Interface Tablet */
    .dialogue-columns {
        gap: 40px;
    }
    
    .character-sprite {
        max-width: 220px;
        max-height: 220px;
    }
    
    .word-bubble {
        max-width: 420px;
        min-height: 300px;
    }
    
    .battle-book {
        width: 150px;
        height: 200px;
    }
    
    .book-icon {
        font-size: 3em;
    }
    
    .book-spell-btn {
        padding: 12px 24px;
        font-size: 1em;
        bottom: -55px;
    }
}

@media (max-width: 768px) {
    /* Game Canvas */
    #gameCanvas {
        width: 95vw;
        height: 60vh;
    }
    
    /* Dialogue Interface Mobile */
    .dialogue-columns {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 20px;
        padding: 10px;
    }
    
    .battle-book-container {
        order: 2;
        margin: 20px 0;
    }
    
    .left-side {
        order: 1;
        align-items: center;
    }
    
    .right-side {
        order: 3;
        align-items: center;
    }
    
    .character-column {
        gap: 15px;
    }
    
    .character-sprite {
        max-width: 150px;
        max-height: 150px;
    }
    
    .word-bubble {
        max-width: 100%;
        min-height: 250px;
        max-height: 350px;
    }
    
    .conversation-scroll {
        font-size: 0.95em;
    }
    
    #playerInput {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 15px;
    }
    
    .npc-name-header {
        font-size: 1.3em;
    }
    
    .battle-book {
        width: 140px;
        height: 180px;
    }
    
    .book-icon {
        font-size: 2.5em;
    }
    
    .book-title {
        font-size: 1em;
    }
    
    .book-spell-btn {
        position: static;
        transform: none;
        margin-top: 20px;
        width: 100%;
        justify-content: center;
    }
    
    .book-spell-btn:hover {
        transform: translateY(-2px) scale(1.05);
    }
    
    /* Embedded Canvas Mobile */
    .open-book-canvas {
        width: 100%;
        max-width: 380px;
        padding: 15px;
    }
    
    .canvas-frame-embedded canvas {
        width: 100%;
        height: 280px;
    }
    
    .embedded-combat-log {
        max-height: 80px;
        min-height: 50px;
        font-size: 0.85em;
    }
    
    .canvas-title-embedded {
        font-size: 1.1em;
    }
    
    .cast-btn-embedded {
        font-size: 1.1em;
        padding: 10px 20px;
    }
    
    .cancel-btn-embedded {
        font-size: 1em;
        padding: 10px 15px;
    }
    
    .close-btn {
        width: 40px;
        height: 40px;
        font-size: 24px;
        top: 10px;
        right: 10px;
    }
    
    /* Combat Canvas Mobile */
    .combat-canvas-container {
        padding: 20px;
        max-width: 95vw;
    }
    
    .canvas-frame {
        padding: 10px;
    }
    
    #drawingCanvas {
        width: 100%;
        max-width: 400px;
        height: 400px;
    }
    
    .canvas-title {
        font-size: 1.4em;
    }
    
    .cast-btn {
        padding: 15px 40px;
        font-size: 1.3em;
    }
    
    .compact-combat-log {
        max-height: 100px;
        font-size: 0.85em;
    }
}

@media (max-width: 480px) {
    /* Extra small mobile */
    #dialogueBox {
        padding: 15px;
        height: 95vh;
    }
    
    .character-sprite {
        max-width: 120px;
        max-height: 120px;
    }
    
    .word-bubble {
        padding: 18px;
        min-height: 200px;
    }
    
    .npc-name-header {
        font-size: 1.1em;
        padding: 10px;
    }
    
    #drawingCanvas {
        height: 300px;
    }
    
    .cast-btn {
        padding: 12px 30px;
        font-size: 1.1em;
    }
    
    /* Tutorial Guide Mobile Responsive */
    #tutorialGuideInterface {
        width: 95vw;
        max-height: 90vh;
    }
    
    #tutorialGuideBox {
        padding: 15px;
    }
    
    #tutorialGuideHeader {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    #tutorialGuideHeader h3 {
        font-size: 1.3em;
    }
    
    #tutorialModeToggle {
        order: 1;
    }
    
    #closeTutorialGuideButton {
        position: absolute;
        top: 10px;
        right: 15px;
    }
    
    #tutorialChatArea {
        height: 50vh;
    }
    
    #tutorialConversationHistory {
        max-height: 35vh;
    }
    
    .tutorial-message {
        max-width: 90%;
        font-size: 14px;
        padding: 8px 10px;
    }
    
    #tutorialPlayerInput {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ============================================
   VICTORY/DEFEAT OVERLAY - DRAMATIC POPUP
   ============================================ */

#combatResultOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    animation: overlayFadeIn 0.5s ease-out forwards;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.combat-result-content {
    text-align: center;
    animation: resultPopIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes resultPopIn {
    0% {
        transform: scale(0.3) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.combat-result-title {
    font-size: 8em;
    font-weight: 900;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 8px;
    animation: titlePulse 2s ease-in-out infinite;
}

.combat-result-title.victory {
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.8),
                 0 0 80px rgba(255, 215, 0, 0.6);
    filter: drop-shadow(0 5px 15px rgba(255, 215, 0, 0.7));
}

.combat-result-title.defeat {
    background: linear-gradient(45deg, #8B0000, #DC143C, #8B0000);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(139, 0, 0, 0.8),
                 0 0 80px rgba(139, 0, 0, 0.6);
    filter: drop-shadow(0 5px 15px rgba(139, 0, 0, 0.7));
}

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

.combat-result-subtitle {
    font-size: 2em;
    color: #FFE4B5;
    margin-bottom: 20px;
    font-weight: 600;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    letter-spacing: 2px;
}

.combat-result-details {
    font-size: 1.5em;
    color: #DAA520;
    margin-top: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
}

/* Responsive for smaller screens */
@media (max-width: 768px) {
    .combat-result-title {
        font-size: 4em;
        letter-spacing: 4px;
    }
    
    .combat-result-subtitle {
        font-size: 1.5em;
    }
    
    .combat-result-details {
        font-size: 1.2em;
    }
}
