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

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

:root {
    --bg-color: #000000;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --danger: #f43f5e;
}

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

body {
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    background: radial-gradient(circle at top right, #1e293b, #000000);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

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

#ui-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 320px;
    max-height: calc(100vh - 40px);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 24px;
    z-index: 2;
    overflow-y: auto;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

header {
    margin-bottom: 24px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 16px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

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

.control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

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

.rotation-category .label {
    font-size: 0.75rem;
    color: var(--accent-color);
    display: block;
    margin-bottom: 4px;
}

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

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

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

.btn.secondary {
    background: transparent;
    border: 1px dashed var(--glass-border);
    font-size: 0.8rem;
}

.btn.danger {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.3);
    color: #fda4af;
    margin-top: 8px;
}

.btn.danger:hover {
    background: rgba(244, 63, 94, 0.2);
}

/* Toggle Switch */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    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: rgba(255, 255, 255, 0.1);
    transition: .4s;
}

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

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

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

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.info-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--glass-border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.info-footer ul {
    list-style: none;
    padding-left: 10px;
}

.info-footer li {
    margin-bottom: 3px;
}

/* 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);
}

#help-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 2;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#help-btn:hover {
    background: var(--accent-color);
    color: #fff;
}

/* === Cayley Graph / Subgroup Builder === */
#cayley-canvas {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    background: radial-gradient(circle at center, #1e293b, #0f172a);
}

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

#generator-selector h3 {
    font-size: 0.85rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.generator-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.generator-row input[type="checkbox"] {
    accent-color: var(--accent-color);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.generator-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.gen-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.subgroup-order {
    margin-top: 10px;
    padding: 8px;
    text-align: center;
    color: #69f0ae;
    font-weight: 600;
    font-size: 0.95rem;
    border-top: 1px solid var(--glass-border);
}

.btn.subgroup-builder-btn {
    background: rgba(56, 189, 248, 0.1);
    border-color: rgba(56, 189, 248, 0.3);
    color: #7dd3fc;
    width: 100%;
    margin-top: 8px;
}

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

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

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

/* 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; }


/* === 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%;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 12px 16px 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 {
        display: flex;
        flex-direction: column;
    }

    #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;
    }

    h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 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);
    }
}
