/*
    Copyright (c) 2026 John Talbot. All rights reserved.
*/

:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.85);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-blue: #38bdf8;
    --accent-green: #4ade80;
    --accent-red: #fb7185;
    --border-color: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#cayley-canvas {
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 2;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    z-index: 10;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 4px;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.controls-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-group {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-color);
}

.control-group h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.rotation-category {
    margin-bottom: 12px;
}

.rotation-category:last-child {
    margin-bottom: 0;
}

.label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
    min-width: 44px;
    text-align: center;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn.active {
    background: rgba(56, 189, 248, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.btn.cayley-selected {
    background: rgba(56, 189, 248, 0.25) !important;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
}

.btn.danger {
    border-color: var(--accent-red);
    color: var(--accent-red);
    width: 100%;
    margin-top: 10px;
}

.btn.danger:hover {
    background: rgba(251, 113, 133, 0.1);
}

.btn.secondary {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
    width: 100%;
}

/* Speed Slider */
input[type=range] {
    flex-grow: 1;
    cursor: pointer;
}

/* Toggle Switches */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-blue);
}

input:checked+.slider:before {
    transform: translateX(14px);
}

#permutation-overlay {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid var(--border-color);
    font-family: 'Outfit', sans-serif;
}

/* Subgroup Builder Styles */
.subgroup-builder-btn {
    width: 100%;
    margin-top: 10px;
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    font-weight: 600;
}

.subgroup-builder-btn:hover {
    background: rgba(56, 189, 248, 0.1);
}

#generator-selector {
    display: none;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-top: 4px;
}

.gen-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Back/breadcrumb link */
.back-link {
    display: inline-block;
    color: #60a5fa;
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.7;
    transition: opacity 0.2s;
    margin-bottom: 8px;
}
.back-link:hover { opacity: 1; }

.poly-switch {
    cursor: pointer;
    transition: -webkit-text-fill-color 0.2s;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    display: inline;
}
.active-poly {
    -webkit-text-fill-color: #ffffff;
}
.inactive-poly {
    -webkit-text-fill-color: #64748b;
}
.inactive-poly:hover {
    -webkit-text-fill-color: #94a3b8;
}


/* === Accessibility === */
:focus-visible {
    outline: 3px solid var(--accent-color, #38bdf8);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* === Mobile: Collapsible Bottom Sheet === */
.panel-handle {
    display: none;
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    margin: 0 auto 12px;
    flex-shrink: 0;
    cursor: pointer;
}

@media (max-width: 640px) {
    /* Panel always sits at the bottom; only .controls-section collapses */
    #ui-overlay {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        border-right: none;
        border-top: 1px solid var(--border-color, rgba(255,255,255,0.1));
        padding: 12px 16px 0;
        gap: 0;
        overflow: hidden;
    }

    .controls-section {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #ui-overlay.panel-expanded {
        height: 80vh;
    }

    #ui-overlay.panel-expanded .controls-section {
        flex: 1 1 0;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        padding-bottom: 20px;
    }

    .panel-handle {
        display: block;
        flex-shrink: 0;
    }

    header {
        flex-shrink: 0;
    }

    header h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-text-fill-color: var(--text-primary, #f8fafc);
        background: none;
    }

    /* Pin Subgroup Builder at top so it is always reachable without scrolling */
    .control-group:has(#subgroup-builder-btn) {
        order: -1;
    }

    #generator-selector {
        order: -1;
    }
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-color, #38bdf8);
    cursor: pointer;
}

/* === Desktop: offset canvas behind control panel === */
@media (min-width: 641px) {
    #canvas-container {
        left: 340px;
        width: calc(100% - 340px);
    }
}
