* {
    box-sizing: border-box;
}

:root {
    --bg-color: #0d0e12;
    --panel-bg: #16181d;
    --text-primary: #ffffff;
    --text-secondary: #c7c7c7;
    --accent-color: #3b82f6;
    /* Blue for selection/active */
    --accent-hover: #2563eb;
    --border-color: #272b36;
    --ball-color: #1c2234;
    /* Red ball */
    --ghost-color: rgba(23, 51, 97, 0.25);
    /* Blue ghosts */
    --timeline-bg: #000000;
}

body {
    margin: 0;
    padding: 0;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100dvh;
    /* Dynamic height to avoid clipping by browser bars */
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    /* Allow scroll if content is too tall (mobile/tablet) */
}

.app-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* Grow to fill body min-height */
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
header {
    height: 100px;
    /* Reduced height for cleaner look */
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Space them out */
    padding: 0 2rem;
    flex-shrink: 0;
}

.header-content {
    text-align: left;
    /* Left align text */
}

.header-content h1 {
    margin: 0;
    font-weight: 700;
}

.header-content p {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.global-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Name Input Styling */
.name-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    /* Pill shape */
    padding: 0.4rem 0.8rem;
    margin: 0;
    /* Align left */
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
    width: 200px;
}

.name-input:focus {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.1);
}

.name-input:read-only {
    /* Look normal but uneditable */
    background: transparent;
    border-color: transparent;
    cursor: default;
    padding-left: 0;
    /* Remove padding to look like text */
    font-weight: 600;
}

.name-input:read-only:focus {
    border-color: transparent;
    outline: none;
    background: transparent;
}

/* Main Area */
main {
    flex: 1;
    display: flex;
    overflow: hidden;
    padding: 2rem;
}

.canvas-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    height: 100%;
}

.canvas-section {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #ec3482;
    position: relative;
    overflow: hidden;
}

canvas {
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    background-color: rgba(255, 255, 255, 0.02);
}

.frame-indicator {
    position: absolute;
    bottom: 20px;
    /* Moved to bottom-left */
    left: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    background: transparent;
    padding: 0;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through if needed */
}

/* Loop Button (Top Right) */
#btnLoop {
    top: 20px;
    right: 20px;
    left: auto;
}

/* Chart Button (Top Left) */
#btnChart {
    top: 20px;
    left: 20px;
    right: auto;
}

/* FPS Button (Bottom Right) */
#btnFps {
    bottom: 20px;
    right: 20px;
    top: auto;
    left: auto;
}

/* Onion Skin Button (Bottom Left) */
#btnOnion {
    bottom: 20px;
    left: 20px;
    top: auto;
    right: auto;
}

.loop-indicator {
    position: absolute;
    /* top/left/right set by ID above */
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

.loop-indicator.active {
    background-color: var(--accent-color);
    color: white;
}

/* Vertical Sliders - Ruler Style */
.slider-vertical-container {
    display: flex;
    justify-content: center;
    height: 600px !important;
    /* Force exact match to canvas */
    width: 60px;
    position: relative;
    flex-shrink: 0;
    /* Prevent shrinking */
    margin: 0;
    padding: 0;
}

.slider-vertical-container label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
    writing-mode: horizontal-tb;
    transform: none;

    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
}

.slider-vertical-container .value-readout {
    /* Re-add readout styling if it was missing or needs absolute positioning */
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--accent-color);
    min-width: 50px;
    text-align: center;

    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
}

.slider-vertical-container input[type=range] {
    writing-mode: vertical-lr;
    /* Keeps slider vertical in modern browsers */
    direction: rtl;
    width: 40px;
    /* Wider for ruler ticks */
    height: 600px !important;
    /* Force exact match */
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    margin: 0;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    display: block;
}

/* Invert Y-Position slider so Top = 0 (Min) and Bottom = 600 (Max) */
#yPosRange {
    transform: rotate(180deg);
}

/*
 * NOTE: Styling vertical ranges cross-browser is tricky.
 * Webkit vertical slider styling is limited.
 * We often need to treat it as a box or rely on defaults.
 * However, we can try to style the track if appearance is none.
 * 
 * Standard approach for custom vertical slider: 
 * transform: rotate(-90deg) is often more reliable for full styling,
 * but 'writing-mode: vertical-lr' is what we have.
 * 
 * Let's try to make it look clean with what we have.
 */

/* Track styling - Webkit */
.slider-vertical-container input[type=range]::-webkit-slider-runnable-track {
    width: 40px;
    border: none;
    border-radius: 0;

    /* Simple Dashes Design */
    background-color: transparent;
    background-image: repeating-linear-gradient(to bottom, var(--border-color) 0, var(--border-color) 1px, transparent 1px, transparent 20px);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

/* Highlight for Squash Slider: Blue dash at 1.0x (Value 1.0 in 0.5-2.0 range is 33.3% from bottom / 66.6% from top) */
#squashRange::-webkit-slider-runnable-track {
    background-image:
        linear-gradient(to bottom, transparent calc(66.66% - 1px), var(--accent-color) calc(66.66% - 1px), var(--accent-color) calc(66.66% + 1px), transparent calc(66.66% + 1px)),
        repeating-linear-gradient(to bottom, var(--border-color) 0, var(--border-color) 1px, transparent 1px, transparent 20px);
}

/* Thumb styling - Webkit */
.slider-vertical-container input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 50px;
    /* Spans full width + overlap */
    height: 4px;
    /* Thin line indicator */
    border-radius: 2px;
    background: var(--accent-color);
    /* Bright blue line */
    border: none;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
    margin-left: -5px;
    /* Center on 40px track: (40 - 50) / 2 = -5 */
    cursor: grab;
    transition: transform 0.1s;
}

.slider-vertical-container input[type=range]:active::-webkit-slider-thumb {
    transform: scaleY(2);
    cursor: grabbing;
}

/* Firefox styling */
.slider-vertical-container input[type=range]::-moz-range-track {
    width: 40px;
    border: none;
    border-radius: 0;
    background-color: transparent;
    background-image: repeating-linear-gradient(to bottom, var(--border-color) 0, var(--border-color) 1px, transparent 1px, transparent 20px);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.slider-vertical-container input[type=range]::-moz-range-thumb {
    width: 50px;
    height: 4px;
    border-radius: 2px;
    background: var(--accent-color);
    border: none;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
    cursor: grab;
}



/* Timeline / Footer */
footer {
    height: 140px;
    background-color: var(--panel-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Spread items */
    padding: 0 2rem;
    gap: 1rem;
}

/* Timeline Wrapper (Layout + Static Overlay) */
/* Timeline Wrapper (Layout + Static Overlay) */
.timeline-wrapper {
    flex: 1;
    /* Allow growing in center */
    margin: 0 1rem;
    /* Spacing from buttons */
    position: relative;
    /* Anchor for static highlight */
    overflow: hidden;
    /* Ensure content stays inside */
}

/* Timeline Container (Scrollable Area) */
.timeline-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
    cursor: grab;
    /* Indicate draggable */
    display: flex;
    /* Ensure strip is handled correctly */
}

.timeline-container:active {
    cursor: grabbing;
}

.timeline-container::-webkit-scrollbar {
    display: none;
}

/* Static Center Highlight Overlay - Attached to Wrapper */
.timeline-wrapper::after {
    content: '';
    position: absolute;
    left: 50%;
    top: calc(50% + 48px);
    /* 40px (half frame) + gap */
    transform: translate(-50%, -50%);
    width: 60px;
    /* Match frame width */
    height: 4px;
    /* Line thickness */
    background: var(--accent-color);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
    pointer-events: none;
    z-index: 10;
}

/* Icon Button (Play) */
.icon-btn {
    background: transparent;
    color: var(--accent-color);
    border: 2px solid var(--accent-color);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    transform: scale(1.05);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* The Strip of Frames */
.frames-strip {
    display: flex;
    gap: 8px;
    /* Large padding allows first/last frames to be centered */
    padding: 20px calc(50% - 30px);
    width: max-content;
    box-sizing: border-box;
    align-items: center;
}

.frame-box {
    width: 60px;
    height: 80px;
    box-sizing: border-box;
    /* Include border in 60px width */
    background-color: #000;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
    scroll-snap-align: center;
}

.frame-box.selected {
    /* No border, static highlight handles it */
    background-color: #1a1e26;
}

.frame-box.active-anim {
    /* State when playing animation */
    background-color: rgba(255, 255, 255, 0.15);
}



.mini-ball {
    width: 12px;
    height: 12px;
    background-color: var(--text-secondary);
    border-radius: 50%;
}

.frame-box.selected .mini-ball {
    background-color: var(--accent-color);
}

/* Controls Components */
button.primary-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    /* Pill shape */
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
}

button.primary-btn:hover {
    background-color: var(--accent-hover);
}

input[type=range] {
    width: 100%;
    background: transparent;
    appearance: none;
    /* Standard property */
    -webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    margin-top: -6px;
    cursor: pointer;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.toggle-switch input {
    display: none;
}

.slider {
    width: 32px;
    height: 18px;
    background-color: var(--border-color);
    border-radius: 18px;
    position: relative;
    transition: 0.3s;
}

.slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    opacity: 1;
}

/* -- Mobile / Responsive Styles -- */
@media (max-width: 768px) {

    /* Hide Header completely to save space */
    header {
        display: none !important;
    }

    /* Hide desktop sliders */
    .slider-vertical-container {
        display: none !important;
    }

    /* Center canvas and ensure generic corners for controls */
    .canvas-section {
        border-radius: 8px;
        /* Slightly smaller radius */
        margin: 0 auto;
        max-width: 100%;
        overflow: hidden;
        /* Prevent overflow */
    }

    /* Ensure controls in corners are visible/sized right */
    .loop-indicator,
    .frame-indicator {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    /* Footer Layout: Wrap contents. row 1=timeline, row 2=controls */
    footer {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 0;
        /* Control gap manually */
        height: auto;
        padding: 10px 5px;
    }

    /* Timeline takes full width at top */
    .timeline-wrapper {
        flex: 0 0 100%;
        width: 100%;
        order: 1;
        margin-bottom: 15px;
    }

    .timeline-container {
        width: 100%;
    }

    /* Playback controls side-by-side below */
    #btnPlayPause {
        order: 2;
        width: 48px;
        height: 48px;
        margin: 0 15px;
        /* Spacing between buttons */
    }

    /* Footer Controls Group (Undo/Redo + Onion Skin) */
    .footer-controls {
        order: 3;
        margin: 0 15px;
        /* Layout for Mobile: Side-by-Side */
        flex-direction: row !important;
        align-items: center;
        gap: 15px;
    }

    /* Ensure specific gap for mobile */
    .undo-redo-group {
        margin-bottom: 0 !important;
        /* Reset desktop margin */
    }

    /* Mobile File Dropdown */
    .mobile-file-dropdown {
        display: block !important;
        order: 4;
        width: 100%;
        margin-top: 10px;
        text-align: center;
    }

    .mobile-file-dropdown summary {
        color: var(--text-secondary);
        font-size: 0.9rem;
        cursor: pointer;
        list-style: none;
        /* Hide default arrow */
        padding: 5px;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        background: var(--panel-bg);
        width: fit-content;
        margin: 0 auto;
    }

    .mobile-file-dropdown summary::-webkit-details-marker {
        display: none;
    }

    .mobile-file-dropdown summary::after {
        content: " ▼";
        font-size: 0.8rem;
    }

    .mobile-file-dropdown[open] summary::after {
        content: " ▲";
    }

    .mobile-file-row {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
        flex-wrap: wrap;
    }

    .mobile-file-row .name-input {
        width: 150px;
    }
}

/* Default state: Hide mobile dropdown */
.mobile-file-dropdown {
    display: none;
}

/* Footer Controls Styling (Desktop Default) */
.footer-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* Align to right/center */
    gap: 8px;
}

.undo-redo-group {
    display: flex;
    gap: 8px;
    margin-bottom: 5px;
    /* Spacing above onion skin on desktop */
}

.icon-btn.small-btn {
    width: 32px;
    height: 32px;
    border-width: 1px;
}

.icon-btn.small-btn svg {
    width: 18px;
    height: 18px;
}

.icon-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.frame-number {
    position: absolute;
    bottom: 4px;
    /* Moved to bottom */
    left: 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    pointer-events: none;
    /* Prevent interference */
}

.duplicate-btn {
    position: absolute;
    top: 4px;
    left: 6px;

    font-size: 0.9rem;
    line-height: 1;
    color: var(--text-secondary);

    cursor: pointer;
    display: none;
    z-index: 10;
    font-weight: bold;
}

.duplicate-btn:hover {
    color: var(--accent-color);
    /* Blue for duplicate */
}

/* Delete Button (Top Right) */
.delete-btn {
    position: absolute;
    top: 4px;
    right: 6px;

    font-size: 0.9rem;
    /* Slightly larger than number for clickability */
    line-height: 1;
    color: var(--text-secondary);

    cursor: pointer;
    display: none;
    z-index: 10;
    font-weight: bold;
}

.delete-btn:hover {
    color: #ef4444;
    /* Red delete */
}

@media (hover: hover) {

    .frame-box:hover .delete-btn,
    .frame-box:hover .duplicate-btn {
        display: block;
    }
}

/* On Mobile/Touch, show buttons when selected */
.frame-box.selected .delete-btn,
.frame-box.selected .duplicate-btn {
    display: block;
}

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

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

/* Mode Toggle (Segmented Control) */
.mode-toggle {
    display: inline-flex;
    background: #1a1d23;
    border-radius: 20px;
    padding: 3px;
    /* margin-left: 15px; Removed for flex gap */
    vertical-align: middle;
    border: 1px solid var(--border-color);
}

.desktop-only {
    display: inline-flex;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }
}

.mode-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 16px;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}