@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

:root {
    --font-main: 'Inter', sans-serif;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 8px;
}

/* =========================================
   THEME 1: DM (Arcane Scholar - Professional)
   ========================================= */
body.dm-theme {
    --bg-app: #f3f4f6;          /* Cool Grey */
    --bg-panel: #ffffff;        /* White */
    --text-main: #1f2937;       /* Dark Slate */
    --text-muted: #6b7280;      /* Muted Grey */
    --primary: #4f46e5;         /* Indigo */
    --primary-light: #eef2ff;   /* Light Indigo Wash */
    --border: #e5e7eb;          /* Light Grey Border */
    --sidebar-bg: #111827;      /* Dark Sidebar for contrast */
    --sidebar-text: #d1d5db;
}

/* =========================================
   THEME 2: PLAYER (Adventurer's Journal)
   ========================================= */
body.player-theme {
    --bg-app: #fdfbf7;          /* Warm Paper */
    --bg-panel: #ffffff;        /* White */
    --text-main: #2d2420;       /* Dark Brown */
    --text-muted: #796b65;      /* Warm Grey */
    --primary: #b45309;         /* Leather/Rust */
    --primary-light: #fff7ed;   /* Light Orange Wash */
    --border: #e7e5e4;          /* Warm Grey Border */
    --sidebar-bg: #451a03;      /* Deep Wood */
    --sidebar-text: #e7e5e4;
}

/* =========================================
   GLOBAL RESET & STRUCTURE
   ========================================= */
* { box-sizing: border-box; }

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-main);
    margin: 0;
    display: flex;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; transition: 0.2s; }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* =========================================
   SIDEBAR LAYOUT (For DM)
   ========================================= */
.app-layout {
    display: flex;
    width: 100%;
}

.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: bold;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    font-size: 0.95rem;
}

.nav-link i { width: 25px; text-align: center; margin-right: 10px; }
.nav-link:hover, .nav-link.active {
    background-color: rgba(255,255,255,0.1);
    color: #fff;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100vh;
}

.top-bar {
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.content-area {
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* =========================================
   COMPONENTS
   ========================================= */

/* Buttons */
.btn {
    display: inline-flex; align-items: center;
    padding: 0.5rem 1rem;
    background-color: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
}
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn:hover { opacity: 0.9; }

/* Cards (Grid) */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    background-color: var(--primary-light);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    margin-right: 1rem;
}

.stat-info h3 { font-size: 1rem; color: var(--text-main); margin-bottom: 0.25rem; }
.stat-info p { font-size: 0.875rem; color: var(--text-muted); margin: 0; }

/* Tables */
.data-table-container {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; text-align: left; }
thead { background-color: #f9fafb; border-bottom: 1px solid var(--border); }
th { padding: 1rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; }
td { padding: 1rem; border-bottom: 1px solid var(--border); color: var(--text-main); font-size: 0.9rem; }
tr:last-child td { border-bottom: none; }
tr:hover { background-color: #f9fafb; }

/* =========================================
   D&D 5E BOOK STYLING (PHB/MM Look)
   ========================================= */
.phb-style {
    font-family: 'Book Antiqua', 'Palatino Linotype', Palatino, serif;
    color: #000;
    line-height: 1.4;
    font-size: 14px;
}

.phb-style h3 {
    font-family: 'MrJeeves', 'Cinzel', serif; /* Fallback to serif if custom fonts not loaded */
    color: #58180D; /* PHB Red */
    border-bottom: 2px solid #58180D;
    font-size: 1.5rem;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.phb-style h4 {
    font-weight: bold;
    font-variant: small-caps;
    margin: 0.5rem 0 0;
    color: #000;
}

/* Monster Stat Block Style (Simplified) */
.stat-block {
    background-color: #fdf1dc; /* Parchment */
    border: 1px solid #dcdcdc;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    padding: 15px;
    font-family: 'Scala Sans', sans-serif; /* Or generic sans */
}

.stat-block hr {
    border: 0;
    height: 2px;
    background-image: linear-gradient(to right, #900, #900 70%, transparent);
    margin: 8px 0;
}

.stat-block .red-text { color: #58180D; }

/* Filter Bar Styling */
.filter-bar {
    background: #fff;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar select, .filter-bar input {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-main);
}

/* ========================
   GALLERY MODULE
   ======================== */
.gallery-grid {
    display: grid;
    /* Smaller thumbnails: 150px min-width */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.gallery-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.gallery-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.img-thumbnail-container {
    height: 120px; /* Reduced height for thumbnail look */
    width: 100%;
    background-color: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Checkerboard pattern */
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    cursor: zoom-in; /* Indicates clickability */
}

.gallery-card img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.gallery-meta {
    padding: 8px;
    border-top: 1px solid var(--border);
}

.gallery-title {
    font-weight: 600;
    font-size: 0.8rem;
    margin-bottom: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.gallery-desc {
    font-size: 0.7rem; color: #6b7280;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.delete-btn {
    position: absolute; top: 4px; right: 4px;
    background: rgba(255, 255, 255, 0.9);
    color: #ef4444; border: 1px solid #ef4444;
    border-radius: 4px; padding: 2px 6px;
    cursor: pointer; font-size: 0.7rem;
    opacity: 0; transition: opacity 0.2s;
    z-index: 10;
}
.gallery-card:hover .delete-btn { opacity: 1; }

/* ========================
   LIGHTBOX (Full View)
   ======================== */
#lightbox {
    position: fixed;
    z-index: 9999;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

#lightbox.active { display: flex; }

#lightbox img {
    max-width: 90%;
    max-height: 85%;
    border: 2px solid #fff;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#lightbox-caption {
    color: #fff;
    margin-top: 15px;
    font-family: var(--font-main);
    font-size: 1.1rem;
}

#lightbox-close {
    position: absolute;
    top: 20px; right: 30px;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
}

/* ========================
   ASSET PICKER (Form)
   ======================== */
.asset-picker-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.asset-preview {
    width: 150px;
    height: 150px;
    border: 1px solid var(--border);
    background-color: #f3f4f6;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    /* Checkerboard for transparency */
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 20px 20px;
}

.asset-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.asset-preview.empty::after {
    content: 'Select Image';
    color: #9ca3af;
    font-size: 0.8rem;
}

/* ========================
   PICKER MODAL
   ======================== */
#picker-modal {
    position: fixed;
    z-index: 10000;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
}

#picker-modal.active { display: flex; }

.picker-content {
    background: #fff;
    width: 80%;
    max-width: 900px;
    height: 80%;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 25px rgba(0,0,0,0.5);
}

.picker-header {
    padding: 15px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fff;
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.picker-item {
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 5px;
    text-align: center;
    transition: 0.2s;
}

.picker-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.picker-item img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.picker-item p {
    font-size: 0.7rem;
    margin: 5px 0 0 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Adventure View */
.adv-layout { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 60px); overflow: hidden; }

/* The Key (Sidebar) */
.adv-sidebar { background: #fff; border-right: 1px solid var(--border); overflow-y: auto; padding: 15px; }
.adv-key-item { 
    display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 4px; 
    cursor: pointer; margin-bottom: 5px; font-size: 0.9rem;
}
.adv-key-item:hover { background: var(--primary-light); }
.adv-key-item.active { background: var(--primary); color: #fff; }
.adv-key-item.completed { opacity: 1; text-decoration: none; color: #5D0EC0; }

/* Content Blocks */
.adv-block { margin-bottom: 20px; position: relative; }

/* Boxed Text (Read Aloud) */
.block-boxed {
    background: #fdf1dc; border-left: 5px solid #d97706; padding: 20px;
    font-family: 'Georgia', serif; box-shadow: 2px 2px 5px rgba(0,0,0,0.05);
}
.block-boxed::before { display: block; font-size: 0.7rem; font-style: normal; font-weight: bold; color: #d97706; margin-bottom: 5px; }

/* DM Note */
.block-note {
    background: #eef2ff; border-left: 5px solid #4f46e5; padding: 15px;
    font-size: 0.95rem; border-radius: 0 4px 4px 0;
}
.block-note::before { content: 'DM NOTE'; display: block; font-size: 0.7rem; font-weight: bold; color: #4f46e5; margin-bottom: 5px; }

/* Illustrations */
.block-image { text-align: center; background: #000; padding: 10px; border-radius: 8px; }
.block-image img { max-width: 100%; max-height: 400px; border: 1px solid #444; }