/* === Theme variables === */
:root {
    --bg-body: #050505;
    --bg-panel: #0a0a0a;
    --bg-button: rgba(20, 20, 25, 0.85);
    --bg-button-hover: rgba(35, 35, 45, 0.95);
    --bg-button-active: rgba(60, 60, 75, 0.95);
    --text-primary: #fff;
    --text-secondary: #b0b0b4;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-button: rgba(255, 255, 255, 0.12);
    --border-active: rgba(255, 255, 255, 0.25);
    --scrollbar-track: #0a0a0a;
    --scrollbar-thumb: #2a2a2e;
    --scrollbar-hover: #3a3a40;
    --pdf-filter: invert(1);
}

@media (prefers-color-scheme: light) {
    :root {
        --bg-body: #f0f0f2;
        --bg-panel: #ffffff;
        --bg-button: rgba(235, 235, 240, 0.9);
        --bg-button-hover: rgba(215, 215, 225, 0.95);
        --bg-button-active: rgba(190, 190, 210, 0.95);
        --text-primary: #1a1a1a;
        --text-secondary: #555;
        --border-subtle: rgba(0, 0, 0, 0.1);
        --border-button: rgba(0, 0, 0, 0.15);
        --border-active: rgba(0, 0, 0, 0.3);
        --scrollbar-track: #f0f0f0;
        --scrollbar-thumb: #c0c0c5;
        --scrollbar-hover: #a0a0a5;
        --pdf-filter: none;
    }
}

html[data-theme="light"] {
    --bg-body: #f0f0f2;
    --bg-panel: #ffffff;
    --bg-button: rgba(235, 235, 240, 0.9);
    --bg-button-hover: rgba(215, 215, 225, 0.95);
    --bg-button-active: rgba(190, 190, 210, 0.95);
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --border-subtle: rgba(0, 0, 0, 0.1);
    --border-button: rgba(0, 0, 0, 0.15);
    --border-active: rgba(0, 0, 0, 0.3);
    --scrollbar-track: #f0f0f0;
    --scrollbar-thumb: #c0c0c5;
    --scrollbar-hover: #a0a0a5;
    --pdf-filter: none;
}

html[data-theme="dark"] {
    --bg-body: #050505;
    --bg-panel: #0a0a0a;
    --bg-button: rgba(20, 20, 25, 0.85);
    --bg-button-hover: rgba(35, 35, 45, 0.95);
    --bg-button-active: rgba(60, 60, 75, 0.95);
    --text-primary: #fff;
    --text-secondary: #b0b0b4;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-button: rgba(255, 255, 255, 0.12);
    --border-active: rgba(255, 255, 255, 0.25);
    --scrollbar-track: #0a0a0a;
    --scrollbar-thumb: #2a2a2e;
    --scrollbar-hover: #3a3a40;
    --pdf-filter: invert(1);
}

/* === Base reset === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-body);
}

#app {
    display: flex;
    width: 100%;
    height: 100%;
}

#viewport-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#viewport {
    display: block;
    width: 100%;
    height: 100%;
}

/* Info bar — block name on hover */
#info-bar {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 20px;
    background: var(--bg-button);
    color: var(--text-primary);
    border-radius: 20px;
    font-size: 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#info-bar.visible {
    opacity: 1;
}

/* Back button */
#back-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 10px 20px;
    background: var(--bg-button);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    display: none;
    transition: background 0.2s ease;
    z-index: 10;
}

#back-btn:hover {
    background: var(--bg-button-hover);
}

#back-btn.visible {
    display: block;
}

/* PDF panel — slides in from right as overlay */
#pdf-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 40%;
    height: 100%;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 20;
}

body.panel-open #pdf-panel {
    transform: translateX(0);
}

#pdf-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    color: var(--text-secondary);
}

#pdf-content {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
}

#pdf-canvas {
    max-width: 100%;
    height: auto;
    filter: var(--pdf-filter);
}

/* Scrollbar */
#pdf-content::-webkit-scrollbar {
    width: 8px;
}

#pdf-content::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

#pdf-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

#pdf-content::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

/* Measure toolbar */
#measure-toolbar {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: none;
    gap: 8px;
    z-index: 10;
}

#measure-toolbar.visible {
    display: flex;
}

.measure-btn {
    padding: 8px 16px;
    background: var(--bg-button);
    color: var(--text-primary);
    border: 1px solid var(--border-button);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.measure-btn:hover {
    background: var(--bg-button-hover);
}

.measure-btn.active {
    background: var(--bg-button-active);
    border-color: var(--border-active);
}

/* Layer toolbar */
#layer-toolbar {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

#layer-toolbar.hidden {
    display: none;
}

.layer-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-button);
    color: var(--text-primary);
    border: 1px solid var(--border-button);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.layer-btn:hover {
    background: var(--bg-button-hover);
}

.layer-btn.active {
    background: var(--bg-button-active);
    border-color: var(--border-active);
}

.layer-btn-alle {
    width: auto;
    padding: 0 10px;
}

/* Theme toggle button */
#theme-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    background: var(--bg-button);
    color: var(--text-primary);
    border: 1px solid var(--border-button);
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle:hover {
    background: var(--bg-button-hover);
}

/* Measurement labels (CSS2DRenderer) */
.measurement-label {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.3;
    pointer-events: none;
    user-select: none;
}

.edge-label {
    background: rgba(255, 180, 40, 0.85);
    color: #000;
}

.angle-label {
    background: rgba(80, 200, 255, 0.85);
    color: #000;
}

.dihedral-label {
    background: rgba(64, 232, 112, 0.85);
    color: #000;
}
