/* ==============================================================
   DYNAMIC BACKGROUND SYSTEM
   ============================================================== */
.scene-bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  overflow: hidden;
  background: #1a1a1a;
}

.scene-bg-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s ease-in-out;
}

.scene-bg-image.active {
  opacity: 1;
}

.scene-bg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--scene-overlay);
  z-index: 1;
  pointer-events: none;
}

/* ==============================================================
   ACCESSIBILITY - Skip Link & Focus Styles
   ============================================================== */
.skip-link {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background: #f16623;
    color: #fff;
    padding: 8px 16px;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    font-weight: 600;
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #ffd700;
    outline-offset: 2px;
}

/* Enhanced focus styles for keyboard navigation */
:focus-visible {
    outline: 3px solid #f16623 !important;
    outline-offset: 2px !important;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid #f16623;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(241, 102, 35, 0.2);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .dice {
        animation: none !important;
    }

    .celebration-emoji,
    .achievement-icon,
    .nat20-icon {
        animation: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --text-primary: #000000;
        --bg-primary: #ffffff;
        --border-color: #000000;
    }

    button, a {
        border: 2px solid currentColor;
    }
}

/* ==============================================================
   CSS CUSTOM PROPERTIES (THEME COLORS)
   ============================================================== */
:root {
  /* Light theme (default) */
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9f9f9;
  --bg-gray: #f1f1f1;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #6b7280;
  --border-color: #cccccc;
  --border-light: #e5e7eb;
  --shadow: rgba(0, 0, 0, 0.08);
  --header-bg: #ffffff;
  --header-text: #1f2937;
  --chat-user-bg: #dbeafe;
  --chat-ai-bg: #e5e7eb;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --modal-bg: #ffffff;
  --dice-bg: #f9fafb;
  --scene-overlay: rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] {
  /* Dark theme */
  --bg-primary: #1f2937;
  --bg-secondary: #374151;
  --bg-tertiary: #1f2937;
  --bg-gray: #4b5563;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --border-color: #4b5563;
  --border-light: #374151;
  --shadow: rgba(0, 0, 0, 0.3);
  --header-bg: #374151;
  --header-text: #f9fafb;
  --chat-user-bg: #1e40af;
  --chat-ai-bg: #4b5563;
  --card-bg: #374151;
  --input-bg: #1f2937;
  --input-border: #4b5563;
  --modal-bg: #374151;
  --dice-bg: #1f2937;
  --scene-overlay: rgba(0, 0, 0, 0.6);
}

/* Smooth theme transitions - disabled on page load to prevent flash */
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ==============================================================
   GLOBAL RESET & TYPOGRAPHY
   ============================================================== */
html, body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin:0; padding:0; height:100%; width:100%; overflow:hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
}
*, *::before, *::after { box-sizing:border-box; }

/* ==============================================================
   TAILWIND OVERRIDES FOR DARK MODE
   ============================================================== */
body.bg-gray-100 {
  background: var(--bg-primary) !important;
}

header.bg-white {
  background: var(--header-bg) !important;
}

h1.text-gray-800 {
  color: var(--header-text) !important;
}

.text-gray-600 {
  color: var(--text-secondary) !important;
}

.text-gray-500 {
  color: var(--text-muted) !important;
}

#chat-container.bg-white {
  background: var(--bg-secondary) !important;
}

.ai-message.bg-gray-100 {
  background: var(--chat-ai-bg) !important;
}

.border-gray-200 {
  border-color: var(--border-light) !important;
}

.border-gray-300 {
  border-color: var(--input-border) !important;
}

#message-input {
  background: var(--input-bg) !important;
  color: var(--text-primary) !important;
}

footer.text-gray-600 {
  color: var(--text-secondary) !important;
}

/* ==============================================================
   THEME TOGGLE BUTTON
   ============================================================== */
.theme-toggle-btn {
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle-btn:hover {
  background: var(--bg-gray);
  transform: scale(1.05);
}

.theme-icon {
  display: inline-block;
}

/* ==============================================================
   CHAT PAGE (original layout – unchanged except for new scroll)
   ============================================================== */
#chat-container {width:100%; height:100%; display:flex; flex-direction:column; background: var(--bg-secondary);}
h1 {text-align:center; padding:15px; margin:0; background: var(--bg-gray); border-bottom:1px solid var(--border-color); flex-shrink:0; color: var(--text-primary);}
#adventure-selection {padding:10px; display:flex; gap:10px; flex-wrap:wrap; justify-content:center; flex-shrink:0;}
.adventure-btn {padding:10px 20px; border:none; background:#28a745; color:#fff; border-radius:4px; cursor:pointer; font-size:16px;}
.adventure-btn:hover {background:#218838;}

#story {
    flex-grow:1; padding:20px; overflow-y:auto; white-space:pre-wrap;
    margin-bottom:70px; display:flex; flex-direction:column;
}
#story::-webkit-scrollbar {width:8px;}
#story::-webkit-scrollbar-track {background: var(--bg-gray);}
#story::-webkit-scrollbar-thumb {background: var(--border-color); border-radius:4px;}
#story::-webkit-scrollbar-thumb:hover {background: var(--text-secondary);}

#input-area {
    position:fixed; bottom:0; left:0; right:0; display:flex; padding:10px;
    border-top:1px solid var(--border-color); background: var(--bg-tertiary); align-items:center; z-index:10;
}
#message {flex-grow:1; padding:10px; border:1px solid var(--border-color); border-radius:4px;
    resize:none; font-size:16px; line-height:1.4; height:40px; overflow-y:auto; background: var(--input-bg); color: var(--text-primary);}
#send {padding:10px 20px; margin-left:10px; border:none; background:#007bff;
    color:#fff; border-radius:4px; cursor:pointer; font-size:16px;}
#send:hover {background:#0056b3;}

/* ----- chat bubbles ----- */
.user-message, .ai-message {
    margin-bottom:10px; padding:10px; border-radius:8px; max-width:70%;
    position: relative;
}
.user-message {
    background: var(--chat-user-bg);
    align-self: flex-end;
    font-weight: bold;
    color: var(--text-primary);
    margin-left: auto;
}
.ai-message {
    background: var(--chat-ai-bg);
    align-self: flex-start;
    color: var(--text-primary);
}

/* Message timestamps */
.message-timestamp {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 4px;
    opacity: 0.7;
}

/* Dark mode adjustments for chat messages */
[data-theme="dark"] .user-message {
    color: #ffffff;
}
[data-theme="dark"] .ai-message {
    color: #f3f4f6;
}

/* ----- Quick Reply Suggestions ----- */
.quick-reply-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    margin-bottom: 10px;
    animation: fadeInUp 0.3s ease-out;
}

.quick-reply-btn {
    background: linear-gradient(to bottom, #f37b42, #f16623);
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    white-space: nowrap;
}

.quick-reply-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(241, 102, 35, 0.4);
}

.quick-reply-btn:active {
    transform: translateY(0);
}

[data-theme="dark"] .quick-reply-btn {
    background: linear-gradient(to bottom, #2563eb, #1e40af);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

[data-theme="dark"] .quick-reply-btn:hover {
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.5);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==============================================================
   STREAK DISPLAY SYSTEM
   ============================================================== */

/* Streak display in header */
#streak-display {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 4px 10px;
    background: linear-gradient(to bottom, rgba(243, 123, 66, 0.1), rgba(241, 102, 35, 0.15));
    border-radius: 16px;
    border: 1px solid rgba(241, 102, 35, 0.3);
    margin-left: 10px;
    cursor: default;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#streak-display:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(241, 102, 35, 0.25);
}

#streak-display.streak-high {
    animation: streak-pulse 2s ease-in-out infinite;
    background: linear-gradient(to bottom, rgba(243, 123, 66, 0.2), rgba(241, 102, 35, 0.25));
}

@keyframes streak-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(241, 102, 35, 0); }
    50% { transform: scale(1.05); box-shadow: 0 0 12px rgba(241, 102, 35, 0.4); }
}

/* Streak celebration overlay */
.streak-celebration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.celebration-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(243, 123, 66, 0.3);
    border: 2px solid rgba(243, 123, 66, 0.5);
    animation: celebrationPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 90vw;
}

@keyframes celebrationPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.celebration-emoji {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 0.6s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.celebration-title {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, #f37b42, #ffd700, #f16623);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2s linear infinite;
    margin-bottom: 0.5rem;
}

@keyframes shimmer {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

.celebration-subtitle {
    font-size: 1.2rem;
    color: #a0a0a0;
    margin-bottom: 1.5rem;
}

.celebration-dismiss {
    background: linear-gradient(to bottom, #f37b42, #f16623);
    color: #fff;
    border: none;
    padding: 12px 32px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.celebration-dismiss:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(243, 123, 66, 0.4);
}

/* Confetti particles */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    top: -20px;
    animation: confetti-fall linear forwards;
    pointer-events: none;
}

@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Streak broken toast */
.streak-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 500;
    z-index: 9999;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.streak-toast.show {
    transform: translateX(-50%) translateY(0);
}

.streak-toast.streak-broken {
    background: linear-gradient(to right, #2d1f1f, #3d2424);
    color: #ff9999;
    border: 1px solid rgba(255, 100, 100, 0.3);
}

/* Dark mode overrides for streak */
[data-theme="dark"] #streak-display {
    background: linear-gradient(to bottom, rgba(243, 123, 66, 0.15), rgba(241, 102, 35, 0.2));
    border-color: rgba(241, 102, 35, 0.4);
    color: #fff;
}

/* ==============================================================
   ACHIEVEMENT SYSTEM
   ============================================================== */

/* Achievement counter in header */
#achievement-counter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 4px 10px;
    background: linear-gradient(to bottom, rgba(255, 215, 0, 0.1), rgba(255, 215, 0, 0.15));
    border-radius: 16px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    margin-left: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#achievement-counter:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.25);
}

#achievement-counter.has-new {
    animation: achievement-glow 1.5s ease-in-out infinite;
}

@keyframes achievement-glow {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
    50% { box-shadow: 0 0 15px rgba(255, 215, 0, 0.5); }
}

/* Achievement unlock toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    right: -400px;
    width: 350px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 215, 0, 0.2);
    border: 2px solid rgba(255, 215, 0, 0.4);
    z-index: 10001;
    transition: right 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.achievement-toast.show {
    right: 20px;
}

.achievement-icon {
    font-size: 3rem;
    animation: achievement-bounce 0.6s ease infinite;
}

@keyframes achievement-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.achievement-info {
    flex: 1;
}

.achievement-unlocked {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #ffd700;
    font-weight: 700;
    margin-bottom: 4px;
}

.achievement-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 2px;
}

.achievement-desc {
    font-size: 0.85rem;
    color: #a0a0a0;
}

/* Dark mode overrides */
[data-theme="dark"] #achievement-counter {
    background: linear-gradient(to bottom, rgba(255, 215, 0, 0.15), rgba(255, 215, 0, 0.2));
    border-color: rgba(255, 215, 0, 0.4);
    color: #fff;
}

/* Natural 20 celebration */
.nat20-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: radial-gradient(circle, #ffd700 0%, #ff8c00 50%, #ff4500 100%);
    padding: 30px 50px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 0 60px rgba(255, 215, 0, 0.8), 0 0 120px rgba(255, 140, 0, 0.5);
    z-index: 10002;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nat20-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.nat20-icon {
    font-size: 4rem;
    animation: nat20-spin 1s ease-out;
}

@keyframes nat20-spin {
    0% { transform: rotate(0deg) scale(0.5); }
    50% { transform: rotate(180deg) scale(1.3); }
    100% { transform: rotate(360deg) scale(1); }
}

.nat20-text {
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 4px;
    animation: nat20-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes nat20-pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

/* ==============================================================
   ONBOARDING HINTS - Progressive user tips
   ============================================================== */
.onboarding-hint {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 9000;
    max-width: 400px;
    width: 90%;
    opacity: 0;
    transition: all 0.3s ease-out;
    pointer-events: none;
}

.onboarding-hint.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.hint-content {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.hint-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 8px;
}

.hint-text {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.5;
    margin-bottom: 12px;
}

.hint-dismiss {
    background: linear-gradient(to bottom, #f37b42, #f16623);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hint-dismiss:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(241, 102, 35, 0.4);
}

/* Dark mode adjustments for hints */
[data-theme="dark"] .hint-content {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border-color: rgba(255, 255, 255, 0.15);
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .onboarding-hint {
        bottom: 80px;
        max-width: 95%;
    }

    .hint-content {
        padding: 14px 16px;
    }

    .hint-title {
        font-size: 1rem;
    }

    .hint-text {
        font-size: 0.9rem;
    }
}

/* ==============================================================
   ACCOUNT PAGES (shared UI)
   ============================================================== */
.account-page {max-width:960px; margin:2rem auto; padding:1rem; background: var(--card-bg);
    border-radius:8px; box-shadow:0 2px 12px var(--shadow);}
.account-header {display:flex; justify-content:space-between; align-items:center;
    margin-bottom:1.5rem;}
.account-header h1 {margin:0; font-size:1.8rem; color: var(--text-primary);}
.logout-btn {background: var(--bg-gray); color: var(--text-primary); padding:.5rem 1rem; border-radius:6px;
    border:1px solid var(--border-color); cursor:pointer; font-weight:bold;}
.section {background: var(--card-bg); padding:1.5rem; margin-bottom:1.5rem;
    border-radius:8px; box-shadow:0 2px 6px var(--shadow);}
.section h2 {margin-top:0; color:#f16623; font-size:1.4rem;
    border-bottom:2px solid #f16623; padding-bottom:.3rem;}
.btn-primary {background:linear-gradient(to bottom,#f37b42,#f16623); color:#fff;
    padding:.75rem 1.5rem; border:none; border-radius:6px; font-weight:bold;
    cursor:pointer; display:inline-block; text-decoration:none;}
.btn-primary:hover {transform:translateY(-2px); box-shadow:0 4px 8px rgba(0,0,0,.15);}

/* ----- navigation menu (you can also edit in WP) ----- */
.account-nav {margin-bottom:1.5rem; text-align:center;}
.account-nav a {margin:0 .5rem; color:#f16623; font-weight:500; text-decoration:none;}
.account-nav a:hover {text-decoration:underline;}

/* ==============================================================
   RESPONSIVE
   ============================================================== */
@media (max-width:600px){
    h1{font-size:18px;padding:10px;}
    #adventure-selection{padding:8px;}
    .adventure-btn{padding:8px 15px;font-size:14px;}
    #story{padding:10px;margin-bottom:60px;}
    #input-area{padding:8px;}
    #message{font-size:14px;height:36px;}
    #send{padding:8px 15px;font-size:14px;margin-left:5px;}
}

/* ==============================================================
   DICE ROLLER SYSTEM STYLES
   ============================================================== */

/* Dice button in chat */
.dice-roller-button {
  padding: 8px 12px;
  margin-right: 8px;
  background: #8b5cf6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

.dice-roller-button:hover {
  background: #7c3aed;
}

/* Modal overlay */
.dice-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  font-family: system-ui, -apple-system, sans-serif;
}

.dice-modal.hidden {
  display: none;
}

.dice-modal-content {
  background: var(--modal-bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
  color: var(--text-primary);
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.dice-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e5e7eb;
}

.dice-modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text-primary);
}

.close-modal-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: #6b7280;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.close-modal-btn:hover {
  color: #1f2937;
}

[data-theme="dark"] .close-modal-btn {
  color: #9ca3af;
}

[data-theme="dark"] .close-modal-btn:hover {
  color: #f9fafb;
}

/* Dice selection grid */
.dice-buttons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.dice-btn {
  padding: 12px 16px;
  border: 2px solid var(--input-border);
  background: var(--input-bg);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.dice-btn:hover {
  border-color: #8b5cf6;
  color: #8b5cf6;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.dice-btn.active {
  background: #8b5cf6;
  color: white;
  border-color: #8b5cf6;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

/* Input controls */
.dice-quantity,
.dice-modifier,
.dice-animation-toggle {
  margin-bottom: 16px;
}

.dice-quantity label,
.dice-modifier label,
.dice-animation-toggle label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.dice-animation-toggle label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.dice-animation-toggle input[type="checkbox"] {
  cursor: pointer;
}

.dice-quantity input,
.dice-modifier input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
  background: var(--input-bg);
  color: var(--text-primary);
}

.dice-quantity input:focus,
.dice-modifier input:focus {
  outline: none;
  border-color: #8b5cf6;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

/* Dice roller container */
.dice-roller {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  padding: 20px;
  background: var(--dice-bg);
  border-radius: 8px;
}

.dice-container {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  min-height: 80px;
}

.dice {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
  animation: rollDice 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  position: relative;
}

@keyframes rollDice {
  0% {
    transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(0.5);
    opacity: 0;
  }
  50% {
    transform: rotateX(720deg) rotateY(720deg) rotateZ(180deg) scale(1.1);
  }
  100% {
    transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(1);
    opacity: 1;
  }
}

/* Result display */
.dice-result {
  background: #f0fdf4;
  border: 2px solid #86efac;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

[data-theme="dark"] .dice-result {
  background: #064e3b;
  border-color: #059669;
}

.dice-result.hidden {
  display: none;
}

.result-header {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-rolls {
  margin-bottom: 12px;
}

.result-rolls-label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 6px;
}

.rolls-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #059669;
}

.result-total {
  padding: 12px;
  background: var(--input-bg);
  border-radius: 6px;
  font-size: 18px;
  font-weight: bold;
  color: #059669;
  text-align: center;
  margin-bottom: 16px;
}

.result-total-label {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 4px;
}

/* Action buttons */
.use-roll-btn,
.roll-again-btn {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
}

.use-roll-btn {
  background: #8b5cf6;
  color: white;
}

.use-roll-btn:hover {
  background: #7c3aed;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.roll-again-btn {
  background: var(--bg-gray);
  color: var(--text-primary);
  border: 1px solid var(--input-border);
}

.roll-again-btn:hover {
  background: var(--border-color);
  border-color: var(--text-muted);
}

/* Mobile responsive */
@media (max-width: 600px) {
  .dice-modal-content {
    width: 95%;
    padding: 16px;
  }

  .dice-buttons-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .dice {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .dice-container {
    gap: 8px;
    min-height: 60px;
  }
}

/* ==============================================================
   ADVENTURE CATALOG STYLES
   ============================================================== */
.browse-adventures-link {
  background: none;
  border: none;
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  margin: 0 4px;
  font-weight: 600;
}

.browse-adventures-link:hover {
  color: #1d4ed8;
}

.adventure-catalog-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.adventure-catalog-list::-webkit-scrollbar {
  width: 8px;
}

.adventure-catalog-list::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.adventure-catalog-list::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.adventure-card {
  background: var(--input-bg);
  border: 2px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.adventure-card:hover {
  border-color: #8b5cf6;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
  transform: translateY(-2px);
}

.adventure-card-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.adventure-card-description {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.adventure-card-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #9ca3af;
}

.adventure-card-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.adventure-tags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.adventure-tag {
  background: #f3f4f6;
  color: #6b7280;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

[data-theme="dark"] .adventure-tag {
  background: #374151;
  color: #d1d5db;
}

/* ==============================================================
   TYPING INDICATOR STYLES
   ============================================================== */
.typing-indicator {
  padding: 12px 16px !important;
  display: inline-block;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-10px);
  }
}

/* ==============================================================
   SCROLL TO BOTTOM BUTTON
   ============================================================== */
.scroll-to-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #8b5cf6;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: all 0.3s ease;
  opacity: 1;
  transform: translateY(0);
}

.scroll-to-bottom-btn.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.scroll-to-bottom-btn:hover {
  background: #7c3aed;
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.5);
  transform: scale(1.1);
}

.scroll-to-bottom-btn:active {
  transform: scale(0.95);
}

@media (max-width: 600px) {
  .scroll-to-bottom-btn {
    bottom: 70px;
    right: 15px;
    width: 36px;
    height: 36px;
  }
}

/* ==============================================================
   ADVENTURE PROGRESS BAR
   ============================================================== */
.adventure-progress {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 300px;
  padding: 8px 12px;
  background: var(--card-bg, #ffffff);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-left: auto;
}

.adventure-progress.active {
  display: flex;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary, #666);
}

.progress-title {
  font-weight: 600;
  color: var(--text-primary, #333);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.progress-text {
  font-weight: 500;
  color: #f16623;
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--bg-gray, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(to right, #f37b42, #f16623);
  border-radius: 4px;
  transition: width 0.5s ease-out;
  width: 0%;
}

.progress-bar-fill.complete {
  background: linear-gradient(to right, #10b981, #059669);
}

.progress-percentage {
  font-size: 0.7rem;
  color: var(--text-secondary, #888);
  text-align: right;
}

/* Dark mode adjustments */
[data-theme="dark"] .adventure-progress {
  background: var(--card-bg, #1f2937);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .progress-bar-container {
  background: var(--bg-gray, #374151);
}

/* Mobile responsiveness */
@media (max-width: 600px) {
  .adventure-progress {
    max-width: none;
    margin: 8px 0 0 0;
  }

  .progress-title {
    max-width: 150px;
  }
}