:root {
    --bg: #121214; --surface: #18181b; --surface-hover: #27272a; 
    --text: #f4f4f5; --text-muted: #a1a1aa; 
    --accent: #38bdf8; 
    --danger: #ef4444; --border: #3f3f46;
}

body { 
    margin: 0; font-family: system-ui, -apple-system, sans-serif; 
    background: var(--bg); color: var(--text); 
    font-size: 18px; 
    -webkit-tap-highlight-color: transparent; 
    user-select: none; -webkit-user-select: none; 
}

#app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.content { flex: 1; overflow-y: auto; padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }

/* Bottom Nav */
.bottom-nav { 
    background: var(--surface); border-top: 2px solid var(--border); 
    display: flex; padding-bottom: env(safe-area-inset-bottom); z-index: 100; 
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; 
}
.bottom-nav::-webkit-scrollbar { display: none; }
.nav-btn { 
    flex: 1; min-width: 0; padding: 1rem 0.5rem; 
    background: none; border: none; color: var(--text-muted); font-size: 12px; font-weight: 600; 
    display: flex; flex-direction: column; align-items: center; gap: 0.3rem; 
    cursor: pointer; text-transform: uppercase; transition: color 0.15s ease-out;
}

.override-input::placeholder {
    color: currentColor;
    opacity: 1;
}
.override-input:focus::placeholder {
    opacity: 0.3;
}

.nav-btn.active { color: var(--accent); }
.nav-btn .material-icons { font-size: 28px; }

/* Global Inputs */
input, select, textarea { user-select: auto; -webkit-user-select: auto; font-family: inherit; box-sizing: border-box; outline: none; margin: 0; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

.box-input {
    width: 100%; padding: 0.75rem; border: 2px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 18px; transition: border-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.box-input:focus { border-color: var(--accent); }
textarea.box-input { resize: none; overflow: hidden; min-height: 140px; }

.line-input {
    width: 100%; padding: 0.5rem 0.2rem; border: none; border-bottom: 2px solid var(--border); border-radius: 0;
    background: transparent; color: var(--text); font-size: 18px; transition: border-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.line-input:focus { border-bottom-color: var(--accent); }

/* Buttons */
.btn { box-sizing: border-box; width: 100%; padding: 0.75rem; border: none !important; outline: none !important; border-radius: 8px; font-size: 18px; font-weight: bold; cursor: pointer; text-align: center; background: var(--surface-hover); color: var(--text); display: flex; align-items: center; justify-content: center; gap: 0.5rem; transition: transform 0.1s, filter 0.15s;}
.btn:active { transform: scale(0.97); filter: brightness(1.2); }
.btn-primary { background: var(--accent); color: #000; cursor: pointer; }
.btn-danger { background: var(--danger); color: #fff; cursor: pointer; }
.btn-disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.btn-disabled:active { transform: scale(1); filter: none; }

/* List Item Controls */
.drag-handle { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; color: var(--border); cursor: grab; transition: color 0.15s; }
.drag-handle:hover { color: var(--text-muted); }
.drag-handle:active { cursor: grabbing; }

.delete-btn { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; color: var(--text-muted); border: none; cursor: pointer; transition: color 0.15s; margin-left: 0.2rem; }
.delete-btn:hover { color: var(--danger); }

/* Layouts */
.card { background: var(--surface); padding: 1rem; border-radius: 12px; margin-bottom: 1rem; }
h1, h2, h3 { margin: 0 0 0.5rem 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }

/* Specific Widgets */
.stat-box { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; padding: 0.5rem; text-align: center; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.stat-box .line-input { text-align: center; font-size: 1.4rem; font-weight: bold; border-bottom: 2px solid transparent; padding: 0; margin: 0; }
.stat-box .line-input:focus { border-bottom-color: var(--accent); }

.slot-circle { width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 2px solid var(--accent); display: flex; align-items: center; justify-content: center; cursor: pointer; margin-right: 0.25rem; transition: background 0.15s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s; color: var(--accent); font-weight: bold; font-size: 12px;}
.slot-circle.filled { background: var(--accent); color: var(--bg); }

.skills-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.5rem; }
.skill-card { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; padding: 0.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem; }
.skill-card-header { font-size: 13px; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; text-transform: uppercase; letter-spacing: 0.5px;}
.skill-card-value { font-size: 1.6rem; font-weight: bold; }
.skill-card-controls { display: flex; gap: 0.8rem; }
.skill-card-controls .slot-circle { width: 1.2rem; height: 1.2rem; border-width: 2px; margin: 0; font-size: 10px; }

/* Modals & Toasts */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1000; display: flex; flex-direction: column; justify-content: flex-end; }
.modal-content { background: var(--surface); padding: 1.5rem; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; max-height: 85vh; overflow-y: auto; animation: slideUp 0.2s cubic-bezier(0.1, 0.9, 0.2, 1); }
.modal-center { justify-content: center; padding: 1rem; }
.modal-center .modal-content { border-radius: 12px; margin: auto; max-height: 90vh; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.toast { position: fixed; top: calc(1rem + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--accent); color: #000; padding: 0.5rem 1.5rem; border-radius: 20px; font-weight: bold; z-index: 2000; animation: fadeDown 0.2s cubic-bezier(0.1, 0.9, 0.2, 1); }
@keyframes fadeDown { from { transform: translate(-50%, -100%); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.list-item { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem; background: var(--bg); border-radius: 8px; margin-bottom: 0.5rem; border: 2px solid var(--border); transition: border-color 0.15s; }
.tag-link { color: var(--accent); text-decoration: underline; cursor: pointer; display: inline-flex; align-items: center; gap: 0.1rem; font-weight: 500;}
.search-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: center; }

/* 3D Dice Overlays */
#dice-box-container { position: fixed !important; top: 0 !important; left: 0 !important; width: 100vw !important; height: 100vh !important; pointer-events: none !important; z-index: 9999 !important; opacity: 1; }
#dice-box-container canvas { width: 100% !important; height: 100% !important; display: block; }

/* Strict Layout Locks for Dice Display (Stops Resizing/Shifting) */
.dice-display-card { 
    background: var(--surface); padding: 1.5rem 1rem; border-radius: 12px; margin-bottom: 1rem;
    display: flex; flex-direction: column; justify-content: center; align-items: center; 
    min-height: 220px;
}
.dice-display-content { width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: space-between; height: 100%; }

.dice-display-header { font-size: 1.2rem; color: var(--text-muted); word-wrap: break-word; overflow-wrap: break-word; width: 100%; line-height: 1.4; min-height: 1.68rem; }
.dice-display-center { display: flex; align-items: center; justify-content: center; height: 5.5rem; width: 100%; margin: 0; }
.dice-display-footer { 
    font-size: 1.2rem; color: var(--text-muted); 
    word-wrap: break-word; overflow-wrap: break-word; width: 100%; 
    max-height: 120px; overflow-y: auto; scrollbar-width: thin; line-height: 1.4; min-height: 1.68rem;
}

/* Standardized Icon & Total Sizes */
.dice-display-total { font-size: 4.5rem; color: var(--accent); font-weight: bold; line-height: 1; margin: 0; }
.dice-display-icon { font-size: 4.5rem !important; line-height: 1; margin: 0; }

@keyframes spinCasino {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.spin-casino {
    animation: spinCasino 0.8s linear infinite;
    color: var(--accent);
}

/* History Log Entries */
.dice-entry { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 0.5rem; }
.dice-result { font-size: 2.5rem; font-weight: bold; color: var(--text); text-align: right; line-height: 1; }

/* --- BOOKS DIRECTORY & READER --- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
.book-card { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; transition: transform 0.15s, border-color 0.15s; display: flex; flex-direction: column; }
.book-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.book-cover-img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-bottom: 2px solid var(--border); background: transparent; }
.book-cover-placeholder { height: 180px; background: var(--surface-hover); display: flex; align-items: center; justify-content: center; border-bottom: 2px solid var(--border); }
.book-cover-placeholder .material-icons { font-size: 64px; color: var(--border); }
.book-title { padding: 0.75rem 0.5rem; font-size: 14px; text-align: center; font-weight: bold; flex: 1; display: flex; align-items: center; justify-content: center; }

/* --- CLASSES LIBRARY --- */
.class-card { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; transition: transform 0.15s, border-color 0.15s; display: flex; flex-direction: column; }
.class-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.class-icon-wrapper { height: 140px; background: var(--surface-hover); display: flex; align-items: center; justify-content: center; border-bottom: 2px solid var(--border); }
.class-icon-wrapper .material-icons { font-size: 64px; opacity: 0.8; }
.class-card-title { padding: 0.75rem 0.5rem 0.25rem; font-size: 16px; text-align: center; font-weight: bold; flex: 1; }
.class-card-subtitle { padding: 0 0.5rem 0.75rem; font-size: 12px; color: var(--text-muted); text-align: center; text-transform: uppercase; }

.reader-content { line-height: 1.6; font-size: 1.05rem; color: var(--text); }
.book-header { color: var(--accent); margin-top: 2rem; margin-bottom: 1rem; border-bottom: 2px solid var(--border); padding-bottom: 0.3rem; }
.book-header:first-child { margin-top: 0; }
.book-quote { border-left: 4px solid var(--accent); margin: 1.5rem 0; padding: 0.5rem 1rem; background: var(--surface-hover); font-style: italic; border-radius: 0 8px 8px 0; }
.book-quote cite { display: block; margin-top: 0.5rem; color: var(--text-muted); font-weight: bold; font-style: normal; }

.book-inset { border: 2px solid var(--border); border-radius: 8px; padding: 1rem; margin: 1.5rem 0; background: var(--bg); }
.book-inset.readaloud { background: var(--surface-hover); border-style: dashed; }
.book-inset h4 { margin-top: 0; margin-bottom: 0.5rem; color: var(--text); font-size: 1.1rem; }

/* Table Formatting */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; border: 2px solid var(--border); border-radius: 8px; }
.book-table { width: 100%; border-collapse: collapse; text-align: left; background: var(--bg); border: none; }
.book-table th, .book-table td { padding: 0.4rem 0.6rem; border: 1px solid var(--border); }
.book-table th { background: var(--surface-hover); color: var(--text); font-weight: bold; white-space: nowrap; border-bottom: 2px solid var(--border); }
.book-table tbody tr:nth-child(even) { background-color: rgba(255, 255, 255, 0.03); }
.book-table tr:last-child td { border-bottom: none; }
.book-table p { margin: 0; padding: 0.2rem 0; }

.book-image { margin: 1.5rem 0; text-align: center; }
.book-image img { max-width: 100%; height: auto; border-radius: 8px; border: 2px solid var(--border); box-shadow: 0 4px 6px rgba(0,0,0,0.3); }
.book-image figcaption { font-size: 14px; color: var(--text-muted); margin-top: 0.5rem; font-style: italic; }
.reader-content ul { padding-left: 1.5rem; margin: 1rem 0; }
.reader-content li { margin-bottom: 0.5rem; }
.reader-content p { margin-bottom: 1rem; }

[v-cloak] { display: none !important; }
.splash-screen { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10000; color: var(--accent); }

.book-quote { 
    border: 2px solid var(--border); margin: 1.5rem 0; padding: 1rem; 
    background: var(--surface-hover); font-style: italic; border-radius: 8px; 
}
.book-quote cite { display: block; margin-top: 0.5rem; color: var(--text-muted); font-weight: bold; font-style: normal; }

.book-inset { 
    border: 2px solid var(--border) !important; border-radius: 8px; padding: 1rem; margin: 1.5rem 0; background: var(--bg); 
}

/* Sub-Navigation Popup Menus */
.nav-overlay {
    position: fixed; inset: 0; z-index: 90; background: transparent;
}
.nav-popup {
    position: absolute; bottom: 80px; background: var(--surface); border: 2px solid var(--border); 
    border-radius: 12px; display: flex; flex-direction: column; padding: 0.5rem; 
    box-shadow: 0 -4px 12px rgba(0,0,0,0.5); gap: 0.2rem; min-width: 150px; z-index: 95;
}

/* Centers directly above the 2nd navigation button (which sits at 37.5% of the screen) */
.nav-popup.details-menu { left: 37.5%; transform: translateX(-50%); }
/* Centers directly above the 4th navigation button (which sits at 87.5% of the screen) */
.nav-popup.right { right: 0; }

.nav-popup button {
    background: transparent; color: var(--text); border: none; padding: 0.75rem 1rem; 
    border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; text-align: left;
    display: flex; align-items: center; justify-content: flex-start; gap: 1rem;
}
.nav-popup button .material-icons {
    font-size: 24px; line-height: 1; margin: 0; display: inline-flex;
    align-items: center; justify-content: center;
    color: var(--text-muted); transition: color 0.15s;
}
.nav-popup button:hover { background: var(--surface-hover); color: var(--accent); }
.nav-popup button:hover .material-icons { color: var(--accent); }

/* Class Page: Sticky Header & Separators */
.class-sticky-header {
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
    padding: 1rem 0;
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.class-toc-select {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    max-width: 150px;
}
.level-separator {
    border: none;
    border-top: 2px dashed var(--border);
    margin: 3rem 0;
    opacity: 0.5;
}

/* Offset for smooth scrolling so headers aren't hidden behind the sticky header */
h2, h3, h4, h5, .level-anchor, [id] {
    scroll-margin-top: 85px; 
}