/* Upload Screen Styles */
#upload-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a28 0%, #0c0c14 100%);
    z-index: 9999;
    transition: opacity 0.6s ease-in-out;
}

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

.upload-content {
    text-align: center;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
}

.upload-icon {
    margin-bottom: 1.5rem;
}

.camera-icon {
    font-size: 4rem;
    animation: float 3s ease-in-out infinite;
}

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

#upload-screen h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
    color: #d4a853;
    text-shadow: 0 0 30px rgba(212, 168, 83, 0.3);
}

.upload-subtitle {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: #9a9590;
    margin-bottom: 2rem;
}

.upload-zone {
    border: 2px dashed rgba(212, 168, 83, 0.4);
    border-radius: 12px;
    padding: 3rem 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(26, 26, 40, 0.5);
    margin-bottom: 1.5rem;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: #d4a853;
    background: rgba(212, 168, 83, 0.08);
}

.upload-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: #9a9590;
    font-family: var(--font-display);
}

.upload-icon-small {
    font-size: 2.5rem;
    color: #d4a853;
    line-height: 1;
}

.uploaded-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.uploaded-image-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(212, 168, 83, 0.3);
    animation: fadeIn 0.3s ease;
}

.uploaded-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(199, 91, 122, 0.9);
    border: none;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.remove-image-btn:hover {
    background: #c75b7a;
    transform: scale(1.1);
}

.upload-actions {
    margin-top: 1rem;
}

#start-story-button {
    padding: 1rem 3rem;
    background: transparent;
    color: #d4a853;
    border: 2px solid #d4a853;
    border-radius: 6px;
    font-family: var(--font-display);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

#start-story-button:hover:not(:disabled) {
    background: #d4a853;
    color: #0c0c14;
}

#start-story-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.upload-error {
    color: #c75b7a;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-top: 1rem;
    min-height: 1.5rem;
}

:root {
    --bg-deep: #0c0c14;
    --bg-mid: #14141f;
    --bg-surface: #1a1a28;
    --text-primary: #f0ede6;
    --text-secondary: #9a9590;
    --accent-gold: #d4a853;
    --accent-copper: #c77b4a;
    --accent-teal: #4a9c8f;
    --accent-violet: #8b6bb5;
    --accent-rose: #c75b7a;
    --border-subtle: rgba(212, 168, 83, 0.15);
    --shadow-deep: rgba(0, 0, 0, 0.6);
    --font-display: 'Crimson Pro', Georgia, serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font-display);
    background: var(--bg-deep);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.6;
}

body.debug-hidden #debug-console-container {
    display: none;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a28 0%, #0c0c14 100%);
    z-index: 9999;
    transition: opacity 0.6s ease-in-out;
}

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

.loading-content {
    text-align: center;
    padding: 2rem;
}

.loading-icon {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 2rem;
}

.quill {
    width: 4px;
    height: 50px;
    background: linear-gradient(to bottom, var(--accent-gold), var(--accent-copper));
    border-radius: 2px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    transform-origin: bottom center;
    animation: write 1.5s ease-in-out infinite;
}

.quill::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -6px;
    width: 16px;
    height: 20px;
    background: var(--accent-gold);
    clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.ink-drops {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
}

.ink-drops span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent-gold);
    border-radius: 50%;
    margin: 0 3px;
    animation: drop 1.5s ease-in-out infinite;
}

.ink-drops span:nth-child(2) { animation-delay: 0.3s; }
.ink-drops span:nth-child(3) { animation-delay: 0.6s; }

@keyframes write {
    0%, 100% { transform: translate(-50%, -50%) rotate(-30deg); }
    50% { transform: translate(-50%, -50%) rotate(-35deg) translateX(5px); }
}

@keyframes drop {
    0%, 100% { opacity: 0.3; transform: scale(0.5); }
    50% { opacity: 1; transform: scale(1); }
}

#loading-screen h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    margin-bottom: 1.5rem;
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(212, 168, 83, 0.3);
}

#loading-status {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    min-height: 1.5rem;
    letter-spacing: 0.05em;
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.progress-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-gold);
    border-radius: 50%;
    animation: dotPulse 1.5s ease-in-out infinite;
}

.progress-dots span:nth-child(1) { animation-delay: 0s; }
.progress-dots span:nth-child(2) { animation-delay: 0.2s; }
.progress-dots span:nth-child(3) { animation-delay: 0.4s; }
.progress-dots span:nth-child(4) { animation-delay: 0.6s; }
.progress-dots span:nth-child(5) { animation-delay: 0.8s; }

@keyframes dotPulse {
    0%, 100% { opacity: 0.2; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

#error-message {
    color: var(--accent-rose);
    margin-top: 1.5rem;
    display: none;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

#retry-button {
    margin-top: 1.5rem;
    padding: 0.75rem 2.5rem;
    background: transparent;
    color: var(--accent-gold);
    border: 1px solid var(--accent-gold);
    border-radius: 4px;
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    display: none;
    transition: all 0.3s ease;
}

#retry-button:hover {
    background: var(--accent-gold);
    color: var(--bg-deep);
}

/* VN App Container */
#vn-app {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#vn-app.visible {
    display: flex;
    opacity: 1;
}

/* Header */
.vn-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.25rem;
    background: linear-gradient(to bottom, rgba(12, 12, 20, 0.95), rgba(12, 12, 20, 0.8));
    backdrop-filter: blur(10px);
    z-index: 100;
    border-bottom: 1px solid var(--border-subtle);
}

.story-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--accent-gold);
    letter-spacing: 0.05em;
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-button {
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s ease;
}

.menu-button span {
    width: 18px;
    height: 2px;
    background: var(--accent-gold);
    border-radius: 1px;
    transition: all 0.3s ease;
}

.menu-button:hover {
    border-color: var(--accent-gold);
    background: rgba(212, 168, 83, 0.1);
}

/* Scene Container */
.scene-container {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    margin-top: 56px;
    background: var(--bg-deep);
    overflow: hidden;
}

.scene-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.5s ease-in-out, filter 0.5s ease-in-out;
}

.scene-image.loading {
    opacity: 0.4;
    filter: blur(20px) saturate(0.5);
}

.scene-vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(12, 12, 20, 0.6) 100%);
    pointer-events: none;
}

.image-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    align-items: center;
    justify-content: center;
}

.loader-ring {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(212, 168, 83, 0.2);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Text Box */
.text-box {
    position: relative;
    margin: -2.5rem 1rem 1rem;
    background: rgba(20, 20, 31, 0.95);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 10px 40px var(--shadow-deep);
    z-index: 10;
}

.text-box-decoration {
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
    border-radius: 2px;
}

.speaker-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid;
    display: inline-block;
}

.speaker-protagonist,
.speaker-youtheplayercharacter { border-color: var(--accent-gold); color: var(--accent-gold); }
.speaker-rival,
.speaker-antagonist { border-color: var(--accent-rose); color: var(--accent-rose); }
.speaker-companion { border-color: var(--accent-teal); color: var(--accent-teal); }
.speaker-mentor { border-color: var(--accent-copper); color: var(--accent-copper); }
.speaker-default { border-color: var(--accent-violet); color: var(--accent-violet); }

.scene-text {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1.8;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.choices-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.choice-button {
    width: 100%;
    min-height: 50px;
    padding: 0.875rem 1.25rem;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-family: var(--font-display);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.choice-marker {
    color: var(--accent-gold);
    font-size: 1.25rem;
    transition: transform 0.3s ease;
}

.choice-button:hover {
    border-color: var(--accent-gold);
    background: rgba(212, 168, 83, 0.08);
    padding-left: 1.5rem;
}

.choice-button:hover .choice-marker {
    transform: translateX(4px);
}

.choice-button:active {
    background: rgba(212, 168, 83, 0.15);
}

.choice-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Custom Choice Input */
#custom-choice-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
}

#custom-choice-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    background: rgba(12, 12, 20, 0.8);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

#custom-choice-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

#custom-choice-input:focus {
    outline: none;
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(212, 168, 83, 0.1);
}

#custom-choice-submit {
    width: 44px;
    height: 44px;
    border-radius: 4px;
    border: 1px solid var(--accent-gold);
    background: transparent;
    color: var(--accent-gold);
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#custom-choice-submit:hover {
    background: var(--accent-gold);
    color: var(--bg-deep);
}

#custom-choice-submit:disabled,
#custom-choice-input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Generating Indicator */
.generating-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 2rem;
    color: var(--accent-gold);
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.05em;
}

.gen-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(212, 168, 83, 0.2);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.error-indicator {
    text-align: center;
    padding: 2rem;
    color: var(--accent-rose);
    font-family: var(--font-display);
}

/* Ending Screen */
.ending-container {
    text-align: center;
    padding: 1.5rem 0.5rem;
}

.ending-badge {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: rgba(212, 168, 83, 0.15);
    border: 1px solid var(--accent-gold);
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--accent-gold);
    margin-bottom: 1rem;
}

.ending-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.ending-description {
    font-family: var(--font-display);
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.ending-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ending-button {
    padding: 1rem 1.5rem;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: transparent;
    color: var(--text-primary);
}

.restart-button {
    border-color: var(--accent-teal);
    color: var(--accent-teal);
}

.restart-button:hover {
    background: var(--accent-teal);
    color: var(--bg-deep);
}

.new-story-button {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.new-story-button:hover {
    background: var(--accent-gold);
    color: var(--bg-deep);
}

/* Menu Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(12, 12, 20, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease-in-out;
}

.modal-overlay.visible {
    display: flex;
}

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

.modal-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 2rem;
    max-width: 360px;
    width: 90%;
    animation: slideIn 0.3s ease-in-out;
}

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

.modal-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--accent-gold);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modal-button {
    padding: 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.3s ease;
    background: transparent;
    color: var(--text-primary);
}

.resume-button {
    border-color: var(--accent-teal);
    color: var(--accent-teal);
}

.resume-button:hover {
    background: var(--accent-teal);
    color: var(--bg-deep);
}

.reset-button {
    border-color: var(--accent-rose);
    color: var(--accent-rose);
}

.reset-button:hover {
    background: var(--accent-rose);
    color: var(--bg-deep);
}

/* Footer */
.vn-footer {
    padding: 1.5rem 1rem;
    text-align: center;
    margin-top: auto;
}

.vn-footer a {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    text-decoration: none;
    opacity: 0.6;
    transition: all 0.3s ease;
}

.vn-footer a:hover {
    opacity: 1;
    color: var(--accent-gold);
}

/* Debug Console */
#debug-console-container {
    margin: 0.5rem 1rem 1rem;
    background: rgba(12, 12, 20, 0.95);
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    overflow: hidden;
}

#debug-console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: rgba(212, 168, 83, 0.08);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent-gold);
}

#debug-toggle-btn {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 3px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
}

#debug-toggle-btn:hover {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

#debug-console-body {
    padding: 0.5rem 0.75rem;
    max-height: 18vh;
    overflow-y: auto;
    white-space: pre-wrap;
}

.debug-line {
    margin-bottom: 0.4rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

.debug-label {
    color: var(--accent-copper);
    font-weight: 500;
}

.debug-success {
    color: var(--accent-teal);
}

.debug-error {
    color: var(--accent-rose);
}

.debug-warning {
    color: var(--accent-gold);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    #loading-screen h1 {
        font-size: 1.6rem;
    }

    .story-title {
        font-size: 1rem;
    }

    .text-box {
        margin: -2rem 0.75rem 0.75rem;
        padding: 1.25rem;
    }

    .scene-text {
        font-size: 1rem;
    }

    .choice-button {
        font-size: 0.95rem;
        min-height: 48px;
    }

    #custom-choice-container {
        flex-direction: row;
    }

    #custom-choice-input {
        font-size: 0.9rem;
    }

    .ending-title {
        font-size: 1.4rem;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
    background: rgba(212, 168, 83, 0.25);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 168, 83, 0.4);
}

/* Selection styling */
::selection {
    background: rgba(212, 168, 83, 0.3);
    color: var(--text-primary);
}