:root {
    --midnight: #f5f3ef;
    --deep-navy: #fffbf5;
    --burgundy: #c1495b;
    --gold: #b8860b;
    --ember: #ff6b35;
    --cream: #2a2520;
    --muted-gold: #8b7355;
    --shadow: rgba(0, 0, 0, 0.15);
    --accent-bg: #fef9f3;
    --card-bg: #ffffff;
}

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

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

@keyframes shimmer {
    0% { background-position: -100% 0; }
    100% { background-position: 200% 0; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes glow {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

body {
    font-family: 'Crimson Text', 'Crimson Pro', serif;
    background: var(--midnight);
    background-image:
        radial-gradient(circle at 20% 50%, rgba(193, 73, 91, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(184, 134, 11, 0.08) 0%, transparent 50%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23b8860b' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    min-height: 100vh;
    padding: 20px;
    color: var(--cream);
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
    pointer-events: none;
    z-index: 1;
}

/* Story Selection Page */
.container {
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

header {
    text-align: center;
    margin-bottom: 80px;
    animation: fadeInUp 1s ease;
    position: relative;
}

header::before {
    content: '✦';
    display: block;
    font-size: 2rem;
    color: var(--gold);
    margin-bottom: 20px;
    animation: glow 3s ease-in-out infinite;
}

header h1 {
    font-family: 'Playfair Display', 'Libre Baskerville', serif;
    font-size: 4.5rem;
    font-weight: 700;
    margin-bottom: 15px;
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--gold) 50%, var(--burgundy) 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
    position: relative;
    animation: shimmer 8s linear infinite;
}

header::after {
    content: '';
    display: block;
    width: 200px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 30px auto 0;
}

.subtitle {
    font-size: 1.3rem;
    color: var(--muted-gold);
    font-style: italic;
    letter-spacing: 1px;
    margin-top: 30px;
}

.gender-filter {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 40px;
    animation: fadeInUp 1s ease;
    animation-delay: 0.3s;
    animation-fill-mode: both;
}

.filter-btn {
    padding: 12px 32px;
    background: var(--card-bg);
    color: var(--muted-gold);
    border: 2px solid rgba(184, 134, 11, 0.3);
    font-family: 'Crimson Text', serif;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.filter-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(193, 73, 91, 0.1) 0%, rgba(184, 134, 11, 0.1) 100%);
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.filter-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(184, 134, 11, 0.2);
}

.filter-btn:hover::before {
    width: 300px;
    height: 300px;
}

.filter-btn.active {
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--ember) 100%);
    color: var(--card-bg);
    border-color: var(--gold);
    box-shadow: 0 4px 20px rgba(184, 134, 11, 0.3);
}

.filter-btn.active::before {
    background: rgba(255, 255, 255, 0.1);
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 50px;
    margin-top: 60px;
}

.story-card {
    background: var(--card-bg);
    border: 2px solid rgba(184, 134, 11, 0.2);
    border-radius: 0;
    padding: 0;
    box-shadow:
        0 20px 60px var(--shadow),
        inset 0 1px 0 rgba(184, 134, 11, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.8s ease;
    animation-fill-mode: both;
}

.story-card:nth-child(1) { animation-delay: 0.1s; }
.story-card:nth-child(2) { animation-delay: 0.2s; }
.story-card:nth-child(3) { animation-delay: 0.3s; }
.story-card:nth-child(4) { animation-delay: 0.4s; }
.story-card:nth-child(5) { animation-delay: 0.5s; }
.story-card:nth-child(6) { animation-delay: 0.6s; }

.story-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--burgundy), var(--gold), var(--ember));
}

.story-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 0%, rgba(184, 134, 11, 0.08), transparent 60%);
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.story-card:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.2),
        0 0 40px rgba(184, 134, 11, 0.15),
        inset 0 1px 0 rgba(184, 134, 11, 0.2);
    border-color: rgba(184, 134, 11, 0.5);
}

.story-card:hover::after {
    opacity: 1;
}

.story-card h2 {
    font-family: 'Playfair Display', 'Libre Baskerville', serif;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--gold);
    letter-spacing: 1px;
    padding: 35px 35px 0;
    position: relative;
}

.story-card h2::after {
    content: '◆';
    display: block;
    font-size: 0.8rem;
    margin-top: 15px;
    opacity: 0.5;
}

.story-card p {
    line-height: 1.9;
    margin-bottom: 30px;
    color: var(--cream);
    font-size: 1.1rem;
    padding: 0 35px;
    opacity: 0.9;
}

.story-buttons {
    margin: 0 35px 35px;
}

.btn {
    display: inline-block;
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--ember) 100%);
    color: var(--cream);
    padding: 16px 40px;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    transition: all 0.3s ease;
    border: 1px solid rgba(212, 175, 55, 0.3);
    position: relative;
    overflow: hidden;
    font-family: 'Crimson Text', serif;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    border-color: var(--gold);
    box-shadow: 0 0 20px rgba(184, 134, 11, 0.3);
    transform: translateY(-2px);
}

.continue-restart-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
}

.btn-continue {
    width: 100%;
    text-align: center;
}

.btn-restart {
    padding: 10px 20px;
    background: transparent;
    color: var(--muted-gold);
    border: 1px solid rgba(184, 134, 11, 0.3);
    font-family: 'Crimson Text', serif;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-restart:hover {
    border-color: var(--burgundy);
    color: var(--burgundy);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(193, 73, 91, 0.2);
}

/* Story Chat Interface */
.story-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    box-shadow:
        0 20px 80px var(--shadow),
        inset 0 1px 0 rgba(184, 134, 11, 0.1);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
    border: 2px solid rgba(184, 134, 11, 0.2);
    position: relative;
    overflow: hidden;
}

.story-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--burgundy), var(--gold), var(--ember));
    z-index: 10;
}

.story-header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 30px;
    border-bottom: 2px solid rgba(184, 134, 11, 0.2);
    background: linear-gradient(135deg, var(--accent-bg) 0%, rgba(255, 251, 245, 0.95) 100%);
    position: relative;
    margin-bottom: 0;
    text-align: left;
    animation: none;
}

.story-header::before {
    display: none;
}

.story-header::after {
    display: none;
}

.back-link {
    color: var(--muted-gold);
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}

.back-link:hover {
    color: var(--gold);
    transform: translateX(-3px);
}

.story-header h1 {
    font-family: 'Playfair Display', 'Libre Baskerville', serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 1px;
    text-align: left;
    margin: 0;
}

.story-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 30px;
    background:
        radial-gradient(circle at 20% 30%, rgba(193, 73, 91, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(184, 134, 11, 0.05) 0%, transparent 50%);
    position: relative;
}

.story-content::-webkit-scrollbar {
    width: 8px;
}

.story-content::-webkit-scrollbar-track {
    background: rgba(184, 134, 11, 0.1);
}

.story-content::-webkit-scrollbar-thumb {
    background: rgba(184, 134, 11, 0.3);
    border-radius: 4px;
}

.story-content::-webkit-scrollbar-thumb:hover {
    background: rgba(184, 134, 11, 0.5);
}

.story-message {
    margin-bottom: 30px;
    line-height: 1.9;
    animation: fadeInUp 0.6s ease;
    animation-fill-mode: both;
}

.story-message.narrator {
    background: linear-gradient(135deg, rgba(254, 249, 243, 0.8) 0%, rgba(255, 251, 245, 0.6) 100%);
    padding: 30px;
    border-left: 3px solid var(--gold);
    border-right: 1px solid rgba(184, 134, 11, 0.2);
    position: relative;
    font-size: 1.15rem;
    color: var(--cream);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.story-message.narrator::before {
    content: '❝';
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 3rem;
    color: var(--gold);
    opacity: 0.15;
    font-family: Georgia, serif;
    line-height: 1;
}

.story-message.narrator::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(184, 134, 11, 0.2), transparent);
}

.story-message.user {
    background: linear-gradient(135deg, rgba(193, 73, 91, 0.08) 0%, rgba(255, 107, 53, 0.06) 100%);
    padding: 20px 30px;
    border-left: 3px solid var(--burgundy);
    font-style: italic;
    color: var(--cream);
    font-size: 1.05rem;
    position: relative;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.06);
}

.story-message.user .user-text::before {
    content: "⚔ You: ";
    font-weight: 700;
    font-style: normal;
    color: var(--burgundy);
    margin-right: 8px;
}

.loading-message {
    text-align: center;
    color: var(--muted-gold);
    font-style: italic;
    padding: 60px 20px;
    font-size: 1.1rem;
    animation: glow 2s ease-in-out infinite;
}

.input-container {
    padding: 20px 30px;
    border-top: 2px solid rgba(184, 134, 11, 0.2);
    background: linear-gradient(135deg, var(--accent-bg) 0%, rgba(255, 251, 245, 0.95) 100%);
    position: relative;
}

.input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

#user-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid rgba(184, 134, 11, 0.3);
    background: rgba(255, 255, 255, 0.9);
    color: var(--cream);
    font-family: 'Crimson Text', serif;
    font-size: 1rem;
    resize: vertical;
    margin-bottom: 12px;
    transition: all 0.3s ease;
    line-height: 1.6;
}

#user-input::placeholder {
    color: var(--muted-gold);
    opacity: 0.5;
    font-style: italic;
}

#user-input:focus {
    outline: none;
    border-color: var(--gold);
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 0 20px rgba(184, 134, 11, 0.15);
}

#submit-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--ember) 100%);
    color: var(--cream);
    border: 1px solid rgba(212, 175, 55, 0.3);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Crimson Text', serif;
    position: relative;
    overflow: hidden;
}

#submit-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

#submit-btn:hover:not(:disabled) {
    border-color: var(--gold);
    box-shadow: 0 0 30px rgba(184, 134, 11, 0.25);
    transform: translateY(-2px);
}

#submit-btn:hover:not(:disabled)::before {
    width: 400px;
    height: 400px;
}

#submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 3rem;
    }

    .story-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .story-container {
        height: calc(100vh - 20px);
    }

    .story-content {
        padding: 12px 20px;
    }

    .input-container {
        padding: 20px 25px;
    }
}

/* View Tabs */
.view-tabs {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.view-tab {
    padding: 6px 16px;
    background: transparent;
    color: var(--muted-gold);
    border: 1px solid rgba(184, 134, 11, 0.3);
    font-family: 'Crimson Text', serif;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
}

.view-tab:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.view-tab.active {
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--ember) 100%);
    color: #fff;
    border-color: var(--gold);
}

/* Debug Metadata */
.debug-meta {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px dashed rgba(184, 134, 11, 0.2);
}

.debug-stat {
    font-size: 0.8rem;
    color: var(--muted-gold);
    font-family: monospace;
    opacity: 0.8;
}

/* Compaction Marker */
.compaction-marker {
    background: linear-gradient(135deg, rgba(184, 134, 11, 0.1) 0%, rgba(193, 73, 91, 0.08) 100%);
    border: 1px solid rgba(184, 134, 11, 0.3);
    border-radius: 4px;
    margin-bottom: 12px;
    overflow: hidden;
}

.compaction-toggle {
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--gold);
    font-family: 'Crimson Text', serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s ease;
}

.compaction-toggle:hover {
    background: rgba(184, 134, 11, 0.1);
}

.compaction-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.compaction-summary {
    border-top: 1px solid rgba(184, 134, 11, 0.2);
}

.summary-label {
    padding: 10px 14px;
    font-size: 0.75rem;
    color: var(--gold);
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: rgba(184, 134, 11, 0.1);
    border-bottom: 1px solid rgba(184, 134, 11, 0.2);
}

.summary-content {
    padding: 14px;
    font-size: 0.9rem;
    color: var(--cream);
    line-height: 1.7;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0.9;
    white-space: pre-wrap;
}

.summary-content strong {
    color: var(--gold);
    display: block;
    margin-top: 12px;
    margin-bottom: 4px;
}

.summary-content strong:first-child {
    margin-top: 0;
}

/* User message debug info */
.user-debug {
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed rgba(193, 73, 91, 0.2);
}

.user-text {
    display: inline;
}

.narrator-text {
    white-space: pre-wrap;
}

/* Start Buttons Container */
.start-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 60px 30px;
    min-height: 400px;
}

.primary-button {
    padding: 20px 60px;
    background: linear-gradient(135deg, var(--burgundy) 0%, var(--ember) 100%);
    color: #fff;
    border: 2px solid var(--gold);
    font-family: 'Crimson Text', serif;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(184, 134, 11, 0.3);
}

.primary-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.primary-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(184, 134, 11, 0.4);
}

.primary-button:hover::before {
    width: 400px;
    height: 400px;
}

.secondary-button {
    padding: 10px 30px;
    background: transparent;
    color: var(--muted-gold);
    border: 1px solid rgba(184, 134, 11, 0.3);
    font-family: 'Crimson Text', serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-button:hover {
    border-color: var(--burgundy);
    color: var(--burgundy);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(193, 73, 91, 0.2);
}

/* Responsive adjustments for tabs */
@media (max-width: 768px) {
    .view-tabs {
        gap: 4px;
    }

    .view-tab {
        padding: 4px 10px;
        font-size: 0.75rem;
    }

    .story-header h1 {
        font-size: 1.1rem;
    }
}
