:root {
    --bg-dark: #050508;
    --card-bg: #111116;
    --text-parchment: #e3d4b5;
    --text-dim: #9a8c73;
    --gold: #c8aa6e;
    --gold-glow: #ebdcb2;
    --void-purple: #9b59b6;
    --border-purple-muted: #5a4a6e;
}

body {
    background-color: var(--bg-dark);
    background: radial-gradient(circle at 50% -20%, #1a1a24 0%, #050508 60%),
                radial-gradient(circle at 80% 80%, #0e0e12 0%, transparent 40%);
    color: var(--text-parchment);
    font-family: 'Alegreya', serif; 
    font-size: 18px;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

/* Starfield */
.stars-layer {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: 
        radial-gradient(1px 1px at 20px 30px, #fff, rgba(0,0,0,0)),
        radial-gradient(1px 1px at 40px 70px, #fff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 90px 40px, #fff, rgba(0,0,0,0));
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.1;
    z-index: -1;
    animation: twinkle 25s infinite linear;
}

@keyframes twinkle {
    0% { transform: translateY(0); }
    100% { transform: translateY(-200px); }
}

.container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    width: 95%;
    text-align: center;
    padding-top: 5vh;
    padding-bottom: 3rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

h1 {
    font-family: 'Alegreya SC', serif; 
    color: var(--text-parchment);
    font-size: 3.5rem;
    margin: 0;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(155, 89, 182, 0.4);
    letter-spacing: 3px;
    line-height: 1;
}

.subtitle {
    color: var(--text-dim);
    margin-top: 0.5rem;
    margin-bottom: 2rem;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.flavor-container {
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid #333;
    border-bottom: 1px solid #333;
    padding: 15px 20px;
    margin: 0 auto 3rem auto;
    max-width: 650px;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.flavor-text {
    font-family: 'Alegreya', serif;
    color: var(--text-parchment);
    font-size: 1.2rem;
    line-height: 1.5;
    margin: 0;
    opacity: 0.95;
    text-shadow: 0 2px 5px rgba(0,0,0,0.8);
}

.highlight-text {
    color: var(--gold);
    font-weight: 700;
    font-family: 'Alegreya SC', serif;
}

a { color: inherit; text-decoration: none; transition: 0.2s; }
a:visited { color: inherit; }

/* Config Panel */
.config-panel {
    background: rgba(19, 19, 24, 0.95);
    border: 1px solid var(--border-purple-muted);
    border-radius: 4px;
    padding: 15px 30px;
    display: inline-flex;
    gap: 3rem;
    justify-content: center;
    align-items: center;
    margin: 0 auto 2.5rem auto;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.config-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

.config-label {
    font-family: 'Alegreya SC', serif;
    color: var(--gold);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* Radio Buttons */
.radio-group { display: flex; gap: 15px; }
.radio-group label { cursor: pointer; display: flex; align-items: center; gap: 8px; position: relative; user-select: none; }
.radio-group input { position: absolute; opacity: 0; cursor: pointer; }
.radio-gem { width: 16px; height: 16px; background: #000; border: 2px solid #555; border-radius: 50%; transition: 0.3s; box-shadow: inset 0 0 5px #000; position: relative; }
.radio-gem::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0); width: 10px; height: 10px; background: var(--gold); border-radius: 50%; box-shadow: 0 0 10px var(--gold), inset 0 0 3px #fff; transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.radio-group input:checked + .radio-gem { border-color: var(--gold); }
.radio-group input:checked + .radio-gem::after { transform: translate(-50%, -50%) scale(1); }
.radio-group:hover .radio-gem { border-color: #888; }
.radio-label { font-family: 'Alegreya SC', serif; color: var(--text-dim); font-size: 1rem; transition: 0.3s; }
.radio-group input:checked ~ .radio-label { color: var(--gold); text-shadow: 0 0 8px rgba(200, 170, 110, 0.3); }

/* Toggle */
.toggle-wrapper { display: flex; align-items: center; }
.toggle-checkbox { display: none; }
.toggle-label { cursor: pointer; display: flex; align-items: center; gap: 12px; font-size: 1rem; color: var(--text-dim); font-family: 'Alegreya SC', serif; user-select: none; }
.toggle-switch { width: 44px; height: 22px; background: #0b0b0f; border: 1px solid #444; border-radius: 20px; position: relative; transition: 0.3s; box-shadow: inset 0 0 5px #000; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #666; border-radius: 50%; transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); box-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.toggle-label:hover .toggle-switch { border-color: #666; }
.toggle-checkbox:checked + .toggle-label .toggle-switch { border-color: var(--void-purple); box-shadow: 0 0 10px rgba(155, 89, 182, 0.2), inset 0 0 5px #000; }
.toggle-checkbox:checked + .toggle-label .toggle-thumb { transform: translateX(22px); background: var(--void-purple); box-shadow: 0 0 10px var(--void-purple), inset 0 0 2px #fff; }
.toggle-checkbox:checked + .toggle-label .toggle-text { color: var(--void-purple); text-shadow: 0 0 8px rgba(155, 89, 182, 0.4); }

/* Exchange Zone */
.exchange-zone { 
    height: 300px; display: flex; justify-content: center; align-items: center; perspective: 1000px; 
    transition: 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
.exchange-zone.collapsed { height: 0; opacity: 0; pointer-events: none; margin-bottom: 0; transform: scale(0.8); }
.deck-container { position: relative; width: 170px; height: 260px; cursor: pointer; transition: transform 0.3s ease; }
.deck-container:hover { transform: scale(1.05) translateY(-5px); }
.div-card-stack { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #111; border: 1px solid #444; transform: rotate(-2deg) translate(-3px, -3px); z-index: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.div-card-stack:nth-child(2) { transform: rotate(2deg) translate(3px, -2px); z-index: 2; }
.div-card-main { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; background: #000; border: 1px solid #444; overflow: hidden; box-shadow: 0 5px 20px rgba(0,0,0,0.8); }
.div-card-main img { width: 100%; height: 100%; object-fit: cover; opacity: 0.9; }
.card-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background: rgba(0,0,0,0.3); pointer-events: none; }
.click-instruction { font-family: 'Alegreya SC', serif; font-size: 1.1rem; font-weight: 700; color: var(--gold-glow); border: 1px solid var(--gold); padding: 6px 14px; background: rgba(0,0,0,0.85); letter-spacing: 1.5px; box-shadow: 0 0 10px rgba(0,0,0,0.5); }

/* Deal Animation */
.deck-container.dealing { 
    animation: deal-anim 0.5s forwards cubic-bezier(0.6, -0.28, 0.735, 0.045); 
}
@keyframes deal-anim { 0% { transform: scale(1); } 50% { transform: scale(1.1) rotate(5deg); box-shadow: 0 0 30px var(--void-purple); } 100% { transform: scale(0) translateY(150px); opacity: 0; } }

/* --- RESULTS --- */
.fate-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch; 
    gap: 20px;
    width: 100%;
    min-height: 0; 
}

.fate-card {
    background: var(--card-bg);
    border: 1px solid var(--border-purple-muted); 
    flex: 1; 
    max-width: 340px; 
    min-width: 260px;
    height: auto;
    min-height: 100%;
    opacity: 0;
    transform: translateY(30px);
    display: none;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    border-radius: 2px;
    position: relative;
    flex-direction: column; 
    padding-bottom: 20px; 
}

.fate-card.revealed {
    display: flex; 
    animation: card-reveal 0.4s forwards cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes card-reveal {
    0% { opacity: 0; transform: translateY(40px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.card-header {
    background: linear-gradient(90deg, transparent, rgba(90, 74, 110, 0.3), transparent);
    color: var(--gold);
    font-family: 'Alegreya SC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 14px;
    border-bottom: 1px solid var(--border-purple-muted);
    letter-spacing: 1px;
    text-shadow: 0 2px 5px rgba(0,0,0,0.8);
    flex-shrink: 0; 
}

.card-inner {
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.fate-card.highlight { box-shadow: 0 0 25px rgba(155, 89, 182, 0.15); }

/* Delays */
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }

.fate-value { font-family: 'Alegreya SC', serif; font-size: 1.6rem; font-weight: 700; color: var(--text-parchment); margin: 10px 0 2px 0; line-height: 1.2; }
.fate-sub { color: var(--text-dim); font-size: 1rem; }

/* Image Frames for Smooth Loading */
.icon-frame {
    width: 64px;
    height: 64px;
    margin-bottom: 15px;
    background: transparent;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Portrait Frame */
.portrait-frame { 
    width: 50px; 
    height: 50px; 
    border-radius: 50%; 
    border: 2px solid var(--border-purple-muted);
}

.main-icon { 
    width: 100%; height: 100%; object-fit: cover;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,0.8));
    transition: transform 0.2s, opacity 0.4s ease-in;
    opacity: 0; 
}
.main-icon.loaded { opacity: 1; }

.result-link { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.result-link:hover .main-icon { transform: scale(1.1); }
.result-link:hover .fate-value { color: var(--gold); text-shadow: 0 0 10px rgba(200, 170, 110, 0.3); }
.result-link:hover .portrait-frame { border-color: var(--gold); }

/* --- KEYSTONES --- */
.keystone-container { display: flex; flex-direction: column; justify-content: center; gap: 15px; height: 100%; }
.keystone-container.dual-mode { justify-content: space-between; gap: 5px; }

.keystone-row { 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; margin: 10px 0; width: 100%; padding: 10px; 
    background: transparent; 
    border-bottom: none;
    transition: 0.2s; flex-grow: 1;
}

.dual-mode .keystone-row { margin: 5px 0; padding: 8px; }
.dual-mode .keystone-text { font-size: 1.3rem; }
.dual-mode .keystone-frame { width: 44px; height: 44px; min-width: 44px; }

.keystone-row:hover .keystone-text { color: var(--gold); text-shadow: 0 0 10px rgba(200, 170, 110, 0.3); }
.keystone-row:hover .keystone-frame { box-shadow: 0 0 15px var(--gold); border-color: var(--gold); transform: scale(1.1); transition: transform 0.2s; }

.keystone-text { font-family: 'Alegreya SC', serif; font-size: 1.5rem; font-weight: 700; color: var(--text-parchment); text-align: center; line-height: 1.1; margin-top: 5px; }
.keystone-frame { width: 50px; height: 50px; min-width: 50px; position: relative; border-radius: 50%; border: 2px solid #c8aa6e; box-shadow: 0 0 5px rgba(0,0,0,0.8), inset 0 0 5px rgba(0,0,0,0.8); background: #000; overflow: hidden; margin-bottom: 5px; }
.keystone-icon { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.3s ease; }
.keystone-icon.loaded { opacity: 1; }

.no-data-msg { font-size: 1.1rem; color: var(--text-dim); font-style: italic; }

/* ACTION BAR CONTAINER (The Fix) */
.action-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    margin-top: 40px;
    width: 100%;
    z-index: 100;
    position: relative; /* REQUIRED so z-index works! */
}

/* NINJA BUTTON */
.ninja-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: linear-gradient(180deg, #1a1a20, #0d0d10);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    padding: 12px 30px;
    font-family: 'Alegreya SC', serif;
    font-size: 1.2rem;
    color: var(--text-parchment);
    text-decoration: none;
    transition: 0.3s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    opacity: 1;
    pointer-events: auto; /* Explicitly enable interaction */
    cursor: pointer;
}

.ninja-btn.hidden { opacity: 0; pointer-events: none; display: none; }

.ninja-btn:hover {
    border-color: var(--gold);
    box-shadow: 0 0 20px rgba(200, 170, 110, 0.2);
    transform: translateY(-2px);
    color: var(--gold);
}

.ninja-icon {
    width: 24px;
    height: 24px;
    min-width: 24px;
    object-fit: contain;
    display: block;
}

/* RESET BUTTON */
.reset-btn {
    background: transparent;
    border: 1px solid var(--border-purple-muted);
    color: var(--text-dim);
    padding: 15px 40px; 
    font-family: 'Alegreya SC', serif;
    font-size: 1.3rem; 
    cursor: pointer;
    transition: 0.3s;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-radius: 2px;
    pointer-events: auto; /* Explicitly enable interaction */
}

.reset-btn.hidden { opacity: 0; pointer-events: none; display: none; }

.reset-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: rgba(200, 170, 110, 0.05);
}

/* MODAL */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px); z-index: 2000; display: flex; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; }
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal-content { background: #111116; border: 1px solid var(--gold); padding: 30px; width: 90%; max-width: 450px; position: relative; box-shadow: 0 0 50px rgba(0,0,0,0.9); transform: translateY(20px); transition: transform 0.3s ease; text-align: center; display: flex; flex-direction: column; gap: 20px; }
.modal-overlay.visible .modal-content { transform: translateY(0); }
.close-modal { position: absolute; top: 10px; right: 15px; font-size: 2rem; color: var(--text-dim); cursor: pointer; line-height: 1; }
.close-modal:hover { color: var(--gold); }
.modal-title { font-family: 'Alegreya SC', serif; color: var(--gold); font-size: 1.8rem; margin: 0; text-shadow: 0 0 10px rgba(200, 170, 110, 0.3); }
.modal-subtitle { color: var(--text-dim); margin: 0; font-size: 1rem; }

.search-options { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; margin: 10px 0; width: 100%; padding: 0 20px; box-sizing: border-box; }
.search-option-row { display: flex; align-items: center; gap: 15px; cursor: pointer; position: relative; user-select: none; font-size: 1.2rem; color: var(--text-parchment); width: 100%; padding: 10px; background: rgba(255,255,255,0.03); border: 1px solid transparent; transition: 0.2s; }
.search-option-row:hover { background: rgba(255,255,255,0.06); border-color: var(--border-purple-muted); }
.search-option-row input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; }
.checkmark { height: 20px; width: 20px; background-color: #000; border: 1px solid #555; position: relative; }
.search-option-row input:checked ~ .checkmark { background-color: var(--gold); border-color: var(--gold); box-shadow: 0 0 5px var(--gold); }
.checkmark:after { content: ""; position: absolute; display: none; }
.search-option-row input:checked ~ .checkmark:after { display: block; }

.modal-action-btn { background: var(--gold); color: #000; font-weight: 700; border: none; padding: 12px 0; width: 100%; font-family: 'Alegreya SC', serif; font-size: 1.2rem; cursor: pointer; transition: 0.2s; text-transform: uppercase; letter-spacing: 1px; margin-top: 10px; }
.modal-action-btn:hover { background: #fff; box-shadow: 0 0 15px #fff; }

@media (max-width: 850px) {
    .fate-grid { flex-direction: column; align-items: center; gap: 25px; }
    .fate-card { width: 100%; max-width: 340px; }
    .config-panel { flex-direction: column; gap: 1rem; }
    .container { padding-top: 2rem; }
}