@font-face {
    font-family: 'Comic Sans MS Custom';
    src: url('/ComicSansMS3.ttf') format('truetype');
}

body {
    margin: 0;
    background-color: #0A0A10; /* Darker with hint of blue */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    font-family: 'Comic Sans MS Custom', cursive;
    color: #e0e0e0; /* Light text for dark theme */
}

/* Ensure app container fills available space correctly */
#app-container {
    position: relative;
    background-color: #12121A; /* Darker app container */
    font-family: 'Comic Sans MS Custom', cursive;
    box-sizing: border-box;
    /* Default is portrait (9:16) */
    width: auto;
    height: 100vh;
    max-width: 100vw;
    aspect-ratio: 9 / 16;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* If the window is narrower (taller) than 9:16, we constrain by width */
@media (max-aspect-ratio: 9/16) {
    #app-container:not(.widescreen) {
        width: 100vw;
        height: auto;
        max-height: 100vh;
    }
}

/* Widescreen mode */
#app-container.widescreen {
    aspect-ratio: 16 / 9;
    width: 100vw;
    height: auto;
    max-height: 100vh;
}

/* If the window is taller than 16:9 (and we are in widescreen mode), constrain by height */
@media (min-aspect-ratio: 16/9) {
    #app-container.widescreen {
        height: 100vh;
        width: auto;
        max-width: 100vw;
    }
}

#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #1A1A22; /* Dark background with blue tint */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 100;
    padding: 2rem;
    box-sizing: border-box;
    text-align: center;
    color: #e0e0e0; /* Light text */
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
}

#splash-screen.hidden {
    display: none !important;
}

#splash-screen img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#start-screen, #explanation-screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    box-sizing: border-box;
    text-align: center;
    background-color: #1A1A22; /* Dark background with blue tint */
    color: #e0e0e0; /* Light text */
}

#start-screen {
    justify-content: flex-start;
    overflow-y: auto;
}

#start-screen-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    box-sizing: border-box;
    text-align: center;
    position: relative; /* Needed for absolute positioning of children */
    padding-bottom: 2rem; /* Adjusted for flowing characters */
}

#start-screen {
    gap: 1rem;
}

/* Improved character list styling */
#start-screen-characters {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
    box-sizing: border-box;
    margin-top: 2rem;
}

.character-card {
    background-color: #25252F;
    border: 2px solid #444;
    border-radius: 15px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.character-card img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    border-radius: 60px;
    background-color: #1A1A22;
    padding: 1rem;
    border: 2px solid #444;
}

.character-card .name {
    font-size: 1.4rem;
    font-weight: bold;
    margin: 0;
    color: #e0e0e0;
}

.character-card .character-description {
    font-size: 1rem;
    color: #b0b0b0;
    margin: 0;
    text-align: center;
    line-height: 1.4;
}

.character-card .character-phrase {
    font-size: 1.1rem;
    color: #8a8aff;
    margin: 0;
    font-style: italic;
    text-align: center;
}

#loading-screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    box-sizing: border-box;
    text-align: center;
    background: linear-gradient(135deg, #1A1A22 0%, #12121A 100%);
    color: #e0e0e0; /* Light text */
    font-family: "Comic Sans MS", cursive, sans-serif;
}

.spinner {
    border-width: 6px;
    border-style: solid;
    border-color: #5a9bd0 transparent #5a9bd0 transparent;
    width: 50px;
    height: 50px;
    filter: drop-shadow(0 0 10px rgba(90, 155, 208, 0.3));
    animation: spin 2s linear infinite;
    margin-bottom: 20px;
}

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

#loading-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: -webkit-linear-gradient(#e0e0e0, #a0a0a0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.hidden {
    display: none !important;
}

#start-button, #radio-button, #user-interactive-button {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 2.5rem;
    padding: 1rem 2rem;
    border: 3px solid #444; /* Darker border */
    background-color: #333; /* Darker button */
    color: #e0e0e0; /* Light text */
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 10px;
    box-shadow: none;
    text-shadow: none;
    transition: background-color 0.2s;
    font-weight: 700;
    width: 80%;
    margin-bottom: 0.5rem;
    text-align: center; /* Explicitly center text */
}

#start-button:last-of-type, #user-interactive-button:last-of-type, #radio-button:last-of-type {
    margin-bottom: 0;
}

.option-section { /* Renamed from radio-section */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80%;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 1rem;
    border: 2px dashed #444; /* Darker dashed border */
    border-radius: 10px;
    background-color: #2A2A35; /* Darker background with blue tint */
}

.option-section label {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.1rem;
    margin: 0;
    color: #e0e0e0; /* Light text */
    font-weight: 700;
}

.option-section input[type="checkbox"] {
    width: 20px; /* Adjust size as needed */
    height: 20px;
    cursor: pointer;
    margin-top: 0.5rem;
    background-color: #555; /* Darker checkbox background */
    border: 1px solid #777; /* Lighter border */
}
.option-section input[type="checkbox"]:checked {
    background-color: #6ab0e6; /* Blue for checked state */
}

#radio-theme-input, #story-length-select {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.1rem;
    width: 100%;
    padding: 0.5rem;
    border: 3px solid #444; /* Darker border */
    border-radius: 10px;
    box-sizing: border-box;
    font-weight: 700;
    text-align: center;
    background-color: #25252F; /* Darker input background with blue tint */
    color: #e0e0e0; /* Light input text */
}
#story-length-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23e0e0e0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-6.5%200-12.3%203.2-16.2%208.1-3.9%204.9-4.8%2011.6-2.7%2017.7l139.3%20220.4c3.4%205.4%209.6%208.6%2016.3%208.6s12.9-3.2%2016.3-8.6L290.7%2090.8c2.1-6.1%201.2-12.8-2.7-17.7z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 0.7em top 50%, 0 0;
    background-size: 0.65em auto, 100%;
    padding-right: 2.5em; /* space for the arrow */
}

#radio-button {
    width: 100%;
    font-size: 2rem;
    padding: 0.8rem 1rem;
    margin-bottom: 0;
}

#start-button:hover, #radio-button:hover, #user-interactive-button:hover {
    background-color: #444; /* Lighter hover */
}

#start-button:active, #radio-button:active, #user-interactive-button:active {
    background-color: #555; /* Even lighter active */
    transform: translateY(2px);
}

#story-length-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90%;
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 1rem;
    border: 2px dashed #444;
    border-radius: 10px;
    background-color: #2A2A35;
}

#story-length-section label {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.1rem;
    color: #e0e0e0;
    font-weight: 700;
}

#story-length-select {
    width: 100%;
    padding: 0.8rem;
    font-size: 1.1rem;
    border: 2px solid #444;
    border-radius: 8px;
    background-color: #25252F;
    color: #e0e0e0;
    cursor: pointer;
}

#example-section {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 80%;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 1rem;
    border: 2px dashed #444; /* Darker dashed border */
    border-radius: 10px;
    background-color: #2A2A35; /* Darker background with blue tint */
}

#example-section p {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.1rem;
    margin: 0 0 0.5rem 0;
    color: #e0e0e0; /* Light text */
    font-weight: 700;
}

.example-button {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1rem;
    padding: 0.5rem 0.8rem;
    border: 2px solid #555; /* Darker border */
    background-color: #444; /* Darker button */
    color: #e0e0e0; /* Light text */
    cursor: pointer;
    border-radius: 8px;
    font-weight: 700;
    transition: background-color 0.2s, transform 0.1s;
}

.example-button:hover {
    background-color: #555; /* Lighter hover */
}

.example-button:active {
    transform: translateY(1px);
}

#explanation-screen label {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    color: #e0e0e0; /* Light text */
    font-weight: 700;
}

#topic-input {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.2rem;
    width: 90%;
    padding: 0.75rem;
    border: 3px solid #444; /* Darker border */
    border-radius: 10px;
    margin-bottom: 1.5rem;
    resize: none;
    box-sizing: border-box;
    font-weight: 700;
    background-color: #25252F; /* Darker input background with blue tint */
    color: #e0e0e0; /* Light input text */
}

#go-button {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 2rem;
    padding: 0.8rem 1.8rem;
    border: 3px solid #444; /* Darker border */
    background-color: #333; /* Darker button */
    color: #e0e0e0; /* Light text */
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 10px;
    box-shadow: none;
    text-shadow: none;
    transition: background-color 0.2s;
    font-weight: 700;
}

#go-button:hover {
    background-color: #444; /* Lighter hover */
}

#go-button:active {
    background-color: #555; /* Even lighter active */
    transform: translateY(2px);
}

/* Enhanced Dialogue Container */
#dialogue-container.fullscreen-dialogue {
    position: relative;
    width: 100%;
    height: 100%;
    background: #12121A;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-sizing: border-box;
    overflow-y: auto;
}

/* Enhanced Dialogue History with Character Icons */
.dialogue-line {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
    margin: 0.5rem 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.dialogue-line:hover {
    background: rgba(50, 50, 60, 0.9);
}

.dialogue-line .character-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.dialogue-line .message-content {
    flex-grow: 1;
    font-size: 1.1rem;
    line-height: 1.4;
    color: #ffffff;
}

.dialogue-line.narrator {
    font-style: italic;
    color: #b0b0b0;
}

.dialogue-line.user-message {
    background: rgba(0, 100, 255, 0.1);
    border-left: 3px solid #4a9eff;
}

/* Character Icon Mappings */
.character-icon[data-character="duck"],
.character-icon[data-character^="duck"] {
    content: url('/duck.png');
}

.character-icon[data-character="goose"] {
    content: url('/goose.png');
}

.character-icon[data-character="frog"] {
    content: url('/Frog.png.jpg');
}

.character-icon[data-character="swan"] {
    content: url('/Swan.png');
}

.character-icon[data-character="segual"] {
    content: url('/Segual.png');
}

.character-icon[data-character="websim"] {
    content: url('/swirl.png');
}

.character-icon[data-character^="mallard"] {
    content: url('/Mallard.png');
}

.character-icon[data-character^="duckling"] {
    content: url('/duckling.webp');
}

.character-icon[data-character="narrator"] {
    content: url('/swirl.png');
    opacity: 0.5;
}

/* Character Base Styles */
.character {
    position: absolute;
    transition: all 0.3s ease-in-out;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.3));
    will-change: transform;
    transform-origin: center;
    pointer-events: none;
}

/* Default Character Sizes */
#duck-1, #duck-2, #duck-3 {
    height: 25%;
    z-index: 12;
}

#goose {
    height: 35%;
    z-index: 10;
}

#frog {
    height: 30%;
    z-index: 10;
}

#swan {
    height: 35%;
    z-index: 11;
}

#segual {
    height: 30%;
    z-index: 11;
}

#websim {
    height: 20%;
    width: auto;
    z-index: 5;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
}

#mallard-1, #mallard-2 {
    height: 25%;
    z-index: 7;
}

#duckling-1, #duckling-2 {
    height: 15%;
    z-index: 13;
}

#user {
    height: 25%;
    z-index: 12;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(0, 0, 0, 0.5);
}

/* Character Default Positions */
.character[id^="duck-"] {
    bottom: 5%;
}

.character[id^="mallard-"] {
    bottom: 8%;
}

.character[id^="duckling-"] {
    bottom: 2%;
}

#goose, #frog {
    bottom: 10%;
}

#swan {
    bottom: 15%;
}

#segual {
    bottom: 20%;
}

/* Improved Speaking Animation */
.speaking {
    animation: speakBounce 0.5s ease-in-out infinite;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.5));
}

@keyframes speakBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-5px) scale(1.02); }
}

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

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

#dialogue-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

#dialogue-history::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Story Control Buttons Enhancement */
#story-control-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#story-control-buttons button {
    flex: 1;
    padding: 0.5rem;
    font-size: 1rem;
    border-radius: 12px;
    background: rgba(70, 70, 90, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transition: all 0.2s ease;
}

#story-control-buttons button:hover {
    background: rgba(80, 80, 100, 0.9);
    transform: translateY(-2px);
}

#story-control-buttons button:active {
    transform: translateY(1px);
}

/* Enhanced User Input Container */
#user-input-container {
    background: rgba(30, 30, 40, 0.9);
    border-radius: 15px;
    padding: 0.5rem;
    margin-top: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

#user-text-input {
    width: 100%;
    padding: 0.5rem;
    min-height: 40px;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(50, 50, 60, 0.9);
    color: #ffffff;
    resize: vertical;
    transition: all 0.2s ease;
}

#user-text-input:focus {
    background: rgba(60, 60, 70, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
    outline: none;
}

/* Improved Items */
.item, .location-item {
    position: absolute;
    transition: all 0.3s ease-in-out;
    z-index: 15;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.3));
    max-height: 15%;
    max-width: 15%;
    pointer-events: none;
}

.held-item {
    position: absolute;
    top: 40%;
    right: -20%;
    transform: translate(-50%, -50%) scale(0.8);
    transition: all 0.3s ease-in-out;
}

.flipped .held-item {
    right: auto;
    left: -20%;
    transform: translate(50%, -50%) scale(0.8) scaleX(-1);
}

/* Responsive Adjustments */
@media screen and (max-width: 768px) {
    #duck-scene {
        height: 60%;
    }

    #dialogue-container {
        height: 40%;
    }

    .character {
        transform: scale(0.9);
    }

    #subtitles {
        font-size: 1.1rem;
        min-height: 2rem;
        padding: 0.5rem;
    }

    #dialogue-history p {
        font-size: 1rem;
        padding: 0.5rem;
    }

    .item, .location-item {
        max-height: 12%;
        max-width: 12%;
    }
}

/* Mobile Specific Adjustments */
@media screen and (max-width: 480px) {
    #duck-scene {
        height: 55%;
    }

    #dialogue-container {
        height: 45%;
    }

    .character {
        transform: scale(0.8);
    }

    #subtitles {
        font-size: 1rem;
        min-height: 1.8rem;
    }

    #dialogue-history p {
        font-size: 0.9rem;
    }

    .item, .location-item {
        max-height: 10%;
        max-width: 10%;
    }
}

/* Character Animations */
@keyframes nod-animation {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(15deg); }
}

@keyframes shake-head-animation {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

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

#continue-story-button, #talk-to-ducks-button {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.3rem;
    padding: 0.7rem 1.2rem;
    border: 3px solid #444;
    background-color: #333;
    color: #e0e0e0;
    cursor: pointer;
    border-radius: 10px;
    font-weight: 700;
    width: 48%; /* To fit two buttons with gap */
    transition: background-color 0.2s, transform 0.1s;
}

#continue-story-button:hover, #talk-to-ducks-button:hover {
    background-color: #444;
}

#continue-story-button:active, #talk-to-ducks-button:active {
    background-color: #555;
    transform: translateY(2px);
}

#user-submit-button, #user-skip-input-button, #user-finish-button {
    font-family: 'Comic Sans MS Custom', cursive, sans-serif;
    font-size: 1.3rem; /* Adjusted font size */
    padding: 0.5rem;
    margin: 0;
    border: 3px solid #444; /* Darker border */
    background-color: #333; /* Darker button */
    color: #e0e0e0; /* Light text */
    cursor: pointer;
    border-radius: 10px;
    font-weight: 700;
    width: 32%; /* Adjust width to fit two buttons */
    transition: background-color 0.2s, transform 0.1s;
}

#user-submit-button:hover, #user-skip-input-button:hover, #user-finish-button:hover {
    background-color: #444;
}

#user-submit-button:active, #user-skip-input-button:active, #user-finish-button:active {
    background-color: #555;
    transform: translateY(2px);
}

#user-skip-input-button {
    background-color: #cc7000; /* Darker orange */
    border-color: #e67e00;
}

#user-skip-input-button:hover {
    background-color: #e67e00;
}

#user-skip-input-button:active {
    background-color: #cc7000;
}

#user-finish-button {
    background-color: #b71c1c; /* Darker red color for end */
    color: white;
    border-color: #9c0c0c;
}

#user-finish-button:hover {
    background-color: #9c0c0c;
}
#user-finish-button:active {
    background-color: #880000;
}

#ai-explanation-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}