body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #111;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: #fff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- THEMES --- */

/* Light Theme */
body.theme-light {
    background: #fffdf0; /* Soft yellow page */
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='1' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noiseFilter)' opacity='0.3'/%3E%3C/svg%3E");
    background-repeat: repeat;
    color: #111;
}

body.theme-light #story-content {
    background: #fffdf0; /* Soft yellow page */
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='1' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noiseFilter)' opacity='0.3'/%3E%3C/svg%3E");
    background-repeat: repeat;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
}

body.theme-light #story-text h1 {
    color: #111;
}

body.theme-light .navbar {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

body.theme-light .navbar-brand {
    color: #333;
}

body.theme-light .navbar-link {
    color: #666;
}

body.theme-light .navbar-link:hover {
    color: #000;
    background: #e9ecef;
    border-color: #ced4da;
}

/* --- FONTS --- */
body.font-sans {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.font-serif {
    font-family: 'Georgia', 'Times New Roman', Times, serif;
}

body.font-mono {
    font-family: 'Courier New', Courier, monospace;
}

#story-text,
#story-text * {
    font-family: inherit !important;
}

#opening-intro,
#opening-intro * {
    font-family: inherit !important;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    transition: opacity 0.6s ease-in-out;
}

#story-view {
    position: relative;
    overflow: hidden;
}

#inline-preloader {
    position: absolute;
    inset: 0;
    background: #000;
    z-index: 1500;
    transition: opacity 0.6s ease-in-out;
}

#inline-preloader.fade-out {
    opacity: 0;
    pointer-events: none;
}

#app-container.fade-out {
    opacity: 0;
}

#story-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: background-image 0.8s ease-in-out;
    z-index: 1;
}

#story-content-wrapper {
    position: relative;
    z-index: 10;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    pointer-events: none; /* Allow clicks to pass through to the wrapper if needed, but not children */
}

#story-content {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 3rem 3rem 8rem 3rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-width: 900px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    text-align: left; /* Changed from center to left for better reading */
    pointer-events: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    position: relative;
    /* Create a stacking context for absolute children like ::after */
    isolation: isolate; 
    margin-top: 20px; /* Add margin to prevent content from being hidden behind toolbar */
}

#story-content table {
    width: 100%;
    margin-bottom: 1rem;
    color: #fff;
    border-collapse: collapse;
    background: rgba(255, 255, 255, 0.05); /* Subtle background for tables */
    border-radius: 4px;
    overflow: hidden;
}

#story-content table th,
#story-content table td {
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1); /* Subtle borders */
    vertical-align: top;
}

#story-content table th {
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

body.theme-light #story-content table {
    color: #111;
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

body.theme-light #story-content table th,
body.theme-light #story-content table td {
    border-color: rgba(0, 0, 0, 0.1);
}

body.theme-light #story-content table th {
    background: rgba(0, 0, 0, 0.05);
}

#story-content > * {
    position: relative;
    z-index: 2;
}

#action-area {
    padding: 20px;
    margin: -20px;
    margin-top: 0;
}

#story-content::-webkit-scrollbar {
    width: 6px;
}

#story-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

#story-text {
    font-size: 1.6rem;
    margin-bottom: 2rem;
    line-height: 1.6;
    font-weight: 300;
}

#story-text figure.se-flex-component {
    margin: 0 0 1rem;
    max-width: 100%;
    overflow-x: auto;
}

#story-text figure.se-flex-component table {
    margin-bottom: 0;
}

#story-text, 
#story-text p,
#story-text li,
#story-text span,
#story-text div,
#story-text strong,
#story-text em,
#story-text b,
#story-text i,
#story-text u,
#story-text blockquote,
#story-text h2,
#story-text h3,
#story-text h4,
#story-text h5,
#story-text h6 {
    color: inherit;
}

body:not(.theme-light) #story-text,
body:not(.theme-light) #story-text p,
body:not(.theme-light) #story-text li,
body:not(.theme-light) #story-text span,
body:not(.theme-light) #story-text div,
body:not(.theme-light) #story-text strong,
body:not(.theme-light) #story-text em,
body:not(.theme-light) #story-text b,
body:not(.theme-light) #story-text i,
body:not(.theme-light) #story-text u,
body:not(.theme-light) #story-text blockquote,
body:not(.theme-light) #story-text h2,
body:not(.theme-light) #story-text h3,
body:not(.theme-light) #story-text h4,
body:not(.theme-light) #story-text h5,
body:not(.theme-light) #story-text h6 {
    color: rgba(255, 255, 255, 0.95) !important;
}

body:not(.theme-light) #story-text a {
    color: #9ec5fe !important;
}

body:not(.theme-light) #story-text a:hover {
    color: #cfe2ff !important;
}

#story-text .story-inline-btn,
#story-text a.story-inline-btn {
    display: inline-block;
    margin: 0.25rem 0.25rem;
    padding: 0.5rem 1rem;
    border-radius: 0.85rem;
    color: #fff !important;
    text-decoration: none !important;
    box-shadow: 0 8px 20px rgba(0,0,0,0.45);
}

#story-text .story-inline-btn:hover,
#story-text a.story-inline-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(0,0,0,0.55);
    color: #fff !important;
    text-decoration: none !important;
}

#opening-intro .story-inline-btn,
#opening-intro a.story-inline-btn,
#opening-intro .story-inline-btn:hover,
#opening-intro a.story-inline-btn:hover {
    color: #fff !important;
    text-decoration: none !important;
}

#story-text h1 {
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #fff;
}

/* Layouts */

/* Default Centered */
.layout-centered #story-image {
    width: 100%;
    height: 100%;
    left: 0;
    right: 0;
    position: absolute;
    background-size: cover;
    background-position: center;
}

.layout-centered #story-content-wrapper {
    width: 100%;
    justify-content: center;
    position: relative;
}

/* Text Left, Image Right */
.layout-text-left #story-image {
    width: 50%;
    height: 100%;
    left: auto;
    right: 0;
    position: absolute;
    background-size: cover;
    background-position: center;
}

.layout-text-left #story-content-wrapper {
    width: 50%;
    height: 100%;
    left: 0;
    justify-content: center;
    padding: 0; /* No padding on wrapper */
    position: absolute;
}

#story-view.layout-text-left #story-content {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    text-align: left;
    max-width: 100%;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none; /* Allow full height */
    padding: 3rem 3rem 8rem 3rem; /* 3rem padding on content, extra bottom */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Was center, changed to flex-start for scrolling */
}

/* Image Left, Text Right */
.layout-image-left #story-image {
    width: 50%;
    height: 100%;
    left: 0;
    right: auto;
    position: absolute;
    background-size: cover;
    background-position: center;
}

.layout-image-left #story-content-wrapper {
    width: 50%;
    height: 100%;
    left: auto;
    right: 0;
    justify-content: center;
    padding: 0; /* No padding on wrapper */
    position: absolute;
}

#story-view.layout-image-left #story-content {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    text-align: left;
    max-width: 100%;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none; /* Allow full height */
    padding: 3rem 3rem 8rem 3rem; /* 3rem padding on content */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Was center, changed to flex-start for scrolling */
}

/* Responsive for split layouts */
@media (max-width: 768px) {
    .layout-text-left #story-image,
    .layout-image-left #story-image {
        position: relative;
        width: 100%;
        height: 300px; /* Fixed height for image on mobile */
        order: 1;
        flex-shrink: 0;
    }
    
    .layout-text-left #story-content-wrapper,
    .layout-image-left #story-content-wrapper {
        position: relative;
        width: 100%;
        height: auto;
        left: auto;
        right: auto;
        order: 2;
        padding: 1.5rem;
        flex-shrink: 0;
    }

    #story-view.layout-text-left,
    #story-view.layout-image-left {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        height: 100%; /* Ensure full height */
    }
}

/* Preloader */
#preloader-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000; /* Force black background */
    z-index: 2000;
    transition: opacity 1s ease-in-out; /* Slow fade out */
    opacity: 1;
}

#preloader-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

body.theme-light #preloader-screen {
    background: #000; /* Override light theme to keep it black */
}

body.theme-light #preloader-screen h3,
body.theme-light #preloader-screen p {
    color: #fff !important; /* Keep text white on black bg */
}

/* Spinner styling */
#preloader-screen .spinner-border {
    width: 4rem;
    height: 4rem;
    border-width: 0.3em;
    color: #fff; /* Force white spinner */
}

#preload-bar {
    transition: width 0.3s ease;
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(13, 110, 253, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13, 110, 253, 0); }
}

.pulse {
    animation: pulse 2s infinite;
}

/* Game Toolbar */
#game-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    z-index: 2000; /* Higher than story content */
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

body.theme-light #game-toolbar {
    background: rgba(255, 255, 255, 0.6);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

/* Adjust Content for Toolbar */
#app-container {
    padding-top: 60px;
}

/* HUD Buttons in Toolbar */
.hud-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.hud-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
    transform: translateY(0); /* No lift in toolbar */
    box-shadow: none;
}

.hud-btn:disabled {
    opacity: 0.5;
    background: transparent;
    color: rgba(255, 255, 255, 0.3);
    border-color: transparent;
}

body.theme-light .hud-btn {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
    border-color: rgba(0, 0, 0, 0.1);
}

body.theme-light .hud-btn:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.1);
    color: #000;
}

#inventory-btn.inventory-btn-anim-gain {
    background: rgba(76, 175, 80, 0.9) !important;
    color: #fff !important;
    border-color: rgba(76, 175, 80, 0.95) !important;
    animation: bounce-glow 0.8s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
    box-shadow: 0 0 18px rgba(76, 175, 80, 0.55);
}

#inventory-btn.inventory-btn-anim-loss {
    background: rgba(244, 67, 54, 0.9) !important;
    color: #fff !important;
    border-color: rgba(244, 67, 54, 0.95) !important;
    animation: shake-fade 0.6s cubic-bezier(.36,.07,.19,.97) forwards;
    box-shadow: 0 0 18px rgba(244, 67, 54, 0.55);
}

/* Counters in Toolbar */
.counter-badge {
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body.theme-light .counter-badge {
    background: rgba(255, 255, 255, 0.5);
    color: #111;
    border-color: rgba(0, 0, 0, 0.1);
}

.journey-modal-content {
    background: rgba(0, 0, 0, 0.92);
    color: #fff;
    max-height: calc(100vh - 3rem);
}

.journey-modal-backdrop {
    z-index: 3000;
}

#journey-modal, #inventory-modal, #restart-modal {
    z-index: 3005;
}

.journey-modal-content .modal-body {
    overflow-y: auto;
}

.journey-modal-close {
    filter: invert(1) grayscale(100%);
}

body.theme-light .journey-modal-content {
    background: #fff;
    color: #111;
    border-color: rgba(0, 0, 0, 0.15) !important;
}

body.theme-light .journey-modal-dismiss {
    border-color: rgba(0, 0, 0, 0.2);
    color: #111;
}

body.theme-light .journey-modal-close {
    filter: none;
}

.opening-screen-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #0b1320;
}

.opening-screen-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

body.theme-light .opening-screen-overlay {
    background: rgba(255, 255, 255, 0.65);
}

.opening-screen-content {
    position: relative;
    height: 100%;
    z-index: 1;
}

.opening-screen-content .opening-top-section {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
}

.opening-screen-content .opening-bottom-section {
    flex: 0 0 auto;
}

.opening-card {
    max-width: 900px;
    padding: 2rem;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    max-height: 70vh;
    max-height: min(70vh, calc(100vh - 220px));
    max-height: min(70vh, calc(100dvh - 220px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.opening-intro {
    line-height: 1.6;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding-right: 0.25rem;
}

body.theme-light .opening-card {
    background: rgba(255, 255, 255, 0.78);
    border-color: rgba(0, 0, 0, 0.08);
    color: #111;
}



/* Ensure background is visible during animations */
.counter-badge.anim-gain {
    background: rgba(76, 175, 80, 0.9) !important;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
}

.counter-badge.anim-loss {
    background: rgba(244, 67, 54, 0.9) !important;
    box-shadow: 0 0 15px rgba(244, 67, 54, 0.5);
}

/* --- ANIMATIONS: GAIN (Bounce & Glow) --- */
@keyframes bounce-glow {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(76, 175, 80, 0); }
    40% { transform: scale(1.2); box-shadow: 0 0 20px rgba(76, 175, 80, 0.8); background-color: rgba(76, 175, 80, 0.9); }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); box-shadow: 0 0 0 rgba(76, 175, 80, 0); background-color: rgba(0, 0, 0, 0.7); }
}

.anim-gain {
    animation: bounce-glow 0.8s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
}

@keyframes float-up-fade {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-40px) scale(1.2); opacity: 0; }
}

.anim-text-gain {
    position: absolute;
    color: #4CAF50; /* Green */
    font-weight: 800;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    animation: float-up-fade 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 1000;
}

/* --- ANIMATIONS: LOSS (Shake & Fade) --- */
@keyframes shake-fade {
    0% { transform: translateX(0); background-color: rgba(0, 0, 0, 0.7); }
    10%, 90% { transform: translateX(-4px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-6px); background-color: rgba(244, 67, 54, 0.8); }
    40%, 60% { transform: translateX(6px); }
    100% { transform: translateX(0); background-color: rgba(0, 0, 0, 0.7); }
}

.anim-loss {
    animation: shake-fade 0.6s cubic-bezier(.36,.07,.19,.97) forwards;
}

@keyframes shake-float-down {
    0% { transform: translateY(0) translateX(0); opacity: 1; }
    25% { transform: translateY(5px) translateX(-3px); }
    50% { transform: translateY(10px) translateX(3px); }
    75% { transform: translateY(15px) translateX(-3px); }
    100% { transform: translateY(30px) translateX(0); opacity: 0; }
}

.anim-text-loss {
    position: absolute;
    color: #F44336; /* Red */
    font-weight: 800;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    animation: shake-float-down 1.2s ease-in forwards;
    pointer-events: none;
    z-index: 1000;
}

/* --- ANIMATIONS: CRITICAL EFFECTS --- */

/* Critical Gain: Sparks */
.anim-critical-gain {
    position: relative;
}

.anim-critical-gain::after {
    content: "✨";
    position: absolute;
    top: -20px;
    right: -10px;
    font-size: 1.5rem;
    animation: float-up-fade 1s ease-out forwards;
}

.anim-critical-gain::before {
    content: "✨";
    position: absolute;
    bottom: -10px;
    left: -10px;
    font-size: 1rem;
    animation: float-up-fade 1.2s ease-out 0.2s forwards;
}

/* Critical Loss: Crack */
@keyframes crack-flash {
    0% { border-color: rgba(255, 255, 255, 0.2); }
    10% { border-color: #fff; box-shadow: 0 0 0 2px #fff, inset 0 0 20px #000; }
    100% { border-color: rgba(255, 255, 255, 0.2); }
}

.anim-critical-loss {
    animation: shake-fade 0.6s cubic-bezier(.36,.07,.19,.97) forwards, crack-flash 0.3s ease-out;
}

#roll-btn {
    font-size: 1.3rem;
    padding: 1rem 3.5rem;
    border-radius: 50px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
    transition: all 0.3s ease;
}

#roll-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(13, 110, 253, 0.5);
}

/* Event Area */
#event-area {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

#event-area h3 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: #ffc107;
    font-weight: 700;
}

#event-area p {
    font-size: 1.6rem; /* Match story text size */
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

#event-result {
    font-size: 1.6rem;
    line-height: 1.6;
    color: inherit;
}

#event-roll-btn {
    font-size: 1.1rem;
    padding: 0.6rem 1.5rem;
    background-color: #ffc107;
    color: #000;
    border: none;
    font-weight: 600;
    border-radius: 4px;
    transition: all 0.2s;
}

#event-roll-btn:hover {
    background-color: #ffca2c;
    transform: translateY(-2px);
}

/* Continue Button */
#continue-btn {
    background-color: #0d6efd; /* Bootstrap Primary Blue */
    color: #fff;
    font-size: 1.3rem; /* Match roll button size */
    padding: 1rem 3.5rem; /* Match roll button padding */
    border-radius: 50px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
    border: none;
    transition: all 0.3s ease;
    margin-top: 1rem;
}

#continue-btn:hover {
    background-color: #0b5ed7;
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(13, 110, 253, 0.5);
}

/* Dice */
#dice-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    display: none;
    filter: drop-shadow(0 20px 40px rgba(0,0,0,0.6));
}

.badge {
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.8em 1.2em;
}

.choice-btn {
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: translateY(0);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0;
    margin: 0.5rem;
}

.choice-btn.visible {
    opacity: 1;
}

.choice-btn:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.7);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #story-content {
        padding: 2rem;
        margin: 1rem;
        max-height: 80vh;
    }
    
    #story-text {
        font-size: 1.3rem;
    }
    
    #roll-btn {
        padding: 0.8rem 2.5rem;
        font-size: 1.1rem;
    }
}

/* Admin Edit Button */
.admin-edit-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    color: #333;
    z-index: 9999;
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.1);
}

.admin-edit-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    color: #000;
    background: #fff;
}

.admin-edit-btn svg {
    width: 24px;
    height: 24px;
}

/* Navbar Styles */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.navbar-brand {
    color: #e0e0e0;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}

.navbar-links {
    display: flex;
    gap: 12px;
    align-items: center;
}

.navbar-link {
    color: #888;
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.navbar-link:hover {
    color: #e0e0e0;
    background: #252525;
    border-color: #333;
}

/* Adjustments for navbar */
body:has(.navbar:not(.d-none)) #app-container {
    padding-top: 56px;
}

body:has(.navbar:not(.d-none)) #controls {
    top: calc(1.5rem + 56px);
}

/* ==========================================================================
   Story-code entry screen only
   Opening, invitation, preloader and gameplay screens retain their existing
   layout. Entry navigation disappears as soon as the access screen closes.
   ========================================================================== */
body#story:has(#access-screen:not(.d-none)),
body#story:has(#access-screen:not(.d-none)) html {
    padding-top: 80px;
    color: var(--brand-ink);
    background: var(--brand-cream) !important;
}

body#story:has(#access-screen:not(.d-none)) #app-container {
    padding-top: 0;
}

body#story:has(#access-screen.d-none) #story-entry-nav {
    display: none;
}

#story-entry-nav,
#access-screen {
    font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
}

.story-entry-header {
    position: fixed;
    z-index: 5000;
    top: 0;
    right: 0;
    left: 0;
    border-bottom: 1px solid var(--brand-line);
    background: rgba(251, 250, 245, 0.96);
    backdrop-filter: blur(16px);
}

.story-entry-nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100% - 3rem, 1280px);
    height: 80px;
    margin: 0 auto;
    gap: 1.5rem;
}

.story-entry-brand {
    flex-shrink: 0;
    font-family: "Lora", Georgia, serif;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.035em;
    text-decoration: none;
}

.story-entry-brand-scroll { color: var(--brand-primary); }
.story-entry-brand-rest { color: var(--brand-accent); }
.story-entry-brand:hover .story-entry-brand-scroll { color: var(--brand-dark); }
.story-entry-brand:hover .story-entry-brand-rest { color: #C4932F; }

.story-entry-links {
    display: flex;
    align-items: center;
    margin-left: auto;
    gap: 0.25rem;
}

.story-entry-links a,
.story-entry-my-stories {
    border-radius: 999px;
    padding: 0.6rem 0.9rem;
    color: #536159;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s ease, background 0.2s ease;
}

.story-entry-links a:hover,
.story-entry-my-stories:hover {
    color: var(--brand-primary);
    background: var(--brand-mint);
}

.story-entry-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.story-entry-signup,
.story-entry-signin,
.story-entry-mobile-signup,
.story-entry-mobile-signin {
    border-radius: 999px;
    padding: 0.65rem 1.15rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.story-entry-signup,
.story-entry-mobile-signup {
    border: 1px solid var(--brand-line);
    color: var(--brand-ink);
    background: rgba(255, 255, 255, 0.7);
}

.story-entry-signin,
.story-entry-mobile-signin {
    border: 1px solid var(--brand-primary);
    color: #fff;
    background: var(--brand-primary);
}

.story-entry-signup:hover { background: #fff; }
.story-entry-signin:hover { color: #fff; background: var(--brand-dark); }

.story-entry-account,
.story-entry-mobile {
    position: relative;
}

.story-entry-account summary,
.story-entry-mobile summary {
    list-style: none;
    cursor: pointer;
}

.story-entry-account summary::-webkit-details-marker,
.story-entry-mobile summary::-webkit-details-marker {
    display: none;
}

.story-entry-account summary {
    display: grid;
    width: 2.4rem;
    height: 2.4rem;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--brand-primary);
    font-size: 0.75rem;
    font-weight: 700;
}

.story-entry-dropdown {
    position: absolute;
    top: calc(100% + 0.75rem);
    right: 0;
    width: 230px;
    padding: 0.6rem;
    border: 1px solid var(--brand-line);
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 18px 45px rgba(36, 53, 46, 0.14);
}

.story-entry-dropdown p,
.story-entry-dropdown span {
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0.35rem 0.6rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-entry-dropdown p { color: var(--brand-ink); font-size: 0.875rem; font-weight: 600; }
.story-entry-dropdown span { color: var(--brand-muted); font-size: 0.75rem; }

.story-entry-dropdown a {
    display: block;
    margin-top: 0.2rem;
    border-radius: 0.65rem;
    padding: 0.55rem 0.6rem;
    color: var(--brand-ink);
    font-size: 0.875rem;
    text-decoration: none;
}

.story-entry-dropdown a:hover { background: var(--brand-mint); }
.story-entry-mobile { display: none; }

#access-screen {
    position: relative;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 2.5rem 1.5rem;
    background:
        radial-gradient(circle at 8% 15%, rgba(251, 240, 211, 0.85), transparent 24rem),
        radial-gradient(circle at 93% 80%, rgba(227, 239, 231, 0.9), transparent 26rem),
        var(--brand-cream);
}

#access-screen::before,
#access-screen::after {
    position: absolute;
    border-radius: 50%;
    content: "";
    pointer-events: none;
}

#access-screen::before {
    top: 9%;
    right: 6%;
    width: 5rem;
    height: 5rem;
    background: rgba(231, 185, 78, 0.5);
}

#access-screen::after {
    bottom: 8%;
    left: 4%;
    width: 3.5rem;
    height: 3.5rem;
    background: rgba(244, 184, 160, 0.55);
}

.story-access-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
    align-items: center;
    width: min(100%, 1080px);
    margin: auto;
    gap: clamp(2.5rem, 7vw, 6rem);
}

.story-access-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    border: 1px solid #D7E6DC;
    border-radius: 999px;
    padding: 0.45rem 0.85rem;
    color: var(--brand-primary);
    background: #EDF4EE;
    font-size: 0.75rem;
    font-weight: 600;
}

.story-access-eyebrow svg { width: 1rem; height: 1rem; }

.story-access-intro h1 {
    margin: 1.4rem 0 0;
    color: var(--brand-ink);
    font-family: "Lora", Georgia, serif;
    font-size: clamp(2.65rem, 4.5vw, 4rem);
    font-weight: 500;
    letter-spacing: -0.045em;
    line-height: 1.1;
}

.story-access-intro h1 em {
    color: var(--brand-primary);
    font-weight: 500;
}

.story-access-lead {
    max-width: 580px;
    margin: 1.35rem 0 0;
    color: var(--brand-muted);
    font-size: 1.05rem;
    line-height: 1.75;
}

.story-access-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 2rem;
    gap: 0.8rem;
}

.story-access-step {
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 1.15rem;
    padding: 1rem;
}

.story-access-step-mint { background: var(--brand-mint); }
.story-access-step-yellow { background: var(--brand-yellow); }
.story-access-step-peach { background: var(--brand-peach); }

.story-access-step-number {
    display: block;
    color: var(--brand-primary);
    font-family: "Lora", Georgia, serif;
    font-size: 0.8rem;
    font-style: italic;
}

.story-access-step h2 {
    margin: 0.75rem 0 0;
    color: var(--brand-ink);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.4;
}

.story-access-step p {
    margin: 0.45rem 0 0;
    color: #5D6962;
    font-size: 0.75rem;
    line-height: 1.55;
}

.story-access-panel {
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.95);
    border-radius: 1.75rem;
    padding: clamp(1.75rem, 4vw, 2.5rem);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 28px 70px -38px rgba(36, 53, 46, 0.4);
}

.story-access-dice {
    display: grid;
    width: 3rem;
    height: 3rem;
    margin-bottom: 1.4rem;
    place-items: center;
    border-radius: 1rem;
    color: var(--brand-primary);
    background: var(--brand-mint);
}

.story-access-dice svg { width: 1.5rem; height: 1.5rem; }

.story-access-panel-kicker {
    color: var(--brand-primary);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.story-access-panel h2 {
    margin: 0.55rem 0 0;
    color: var(--brand-ink);
    font-family: "Lora", Georgia, serif;
    font-size: 1.8rem;
    font-weight: 600;
    letter-spacing: -0.035em;
}

.story-access-panel-copy {
    margin: 0.65rem 0 1.5rem;
    color: var(--brand-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.story-access-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--brand-ink);
    font-size: 0.8rem;
    font-weight: 600;
}

#access-screen .story-access-input {
    min-height: 3.4rem;
    border: 1px solid #D9DDD5;
    border-radius: 0.9rem;
    padding: 0.8rem 1rem;
    color: var(--brand-ink);
    background: var(--brand-cream);
    font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-align: center;
    text-transform: uppercase;
}

#access-screen .story-access-input::placeholder {
    color: #919B94;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.08em;
}

#access-screen .story-access-input:focus {
    border-color: var(--brand-primary);
    background: #fff;
    box-shadow: 0 0 0 0.22rem rgba(23, 107, 87, 0.12);
}

.story-access-hint {
    margin: 0.5rem 0 1rem;
    color: var(--brand-muted);
    font-size: 0.75rem;
    text-align: center;
}

.story-access-submit {
    min-height: 3.25rem;
    border: 1px solid var(--brand-primary);
    border-radius: 999px;
    color: #fff;
    background: var(--brand-primary);
    box-shadow: 0 12px 24px rgba(18, 63, 53, 0.15);
    font-weight: 600;
    transition: transform 0.2s ease, background 0.2s ease;
}

.story-access-submit:hover:not(:disabled) {
    background: var(--brand-dark);
    transform: translateY(-2px);
}

.story-access-submit:disabled { opacity: 0.65; }

#access-screen .story-access-error {
    margin-top: 1rem;
    border: 1px solid #EAC6B8;
    border-radius: 0.85rem;
    padding: 0.75rem 1rem;
    color: #8C3827;
    background: #FCEAE2;
    font-size: 0.8rem;
    text-align: center;
}

.story-access-reassurance {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1.35rem;
    gap: 0.45rem;
    color: var(--brand-muted);
    font-size: 0.72rem;
}

.story-access-reassurance svg {
    width: 0.9rem;
    height: 0.9rem;
    flex-shrink: 0;
    color: var(--brand-primary);
}

@media (max-width: 900px) {
    .story-access-shell {
        grid-template-columns: 1fr;
        width: min(100%, 600px);
        gap: 2rem;
    }

    .story-access-intro { text-align: center; }
    .story-access-lead { margin-right: auto; margin-left: auto; }
    .story-access-steps { text-align: left; }
    .story-access-panel { width: min(100%, 440px); margin: 0 auto; }
}

@media (max-width: 767px) {
    .story-entry-nav-inner { width: min(100% - 2rem, 1280px); }
    .story-entry-links,
    .story-entry-actions { display: none; }
    .story-entry-mobile { display: block; }

    .story-entry-mobile summary {
        display: grid;
        width: 2.5rem;
        height: 2.5rem;
        place-items: center;
        border: 1px solid var(--brand-line);
        border-radius: 50%;
        color: var(--brand-ink);
        background: #fff;
    }

    .story-entry-mobile summary svg { width: 1.2rem; height: 1.2rem; }

    .story-entry-mobile-menu {
        position: absolute;
        top: calc(100% + 0.8rem);
        right: 0;
        width: 220px;
        padding: 0.65rem;
        border: 1px solid var(--brand-line);
        border-radius: 1rem;
        background: #fff;
        box-shadow: 0 18px 45px rgba(36, 53, 46, 0.14);
    }

    .story-entry-mobile-menu > a {
        display: block;
        border-radius: 0.65rem;
        padding: 0.65rem 0.75rem;
        color: var(--brand-ink);
        font-size: 0.875rem;
        font-weight: 500;
        text-decoration: none;
    }

    .story-entry-mobile-menu > a:hover { background: var(--brand-mint); }
    .story-entry-mobile-menu .story-entry-mobile-signup,
    .story-entry-mobile-menu .story-entry-mobile-signin { margin-top: 0.5rem; }
    .story-entry-mobile-menu .story-entry-mobile-signin { color: #fff; }
}

@media (max-width: 639px) {
    body:has(#access-screen:not(.d-none)) { padding-top: 64px; }
    .story-entry-nav-inner { height: 64px; }
    .story-entry-brand { font-size: 1.2rem; }

    #access-screen {
        align-items: flex-start;
        padding: 2rem 1rem 2.5rem;
    }

    #access-screen::before { width: 3.5rem; height: 3.5rem; }
    #access-screen::after { display: none; }

    .story-access-shell { gap: 1.75rem; }
    .story-access-intro h1 { font-size: clamp(2.35rem, 11vw, 3rem); }
    .story-access-lead { font-size: 0.95rem; }
    .story-access-steps { grid-template-columns: 1fr; margin-top: 1.5rem; }

    .story-access-step {
        display: flex;
        align-items: flex-start;
        gap: 0.9rem;
    }

    .story-access-step-number { padding-top: 0.1rem; }
    .story-access-step h2 { margin-top: 0; }
    .story-access-panel { padding: 1.5rem; border-radius: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
    .story-access-submit,
    .story-entry-links a { transition: none; }
}
