:root {
    --bg-start: #1a1a2e;
    --bg-end: #16213e;
    --char-color: #4285F4;
    --eye-color: #FFFFFF;
    --ui-text: rgba(255, 255, 255, 0.5);
    --control-bg: rgba(255, 255, 255, 0.1);
    --control-active-bg: #4285F4;
    --control-color: rgba(255, 255, 255, 0.7);
    --accent: #4285F4;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #000;
    /* prevent overscroll-to-refresh on supporting browsers while letting internal scrolls work */
    overscroll-behavior: contain;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* disable long-press to copy on iOS */
    touch-action: manipulation; /* limit default gestures (prevents pinch/scroll conflicts) */
}

body {
    background: radial-gradient(circle at center, var(--bg-start) 0%, var(--bg-end) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.5s ease;
}

#container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
    pointer-events: none !important; /* ensure background canvas never receives pointer events */
    touch-action: none;              /* prevent any accidental gesture handling on the bg canvas */
    z-index: 1;                      /* keep behind main canvas (z-index:2) and touch overlay (z-index:4) */
}

#canvas {
    position: relative;
    z-index: 2;
    cursor: grab;
    touch-action: none;
    filter: drop-shadow(0 10px 30px rgba(0,0,0,0.3));
    /* Make the canvas visually occupy the full available viewport height while capping width to avoid excessive growth */
    display: block;
    height: 100vh;             /* fill available height */
    max-height: 900px;         /* sensible cap for very tall screens */
    width: auto;
    max-width: 95vw;           /* prevent overflowing horizontally */
    margin: 0 auto;
}

/* Full-width invisible overlay to increase touchable area without affecting visuals */
#touch-overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 4; /* above canvases but below modals and top UI */
    pointer-events: auto;
    touch-action: none; /* ensure consistent pointer/touch handling */
    background: transparent;
}

#canvas:active {
    cursor: grabbing;
}

#ui-overlay {
    position: fixed;
    top: 30px;
    left: 0;
    right: 0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    z-index: 9999999; /* ensure the overlay container sits above everything */
}

/* When any modal is open we hide the main quick action UI to focus on the modal.
   This uses a class added to <body> by JS: body.modal-open */
body.modal-open #playpause-btn,
body.modal-open #melody-btn,
body.modal-open #preset-manager-toggle,
body.modal-open #controls-toggle,
body.modal-open #randomize-toggle,
body.modal-open #settings-toggle,
body.modal-open #audiofx-toggle,
body.modal-open #camera-btn,
body.modal-open .preset-toggle,
body.modal-open #randomize-toggle {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* keep modals accessible while modal-open is active */
body.modal-open .modal-content {
    pointer-events: auto;
}

/* Ensure the app title and Hz meter always sit above all other UI elements */
#app-title,
#freq-display {
    position: relative;
    z-index: 10000000 !important;
    pointer-events: none; /* keep them non-interactive */
    -webkit-transform: translateZ(0); /* promote to its own layer for stable stacking */
    transform: translateZ(0);
}

/* Preset toast that briefly appears when choosing a waveform */
#preset-toast {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    top: 76px;
    min-width: 140px;
    max-width: 80%;
    padding: 8px 14px;
    border-radius: 14px;
    background: rgba(0,0,0,0.72);
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    transform-origin: center top;
    transition: opacity 300ms ease, transform 350ms cubic-bezier(.2,.9,.2,1);
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* visible state */
#preset-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
}

/* subtle pop animation for entrance */
@keyframes preset-pop {
    0% { transform: translateX(-50%) translateY(-8px) scale(0.96); opacity: 0; }
    60% { transform: translateX(-50%) translateY(2px) scale(1.04); opacity: 1; }
    100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}
#preset-toast.animate-in {
    animation: preset-pop 360ms cubic-bezier(.2,.9,.2,1) both;
}

/* fade-out class */
#preset-toast.animate-out {
    transition: opacity 420ms ease, transform 420ms ease;
    opacity: 0;
    transform: translateX(-50%) translateY(-6px) scale(0.98);
}

/* hidden utility override to ensure accessibility hiding doesn't conflict with animation */
#preset-toast.hidden {
    display: none !important;
    opacity: 0;
}

#pagination {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 16px; /* sit at bottom side for easy thumb access on mobile */
    margin: 0 auto;
    width: 100%;
    max-width: calc(100% - 40px); /* keep some horizontal padding */
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 8px 12px;
    z-index: 18;
    transition: opacity 0.25s;
    pointer-events: auto;
    /* allow wrapping and scrolling to avoid overflow when many pages exist */
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    align-content: center;
    backdrop-filter: blur(6px);
    border-radius: 999px;
}

#pagination.hidden {
    display: none;
    opacity: 0;
}

/* ensure page buttons don't shrink and remain tappable */
.page-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: white;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: 18px;
    cursor: pointer;
    font-weight: 700;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex: 0 0 auto; /* prevent shrinking */
    white-space: nowrap;
    box-sizing: border-box;
    transition: transform 0.12s ease;
}

.page-btn.active {
    background: var(--accent);
    border-color: white;
    box-shadow: 0 0 10px var(--accent);
}

#app-title {
    color: var(--ui-text);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: none;
    margin-bottom: 6px;
    text-shadow: 0 0 8px rgba(255,255,255,0.06);
    pointer-events: none;
    opacity: 0.95;
}

/* reduced frequency label size and slightly lifted so title sits above it */
#freq-display {
    color: var(--ui-text);
    font-size: 1.0rem; /* reduced from 1.2rem */
    font-weight: 400;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.22);
    margin-top: 2px;
}

/* Play/Pause autoplay button: match round toggle design used elsewhere (left-toggle style) */
#playpause-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 101;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    border: none;
    color: white;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s;
    backdrop-filter: blur(5px);
}
#playpause-btn:hover { transform: translateY(-3px); background: rgba(255,255,255,0.12); }
#playpause-btn:active { transform: scale(0.98); }
/* active state */
#playpause-btn.active { background: var(--accent); box-shadow: 0 8px 20px rgba(0,0,0,0.35); color: #fff; }

/* Melody button: same round style as play/pause but slightly lower */
#melody-btn {
    position: absolute;
    top: 80px; /* placed beneath the play button */
    left: 20px;
    z-index: 101;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: none;
    color: white;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s;
    backdrop-filter: blur(5px);
}
#melody-btn:hover { transform: translateY(-3px); background: rgba(255,255,255,0.12); }
#melody-btn:active { transform: scale(0.98); }
#melody-btn.active { background: var(--accent); box-shadow: 0 8px 20px rgba(0,0,0,0.35); color: #fff; }

#settings-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

/* Waveform-toggle (left) mirrors settings look */
.left-toggle, #waveform-toggle, #controls-toggle {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    background: rgba(255,255,255,0.08);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

/* place controls-toggle slightly right so it doesn't overlap waveform button */
#controls-toggle { left: 76px; z-index: 9999; pointer-events: auto; }

/* Move controls toggle to bottom-left so it's visible and reachable on mobile */
#controls-toggle {
    top: auto;
    bottom: 20px;
    left: 20px;
    z-index: 9999; /* ensure the controls selector sits above all other UI layers */
    pointer-events: auto;
}

/* Preset manager button: match the round toggle style and sit above character controls in bottom-left */
.preset-toggle {
    /* keep explicit absolute positioning so inline top/left overrides won't accidentally re-locate the button */
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    transition: transform 0.12s ease, background 0.12s;
}

/* preserve inline location override but ensure consistent hover/active states */
.preset-toggle:hover { transform: translateY(-3px); background: rgba(255,255,255,0.12); }
.preset-toggle:active { transform: scale(0.98); }

/* Mobile: hide the controls bar by default and show the controls toggle */
@media (max-width: 900px), (max-height: 700px) {
    #controls { display: none !important; pointer-events: none; opacity: 0; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s; }
    #controls-toggle { display: flex; }
    /* when container has .controls-visible, reveal controls */
    #container.controls-visible #controls { display: flex !important; pointer-events: auto; opacity: 1; transform: translateY(0); }

    /* When controls are visible, hide the quick action buttons to avoid overlap and accidental taps.
       Also hide the controls-toggle and camera button so the UI is focused on the controls panel. */
    #container.controls-visible #randomize-toggle,
    #container.controls-visible #preset-manager-toggle,
    #container.controls-visible #waveform-toggle,
    #container.controls-visible #settings-toggle,
    #container.controls-visible #audiofx-toggle,
    #container.controls-visible #playpause-btn,
    #container.controls-visible #melody-btn,
    #container.controls-visible #camera-btn,
    #container.controls-visible #controls-toggle,
    #container.controls-visible .preset-toggle {
        display: none !important;
        pointer-events: none !important;
        opacity: 0 !important;
    }
}

/* ensure desktop keeps existing behavior */
@media (min-width: 901px) {
    #controls { display: flex; opacity: 1; pointer-events: auto; transform: none; }
}

/* Audio FX modal: ensure it is centered, fully on-screen and above other modals */
#audiofx-modal {
    position: fixed;
    inset: 0; /* top:0; right:0; bottom:0; left:0; */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 230; /* above settings/waveform modals */
    background: rgba(0,0,0,0.6);
    pointer-events: auto;
    transition: opacity 180ms ease, visibility 180ms ease;
    padding: 16px;
    box-sizing: border-box;
}
#audiofx-modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* inner modal content for audiofx matches visual language but with a slightly larger max width */
#audiofx-modal .modal-content {
    width: 94%;
    max-width: 520px;
    padding: 18px;
    border-radius: 14px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

/* Waveform modal uses same structure as settings */
#waveform-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s;
}
#waveform-modal.hidden { display: none; opacity: 0; }

/* Preset Manager modal: ensure it is centered, reachable and above other modals */
#preset-modal {
    position: fixed;
    inset: 0; /* shorthand for top:0; right:0; bottom:0; left:0; */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 205; /* sit above waveform/settings but below audiofx */
    background: rgba(0,0,0,0.6);
    pointer-events: auto;
    transition: opacity 180ms ease, visibility 180ms ease;
    padding: 16px;
    box-sizing: border-box;
}
#preset-modal.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}
#preset-modal .modal-content {
    width: 94%;
    max-width: 560px; /* wider to accommodate preset list without horizontal overflow */
    padding: 16px;
    border-radius: 14px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.wave-choice {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: #fff;
    padding: 10px;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
}
.wave-choice:hover { background: rgba(255,255,255,0.04); transform: translateY(-3px); }

#settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s;
}

/* Melody scale modal: ensure it is centered, above other modals, and keyboard/touch accessible.
   Use similar visual language as other modals but with its own stacking so it doesn't get hidden. */
#melody-scale-modal {
    position: fixed;
    inset: 0; /* shorthand for top:0; right:0; bottom:0; left:0; */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 210; /* higher than settings/waveform modals */
    background: rgba(0,0,0,0.55);
    transition: opacity 220ms ease, visibility 220ms ease;
    pointer-events: auto;
}

/* keep modal hidden when .hidden applied */
#melody-scale-modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* inner modal content sizing override (matches other .modal-content but with safe max-width for mobile) */
#melody-scale-modal .modal-content {
    width: 92%;
    max-width: 420px;
    padding: 14px;
    box-sizing: border-box;
    border-radius: 14px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    -webkit-overflow-scrolling: touch;
}

/* ensure the modal receives focus outline-friendly styles for keyboard navigation */
#melody-scale-modal .modal-content:focus {
    outline: 3px solid rgba(255,255,255,0.06);
    outline-offset: 4px;
}

/* Playback options modal: ensure it is centered, above other modals and reachable on all viewports.
   Provide a safe max-width, consistent modal-content styles and a slightly stronger backdrop so it can't render off-screen. */
#playback-modal {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 215; /* above melody/settings/waveform modals */
    background: rgba(0,0,0,0.6);
    pointer-events: auto;
    transition: opacity 180ms ease, visibility 180ms ease;
}

/* keep modal hidden when .hidden applied */
#playback-modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* ensure the playback modal content follows the app modal visual language and fits small screens */
#playback-modal .modal-content {
    width: 94%;
    max-width: 480px;
    padding: 14px;
    box-sizing: border-box;
    border-radius: 14px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    -webkit-overflow-scrolling: touch;
    transform: translateY(0);
}

#settings-modal.hidden {
    display: none;
    opacity: 0;
}

/* Generic hidden utility to consistently hide elements when .hidden is applied */
.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* Capture options modal styling (keeps it hidden unless explicitly shown) */
#capture-options-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 210;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.2s ease;
}
#capture-options-modal .modal-content {
    background: #111;
    padding: 16px;
    border-radius: 16px;
    width: 92%;
    max-width: 420px;
    box-sizing: border-box;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.06);
}
#capture-options-modal.hidden {
    display: none !important;
    opacity: 0;
}

.modal-content {
    background: #1a1a2e;
    padding: 20px;
    border-radius: 24px;
    width: 80%;
    max-width: 320px;
    max-height: 80vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    color: white;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Small top-right close button for modal */
.modal-close-x {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.05rem;
    line-height: 1;
    backdrop-filter: blur(4px);
}
.modal-close-x:hover {
    background: rgba(255,255,255,0.04);
    transform: translateY(-2px);
}
.modal-close-x:active { transform: scale(0.98); }

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
}

.hint {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 20px;
}

#close-settings {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    border: none;
    color: white;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
}

/* Switch Styles */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #333;
  transition: .4s;
  border-radius: 34px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}
input:checked + .slider { 
    /* force switches to use the unified dark-blue active gradient */
    background: linear-gradient(180deg, #072241 0%, #12375a 100%);
}
input:checked + .slider:before { transform: translateX(26px); }

#controls {
    position: absolute;
    bottom: 32px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    z-index: 99999;
    padding: 6px 10px;
    box-sizing: border-box;
    /* increased max-height so more rows (≈8 rows on many viewports) can be shown without clipping */
    max-height: 72vh;
    overflow-y: auto;  /* allow scrolling when many buttons */
    gap: 6px;
    /* subtle interior gradient to hint there is more content to scroll */
    background-image: linear-gradient(to top, rgba(0,0,0,0.22), rgba(0,0,0,0.06));
    /* make scrollbar thin and visible on supported browsers */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
    -webkit-overflow-scrolling: touch;
}

/* WebKit scrollbar styling for a light scroll indicator */
#controls::-webkit-scrollbar { width: 8px; height: 8px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.06));
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.25);
}

/* top/bottom shadow hints that appear only when the content is actually scrollable */
#controls.scroll-hint-top::before,
#controls.scroll-hint-bottom::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 18px;
    pointer-events: none;
    z-index: 999999;
}
#controls.scroll-hint-top::before {
    top: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.28), rgba(0,0,0,0));
}
#controls.scroll-hint-bottom::after {
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.28), rgba(0,0,0,0));
}

.osc-button {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background-color: var(--control-bg);
    color: var(--control-color);
    margin: 6px;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    box-sizing: border-box;
    backdrop-filter: blur(8px);
    flex: 0 0 auto; /* prevent shrinking/stretching when container scrolls */
}

.osc-button.hidden {
    display: none;
}

.osc-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-5px);
}

.osc-button.active {
    background-color: var(--control-active-bg);
    color: white;
    transform: scale(1.15) translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2), 0 0 30px var(--control-active-bg);
}

.osc-button svg {
    width: 100%;
    height: 100%;
}

/* Color overrides */
.osc-button[data-type="sine"].active { --control-active-bg: #4285F4; }
.osc-button[data-type="triangle"].active { --control-active-bg: #E91E63; } /* triangle -> pink */
.osc-button[data-type="sawtooth"].active { --control-active-bg: #FFEB3B; } /* sawtooth -> yellow */
.osc-button[data-type="square"].active { --control-active-bg: #34A853; } /* square -> green */
.osc-button[data-type="rectangle"].active { --control-active-bg: #FF6D00; }
.osc-button[data-type="noise"].active { --control-active-bg: #9C27B0; }
.osc-button[data-type="pulse"].active { --control-active-bg: #E91E63; }
.osc-button[data-type="organ"].active { --control-active-bg: #00BCD4; }
.osc-button[data-type="fm"].active { --control-active-bg: #7C4DFF; }
.osc-button[data-type="bit"].active { --control-active-bg: #00E676; }
.osc-button[data-type="super"].active { --control-active-bg: #FFFFFF; color: #000; }
.osc-button[data-type="kick"].active { --control-active-bg: #FFEB3B; color: #000; }
.osc-button[data-type="snare"].active { --control-active-bg: #FF5722; }
.osc-button[data-type="hihat"].active { --control-active-bg: #00E5FF; color: #000; }
.osc-button[data-type="groove"].active { --control-active-bg: #76FF03; color: #000; }

@media (max-height: 600px) {
    #controls { bottom: 10px; max-height: 40vh; padding: 6px 8px; }
    .osc-button { width: 40px; height: 40px; padding: 6px; margin: 4px; border-radius: 12px; }
}

/* Achievements styles */
#achievements-list {
    padding: 6px;
}
.achievement {
    display:flex;
    gap:8px;
    align-items:center;
    padding:8px;
    border-radius:8px;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.03);
    color: var(--ui-text);
    font-size:0.9rem;
}
.achievement.unlocked {
    background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
    box-shadow: 0 4px 14px rgba(0,0,0,0.45), 0 0 8px rgba(255,255,255,0.02) inset;
    color: white;
}
.achievement .dot {
    width:14px; height:14px; border-radius:50%; flex:0 0 14px;
    background: rgba(255,255,255,0.06);
}
.achievement.unlocked .dot {
    box-shadow: 0 0 10px var(--accent);
    background: var(--accent);
}
.achievement .meta { opacity: 0.65; font-size:0.8rem; }

/* Disable mobile/webkit tap highlight and remove focus/press outlines on primary UI buttons */
button,
.left-toggle,
#settings-toggle,
#randomize-toggle,
.page-btn,
.osc-button {
    -webkit-tap-highlight-color: transparent;
    outline: none;
    box-shadow: none;
}

/* ensure focus and active states do not add browser-specific highlights */
button:focus,
.left-toggle:focus,
#settings-toggle:focus,
#randomize-toggle:focus,
.page-btn:focus,
.osc-button:focus,
button:active,
.left-toggle:active,
#settings-toggle:active,
#randomize-toggle:active,
.page-btn:active,
.osc-button:active {
    outline: none;
    box-shadow: none;
}

/* Randomize button styling: mirrors other round toggles but positioned bottom-right */
#randomize-toggle {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    background: rgba(255,255,255,0.08);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#randomize-toggle:active { transform: scale(0.96); }
#randomize-toggle:hover { box-shadow: 0 6px 18px rgba(0,0,0,0.35); }

/* Small numeric badge for oscillator buttons (hidden) */
.osc-button {
    position: relative;
}

/* footer credit */
#app-footer {
    position: absolute;
    bottom: 8px;
    left: 12px;
    right: 12px;
    text-align: center;
    z-index: 120;
    color: rgba(255,255,255,0.55);
    font-size: 0.8rem;
    pointer-events: auto;
}
#app-footer a { color: inherit; text-decoration: underline; }

/* Recording timer shown above camera button while video recording is active */
#record-timer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 96px; /* positioned above the camera button (camera bottom is 40px) */
    z-index: 140;
    min-width: 56px;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(0,0,0,0.7);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    text-align: center;
    box-shadow: 0 8px 20px rgba(0,0,0,0.45);
    pointer-events: none;
}

/* Camera capture button centered above footer */
#camera-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 40px; /* sits just above footer */
    z-index: 130;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    backdrop-filter: blur(6px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
#camera-btn:active { transform: translateX(-50%) scale(0.96); }
#camera-btn svg { pointer-events: none; width: 18px; height: 18px; color: inherit; }
/* Hide numeric badges visually but keep DOM elements for possible future use */
.osc-button .osc-index {
    display: none;
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 10px rgba(0,0,0,0.45);
    pointer-events: none;
    z-index: 5;
}
.osc-button .osc-index.small {
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    font-size: 0.65rem;
}

/* Force a consistent dark-blue active style across the UI so randomization won't change active tint.
   This overrides the per-type --control-active-bg color rules and makes switches/sliders match. */
.osc-button.active,
.page-btn.active,
#playpause-btn.active,
#melody-btn.active,
.left-toggle.active,
button.active {
    background: linear-gradient(180deg, #072241 0%, #12375a 100%) !important;
    color: #ffffff !important;
    border-color: rgba(255,255,255,0.06) !important;
    box-shadow: 0 10px 24px rgba(18,55,90,0.35), 0 0 28px rgba(9,28,52,0.25) !important;
    transform: scale(1.08) translateY(-4px) !important;
}

/* Ensure page button active state uses same dark-blue gradient */
.page-btn.active {
    background: linear-gradient(180deg, #072241 0%, #12375a 100%) !important;
    border-color: rgba(255,255,255,0.08) !important;
    box-shadow: 0 6px 18px rgba(18,55,90,0.28) !important;
}

/* Switch slider and small toggle visuals: tighten to dark-blue for checked state */
.switch input:checked + .slider {
    background: linear-gradient(180deg, #072241 0%, #12375a 100%) !important;
    box-shadow: 0 6px 16px rgba(18,55,90,0.28);
}

/* Radio/selected-like controls which used --accent should also prefer the dark-blue active */
:root {
    --active-dark-1: #072241;
    --active-dark-2: #12375a;
}

/* Ensure any remaining uses of var(--accent) for active UI won't override the dark-blue look in practice */
.osc-button.active svg,
.page-btn.active,
.left-toggle.active svg {
    color: #fff !important;
    filter: none !important;
}

/* Confirmation modals (preset delete / reset) — ensure they center, cover viewport and are accessible */
#confirm-delete-modal,
#confirm-reset-modal {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 220; /* above most UI but below audiofx which intentionally uses 230 */
    background: rgba(0,0,0,0.55);
    pointer-events: auto;
    padding: 18px;
    box-sizing: border-box;
    transition: opacity 180ms ease, visibility 180ms ease;
}

/* keep hidden behavior consistent with other modals */
#confirm-delete-modal.hidden,
#confirm-reset-modal.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* inner content sizing tuned for these confirm dialogs so they never overflow on narrow screens */
#confirm-delete-modal .modal-content,
#confirm-reset-modal .modal-content {
    width: 94%;
    max-width: 480px;
    padding: 16px;
    border-radius: 12px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    box-sizing: border-box;
    max-height: 80vh;
    overflow: auto;
}

/* Import result modal: ensure it is fully centered, above other modals and not clipped on the right;
   also close other modals before showing it to guarantee proper stacking. */
#import-result-modal {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 240; /* higher than other modals to avoid clipping/overlap */
    background: rgba(0,0,0,0.7);
    pointer-events: auto;
    padding: 18px;
    box-sizing: border-box;
    transition: opacity 160ms ease, visibility 160ms ease;
}
#import-result-modal.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}
#import-result-modal .modal-content {
    width: 94%;
    max-width: 520px; /* allow slightly wider modal so content doesn't get cut on narrow viewports */
    padding: 16px;
    border-radius: 12px;
    background: #11171f;
    border: 1px solid rgba(255,255,255,0.06);
    color: white;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    max-height: 86vh;
    overflow: auto;
}