/* ── Reset & Base ─────────────────────────────────────────────────────────── */

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #f5f3ee url('canvasbg.webp') repeat;
}

canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    contain: strict;
    will-change: transform;
}

/* ── Overlay ──────────────────────────────────────────────────────────────── */

#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    opacity: 1;
    transition: opacity 1.5s ease;
}

#overlay.state-active {
    opacity: 0;
    pointer-events: none;
}

/* ── Screen Panels ────────────────────────────────────────────────────────── */

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.state-start .screen-start,
.state-loading .screen-loading,
.state-error .screen-error {
    opacity: 1;
    pointer-events: auto;
}

/* ── Start Screen ─────────────────────────────────────────────────────────── */

.title {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 200;
    color: #fff;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    animation: titleGlow 4s ease-in-out infinite, fadeInUp 0.7s ease both;
}

@keyframes titleGlow {
    0%, 100% {
        text-shadow:
            0 0 20px rgba(255, 165, 0, 0.12),
            0 0 60px rgba(255, 107, 107, 0.06);
    }
    50% {
        text-shadow:
            0 0 30px rgba(255, 165, 0, 0.28),
            0 0 80px rgba(213, 0, 249, 0.1);
    }
}

.flavor {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: clamp(0.85rem, 1.8vw, 1.1rem);
    font-weight: 300;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.08em;
    margin-bottom: 0.5rem;
    animation: fadeInUp 0.7s ease 0.15s both;
}

.version {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.75rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 0.1em;
    position: absolute;
    bottom: 1.5rem;
    animation: fadeInUp 0.7s ease 0.3s both;
}

.start-btn {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 1.05rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #000;
    background: linear-gradient(135deg, #ff6b6b, #ffa500, #ffd700, #00e676, #448aff, #d500f9);
    background-size: 300% 300%;
    border: none;
    padding: 1rem 3.5rem;
    border-radius: 50px;
    margin-top: 2rem;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    box-shadow: 0 0 30px rgba(255, 165, 0, 0.25);
    animation: gradientShift 8s ease infinite, fadeInUp 0.7s ease 0.3s both;
}

@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.start-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 0 50px rgba(255, 165, 0, 0.45);
}

.start-btn:active {
    transform: scale(0.97);
}

/* ── Loading Screen ───────────────────────────────────────────────────────── */

.loading-ring {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: conic-gradient(
        from 0deg,
        transparent 0%,
        #ff6b6b 10%,
        #ffa500 25%,
        #ffd700 40%,
        #00e676 55%,
        #448aff 70%,
        #d500f9 85%,
        transparent 100%
    );
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    animation: spin 1.5s linear infinite;
    margin-bottom: 1.5rem;
}

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

.loading-text {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.08em;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.45; }
    50%      { opacity: 0.85; }
}

/* ── Error Screen ─────────────────────────────────────────────────────────── */

.error-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(255, 107, 107, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 1.8rem;
    font-weight: 300;
    color: #ff6b6b;
    margin-bottom: 1.5rem;
}

.error-text {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 0.04em;
    text-align: center;
    max-width: 380px;
    line-height: 1.65;
    margin-bottom: 2rem;
}

.retry-btn {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fff;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: 0.8rem 2.5rem;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
}

.retry-btn:hover {
    background: rgba(255, 255, 255, 0.13);
    border-color: rgba(255, 255, 255, 0.25);
    transform: scale(1.04);
}

.retry-btn:active {
    transform: scale(0.97);
    background: rgba(255, 255, 255, 0.05);
}

/* ── Debug Config Panel (ImGui style) ─────────────────────────────────────── */

.config-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 240px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    padding: 4px;
    z-index: 110;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    display: none;
    pointer-events: auto;
}

.config-panel.open {
    display: block;
}

/* Custom scrollbar */
.config-panel::-webkit-scrollbar {
    width: 4px;
}

.config-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.config-panel::-webkit-scrollbar-track {
    background: transparent;
}

.cp-title {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 2px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 2px;
    user-select: none;
}

.cp-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    min-height: 20px;
}

.cp-row + .cp-row {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.cp-label {
    flex: 1;
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.cp-val {
    width: 42px;
    text-align: right;
    color: rgba(255, 255, 255, 0.45);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    padding-right: 2px;
}

/* ── Range Slider (ImGui style) ───────────────────────────────────────────── */

.cp-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 88px;
    height: 14px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 1px;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
}

.cp-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 8px;
    height: 14px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 1px;
    cursor: pointer;
}

.cp-row input[type="range"]::-webkit-slider-thumb:hover {
    background: rgba(255, 255, 255, 0.7);
}

.cp-row input[type="range"]::-moz-range-thumb {
    width: 8px;
    height: 14px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 1px;
    cursor: pointer;
    border: none;
}

.cp-row input[type="range"]::-moz-range-track {
    height: 14px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 1px;
    border: none;
}

/* ── Checkbox (ImGui style) ───────────────────────────────────────────────── */

.cp-row input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 1px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
}

.cp-row input[type="checkbox"]:checked {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.35);
}

.cp-row input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 4px;
    height: 7px;
    border: solid rgba(255, 255, 255, 0.9);
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}

.cp-toggle {
    justify-content: space-between;
}

.cp-reset {
    margin-top: 4px;
}

.cp-reset-btn {
    width: 100%;
    padding: 5px 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.75);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}

.cp-reset-btn:hover {
    background: rgba(255, 80, 80, 0.25);
    border-color: rgba(255, 80, 80, 0.4);
    color: rgba(255, 255, 255, 0.95);
}

/* ── Config Toggle Button ─────────────────────────────────────────────────── */

.config-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 111;
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    color: rgba(0, 0, 0, 0.3);
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    font-family: monospace;
    transition: color 0.15s;
}

.config-toggle-btn:hover {
    color: rgba(0, 0, 0, 0.7);
}

/* ── Fullscreen Button ─────────────────────────────────────────────────────── */

.fullscreen-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 111;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: rgba(0, 0, 0, 0.35);
    font-size: 20px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.fullscreen-btn:hover {
    color: rgba(0, 0, 0, 0.75);
}

.fullscreen-btn:hover {
    color: rgba(255, 255, 255, 0.8);
}

.fullscreen-btn:hover {
    color: rgba(255, 255, 255, 0.8);
}

/* ── Status Bar ───────────────────────────────────────────────────────────── */


/* ── Note Display ──────────────────────────────────────────────────────────── */

.note-display {
    position: fixed;
    bottom: 16px;
    left: 16px;
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.45);
    pointer-events: none;
    z-index: 10;
    white-space: pre;
    letter-spacing: 0.5px;
    transition: opacity 0.15s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.db-meter {
    display: inline-block;
    width: 80px;
    height: 6px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

.db-fill {
    display: block;
    height: 100%;
    width: 0%;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 3px;
    transition: width 0.06s linear;
}

/* ── Shared Animation ─────────────────────────────────────────────────────── */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
