/**
 * Book Layout and Parchment Styling
 *
 * Creates an enchanted book aesthetic with aged paper background,
 * decorative edges, and medieval styling.
 */

/* CSS Variables */
:root {
    --parchment-light: #f5f0e1;
    --parchment-dark: #e8dcc8;
    --parchment-edge: #d4c4a8;
    --ink-black: #2c1810;
    --ink-brown: #3d2914;
    --ink-red: #8b0000;
    --ink-faded: #5c4a3d;
    --border-ornate: #8b7355;
    --shadow-soft: rgba(44, 24, 16, 0.15);
    --shadow-deep: rgba(44, 24, 16, 0.3);

    /* Spacing */
    --page-padding: 3rem;
    --page-padding-mobile: 1.5rem;

    /* Sizing */
    --max-page-width: 600px;
    --book-spine-width: 40px;
    --book-edge-width: 20px;
}

/* Dark Mode Variables */
:root.dark-mode {
    --parchment-light: #1a1a1a;
    --parchment-dark: #121212;
    --parchment-edge: #2a2a2a;
    --ink-black: #e8e0d0;
    --ink-brown: #d4c4a8;
    --ink-red: #c45c5c;
    --ink-faded: #9a8a7a;
    --border-ornate: #4a4a4a;
    --shadow-soft: rgba(0, 0, 0, 0.3);
    --shadow-deep: rgba(0, 0, 0, 0.5);
}

/* Dark mode specific overrides */

/* Hide parchment background images, use solid dark colors */
:root.dark-mode body {
    background: #1a1a1a !important;
}

/* Hide the parchment texture layers */
:root.dark-mode .parchment-bg,
:root.dark-mode .parchment-base,
:root.dark-mode .paper-texture {
    display: none !important;
}

:root.dark-mode .book-page,
:root.dark-mode .modal-content,
:root.dark-mode .character-creation {
    background: #1a1a1a !important;
    background-image: none !important;
}

:root.dark-mode .page-content {
    background: transparent !important;
    background-image: none !important;
}

/* Form inputs in dark mode - better contrast */
:root.dark-mode input,
:root.dark-mode select,
:root.dark-mode textarea {
    background: #2a2a2a !important;
    color: #e8e0d0 !important;
    border-color: #4a4a4a !important;
}

:root.dark-mode input::placeholder,
:root.dark-mode textarea::placeholder {
    color: #7a7a7a !important;
}

:root.dark-mode input:focus,
:root.dark-mode select:focus,
:root.dark-mode textarea:focus {
    background: #333 !important;
    border-color: #666 !important;
}

/* Player input in game screen - transparent background */
:root.dark-mode #player-input {
    background: transparent !important;
    border-color: transparent !important;
}

:root.dark-mode #player-input:focus {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* Keep images visible in dark mode */
:root.dark-mode img {
    opacity: 0.9;
}

/* Invert dark icons/images to make them visible */
:root.dark-mode .drop-cap img,
:root.dark-mode .prefix-icon img,
:root.dark-mode .quill-caret,
:root.dark-mode .input-line img,
:root.dark-mode [src*="quill"],
:root.dark-mode [src*="d20"] {
    filter: invert(0.85) sepia(0.1) !important;
    opacity: 1 !important;
}

/* Don't invert skill icons or other colored images */
:root.dark-mode .skill-icon,
:root.dark-mode .loading-dice img,
:root.dark-mode .dice-icon {
    filter: none;
    opacity: 1;
}

/* Local Fonts */
@font-face {
    font-family: 'Metamorphous';
    src: url('/static/fonts/Metamorphous-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Pirata One';
    src: url('/static/fonts/PirataOne-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Reset and Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    height: 100vh;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #f7f3eb;
}

/* Parchment texture layers */
.parchment-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.parchment-base {
    position: absolute;
    inset: 0;
    background: url('/static/images/background-4k.jpg') center center / cover no-repeat;
}

.paper-texture {
    position: absolute;
    inset: 0;
    opacity: 0.1;
    filter: url(#paper-noise);
    background: #e8e0d0;
}

.water-stain-topleft {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 60%;
    height: 50%;
    background: radial-gradient(
        ellipse at 30% 30%,
        rgba(180, 130, 90, 0.35) 0%,
        rgba(165, 120, 80, 0.25) 20%,
        rgba(150, 110, 70, 0.15) 40%,
        rgba(140, 100, 60, 0.08) 60%,
        transparent 75%
    );
    filter: blur(20px);
}

.water-stain-topleft-2 {
    position: absolute;
    top: 0;
    left: 0;
    width: 45%;
    height: 35%;
    background: radial-gradient(
        ellipse at 20% 20%,
        rgba(160, 100, 60, 0.2) 0%,
        rgba(140, 90, 50, 0.1) 40%,
        transparent 70%
    );
    filter: blur(15px);
}

.parchment-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(
        ellipse at center,
        transparent 60%,
        rgba(120, 100, 80, 0.06) 85%,
        rgba(100, 80, 60, 0.12) 100%
    );
}

.foxing {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.fox-spot {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(
        ellipse at center,
        rgba(140, 110, 80, 0.25) 0%,
        rgba(130, 100, 70, 0.1) 40%,
        transparent 70%
    );
}

.age-spot {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(
        ellipse at center,
        rgba(120, 90, 60, 0.2) 0%,
        rgba(110, 80, 55, 0.08) 50%,
        transparent 70%
    );
}

.fibers {
    position: absolute;
    inset: 0;
    opacity: 0.08;
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(100, 80, 60, 0.3) 2px,
            rgba(100, 80, 60, 0.3) 3px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 3px,
            rgba(100, 80, 60, 0.2) 3px,
            rgba(100, 80, 60, 0.2) 4px
        );
}

.random-stains {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.random-stain {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(
        ellipse at center,
        rgba(140, 100, 70, 0.12) 0%,
        transparent 70%
    );
    filter: blur(10px);
}

/* Book Container */
.book-container {
    display: flex;
    flex-direction: column;
    max-width: var(--max-page-width);
    width: 100%;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* Hide book spine and edge - no longer needed with full page background */
.book-spine,
.book-edge {
    display: none;
}

/* Main Book Page */
.book-page {
    flex: 1;
    background: transparent;
    padding: var(--page-padding);
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

/* Book Header - Hidden by default, shown when .visible is added */
.book-header {
    display: none;
}

.book-header.visible {
    display: block;
}

/* Page Sections */
.page-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    min-height: 0;
}

.page-section.hidden {
    display: none;
}

/* Character creation - scrollable when content overflows, hidden scrollbar */
#character-creation {
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

#character-creation::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Opera */
}

/* Game screen layout - fixed input at bottom */
#game-screen {
    height: calc(100vh - 6rem);
    max-height: calc(100vh - 6rem);
}

/* Location Image (inline in message flow) */
.location-image-entry {
    margin-bottom: 1.5rem;
}

.location-image-wrapper {
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow-soft);
}

.location-image {
    width: 100%;
    height: auto;
    display: block;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.location-image.loaded {
    opacity: 1;
}

/* Character Header (scrolls with content) */
.character-header {
    text-align: center;
    padding: 1rem 0 1.5rem 0;
    margin-bottom: 0.5rem;
}

.character-header.hidden {
    display: none;
}

.character-header-name {
    font-family: 'Pirata One', cursive;
    font-size: 2.75rem;
    color: var(--ink-brown);
    letter-spacing: 0.02em;
    line-height: 1.2;
}

/* Story Content Area */
.story-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* Messages container - scrollable */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 1rem;
    margin-right: -1rem;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Fade content at top when scrolled - uses mask to fade actual content */
.story-content.scrolled .messages-container {
    mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        black 6rem
    );
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        black 6rem
    );
}

/* Messages wrapper - content flows naturally, no forced expansion */
.messages-wrapper {
    /* No flex-grow - input follows content directly */
}

/* Input area - stays at bottom of scroll area */
.messages-container .input-area {
    flex-shrink: 0;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

/* Custom Scrollbar */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: rgba(139, 115, 85, 0.1);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-ornate);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--ink-brown);
}

/* Message Entries */
.message-entry {
    margin-bottom: 1.5rem;
}

.message-entry.player-message {
    padding-left: 1.5rem;
    border-left: 2px solid var(--border-ornate);
}

.message-entry.dm-message {
    /* DM messages get drop caps via typography.css */
    /* Establish block formatting context for proper float containment on iOS Safari */
    display: flow-root;
}

/* Input Area - Inline after content */
.input-area {
    margin-top: 1rem;
    position: relative;
    overflow: visible;
}

/* Slash Command Suggestions */
.command-suggestions {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--parchment-light);
    border: 1px solid var(--border-ornate);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 -2px 8px var(--shadow-soft);
    z-index: 100;
}

.command-suggestions.hidden {
    display: none;
}

.command-suggestion {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(139, 115, 85, 0.15);
}

.command-suggestion:last-child {
    border-bottom: none;
}

.command-suggestion:hover,
.command-suggestion.selected {
    background: rgba(139, 115, 85, 0.15);
}

.command-suggestion-name {
    font-family: 'Metamorphous', serif;
    font-weight: 600;
    color: var(--ink-brown);
    min-width: 140px;
    font-size: 0.85rem;
}

.command-suggestion-desc {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-faded);
}

.input-line {
    display: flex;
    align-items: baseline;
    position: relative;
    overflow: visible;
    padding-top: 20px;
    margin-top: -20px;
}

.input-prefix {
    font-family: 'Pirata One', cursive;
    font-size: 1.05rem;
    color: var(--ink-faded);
    opacity: 0.7;
    user-select: none;
    cursor: text;
    letter-spacing: 0.02em;
    margin-right: 0.5em;
    line-height: 1.6;
    display: flex;
    align-items: center;
}

.prefix-text {
    display: inline;
    transform: translateY(1px);
    margin-right: 0.3em;
}

.prefix-oracle {
    width: 20px;
    height: 20px;
    opacity: 0.6;
    margin-right: calc(4px + 0.3em);
    transform: translateY(3px);
}

.prefix-oracle.hidden {
    display: none;
}

.prefix-oracle.rolling {
    animation: diceRoll 0.4s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}

@keyframes diceRoll {
    0% {
        transform: translateY(3px) rotate(0deg) scale(0.8);
        opacity: 0.3;
    }
    25% {
        transform: translateY(3px) rotate(180deg) scale(1.1);
        opacity: 0.7;
    }
    50% {
        transform: translateY(3px) rotate(360deg) scale(1.05);
    }
    75% {
        transform: translateY(3px) rotate(540deg) scale(1);
    }
    100% {
        transform: translateY(3px) rotate(720deg) scale(1);
        opacity: 0.6;
    }
}

.prefix-text.hidden {
    display: none;
}

.input-line.hidden {
    visibility: hidden;
}

.player-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0;
    font-family: 'Metamorphous', serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ink-faded);
    outline: none;
    caret-color: transparent;
    resize: none;
    overflow: hidden;
    overflow-x: hidden;
    min-height: 1.6em;
    max-height: 10em;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: break-spaces;
    word-break: break-all;
    /* Override body's text-align: justify - justified text causes caret drift */
    text-align: left;
    text-justify: none;
}

/* Custom quill caret */
.quill-caret {
    position: absolute;
    width: 20px;
    height: 26px;
    background-image: url('/static/images/quill-cursor.png');
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, left 0.03s ease-out, top 0.03s ease-out;
    transform: rotate(15deg);
    transform-origin: bottom left;
    z-index: 100;
    left: 0;
    top: 0;
}

.quill-caret.visible {
    opacity: 0.55;
    animation: quillIdle 1.5s ease-in-out infinite;
}

.quill-caret.stroke {
    animation: quillStroke 0.15s ease-out forwards;
}

@keyframes quillIdle {
    0%, 100% {
        transform: rotate(12deg) translateY(0);
    }
    50% {
        transform: rotate(20deg) translateY(-2px);
    }
}

@keyframes quillStroke {
    0% {
        transform: rotate(14deg) translateY(0) translateX(0) scale(1);
    }
    40% {
        transform: rotate(18deg) translateY(2px) translateX(-2px) scale(0.97);
    }
    100% {
        transform: rotate(14deg) translateY(0) translateX(0) scale(1);
    }
}

/* Fresh ink effect - briefly shows darker color on just-typed character */
.ink-fresh {
    position: absolute;
    pointer-events: none;
    font-family: 'Metamorphous', serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ink-black);
    opacity: 0;
    z-index: 50;
}

.ink-fresh.flash {
    animation: inkFlash 0.35s ease-out forwards;
}

@keyframes inkFlash {
    0% {
        opacity: 1;
        color: #1a0f08;
    }
    100% {
        opacity: 0;
    }
}

.player-input::placeholder {
    color: var(--ink-faded);
    font-style: italic;
    opacity: 0.3;
}

.player-input:disabled {
    opacity: 0.5;
}

/* Microphone Button */
.mic-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: 8px;
    opacity: 0.5;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.mic-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.mic-btn:active {
    transform: scale(0.95);
}

.mic-btn .mic-icon {
    width: 18px;
    height: 18px;
    stroke: var(--ink-brown);
}

/* Recording state */
.mic-btn.recording {
    opacity: 1;
}

.mic-btn.recording .mic-icon {
    stroke: var(--ink-red);
    animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Processing state (transcribing) */
.mic-btn.processing {
    opacity: 1;
    pointer-events: none;
    animation: mic-breathe 0.8s ease-in-out infinite;
}

@keyframes mic-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Hide mic button when input is disabled */
.player-input:disabled ~ .mic-btn {
    display: none;
}

/* Floating mic button on touch devices (mobile/tablet) */
@media (pointer: coarse) {
    .mic-btn {
        position: fixed;
        bottom: 1.5rem;
        left: 1.5rem;
        z-index: 9999;
        width: 88px;
        height: 88px;
        margin: 0;
        opacity: 0.6;
        border-radius: 50%;
        border: 2px solid var(--border-ornate);
        background: linear-gradient(135deg, #f5e6c8 0%, #e8dcc8 100%);
        box-shadow: 0 4px 16px var(--shadow-soft);
        transition: opacity 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    }

    .mic-btn:hover,
    .mic-btn:active {
        opacity: 1;
        transform: scale(1.05);
        box-shadow: 0 6px 20px var(--shadow-deep);
    }

    .mic-btn .mic-icon {
        width: 44px;
        height: 44px;
    }

    .mic-btn.recording {
        opacity: 1;
        background: linear-gradient(135deg, #f8d4d4 0%, #e8c4c4 100%);
        border-color: var(--ink-red);
    }

    .mic-btn.processing {
        opacity: 1;
    }

    /* Dark mode floating mic button */
    :root.dark-mode .mic-btn {
        background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
        border-color: #4a4a4a;
    }

    :root.dark-mode .mic-btn:hover,
    :root.dark-mode .mic-btn:active {
        background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
    }

    :root.dark-mode .mic-btn.recording {
        background: linear-gradient(135deg, #4a2a2a 0%, #3a1a1a 100%);
        border-color: #ff6b6b;
    }
}

/* Also float on small screens as fallback */
@media (max-width: 768px) {
    .mic-btn {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        z-index: 9999;
        width: 80px;
        height: 80px;
        margin: 0;
        opacity: 0.6;
        border-radius: 50%;
        border: 2px solid var(--border-ornate);
        background: linear-gradient(135deg, #f5e6c8 0%, #e8dcc8 100%);
        box-shadow: 0 4px 16px var(--shadow-soft);
    }

    .mic-btn .mic-icon {
        width: 40px;
        height: 40px;
    }

    .mic-btn.recording {
        opacity: 1;
        background: linear-gradient(135deg, #f8d4d4 0%, #e8c4c4 100%);
        border-color: var(--ink-red);
    }

    :root.dark-mode .mic-btn {
        background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
        border-color: #4a4a4a;
    }

    :root.dark-mode .mic-btn.recording {
        background: linear-gradient(135deg, #4a2a2a 0%, #3a1a1a 100%);
        border-color: #ff6b6b;
    }
}

/* Dark mode mic button */
:root.dark-mode .mic-btn .mic-icon {
    stroke: #d4c4a8;
}

:root.dark-mode .mic-btn.recording .mic-icon {
    stroke: #ff6b6b;
}

:root.dark-mode .mic-btn:hover .mic-icon {
    stroke: #fff;
}

/* Hide mic button if speech recognition not supported */
.mic-btn.unsupported {
    display: none;
}

/* Add padding at bottom of input area on touch devices to make room for floating mic button */
@media (pointer: coarse) {
    .messages-container .input-area {
        padding-bottom: calc(88px + 2rem); /* mic button height + margin */
    }
}

/* Also on small screens as fallback */
@media (max-width: 768px) {
    .messages-container .input-area {
        padding-bottom: calc(80px + 1.5rem); /* mic button height + margin */
    }
}

/* Hide send button */
.send-btn {
    display: none;
}

/* Hide input hints */
.input-hints {
    display: none;
}

/* Pending Check Indicator */
.check-pending {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(139, 0, 0, 0.08);
    border-left: 3px solid var(--ink-red);
    border-radius: 0 4px 4px 0;
}

.check-pending.hidden {
    display: none;
}

.check-label {
    color: var(--ink-red);
    font-family: 'Metamorphous', serif;
    font-size: 0.875rem;
    font-weight: 600;
}

.check-type {
    color: var(--ink-black);
    font-family: 'Metamorphous', serif;
    font-weight: 600;
}

/* Roll Input Panel */
.roll-panel {
    margin-top: 1.5rem;
    padding: 1.5rem;
    text-align: center;
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.06) 0%, rgba(139, 0, 0, 0.02) 100%);
    border-radius: 8px;
    border: 1px solid rgba(139, 0, 0, 0.15);
}

.roll-panel.hidden {
    display: none;
}

.roll-panel-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.roll-panel-icon {
    width: 32px;
    height: 32px;
    opacity: 0.8;
}

.roll-check-type {
    font-family: 'Pirata One', cursive;
    font-size: 1.4rem;
    color: var(--ink-red);
}

.roll-panel-input {
    margin-bottom: 1rem;
}

.roll-value-input {
    width: 80px;
    height: 60px;
    font-family: 'Pirata One', cursive;
    font-size: 2rem;
    text-align: center;
    color: var(--ink-brown);
    background: var(--parchment-light);
    border: 2px solid var(--border-ornate);
    border-radius: 8px;
    outline: none;
    -moz-appearance: textfield;
}

.roll-value-input::-webkit-outer-spin-button,
.roll-value-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.roll-value-input:focus {
    border-color: var(--ink-red);
    box-shadow: 0 0 0 2px rgba(139, 0, 0, 0.1);
}

.roll-value-input::placeholder {
    color: var(--ink-faded);
    opacity: 0.4;
}

.roll-panel-numpad {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    margin-bottom: 1rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.roll-num-btn {
    padding: 0.5rem 0;
    font-family: 'Crimson Text', serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink-brown);
    background: var(--parchment-light);
    border: 1px solid var(--border-ornate);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 32px;
}

.roll-num-btn:hover {
    background: var(--parchment-dark);
    border-color: var(--ink-brown);
}

.roll-num-btn:active {
    transform: scale(0.95);
}

.roll-num-btn.crit {
    background: linear-gradient(135deg, #fff8e7 0%, #ffe4b5 100%);
    border-color: #b8860b;
    color: #8b4513;
}

.roll-num-btn.crit:hover {
    background: linear-gradient(135deg, #ffe4b5 0%, #ffd700 100%);
}

.roll-num-btn.selected {
    background: var(--ink-red);
    color: var(--parchment-light);
    border-color: var(--ink-red);
}

.roll-submit-btn {
    padding: 0.75rem 2rem;
    font-family: 'Pirata One', cursive;
    font-size: 1.2rem;
    color: var(--parchment-light);
    background: var(--ink-red);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.5;
}

.roll-submit-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.roll-submit-btn:not(:disabled) {
    opacity: 1;
}

.roll-submit-btn:not(:disabled):hover {
    background: #a00000;
    transform: translateY(-1px);
}

.roll-submit-btn:not(:disabled):active {
    transform: translateY(0);
}

/* Mobile: 2 rows of 10 numbers */
@media (max-width: 480px) {
    .roll-panel-numpad {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }

    .roll-num-btn {
        padding: 0.75rem 0;
        font-size: 1.1rem;
    }

    .roll-value-input {
        width: 100px;
        height: 70px;
        font-size: 2.5rem;
    }
}

/* Torch indicator */
.prefix-torch {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    margin-right: 0.35em;
    vertical-align: middle;
    transform: translateY(1px);
    display: inline-block;
}

.prefix-torch.hidden {
    display: none;
}

/* Victory Reward Message (XP + Loot combined) */
.victory-reward-message {
    text-align: center;
    margin: 1.5rem 0;
    animation: victory-fade-in 0.6s ease-out;
}

@keyframes victory-fade-in {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
}

.victory-reward-text {
    font-family: 'Crimson Text', serif;
    font-size: 1.1em;
    font-style: italic;
    margin: 0;
}

.victory-xp {
    color: #8B6914;
    font-weight: 600;
}

.victory-loot {
    color: #6B5B3D;
}

.victory-separator {
    color: var(--ink-faded);
    margin: 0 0.5em;
}

/* AI Thinking Placeholder */
.thinking-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 0;
}

.thinking-placeholder.hidden {
    display: none;
}

.thinking-dice {
    width: 24px;
    height: 24px;
    opacity: 0.35;
    animation: thinking-spin 0.8s linear infinite;
}

@keyframes thinking-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 15, 10, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 2rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background:
        linear-gradient(
            180deg,
            var(--parchment-light) 0%,
            var(--parchment-dark) 100%
        );
    padding: 2rem;
    border-radius: 8px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px var(--shadow-deep);
}

.modal-content h3 {
    font-family: 'Metamorphous', serif;
    color: var(--ink-red);
    margin: 0 0 1.5rem 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-ornate);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Item Confirmation Modal */
.item-confirm-content {
    max-width: 360px;
    text-align: center;
}

.item-confirm-message {
    font-family: 'Metamorphous', serif;
    color: var(--ink-brown);
    margin: 0 0 1.25rem 0;
    line-height: 1.5;
}

.item-confirm-cost {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(139, 115, 85, 0.1);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.item-cost-label {
    font-family: 'Metamorphous', serif;
    color: var(--ink-faded);
    font-size: 0.9rem;
}

.item-cost-value {
    font-family: 'Metamorphous', serif;
    color: var(--ink-red);
    font-weight: 600;
    font-size: 1.1rem;
}

.item-confirm-content .modal-actions {
    justify-content: center;
}

/* Saves List */
.saves-list {
    max-height: 300px;
    overflow-y: auto;
}

.save-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(139, 115, 85, 0.1);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.save-item:hover {
    background: rgba(139, 115, 85, 0.2);
}

.save-item-info {
    flex: 1;
    cursor: pointer;
}

.save-item-name {
    font-family: 'Metamorphous', serif;
    font-weight: 600;
    color: var(--ink-black);
}

.save-item-details {
    font-family: 'Metamorphous', serif;
    font-size: 0.875rem;
    color: var(--ink-faded);
    margin-top: 0.25rem;
}

.save-item-delete {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--ink-faded);
    cursor: pointer;
    padding: 0 0.5rem;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.save-item-delete:hover {
    opacity: 1;
    color: var(--ink-red);
}

/* State Details */
.state-details {
    font-family: 'Metamorphous', serif;
}

.state-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(139, 115, 85, 0.2);
}

.state-row:last-child {
    border-bottom: none;
}

.state-key {
    color: var(--ink-faded);
}

.state-value {
    color: var(--ink-black);
    font-weight: 600;
}

/* Skills Modal */
.skills-modal-content {
    max-width: 550px;
}

.skills-section {
    margin-bottom: 1.5rem;
}

.skills-section:last-of-type {
    margin-bottom: 0;
}

.skills-category {
    font-family: 'Pirata One', cursive;
    font-size: 1.1rem;
    color: var(--ink-brown);
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed var(--border-ornate);
}

.skills-intro {
    font-size: 0.85rem;
    color: var(--ink-faded);
    font-style: italic;
    margin: 0 0 0.6rem 0;
}

.quick-modes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.3rem 1rem;
}

.quick-modes .command-name {
    min-width: 1.5rem;
}

.skills-grid {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.skill-group {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.4rem;
}

.skill-group-label {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-faded);
    min-width: 85px;
}

.skill-item {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-black);
    background: rgba(139, 115, 85, 0.12);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
}

.commands-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.command-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: baseline;
    padding: 0.4rem 0;
    border-bottom: 1px dotted rgba(139, 115, 85, 0.2);
}

.command-row:last-child {
    border-bottom: none;
}

.command-name {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-black);
    background: rgba(139, 115, 85, 0.12);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    white-space: nowrap;
}

.command-desc {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-faded);
}

/* Intro Modal */
.intro-modal-content {
    max-width: 550px;
}

.intro-modal-content h3 {
    text-align: center;
    font-size: 1.5rem;
}

.intro-section {
    margin-bottom: 1.25rem;
}

.intro-section h4 {
    font-family: 'Metamorphous', serif;
    color: var(--ink-red);
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
}

.intro-section p {
    font-family: 'Metamorphous', serif;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--ink-brown);
    margin: 0;
}

.intro-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.intro-list li {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-brown);
    padding: 0.35rem 0;
    padding-left: 1.25rem;
    position: relative;
}

.intro-list li::before {
    content: "◆";
    position: absolute;
    left: 0;
    color: var(--ink-red);
    font-size: 0.6rem;
    top: 0.55rem;
}

.intro-list li strong {
    color: var(--ink-dark);
}

.intro-note {
    background: rgba(139, 69, 19, 0.08);
    padding: 0.75rem 1rem;
    border-radius: 4px;
    border-left: 3px solid var(--ink-red);
}

.intro-note p {
    font-size: 0.85rem;
    font-style: italic;
}

.intro-modal-content .modal-actions {
    justify-content: center;
    gap: 1.5rem;
}

/* Rooms Modal */
.rooms-modal-content {
    width: 500px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.rooms-header {
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed var(--border-ornate);
}

.rooms-header h3 {
    font-family: 'Pirata One', cursive;
    font-size: 1.5rem;
    color: var(--ink-red);
    margin-bottom: 0.25rem;
}

.rooms-icon {
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.5rem;
    vertical-align: middle;
    opacity: 0.85;
}

.rooms-dungeon-name {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-faded);
    font-style: italic;
}

.rooms-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
    padding-right: 0.5rem;
}

.room-entry {
    display: flex;
    align-items: flex-start;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.5rem;
    background: rgba(90, 70, 50, 0.05);
    border: 1px solid rgba(139, 115, 85, 0.2);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.room-entry:hover {
    background: rgba(90, 70, 50, 0.1);
}

.room-entry.is-current {
    background: rgba(139, 115, 85, 0.15);
    border-color: var(--border-ornate);
}

.room-markers {
    display: flex;
    gap: 0.3rem;
    margin-right: 0.6rem;
    min-width: 3.5rem;
    justify-content: flex-end;
}

.room-marker {
    font-size: 0.85rem;
    line-height: 1;
}

.room-marker.current { color: var(--ink-brown); }
.room-marker.entry { color: #8b6914; }
.room-marker.cleared { color: #2d6a2d; }
.room-marker.searched { color: #4a6a8a; }
.room-marker.barricaded { color: #6a4a8a; }

.room-info {
    flex: 1;
}

.room-name {
    font-family: 'Metamorphous', serif;
    font-weight: 600;
    color: var(--ink-brown);
    font-size: 0.95rem;
}

.room-id {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--ink-faded);
    margin-left: 0.5rem;
}

.room-type {
    font-size: 0.8rem;
    color: var(--ink-faded);
    font-style: italic;
}

.room-exits {
    font-size: 0.75rem;
    color: var(--ink-faded);
    margin-top: 0.2rem;
}

.room-notes {
    font-size: 0.8rem;
    color: var(--ink-brown);
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px dotted rgba(139, 115, 85, 0.3);
    font-style: italic;
}

.rooms-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem;
    margin-bottom: 1rem;
    background: rgba(90, 70, 50, 0.05);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--ink-faded);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.legend-marker {
    font-size: 0.85rem;
}

.legend-marker.current { color: var(--ink-brown); }
.legend-marker.entry { color: #8b6914; }
.legend-marker.cleared { color: #2d6a2d; }
.legend-marker.searched { color: #4a6a8a; }

.rooms-empty {
    text-align: center;
    padding: 2rem;
    color: var(--ink-faded);
    font-style: italic;
}

/* Combat Modal */
.combat-modal-content {
    width: 600px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: url('/static/images/parchment-bg.png') center center / 100% 100% no-repeat;
    /* Asymmetric padding to avoid the folded corner (bottom-left) and rough edges */
    padding: 2rem 2.5rem 5rem 3rem;
    position: relative;
}

.combat-sections {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    padding-bottom: 4rem; /* Space for fixed action buttons */
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: relative;
}

/* Scroll indicator - floating at bottom right */
.combat-scroll-indicator {
    position: absolute;
    bottom: 5.5rem;
    right: calc(2rem + 30px);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.combat-scroll-indicator.hidden {
    opacity: 0;
}

.scroll-arrow {
    font-size: 1.1rem;
    color: var(--ink-brown);
    opacity: 0.5;
    animation: scrollBounce 1.5s ease-in-out infinite;
}

@keyframes scrollBounce {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    50% {
        transform: translateY(4px);
        opacity: 0.8;
    }
}

.combat-header h3 {
    font-family: 'Pirata One', cursive;
    font-size: 4.8rem;
    font-weight: normal;
    text-align: center;
    color: var(--ink-brown);
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.combat-divider {
    display: block;
    width: 100%;
    height: auto;
    margin: -0.25rem auto 1rem auto;
    opacity: 0.85;
}

.combat-narrative {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    font-style: italic;
    color: var(--ink-brown);
    text-align: center;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: rgba(139, 115, 85, 0.08);
    border-radius: 4px;
    border-left: 3px solid var(--ink-red);
}

.combat-section {
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border-ornate);
}

.combat-section:last-child {
    border-bottom: none;
}

.combat-section-title {
    font-family: 'Pirata One', cursive;
    font-size: 1.1rem;
    color: var(--ink-red);
    margin: 0 0 0.75rem 0;
}

.combat-enemies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: flex-start;
}

/* D&D-style Monster Stat Block - Tabbed Version */
.monster-stat-block {
    background: linear-gradient(to bottom, #fdf1dc 0%, #f8e5c0 100%);
    border: 2px solid #a07868;
    padding: 0;
    width: 100%;
    min-width: 280px;
    max-width: 300px;
    font-family: 'Metamorphous', 'Noto Sans', 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    flex: 1 1 280px;
}

/* Single monster gets more width */
.combat-enemies:has(.monster-stat-block:only-child) .monster-stat-block {
    max-width: 380px;
}

.monster-stat-block::before {
    content: '';
    display: block;
    height: 4px;
    background: linear-gradient(to right, #8b5545 0%, #a07060 12%, #a07060 88%, #8b5545 100%);
}

.stat-block-content {
    padding: 0.5rem 0.75rem;
}

/* Monster Header - With AC/HP */
.monster-header {
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid #a07868;
}

.monster-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.monster-name-section {
    flex: 1;
    min-width: 0;
}

.monster-name {
    font-family: 'Pirata One', 'Libre Baskerville', Georgia, serif;
    font-size: 1.15rem;
    font-weight: normal;
    color: #8b5545;
    letter-spacing: 0.5px;
    margin: 0;
    line-height: 1.1;
}

.monster-name .monster-count {
    font-size: 0.85rem;
    color: #6a4a3a;
    font-family: 'Metamorphous', serif;
}

.monster-meta {
    font-style: italic;
    font-size: 0.65rem;
    color: #6a4a3a;
    margin-top: 0.1rem;
}

/* AC/HP in header */
.monster-stats-inline {
    display: flex;
    gap: 0.6rem;
    flex-shrink: 0;
}

.stat-box {
    text-align: center;
    min-width: 38px;
}

.stat-box-label {
    font-size: 0.55rem;
    font-weight: bold;
    color: #8b5545;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: block;
}

.stat-box-value {
    font-size: 1rem;
    font-weight: bold;
    color: #6a4a3a;
    line-height: 1;
}

.stat-box-sub {
    font-size: 0.5rem;
    color: #8b5545;
    font-style: italic;
    display: block;
    max-width: 45px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tab Navigation */
.monster-tabs {
    display: flex;
    border-bottom: 1px solid #a07868;
    margin-bottom: 0.4rem;
    gap: 0;
}

.monster-tab {
    flex: 1;
    padding: 0.3rem 0.4rem;
    font-family: 'Metamorphous', serif;
    font-size: 0.7rem;
    color: #8b5545;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: center;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s ease;
}

.monster-tab:hover {
    background: rgba(139, 85, 69, 0.08);
}

.monster-tab.active {
    color: #6a4a3a;
    border-bottom-color: #8b5545;
    background: rgba(139, 85, 69, 0.05);
    font-weight: bold;
}

/* Tab Content Panels */
.monster-tab-content {
    display: none;
    min-height: 120px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.monster-tab-content.active {
    display: block;
}

/* Custom scrollbar for tab content */
.monster-tab-content::-webkit-scrollbar {
    width: 6px;
}

.monster-tab-content::-webkit-scrollbar-track {
    background: rgba(139, 85, 69, 0.1);
    border-radius: 3px;
}

.monster-tab-content::-webkit-scrollbar-thumb {
    background: rgba(139, 85, 69, 0.3);
    border-radius: 3px;
}

.monster-tab-content::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 85, 69, 0.5);
}


/* Traits Tab */
.traits-content {
    font-size: 0.75rem;
    color: #6a4a3a;
    line-height: 1.4;
    text-align: left;
}

.trait-entry {
    margin-bottom: 0.5rem;
}

.trait-name {
    font-weight: bold;
    font-style: italic;
    color: #6a4a3a;
}

/* Actions Tab */
.actions-content {
    font-size: 0.75rem;
    color: #6a4a3a;
    line-height: 1.4;
    text-align: left;
}

.action-entry {
    margin-bottom: 0.5rem;
}

.action-name {
    font-weight: bold;
    font-style: italic;
    color: #6a4a3a;
}

/* Position/Tactical info - Compact Footer */
.monster-footer {
    border-top: 1px solid #a07868;
    padding-top: 0.3rem;
    margin-top: 0.3rem;
    text-align: center;
}

.monster-position {
    font-family: 'Metamorphous', serif;
    font-size: 0.7rem;
    font-style: italic;
    color: #6a4a3a;
}

.monster-tactical-notes {
    font-family: 'Metamorphous', serif;
    font-size: 0.65rem;
    color: #8b5545;
    font-style: italic;
}

/* Challenge Rating in footer */
.monster-cr {
    font-size: 0.65rem;
    color: #8b5545;
    margin-top: 0.2rem;
}

/* Fallback simple enemy card (no stats) */
.enemy-card {
    background: rgba(139, 0, 0, 0.05);
    border: 1px solid rgba(139, 0, 0, 0.15);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    width: 100%;
    max-width: 300px;
}

.enemy-name {
    font-family: 'Pirata One', cursive;
    font-size: 1.1rem;
    color: #8b5545;
    margin-bottom: 0.25rem;
}

.enemy-position {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-faded);
}

.enemy-notes {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    font-style: italic;
    color: var(--ink-brown);
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px dotted rgba(139, 115, 85, 0.2);
}

.combat-environment {
    font-family: 'Metamorphous', serif;
}

.env-paragraph {
    font-size: 0.95rem;
    color: #6a4a3a;
    margin: 0;
    line-height: 1.5;
}

.combat-tactical {
    background: rgba(139, 115, 85, 0.1);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
}

.combat-tactical.hidden {
    display: none;
}

.combat-tactical p {
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-brown);
    margin: 0;
}

.combat-actions {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 10;
}

/* Combat outcome buttons */
.combat-outcome-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.combat-outcome-buttons.hidden {
    display: none;
}


/* Combat outcome form */
.combat-outcome-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: formSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.combat-outcome-form.hidden {
    display: none;
}

@keyframes formSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Buttons fade out when transitioning */
.combat-outcome-buttons.fading-out {
    animation: buttonsFadeOut 0.2s ease forwards;
}

@keyframes buttonsFadeOut {
    to {
        opacity: 0;
        transform: translateY(5px);
    }
}

.outcome-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: 'Metamorphous', serif;
}

.outcome-label {
    font-size: 0.9rem;
    color: var(--ink-faded);
}

.outcome-type {
    font-family: 'Pirata One', cursive;
    font-size: 1.2rem;
    font-weight: bold;
}

.outcome-victory {
    color: #3d5636;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
}

.outcome-defeat {
    color: #722f2f;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
}

.outcome-flight {
    color: #5c4a36;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
}

.outcome-fled {
    color: #8b7355;
}

.combat-outcome-desc {
    font-family: 'Metamorphous', serif;
    font-size: 0.95rem;
    padding: 0.75rem;
    border: 1px solid var(--border-ornate);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.5);
    resize: vertical;
    min-height: 80px;
}

.combat-outcome-desc:focus {
    outline: none;
    border-color: var(--ink-brown);
    box-shadow: 0 0 0 2px rgba(139, 115, 85, 0.2);
}

.combat-outcome-desc::placeholder {
    color: var(--ink-faded);
    opacity: 0.6;
}

.combat-outcome-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ==========================================
   Floating Combat Overlay (replaces modal)
   ========================================== */

.combat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 2rem;
    /* Dark backdrop with blur */
    background: rgba(44, 24, 16, 0.35);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    /* Fade in animation */
    animation: overlayFadeIn 0.4s ease-out forwards;
}

@keyframes overlayFadeIn {
    from {
        background: rgba(44, 24, 16, 0);
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
    }
    to {
        background: rgba(44, 24, 16, 0.35);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
    }
}

.combat-overlay.hidden {
    display: none;
}

/* Floating enemy cards container - centered */
.floating-enemy-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 2rem;
    max-width: 100%;
    pointer-events: auto;
}

/* Floating enemy card - parchment note style */
.floating-enemy-card {
    /* Parchment texture with folded corner */
    background: url('/static/images/parchment-bg.png') center center / 100% 100% no-repeat;
    /* Asymmetric padding to avoid folded corner (bottom-left) */
    padding: 1.75rem 2rem 3rem 2.5rem;
    width: 680px;
    max-width: 95vw;
    font-family: 'Metamorphous', serif;
    animation: cardAppear 0.5s ease-out forwards;
    display: flex;
    flex-direction: row;
    gap: 1.75rem;
    position: relative;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Left side - image and name (prominent illustration) */
.floating-card-left {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Monster image section - large, blends with parchment via edge fade */
.monster-image-section {
    position: relative;
    width: 260px;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.monster-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    /* Fade all edges into parchment - works for any aspect ratio */
    -webkit-mask-image:
        linear-gradient(to right, transparent, black 15%, black 85%, transparent),
        linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
    -webkit-mask-composite: source-in;
    mask-image:
        linear-gradient(to right, transparent, black 15%, black 85%, transparent),
        linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
    mask-composite: intersect;
}

.monster-image-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    color: var(--ink-faded);
    opacity: 0.4;
}

/* Name section below image */
.floating-card-name-section {
    padding: 0.75rem 0.5rem;
    text-align: center;
}

.floating-card-name {
    font-family: 'Pirata One', cursive;
    font-size: 1.6rem;
    color: var(--ink-brown);
    line-height: 1.1;
    margin: 0;
}

.floating-card-name .monster-count {
    font-family: 'Metamorphous', serif;
    font-size: 1rem;
    color: var(--ink-faded);
}

.floating-card-meta {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--ink-faded);
    margin-top: 0.3rem;
}

/* Right side - stats and content */
.floating-card-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Subtle left border like a margin line */
    border-left: 1px dashed rgba(139, 115, 85, 0.25);
    padding-left: 1.5rem;
}

/* Stats header - compact stat strip */
.floating-card-stats-header {
    padding-bottom: 0.6rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px dashed rgba(139, 115, 85, 0.3);
}

/* Primary stats row: AC | HP | Speed */
.floating-stats-row {
    display: flex;
    justify-content: flex-start;
    gap: 1.5rem;
    margin-bottom: 0.4rem;
}

.floating-stat-box {
    text-align: center;
}

.floating-stat-label {
    font-size: 0.65rem;
    font-weight: normal;
    color: var(--ink-faded);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 0.1rem;
}

.floating-stat-value {
    font-family: 'Pirata One', cursive;
    font-size: 1.5rem;
    color: var(--ink-brown);
    line-height: 1;
}

.floating-stat-sub {
    font-size: 0.65rem;
    color: var(--ink-faded);
    font-style: italic;
    display: block;
    margin-top: 0.1rem;
}

/* Reactive row: PP | Senses | Saves */
.floating-reactive-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    font-size: 0.72rem;
    color: var(--ink-faded);
    line-height: 1.4;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px dotted rgba(139, 115, 85, 0.2);
}

.reactive-item {
    white-space: nowrap;
}

.reactive-item .stat-label {
    font-weight: bold;
    color: var(--ink-brown);
    margin-right: 0.2rem;
}

.reactive-item .save-entry {
    font-family: 'Courier New', monospace;
    font-size: 0.68rem;
    color: var(--ink-faded);
    margin-right: 0.3rem;
}

/* Highlight proficient saves */
.reactive-item .save-entry.save-proficient {
    color: var(--ink-brown);
    font-weight: bold;
}

/* Content area - traits and actions */
.floating-card-content {
    flex: 1;
    overflow-y: scroll;
    max-height: 280px;
    padding-right: 1rem; /* Space for scrollbar so it doesn't cover text */
    margin-right: -0.25rem;
}

/* Parchment scroll-style scrollbar - always visible */
.floating-card-content::-webkit-scrollbar {
    -webkit-appearance: none; /* Disable macOS overlay scrollbar */
    width: 14px;
    background: transparent;
}

.floating-card-content::-webkit-scrollbar-track {
    /* Parchment scroll track - light tan with subtle texture feel */
    background: linear-gradient(
        to right,
        rgba(180, 155, 120, 0.15) 0%,
        rgba(160, 135, 100, 0.25) 30%,
        rgba(160, 135, 100, 0.25) 70%,
        rgba(180, 155, 120, 0.15) 100%
    );
    border-radius: 7px;
    border: 1px solid rgba(139, 115, 85, 0.2);
}

.floating-card-content::-webkit-scrollbar-thumb {
    /* Scroll handle - darker rolled parchment look */
    background: linear-gradient(
        to right,
        rgba(120, 95, 65, 0.5) 0%,
        rgba(139, 115, 85, 0.7) 20%,
        rgba(150, 125, 95, 0.6) 50%,
        rgba(139, 115, 85, 0.7) 80%,
        rgba(120, 95, 65, 0.5) 100%
    );
    border-radius: 7px;
    border: 1px solid rgba(100, 80, 55, 0.3);
    /* Inner shadow for rolled paper effect */
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2),
                inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.floating-card-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(
        to right,
        rgba(100, 80, 55, 0.6) 0%,
        rgba(120, 95, 70, 0.8) 20%,
        rgba(130, 105, 80, 0.7) 50%,
        rgba(120, 95, 70, 0.8) 80%,
        rgba(100, 80, 55, 0.6) 100%
    );
}

/* Firefox scrollbar */
.floating-card-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 115, 85, 0.6) rgba(160, 135, 100, 0.2);
}

/* Section headers - like chapter headings */
.floating-section-title {
    font-family: 'Pirata One', cursive;
    font-size: 1.1rem;
    color: var(--ink-brown);
    margin: 0 0 0.5rem 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid rgba(139, 115, 85, 0.2);
}

.floating-section-title:not(:first-child) {
    margin-top: 1rem;
}

/* Traits and actions entries - like handwritten notes */
.floating-trait-entry,
.floating-action-entry {
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    color: var(--ink-brown);
    line-height: 1.5;
    text-align: justify;
}

.floating-trait-name,
.floating-action-name {
    font-weight: bold;
    font-style: italic;
    color: var(--ink-black);
}

.floating-no-content {
    font-style: italic;
    color: var(--ink-faded);
    font-size: 0.9rem;
}

/* SRD HTML content styling */
.floating-traits-html,
.floating-actions-html {
    font-size: 0.9rem;
    color: var(--ink-brown);
    line-height: 1.5;
}

.floating-traits-html p,
.floating-actions-html p {
    margin: 0 0 0.6rem 0;
    text-align: justify;
    /* Hanging indent: negative text-indent pulls first line left, padding compensates */
    text-indent: -1rem;
    padding-left: 1rem;
}

.floating-traits-html p:last-child,
.floating-actions-html p:last-child {
    margin-bottom: 0;
}

/* Action/trait names are bold italic */
.floating-traits-html em strong,
.floating-actions-html em strong,
.floating-traits-html strong em,
.floating-actions-html strong em {
    font-style: italic;
    font-weight: bold;
    color: var(--ink-black);
}

/* Italic labels like "Melee Weapon Attack:" and "Hit:" */
.floating-traits-html em,
.floating-actions-html em {
    font-style: italic;
}

/* Footer with narrative setup (separated from mechanics) */
.floating-card-footer {
    margin-top: auto;
    padding-top: 0.6rem;
    border-top: 1px dashed rgba(139, 115, 85, 0.25);
}

.floating-card-footer::before {
    content: "Setup";
    display: block;
    font-size: 0.6rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ink-faded);
    margin-bottom: 0.2rem;
}

.floating-card-position {
    font-size: 0.82rem;
    font-style: italic;
    color: var(--ink-brown);
    line-height: 1.4;
}

/* Responsive - stack vertically on narrow screens */
@media (max-width: 680px) {
    .floating-enemy-card {
        flex-direction: column;
        width: 380px;
        padding: 1.5rem 1.5rem 2.5rem 1.5rem;
        gap: 0.75rem;
        align-items: center;
    }

    .floating-card-left {
        width: 220px;
    }

    .monster-image-section {
        width: 220px;
        height: 250px;
    }

    .floating-card-right {
        border-left: none;
        border-top: 1px dashed rgba(139, 115, 85, 0.25);
        padding-left: 0;
        padding-top: 1rem;
        width: 100%;
    }

    .floating-card-content {
        max-height: 180px;
        padding-right: 0.75rem;
    }

    .floating-card-content::-webkit-scrollbar {
        width: 10px;
    }
}

/* Floating action buttons at bottom */
.combat-floating-actions {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
    z-index: 1001;
    padding: 1.25rem 2rem;
}

/* Reuse existing outcome button styles */
.combat-floating-actions .combat-outcome-buttons {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
}

.combat-floating-actions .combat-outcome-form {
    max-width: 450px;
    min-width: 380px;
    background: linear-gradient(135deg,
        #f7f3e8 0%,
        #f3efe2 50%,
        #efe9db 100%);
    border: 3px solid #d4c4a8;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow:
        0 8px 32px rgba(44, 24, 16, 0.35),
        0 2px 8px rgba(44, 24, 16, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
}

/* Decorative inner border */
.combat-floating-actions .combat-outcome-form::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(180, 165, 140, 0.4);
    border-radius: 4px;
    pointer-events: none;
}

.combat-floating-actions .outcome-selected {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(180, 165, 140, 0.5);
}

.combat-floating-actions .outcome-label {
    color: #5c4a36;
}

.combat-floating-actions .outcome-type {
    font-size: 1.4rem;
}

.combat-floating-actions .combat-outcome-desc {
    width: 100%;
    max-width: 100%;
    background: rgba(255, 253, 245, 0.8);
    border: 1px solid #d4c4a8;
    border-radius: 4px;
    padding: 0.875rem;
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 1rem;
    color: #2c1810;
    resize: vertical;
    min-height: 80px;
}

.combat-floating-actions .combat-outcome-desc::placeholder {
    color: #8b7355;
    font-style: italic;
}

.combat-floating-actions .combat-outcome-desc:focus {
    outline: none;
    border-color: #8b6914;
    box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.15);
}

.combat-floating-actions .combat-outcome-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.combat-floating-actions .combat-outcome-actions .btn {
    min-width: 140px;
}

/* Combat outcome buttons - distinct colors with proper states */
.combat-floating-actions .btn-victory,
.combat-floating-actions .btn-defeat,
.combat-floating-actions .btn-fled {
    min-width: 120px;
    padding: 0.875rem 1.75rem;
    border: 2px solid transparent;
    transition: all 0.15s ease, transform 0.1s ease;
    position: relative;
    overflow: hidden;
}

/* Victory button - forest green tones */
.combat-floating-actions .btn-victory {
    background: linear-gradient(135deg, #4a6741 0%, #3d5636 50%, #2d4228 100%);
    border-color: #5a7a50;
    box-shadow: 0 3px 8px rgba(45, 66, 40, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.combat-floating-actions .btn-victory:hover {
    background: linear-gradient(135deg, #5a7a50 0%, #4a6741 50%, #3d5636 100%);
    border-color: #6a8a60;
    box-shadow: 0 5px 15px rgba(45, 66, 40, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    filter: none;
}

.combat-floating-actions .btn-victory:active {
    background: linear-gradient(135deg, #2d4228 0%, #3d5636 50%, #4a6741 100%);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(45, 66, 40, 0.3);
    transform: translateY(1px) scale(0.98);
}

/* Defeat button - deep crimson tones */
.combat-floating-actions .btn-defeat {
    background: linear-gradient(135deg, #8b3a3a 0%, #722f2f 50%, #5a2424 100%);
    border-color: #9b4a4a;
    box-shadow: 0 3px 8px rgba(90, 36, 36, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.combat-floating-actions .btn-defeat:hover {
    background: linear-gradient(135deg, #9b4a4a 0%, #8b3a3a 50%, #722f2f 100%);
    border-color: #ab5a5a;
    box-shadow: 0 5px 15px rgba(90, 36, 36, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    filter: none;
}

.combat-floating-actions .btn-defeat:active {
    background: linear-gradient(135deg, #5a2424 0%, #722f2f 50%, #8b3a3a 100%);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(90, 36, 36, 0.3);
    transform: translateY(1px) scale(0.98);
}

/* Flight button - warm brown/tan tones */
.combat-floating-actions .btn-fled {
    background: linear-gradient(135deg, #8b7355 0%, #7a6348 50%, #5c4a36 100%);
    border-color: #9b8365;
    box-shadow: 0 3px 8px rgba(92, 74, 54, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.combat-floating-actions .btn-fled:hover {
    background: linear-gradient(135deg, #9b8365 0%, #8b7355 50%, #7a6348 100%);
    border-color: #ab9375;
    box-shadow: 0 5px 15px rgba(92, 74, 54, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    filter: none;
}

.combat-floating-actions .btn-fled:active {
    background: linear-gradient(135deg, #5c4a36 0%, #7a6348 50%, #8b7355 100%);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(92, 74, 54, 0.3);
    transform: translateY(1px) scale(0.98);
}

/* Selected state - pulse before transitioning */
.combat-floating-actions .btn-victory.selected,
.combat-floating-actions .btn-defeat.selected,
.combat-floating-actions .btn-fled.selected {
    animation: buttonSelected 0.3s ease forwards;
}

@keyframes buttonSelected {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    }
    100% {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Responsive adjustments for floating cards */
@media (max-width: 768px) {
    .combat-overlay {
        padding: 1rem;
        gap: 1rem;
    }

    .combat-floating-actions {
        bottom: 1rem;
        padding: 0.75rem 1rem;
    }
}

/* Loading */
.loading {
    text-align: center;
    color: var(--ink-faded);
    font-style: italic;
    padding: 2rem;
}

/* Loading Indicator (AI thinking) */
.loading-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 0;
}

.loading-indicator.hidden {
    display: none;
}

.loading-dice {
    width: 300px;
    height: 300px;
    opacity: 0.9;
    animation: diceLoadingPulse 2s ease-in-out infinite;
}

@keyframes diceLoadingPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.85;
    }
    50% {
        transform: scale(1.03);
        opacity: 0.95;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .book-page {
        padding: var(--page-padding-mobile);
    }
}

/* ==========================================
   Settings Controls (Bottom Right)
   ========================================== */

.settings-controls {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.settings-controls:hover {
    opacity: 1;
}

.settings-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-ornate);
    background: linear-gradient(135deg, #f5e6c8 0%, #e8dcc8 100%);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 6px var(--shadow-soft);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.settings-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 10px var(--shadow-deep);
}

.settings-btn:active {
    transform: scale(0.95);
}

.settings-btn .settings-icon {
    width: 18px;
    height: 18px;
    stroke: var(--ink-brown);
    transition: stroke 0.15s ease;
}

.settings-btn .settings-icon.hidden {
    display: none;
}

/* Narration active state */
.settings-btn.narration-active {
    background: linear-gradient(135deg, #d4e8d4 0%, #b8d4b8 100%);
    border-color: #5a8a5a;
}

.settings-btn.narration-active .settings-icon {
    stroke: #2d5a2d;
}

/* Narration playing animation */
.settings-btn.narration-playing .sound-waves {
    animation: sound-pulse 1s ease-in-out infinite;
}

@keyframes sound-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Dark mode button states */
:root.dark-mode .settings-btn {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    border-color: #4a4a4a;
}

:root.dark-mode .settings-btn .settings-icon {
    stroke: #d4c4a8;
}

:root.dark-mode .settings-btn:hover {
    background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
}

:root.dark-mode .settings-btn.narration-active {
    background: linear-gradient(135deg, #2d4a2d 0%, #1a3a1a 100%);
    border-color: #4a7a4a;
}

:root.dark-mode .settings-btn.narration-active .settings-icon {
    stroke: #8ac48a;
}

/* Show correct icons based on dark mode state */
:root.dark-mode .sun-icon {
    display: block;
}

:root.dark-mode .moon-icon {
    display: none;
}

:root:not(.dark-mode) .sun-icon {
    display: none;
}

:root:not(.dark-mode) .moon-icon {
    display: block;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .settings-controls {
        bottom: 1rem;
        right: 1rem;
    }

    .settings-btn {
        width: 32px;
        height: 32px;
    }

    .settings-btn .settings-icon {
        width: 16px;
        height: 16px;
    }
}

/* ==========================================
   Toast Notifications
   ========================================== */

.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: linear-gradient(135deg, #f5e6c8 0%, #e8dcc8 100%);
    border: 2px solid var(--border-ornate);
    border-radius: 4px;
    padding: 0.75rem 1.25rem;
    box-shadow: 0 4px 12px rgba(44, 24, 16, 0.3);
    font-family: 'Metamorphous', serif;
    font-size: 0.9rem;
    color: var(--ink-brown);
    max-width: 400px;
    text-align: center;
    pointer-events: auto;

    /* Animation */
    opacity: 0;
    transform: translateY(20px);
    animation: toast-in 0.3s ease forwards;
}

.toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.toast-icon {
    margin-right: 0.5rem;
}

.toast-command {
    font-family: 'Pirata One', cursive;
    color: var(--ink-red);
    font-size: 1rem;
}

/* ==========================================
   Help Modal (Adventurer's Handbook)
   ========================================== */

.help-modal-content {
    width: 650px;
    max-width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 2rem 1.5rem 2rem;
}

.help-header {
    text-align: center;
    margin-bottom: 0.5rem;
}

.help-header h3 {
    font-family: 'Pirata One', cursive;
    font-size: 2rem;
    color: var(--ink-brown);
    margin: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.help-divider {
    width: 80%;
    max-width: 300px;
    height: auto;
    margin: 0.25rem auto 0.5rem auto;
    opacity: 0.75;
    display: block;
}

/* Tab Navigation */
.help-tabs {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.25rem;
    background: rgba(139, 115, 85, 0.08);
    border-radius: 6px;
}

.help-tab {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    background: transparent;
    border: none;
    color: var(--ink-faded);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.help-tab:hover {
    color: var(--ink-brown);
    background: rgba(139, 115, 85, 0.1);
}

.help-tab.active {
    background: rgba(255, 255, 255, 0.7);
    color: var(--ink-brown);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Tab Content */
.help-tab-content {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.help-panel {
    display: none;
}

.help-panel.active {
    display: block;
}

.help-intro {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-faded);
    font-style: italic;
    margin: 0 0 1rem 0;
    text-align: center;
}

.help-intro .cmd {
    font-style: normal;
    background: rgba(139, 115, 85, 0.15);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    color: var(--ink-brown);
    font-weight: 600;
}

/* Skills Tab - Column Layout */
.skills-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.skill-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.skill-group-box {
    background: rgba(139, 115, 85, 0.06);
    border: 1px solid rgba(139, 115, 85, 0.15);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.skill-ability {
    font-family: 'Pirata One', cursive;
    font-size: 0.95rem;
    color: var(--ink-red);
    margin-bottom: 0.2rem;
}

.skill-cmd {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-brown);
    background: rgba(255, 255, 255, 0.5);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    display: inline-block;
    width: fit-content;
}

.skill-cmd-note {
    font-family: 'Metamorphous', serif;
    font-size: 0.75rem;
    color: var(--ink-faded);
    font-style: italic;
}

.help-note {
    margin-top: 1rem;
    padding: 0.6rem 0.75rem;
    background: rgba(139, 115, 85, 0.08);
    border-radius: 4px;
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-brown);
    text-align: center;
}

.help-note .cmd {
    background: rgba(139, 115, 85, 0.15);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-weight: 600;
}

.help-note-small {
    margin-top: 0.5rem;
    font-family: 'Metamorphous', serif;
    font-size: 0.75rem;
    color: var(--ink-light);
    font-style: italic;
}

/* Quick Modes Tab */
.quickmode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.quickmode-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.quickmode-card.oracle-card {
    background: linear-gradient(135deg, rgba(100, 80, 140, 0.1) 0%, rgba(80, 60, 120, 0.15) 100%);
    border: 1px solid rgba(100, 80, 140, 0.25);
}

.quickmode-card.combat-card {
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.08) 0%, rgba(139, 0, 0, 0.12) 100%);
    border: 1px solid rgba(139, 0, 0, 0.2);
}

.quickmode-key {
    font-family: 'Pirata One', cursive;
    font-size: 2rem;
    color: var(--ink-brown);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.quickmode-name {
    font-family: 'Pirata One', cursive;
    font-size: 1.1rem;
    color: var(--ink-black);
    margin-bottom: 0.25rem;
}

.quickmode-desc {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
}

.quickmode-skills {
    background: rgba(139, 115, 85, 0.06);
    border: 1px solid rgba(139, 115, 85, 0.15);
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.quickmode-skills-title {
    font-family: 'Pirata One', cursive;
    font-size: 0.95rem;
    color: var(--ink-brown);
    margin: 0 0 0.6rem 0;
    text-align: center;
}

.quickmode-skill-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem 0.75rem;
}

.qm-skill {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-brown);
}

.qm-key {
    display: inline-block;
    width: 1.4rem;
    height: 1.4rem;
    line-height: 1.4rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(139, 115, 85, 0.3);
    border-radius: 3px;
    font-family: 'Pirata One', cursive;
    font-size: 0.9rem;
    color: var(--ink-black);
    margin-right: 0.3rem;
}

.help-tip {
    margin-top: 1rem;
    padding: 0.5rem 0.75rem;
    background: rgba(139, 115, 85, 0.08);
    border-left: 3px solid var(--border-ornate);
    border-radius: 0 4px 4px 0;
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
}

.help-tip .key {
    background: rgba(139, 115, 85, 0.15);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    color: var(--ink-brown);
}

/* Commands Tab */
.command-category {
    margin-bottom: 1rem;
}

.command-category:last-child {
    margin-bottom: 0;
}

.command-category-title {
    font-family: 'Pirata One', cursive;
    font-size: 1rem;
    color: var(--ink-red);
    margin: 0 0 0.5rem 0;
    padding-bottom: 0.25rem;
    border-bottom: 1px dashed rgba(139, 115, 85, 0.3);
}

.command-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.cmd-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.25rem 0;
}

.cmd {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    background: rgba(139, 115, 85, 0.12);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    color: var(--ink-black);
    white-space: nowrap;
    min-width: 140px;
}

.cmd-desc {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-faded);
}

/* Dungeon Tab - Navigation Keys */
.nav-keys {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem;
    background: rgba(139, 115, 85, 0.06);
    border-radius: 6px;
}

.nav-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-row-group {
    display: flex;
    gap: 2rem;
}

.nav-row-vertical {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed rgba(139, 115, 85, 0.25);
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
}

.nav-key {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    line-height: 2rem;
    text-align: center;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.8) 0%, rgba(245, 240, 225, 0.9) 100%);
    border: 1px solid rgba(139, 115, 85, 0.35);
    border-radius: 4px;
    font-family: 'Pirata One', cursive;
    font-size: 1rem;
    color: var(--ink-brown);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.nav-label {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
    min-width: 3rem;
}

/* Oracle Tab */
.oracle-section {
    margin-bottom: 1rem;
}

.oracle-section:last-child {
    margin-bottom: 0;
}

.oracle-title {
    font-family: 'Pirata One', cursive;
    font-size: 1rem;
    color: var(--ink-brown);
    margin: 0 0 0.4rem 0;
}

.oracle-text {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
    color: var(--ink-brown);
    line-height: 1.5;
    margin: 0 0 0.5rem 0;
}

.oracle-text .cmd {
    background: rgba(139, 115, 85, 0.15);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    color: var(--ink-black);
    font-weight: 600;
}

.oracle-text-small {
    font-family: 'Metamorphous', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
    font-style: italic;
    margin: 0.5rem 0 0 0;
}

.oracle-examples {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-left: 1rem;
}

.oracle-example {
    font-family: 'Metamorphous', serif;
    font-size: 0.85rem;
}

.oracle-q {
    background: rgba(100, 80, 140, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: var(--ink-brown);
}

.discover-meaning-example {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(139, 115, 85, 0.08);
    border-radius: 6px;
    margin: 0.5rem 0;
}

.dm-action, .dm-desc {
    font-family: 'Pirata One', cursive;
    font-size: 1.2rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
}

.dm-action {
    background: rgba(139, 0, 0, 0.1);
    color: var(--ink-red);
}

.dm-desc {
    background: rgba(40, 80, 40, 0.1);
    color: #2d5a27;
}

.oracle-outcomes {
    background: rgba(139, 115, 85, 0.06);
    border-radius: 6px;
    padding: 0.75rem;
    margin-top: 1rem;
}

.oracle-outcomes .oracle-title {
    text-align: center;
    margin-bottom: 0.6rem;
}

.outcome-chips {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.outcome-chip {
    font-family: 'Metamorphous', serif;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-weight: 600;
}

.outcome-chip.exceptional-yes {
    background: rgba(40, 120, 40, 0.15);
    color: #1a5a1a;
    border: 1px solid rgba(40, 120, 40, 0.3);
}

.outcome-chip.yes {
    background: rgba(80, 140, 80, 0.12);
    color: #2d6a2d;
    border: 1px solid rgba(80, 140, 80, 0.25);
}

.outcome-chip.no {
    background: rgba(180, 80, 80, 0.1);
    color: #8b4040;
    border: 1px solid rgba(180, 80, 80, 0.2);
}

.outcome-chip.exceptional-no {
    background: rgba(139, 0, 0, 0.12);
    color: #8b0000;
    border: 1px solid rgba(139, 0, 0, 0.25);
}

/* Help Modal Responsive */
@media (max-width: 600px) {
    .help-modal-content {
        padding: 1rem 1.25rem;
    }

    .help-tabs {
        flex-wrap: wrap;
    }

    .help-tab {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    .skills-columns {
        grid-template-columns: 1fr;
    }

    .quickmode-grid {
        grid-template-columns: 1fr;
    }

    .quickmode-skill-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
