/*
  MIT License
  Copyright (c) 2026 buchio
  See LICENSE file for details.
*/

:root {
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --accent-color: #58a6ff;
    --panel-bg: rgba(22, 27, 34, 0.7);
    --panel-border: rgba(240, 246, 252, 0.1);
    --input-bg: #0d1117;
    --input-border: #30363d;
    --glass-blur: 12px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    /* Canvas handles scrolling */
    width: 100vw;
    height: 100vh;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

canvas {
    display: block;
    flex-grow: 1;
    width: 0;
    /* Important for flex shrinking */
    height: 100%;
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

.control-panel {
    position: relative;
    /* Reset from absolute */
    width: 320px;
    height: 100%;
    flex-shrink: 0;

    background: var(--panel-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--panel-border);
    /* Remove rounded corners for sidebar */
    border-radius: 0;
    padding: 24px;
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.3);

    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Remove scroll, we scale to fit */
    overflow: hidden;
    z-index: 10;
}

.panel-scaler {
    width: 100%;
    transform-origin: top left;
    padding-bottom: 24px;
    /* Ensure space below footer */
}

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

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 4px;
}

header p {
    font-size: 0.9rem;
    color: #8b949e;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 40px;
    /* Space for bottom content if any */
}

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

/* Horizontal layout for sliders */
.control-group:has(input[type="range"]) {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.control-group:has(input[type="range"]) label {
    min-width: 100px;
    /* Ensure labels align nicely */
    flex-shrink: 0;
}

.control-group:has(input[type="range"]) input {
    flex-grow: 1;
    cursor: pointer;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
}

input[type="number"] {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.15s ease;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

button {
    background: var(--accent-color);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #409eff;
}

button:active {
    transform: translateY(1px);
}

.status-bar {
    margin-top: 16px;
    font-size: 0.8rem;
    color: #8b949e;
    text-align: right;
}

/* GitHub Ribbon */
.github-ribbon {
    position: fixed;
    /* Fixed to viewport */
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    overflow: hidden;
    z-index: 2000;
    pointer-events: none;
}

.github-ribbon a {
    display: block;
    width: 150px;
    padding: 6px 0;
    background-color: #aa0000;
    color: #fff;
    text-align: center;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.8rem;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);

    position: absolute;
    top: 25px;
    right: -35px;
    transform: rotate(45deg);

    pointer-events: auto;
    transition: background-color 0.2s;
}

.github-ribbon a::before,
.github-ribbon a::after {
    content: "";
    width: 100%;
    display: block;
    position: absolute;
    top: 2px;
    left: 0;
    height: 1px;
    background: #fff;
    opacity: 0.3;
}

.github-ribbon a::after {
    bottom: 2px;
    top: auto;
}

.github-ribbon a:hover {
    background-color: #cc0000;
}

/* Toggle Buttons */
#btn-open-panel {
    position: fixed;
    /* Fixed to viewport */
    top: 20px;
    left: 20px;
    z-index: 2000;
    /* Ensure on top */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--panel-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--panel-border);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, background-color 0.2s;
}

#btn-open-panel.visible {
    opacity: 1;
    pointer-events: auto;
}

#btn-open-panel:hover {
    background-color: rgba(48, 54, 61, 0.8);
    color: var(--accent-color);
}

#btn-close-panel {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 4px;
    margin: -4px -4px 0 0;
    /* Align with header */
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}

#btn-close-panel:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Panel Transition & Hidden State */
.control-panel.hidden {
    margin-left: -320px;
    opacity: 1;
    /* Keep visible for transition */
}

/* Responsive Design for Mobile */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
        /* Stack Vertically */
    }

    .control-panel {
        /* Reset Desktop Styles */
        position: relative;
        left: auto;
        top: auto;

        /* Mobile Fixed Layout (Top) */
        order: 1;
        /* Place at top */
        width: 100%;
        height: calc(45vh + env(safe-area-inset-top));
        /* Occupy top part of screen + safe area */
        max-height: 100vh;
        /* Safeguard: Never exceed screen */

        border-right: none;
        border-top: none;
        border-bottom: 2px solid var(--accent-color);
        /* distinctive separator */
        border-radius: 0 0 12px 12px;

        box-shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
        /* Strong downward shadow */
        z-index: 20;
        /* Ensure it stays on top */

        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top));
        /* Clear the notch */
        margin-left: 0;

        /* Animate height for toggle */
        transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
        overflow: hidden;
        /* Ensure content hides when height is 0 */
    }

    .control-panel.hidden {
        margin-left: 0;
        height: 0;
        padding-top: 0;
        padding-bottom: 0;
        border-bottom: none;
        /* Hide border when closed */
    }

    .control-panel.hidden * {
        /* Hint to browser to ignore contents when hidden for perf */
        display: none;
    }

    /* Reset Canvas */
    canvas {
        order: 2;
        /* Place at bottom */
        width: 100%;
        height: 0;
        /* Flex shrink/grow */
    }

    #btn-open-panel {
        top: calc(20px + env(safe-area-inset-top));
        /* Top left + safe area */
        bottom: auto;
        left: 20px;
        z-index: 1100;

        /* Adjust position slightly to not overlap with potentially small UI */
    }

    .github-ribbon {
        width: 70px;
        height: 70px;
        top: env(safe-area-inset-top);
    }

    .github-ribbon a {
        font-size: 0.6rem;
        width: 100px;
        top: 15px;
        right: -25px;
    }

    /* Adjust controls for touch */
    button,
    input[type="number"],
    select {
        min-height: 44px;
        /* Touch target size */
    }

    .control-group label {
        font-size: 0.9rem;
    }

    /* Rotate close icon to point up on mobile */
    #btn-close-panel svg {
        transform: rotate(90deg);
        transition: transform 0.3s ease;
    }
}