:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-app: #f4f4f4;
    --bg-panel: #ffffff;
    --bg-elevated: #e8e8e8;
    --bg-canvas: #fafafa;
    --text-main: #1a1a1a;
    --text-muted: #555;
    --text-inverse: #ffffff;
    --border-color: #cbd5e1;
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.1);
    --accent-success: #22c55e;
    --accent-error: #ef4444;
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-app: #0f172a;
    --bg-panel: #1e293b;
    --bg-elevated: #334155;
    --bg-canvas: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-inverse: #0f172a;
    --border-color: #334155;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-success: #22c55e;
    --accent-error: #ef4444;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.round-indicator {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.score-display {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent-success);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-elevated);
}

.theme-toggle {
    background: var(--bg-elevated);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--text-main);
    color: var(--text-inverse);
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Reference Panel (Sidebar) */
aside {
    width: 350px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    transition: transform 0.3s ease, background-color 0.2s ease, border-color 0.2s ease;
    z-index: 20;
    overflow-y: auto;
    position: relative;
}

aside.hidden {
    display: none;
}

aside h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th,
td {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-weight: 500;
}

td:nth-child(3) {
    white-space: nowrap;
    font-family: monospace;
}

/* Spectrum View */
.spectrum-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow: hidden;
}

.canvas-wrapper {
    flex: 1;
    background: white;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    min-height: 0;
    border: 1px solid var(--border-color);
}

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

.drop-zone {
    position: absolute;
    top: 10%;
    right: 5%;
    width: 200px;
    height: 120px;
    border: 2px dashed var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    font-weight: 600;
    transition: all 0.2s;
    z-index: 5;
}

.drop-zone.drag-over {
    background: rgba(37, 99, 235, 0.2);
    transform: scale(1.05);
}

.feedback {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 6px;
    text-align: center;
    font-weight: 500;
}

.feedback.success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--accent-success);
    border: 1px solid var(--accent-success);
}

.feedback.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-error);
    border: 1px solid var(--accent-error);
}

.hidden {
    display: none !important;
}

/* Molecules Dock */
.molecules-dock {
    height: 180px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    display: flex;
    align-items: center;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.dock-scroll {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    width: 100%;
    padding-bottom: 0.5rem;
}

.molecule-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 160px;
    height: 120px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: transform 0.2s, background-color 0.2s ease, border-color 0.2s ease;
    user-select: none;
    overflow: hidden;
}

.molecule-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.molecule-card:active {
    cursor: grabbing;
}

.molecule-name {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.molecule-formula-placeholder {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
    overflow-y: hidden;
}

/* MathJax Specific Tweaks */
mjx-container {
    font-size: 90% !important;
    outline: none;
    max-width: 100%;
}

mjx-container svg {
    max-width: 100%;
    height: auto;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    aside {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--bg-panel);
        border-right: none;
    }

    .spectrum-container {
        padding: 0.5rem;
    }

    .drop-zone {
        width: 140px;
        height: 80px;
        font-size: 0.8rem;
    }

    .molecules-dock {
        height: 160px;
        padding: 0.5rem;
    }

    .molecule-card {
        min-width: 140px;
        height: 110px;
    }

    mjx-container {
        font-size: 80% !important;
    }
}
