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

body {
    font-family: 'Outfit', sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    overflow: hidden;
}

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

.ui-panel {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 340px;
    max-height: calc(100vh - 40px);
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    z-index: 100;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.back-link {
    display: inline-block;
    color: #60a5fa;
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.back-link:hover {
    text-decoration: underline;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #60a5fa, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.description {
    font-size: 0.92rem;
    color: #94a3b8;
    line-height: 1.5;
    margin-bottom: 24px;
}

.control-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 0.95rem;
    font-weight: 400;
    margin-bottom: 8px;
    color: #e2e8f0;
}

.input-row {
    display: flex;
    gap: 12px;
}

input[type="number"] {
    width: 60px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px;
    color: #e2e8f0;
    font-family: inherit;
    font-size: 0.9rem;
    text-align: center;
}

input[type="number"]:focus {
    outline: none;
    border-color: #60a5fa;
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.toggle-row label {
    margin-bottom: 0;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.info-box {
    background: rgba(15, 23, 42, 0.4);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.stat:last-child {
    margin-bottom: 0;
}

.presentation-block {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.presentation-block .label {
    display: block;
    margin-bottom: 6px;
}

#presentation-val {
    font-size: 0.9rem;
    color: #60a5fa;
    font-weight: 600;
    line-height: 1.6;
}

.gen-link {
    cursor: pointer;
    font-weight: 700;
    padding: 0 3px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.gen-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.12);
}

.gen-link.active {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.18);
}

.rel-link {
    cursor: pointer;
    font-weight: 700;
    padding: 0 3px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.rel-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.12);
}

.rel-link.active {
    color: #22d3ee;
    background: rgba(34, 211, 238, 0.15);
}

.label {
    font-size: 0.92rem;
    color: #94a3b8;
}

.value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #60a5fa;
}

.btn {
    width: 100%;
    background: linear-gradient(135deg, #3b82f6, #4f46e5);
    border: none;
    border-radius: 8px;
    padding: 12px;
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.btn.pending {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.7; }
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    margin-top: 8px;
    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;
}

/* === Tiling overlay === */
#tiling-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: #e2e8f0;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    pointer-events: none;
}

#tiling-overlay.hidden { display: none; }

.spinner {
    width: 52px;
    height: 52px;
    border: 4px solid rgba(255, 255, 255, 0.12);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Curvature note === */
.curvature-note {
    font-size: 0.88rem;
    color: #94a3b8;
    line-height: 1.5;
}

.curvature-note p {
    margin-bottom: 6px;
}

.curvature-note p:last-child {
    margin-bottom: 0;
}

.curvature-note .formula {
    text-align: center;
    color: #60a5fa;
    font-weight: 600;
    letter-spacing: 0.03em;
    margin: 8px 0;
}

/* === 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) {
    .ui-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding: 12px 16px 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

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

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

    .ui-panel.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;
    }

    h1 {
        font-size: 1.1rem;
        -webkit-text-fill-color: #e2e8f0;
        background: none;
        margin-bottom: 0;
    }

    .description {
        display: none;
    }
}

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