/* --- YOIMIYA PALETTE & GLOBAL STYLES --- */
:root {
    --yoi-dark-bg: #1a1a2e;
    --yoi-panel-bg: #252540;
    --yoi-orange-vivid: #FF4500;
    --yoi-orange-light: #FF8C00;
    --yoi-gold: #FFD700;
    --yoi-gold-glow: #ffeba1;
    --text-primary: #ffffff;
    --text-secondary: #b0b0d0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Montserrat', sans-serif;
    background-color: var(--yoi-dark-bg);
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(255, 140, 0, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 69, 0, 0.15) 0%, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* Needed for absolute positioning of creator info */
}

.app-container {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    position: relative;
    z-index: 1;
}

header h1 {
    font-weight: 900;
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 30px;
    text-align: center;
    line-height: 1.2;
    background: linear-gradient(to right, var(--yoi-gold), var(--yoi-orange-light), var(--yoi-orange-vivid));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 140, 0, 0.5);
}

/* --- FIREWORKS SYSTEM --- */
#fireworks-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.app-container {
    z-index: 1; 
    position: relative;
}

/* The individual spark particle */
.spark {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    opacity: 0;
    transform: translate(0, 0);
    animation: explode 2s ease-out forwards;
}

@keyframes explode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translate(var(--dx), var(--dy)) scale(0);
        opacity: 0;
    }
}

/* --- FLOATING SETTINGS BUTTON --- */
.settings-floater {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    
    background: rgba(37, 37, 64, 0.8);
    border: 2px solid var(--yoi-gold);
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    cursor: pointer;
    z-index: 3;
    backdrop-filter: blur(5px);
    
    overflow: hidden;
    transition: transform 0.5s ease, border-color 0.5s ease;
}

/* The Gradient Overlay (Hidden by default) */
.settings-floater::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    
    background: linear-gradient(to right, var(--yoi-gold), var(--yoi-orange-light), var(--yoi-orange-vivid));
    
    opacity: 0;
    transition: opacity 0.5s ease;
    
    z-index: 0;
}

/* The Image/Icon inside */
.settings-floater img {
    position: relative;
    z-index: 1;
    transition: filter 0.5s ease;
}

/* --- HOVER STATES --- */
.settings-floater:hover {
    transform: rotate(180deg);
    border-color: #fff;
}

.settings-floater:hover::before {
    opacity: 1;
}

/* Settings Group */
.settings-group {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid #444;
}

.settings-group h3 {
    margin-top: 0;
    color: var(--yoi-orange-light);
    font-size: 1rem;
    margin-bottom: 15px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    gap: 15px;
}

.setting-row label {
    color: #ccc;
    font-size: 0.9rem;
    min-width: 100px;
}

.separator {
    border: 0;
    height: 1px;
    background: #444;
    margin: 20px 0;
}

/* Range Slider */
.range-container {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-grow: 1;
    padding: 0 5px;
}

.range-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--yoi-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 5px rgba(0,0,0,0.8);
}

/* The Range Input Base */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent; 
    height: 30px;
    cursor: pointer;
}

input[type=range]:focus {
    outline: none;
}

/* --- THE TRACK (The Fuse Line) --- */
/* Chrome/Safari/Edge */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #1a1a2e;
    border-radius: 3px;
    border: 1px solid #444;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.8);
}
/* Firefox */
input[type=range]::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #1a1a2e;
    border-radius: 3px;
    border: 1px solid #444;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.8);
}

/* --- THE THUMB (The Spark) --- */
/* Chrome/Safari/Edge */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 22px;
    width: 22px;
    margin-top: -9px;
    
    /* The Fireball Look */
    background: radial-gradient(circle at 35% 35%, var(--yoi-gold-glow) 0%, var(--yoi-orange-vivid) 60%, var(--yoi-orange-light) 100%);
    border: 1px solid #fff;
    border-radius: 10%;
    
    /* The Glow */
    box-shadow: 
        0 0 10px var(--yoi-orange-vivid), 
        0 0 4px var(--yoi-gold) inset;
    
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s;
}

/* Firefox */
input[type=range]::-moz-range-thumb {
    height: 7px;
    width: 22px;
    border: none;
    
    /* The Fireball Look */
    background: radial-gradient(circle at 35% 35%, var(--yoi-gold-glow) 0%, var(--yoi-orange-vivid) 60%, var(--yoi-orange-light) 100%);
    border: 1px solid #fff;
    border-radius: 10%;
    
    box-shadow: 
        0 0 10px var(--yoi-orange-vivid), 
        0 0 4px var(--yoi-gold) inset;
        
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s;
}

/* --- INTERACTIVE STATES --- */
input[type=range]:hover::-webkit-slider-runnable-track {
    background: #202035;
}

/* When GRABBING the spark */
input[type=range]:active::-webkit-slider-thumb {
    transform: scale(1.3);
    background: var(--yoi-gold);
    box-shadow: 
        0 0 20px var(--yoi-gold), 
        0 0 10px var(--yoi-orange-vivid);
}

input[type=range]:active::-moz-range-thumb {
    transform: scale(1.3);
    background: var(--yoi-gold);
    box-shadow: 
        0 0 20px var(--yoi-gold), 
        0 0 10px var(--yoi-orange-vivid);
}

/* --- VISUAL TREE EDITOR STYLES --- */
#tree-editor-container {
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 15px;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    background: #181825;
}

.tree-node {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.node-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px;
    border-radius: 6px;
    border: 1px solid transparent;
}
.node-row:hover { border-color: #444; }

.node-children {
    margin-left: 15px;
    padding-left: 8px;
    border-left: 2px solid var(--yoi-orange-light);
    margin-top: 5px;
}

.tree-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid #555;
    color: var(--yoi-gold-glow);
    font-family: 'Montserrat', sans-serif;
    padding: 5px;
    flex-grow: 1;
    font-size: 0.9rem;
    min-width: 0; /* Prevents input from overflowing flex container */
}
.tree-input:focus {
    outline: none;
    border-bottom-color: var(--yoi-orange-vivid);
}

.btn-icon {
    background: none;
    border: 1px solid #555;
    color: #888;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    flex-shrink: 0;
    transition: all 0.2s;
}
.btn-icon:hover { color: #fff; border-color: #fff; }

.btn-add-sub { color: var(--yoi-gold); border-color: var(--yoi-gold); }
.btn-add-sub:hover { background: var(--yoi-gold); color: #000; }
.btn-del { color: #ff6b6b; border-color: #ff6b6b; }
.btn-del:hover { background: #ff6b6b; color: #fff; }

.btn-add-root {
    width: 100%;
    margin-top: 10px;
    border: 2px dashed #555;
    background: transparent;
    color: #888;
    padding: 12px;
    cursor: pointer;
}
.btn-add-root:hover { border-color: var(--yoi-gold); color: var(--yoi-gold); }

/* --- LOG --- */
.log-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    height: 100vh;
    background: rgba(26, 26, 46, 0.95); 
    border-right: 2px solid var(--yoi-gold);
    display: flex;
    z-index: 2;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 5px 0 20px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
}

/* Minimized State (Desktop) */
.log-sidebar.minimized {
    transform: translateX(-280px);
}

/* The Toggle Button (Desktop) */
#toggleLogBtn {
    position: absolute;
    right: -30px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(26, 26, 46, 0.95); 
    border: 2px solid var(--yoi-gold);
    border-left: 2px solid rgba(26, 26, 46, 0.95);
    border-radius: 0 8px 8px 0;
    color: var(--yoi-gold);
    width: 30px;
    height: 60px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-shadow: 5px 0 10px rgba(0,0,0,0.3);
}

/* --- LOG CONTENT STYLING --- */
.log-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.log-header h3 { margin: 0; color: var(--yoi-gold); font-size: 1rem; text-transform: uppercase; letter-spacing: 1px; }

.log-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Individual Log Item */
.log-entry {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 6px;
    border-left: 3px solid var(--yoi-orange-light);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
}
.log-entry .timestamp {
    display: block;
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 3px;
}
.log-entry .result-path {
    color: var(--text-primary);
    font-weight: bold;
}
.log-entry .final-val { color: var(--yoi-gold-glow); }

.log-footer {
    padding: 15px;
    border-top: 1px solid rgba(255, 215, 0, 0.2);
    text-align: center;
}

.btn-danger-text {
    color: #ff6b6b;
    border-color: #5a1e1e;
}
.btn-danger-text:hover { background: #5a1e1e; color: white; }
.empty-state { color: #666; font-style: italic; text-align: center; margin-top: 20px; }

/* --- STAGE AREA & ROLLING BOXES --- */
#stage-area {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    min-height: 180px;
    margin-bottom: 50px;
}

.placeholder-message {
    color: var(--text-secondary);
    font-style: italic;
    align-self: center;
    text-align: center;
}

.fate-box {
    position: relative;
    width: 220px;
    height: 140px;
    background: var(--yoi-panel-bg);
    border-radius: 16px;
    border: 3px solid #444;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.4);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.fate-box .tier-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--yoi-gold);
    opacity: 0.8;
    margin-bottom: 5px;
}

.fate-box .fate-value {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    padding: 0 15px;
    z-index: 2;
    word-wrap: break-word; /* Prevents long words breaking layout */
}

.fate-box.rolling {
    border-color: var(--yoi-orange-light);
    box-shadow: 0 0 25px var(--yoi-orange-light), inset 0 0 10px var(--yoi-orange-light);
    animation: slight-vibration 0.1s infinite;
}

.fate-box.locked {
    border-color: var(--yoi-gold);
    background: linear-gradient(135deg, var(--yoi-panel-bg), #3a2520);
    animation: landmark-flash 0.6s ease-out forwards;
}
.fate-box.locked .fate-value {
    color: var(--yoi-gold-glow);
    text-shadow: 0 0 10px var(--yoi-gold);
}


/* --- CONTROLS --- */
.controls-area {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    flex-direction: column; /* Stack button and dropdown vertically */
    gap: 15px;
    align-items: center;
    width: 100%;
    max-width: 300px;
}

.btn {
    padding: 15px 30px;
    width: 100%;
    border: none;
    border-radius: 50px;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn:active { transform: scale(0.97); }

.fire-btn {
    background: linear-gradient(to right, var(--yoi-orange-vivid), var(--yoi-orange-light));
    color: white;
    box-shadow: 0 4px 15px rgba(255, 69, 0, 0.4);
}
.fire-btn:hover { box-shadow: 0 6px 25px rgba(255, 69, 0, 0.6); }

.btn-secondary {
    background: transparent;
    border: 2px solid var(--yoi-orange-light);
    color: var(--yoi-orange-light);
}
.btn-secondary:hover { background: rgba(255, 140, 0, 0.1); }
.btn-danger { background: #5a1e1e; color: #ff9999; }


/* --- DROPDOWN STYLE --- */
.select-wrapper {
    width: 100%;
    position: relative;
}

/* Custom Arrow using CSS pseudo-element */
.select-wrapper::after {
    content: '▼';
    font-size: 0.8rem;
    color: var(--yoi-gold);
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.fate-select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    
    background-color: rgba(37, 37, 64, 0.9);
    border: 2px solid var(--yoi-orange-light);
    color: var(--yoi-gold-glow);
    padding: 12px 15px;
    border-radius: 8px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    text-align-last: center; /* Centers text for Chrome */
}

.fate-select:hover {
    border-color: var(--yoi-gold);
    box-shadow: 0 0 10px rgba(255, 140, 0, 0.3);
}

.fate-select:focus {
    outline: none;
    border-color: var(--yoi-orange-vivid);
    box-shadow: 0 0 15px var(--yoi-orange-vivid);
}

/* Styling for the options inside the dropdown (Browser dependent, but helps) */
.fate-select option {
    background-color: var(--yoi-dark-bg);
    color: #fff;
    padding: 10px;
}


/* --- MODAL (SETTINGS) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    display: none; 
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--yoi-panel-bg);
    width: 100%;
    max-width: 800px;
    max-height: 90vh; /* Don't overflow screen height */
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    border: 2px solid var(--yoi-orange-vivid);
    box-shadow: 0 0 30px rgba(255, 69, 0, 0.3);
}

.modal-header {
    padding: 15px 20px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; color: var(--yoi-gold); }
.close-modal {
    background: none; border: none; color: var(--text-secondary); font-size: 2rem; cursor: pointer; padding: 0; line-height: 1;
}

.modal-body { 
    padding: 20px; 
    overflow-y: auto; /* Scroll inside modal if content is long */
}

.modal-footer {
    padding: 15px 20px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.main-actions, .backup-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-text-only {
    background: transparent;
    border: 1px solid #555;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-text-only:hover {
    border-color: var(--yoi-gold);
    color: var(--yoi-gold);
    background: rgba(255, 215, 0, 0.05);
}

/* --- CREATOR INFO --- */
#creator-info {
    margin-top: 25px;
    
    /* Center text */
    text-align: center;
    width: 100%;
    
    /* Typography */
    font-family: 'Montserrat', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
    
    color: var(--yoi-gold);
    opacity: 0.6;
    
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    
    /* Non-interactive */
    pointer-events: none;
    user-select: none;
    
    animation: fadeInSlow 0.5s ease-out forwards;
}

/* --- ANIMATIONS --- */
@keyframes slight-vibration {
    0% { transform: translate(0,0); }
    25% { transform: translate(1px, 1px); }
    50% { transform: translate(0,0); }
    75% { transform: translate(-1px, -1px); }
    100% { transform: translate(0,0); }
}

@keyframes landmark-flash {
    0% { transform: scale(1); box-shadow: 0 0 0 var(--yoi-gold); }
    10% { transform: scale(1.05); background-color: var(--yoi-gold); box-shadow: 0 0 50px var(--yoi-gold); }
    100% { transform: scale(1); box-shadow: 0 10px 25px rgba(255, 215, 0, 0.3); }
}

@keyframes fadeInSlow {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 0.6; transform: translateY(0); }
}

/* MOBILE RESPONSIVENESS */

@media (max-width: 768px) {
    /* FORCE VERTICAL STACKING */
    body {
        flex-direction: column;
        justify-content: flex-start;
        padding-bottom: 40px;
    }

    /* Header Adjustments */
    header h1 {
        margin-top: 60px; /* Clear the settings button */
        font-size: 1.8rem; 
        margin-bottom: 20px;
    }

    /* Floating Button Size */
    .settings-floater {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        top: 15px;
        right: 15px;
    }

    /* Adventure Log*/
    .log-sidebar {
        /* Stop floating on the screen */
        position: relative; 
        top: auto; left: auto;
        
        /* Layout & Dimensions */
        width: 95%; /* Match app width */
        max-width: 500px;
        height: auto; /* Grow with content */
        min-height: 250px;
        max-height: 400px;
        
        /* Placement */
        margin-top: 40px;
        order: 10;
        
        /* Styling Override */
        background: rgba(26, 26, 46, 0.6);
        border-right: none;
        border: 2px solid var(--yoi-gold);
        border-radius: 12px;
        
        /* Disable Desktop Interaction */
        transform: none !important;
        box-shadow: none;
    }
    
    /* Hide the minimize arrow on mobile */
    #toggleLogBtn { display: none; }
    
    .log-content {
        max-height: 250px;
    }

    /* Stage Area & Boxes */
    #stage-area {
        gap: 15px;
        margin-bottom: 30px;
    }
    
    .fate-box {
        width: 100%; 
        max-width: 300px; 
        height: 100px; 
    }
    
    .fate-box .fate-value { font-size: 1.2rem; }

    /* Modal Adjustments */
    .modal-content {
        height: auto;
        max-height: 85vh;
        width: 95%;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 15px;
    }

    .main-actions, .backup-controls {
        width: 100%;
        justify-content: center;
    }

    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .setting-row input {
        width: 100%;
    }

    /* Creator Info */
    #creator-info {
        position: static;
        margin-top: 20px;
    }
}