:root {
    --bg-dark: #0f0f23;
    --panel-bg: #1a1a2e;
    --sidebar-bg: #16213e;
    --text-color: #ffffff;
    --text-muted: #b8b8c8;
    --accent: #e94560;
    --border-color: #2a2a4e;
    --focus-ring: #f0a0b0;
}

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

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-color);
    overflow: hidden;
    width: 100%;
    height: 100%;
}

html {
    width: 100%;
    height: 100%;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100dvh;
}

/* Header / Control Panel — flex child so wrapped height never covers the canvas */
#control-panel {
    flex-shrink: 0;
    background-color: var(--panel-bg);
    display: flex;
    align-items: center;
    padding: 10px 20px;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
    z-index: 40;
    flex-wrap: wrap;
    position: relative;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.control-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

select, input[type="text"] {
    background-color: var(--bg-dark);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
}

select:focus-visible,
input[type="text"]:focus-visible,
input[type="range"]:focus-visible,
button:focus-visible,
canvas:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

select:focus, input[type="text"]:focus {
    border-color: var(--accent);
}

input[type="range"] {
    width: 100px;
}

button {
    background-color: var(--bg-dark);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s, border-color 0.2s;
}

button:hover {
    background-color: #2a2a4e;
}

button.active {
    background-color: var(--accent);
    border-color: var(--accent);
}

/* Main Area */
main {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
}

#canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    height: 100%;
    min-width: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 15, 35, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        border-left-color: var(--accent);
        opacity: 0.8;
    }
    button {
        transition: none;
    }
    #sidebar {
        transition: none;
    }
}

/* Tooltip */
#tooltip {
    position: absolute;
    background-color: rgba(26, 26, 46, 0.95);
    border: 1px solid var(--border-color);
    padding: 10px 15px;
    border-radius: 6px;
    pointer-events: none;
    z-index: 50;
    font-size: 0.9rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    transform: translate(-50%, -100%);
    margin-top: -15px;
    white-space: pre-wrap;
    max-width: 300px;
}

#tooltip.hidden {
    display: none;
}

/* Legend */
#legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    width: 200px;
    z-index: 20;
    background-color: rgba(22, 33, 62, 0.8);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.legend-gradient {
    height: 10px;
    background: linear-gradient(to right, #8B00FF, #0000FF, #00FF00, #FFFF00, #FFA500, #FF0000);
    border-radius: 5px;
    margin-bottom: 5px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Sidebar */
#sidebar {
    width: min(300px, 85vw);
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    transition: transform 0.3s ease;
    z-index: 30;
    display: flex;
}

#sidebar.collapsed {
    transform: translateX(100%);
}

/* Accordion */
.accordion { width: 100%; }
.accordion-item { border-top: 1px solid var(--border-color); }
.accordion-header {
    width: 100%;
    padding: 15px 0;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    border-radius: 0;
    color: inherit;
    font-size: 1rem;
    text-align: left;
}
.accordion-header:hover { color: var(--accent); }
.accordion-header span { font-size: 0.8rem; color: var(--text-muted); }
.accordion-body { padding-bottom: 15px; }
.accordion-body.hidden { display: none; }
.bible-text-box { margin-top: 15px; padding: 10px; background-color: rgba(255,255,255,0.05); border-radius: 4px; font-size: 0.85rem; line-height: 1.4; color: #ddd; max-height: 200px; overflow-y: auto; font-style: italic; }

.sidebar-toggle {
    position: absolute;
    left: -40px;
    top: 20px;
    width: 40px;
    height: 44px;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: 8px 0 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.sidebar-content {
    padding: 20px;
    width: 100%;
    overflow-y: auto;
}

.sidebar-content h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.stat-box {
    background-color: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    text-align: center;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-section {
    margin-bottom: 25px;
}

.stat-section h3 {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* D3 Charts placeholders in sidebar */
#donut-chart, #top-books-chart, #top-chapters-chart {
    height: 150px;
    width: 100%;
}

.chapter-details {
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.chapter-details.hidden {
    display: none;
}

#chapter-links-list {
    list-style: none;
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
}

#chapter-links-list li {
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
    cursor: pointer;
}

#chapter-links-list li:hover,
#chapter-links-list li:focus-visible {
    color: var(--accent);
}

.error-text {
    color: var(--accent);
    font-size: 0.8rem;
    margin-left: 8px;
}

.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    #control-panel {
        padding: 8px 12px;
        gap: 10px;
    }
    #legend {
        width: 140px;
        bottom: 12px;
        left: 12px;
        padding: 8px;
    }
    .sidebar-toggle {
        left: -44px;
        width: 44px;
        height: 48px;
    }
}
