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

body {
    font-family: 'Inter', sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    user-select: none; /* Disable text selection on drag */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: #2a2a2a;
    border-bottom: 1px solid #404040;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ui-toggles {
    display: flex;
    gap: 5px;
    padding-right: 10px;
    margin-right: 5px;
    border-right: 1px solid #404040;
}

.timeline-toggle-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-mini {
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1;
    min-width: 0;
}

.ui-toggles .btn {
    padding: 6px 12px;
    font-size: 13px;
}

/* Subtle watermark near the title */
.watermark {
    color: #2b2b2b; /* one hex step from #2a2a2a */
    margin-left: 8px;
    font-size: 16px;
    font-weight: 500;
    user-select: none;
    pointer-events: none;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebars */
.sidebar {
    background: #2a2a2a;
    border-right: 1px solid #404040;
    padding: 20px;
    overflow-y: auto;
    transition: width 0.3s ease, padding 0.3s ease, opacity 0.3s ease; /* Smooth transition for hiding */
    display: flex; /* New */
    flex-direction: column; /* New */
}

.sidebar-left {
    width: 250px;
}

.sidebar-right {
    width: 280px;
    border-left: 1px solid #404040;
    border-right: none;
}

/* New styles for hidden sidebars */
.sidebar.hidden {
    width: 0;
    padding: 20px 0;
    opacity: 0;
    overflow: hidden;
}

.sidebar h3 {
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 500;
}

/* New: Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid #404040;
    margin: -20px -20px 20px -20px; /* Extend to edges of sidebar padding */
    padding: 0 20px;
}

.tab-btn {
    padding: 10px 15px;
    cursor: pointer;
    border: none;
    background: none;
    color: #999;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: #fff;
}

.tab-btn.active {
    color: #fff;
    border-bottom-color: #ffffff;
}

.tab-panel {
    display: none;
    flex: 1; /* Allow panel to fill remaining space */
    min-height: 0; /* Necessary for overflow to work in flexbox */
    flex-direction: column; /* For potential internal scrolling */
}

.tab-panel.active {
    display: flex;
}

/* Make asset grid scrollable within its panel */
#assets-panel .assets-grid {
    flex: 1;
    overflow-y: auto;
}

/* New: Audio Panel Styles */
#audio-info {
    margin-top: 20px;
    padding: 15px;
    background: #1f1f1f;
    border-radius: 4px;
    border: 1px solid #404040;
}

#audio-info p {
    font-size: 13px;
    line-height: 1.5;
    word-break: break-all;
}

#audio-info p strong {
    color: #ccc;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    background: #1a1a1a;
    display: flex;
    align-items: center; /* Keep vertical centering */
    justify-content: flex-start; /* Align canvas to the left */
    position: relative;
    overflow: hidden;
}

/* Full-preview mode: make canvas area cover the entire viewport */
.canvas-container.preview-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
}

#main-canvas {
    background-image: 
        linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333),
        linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    background-color: #2a2a2a;
    border: 1px solid #404040;
}

/* New: Countdown overlay */
.countdown-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 15vw; /* Responsive font size */
    font-weight: bold;
    color: rgba(255, 255, 255, 0.9);
    z-index: 100;
    pointer-events: none; /* Make sure it doesn't block canvas interactions */
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
}

/* Assets Grid */
.assets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); /* smaller asset cells */
    gap: 10px;
    margin-top: 12px;
    align-content: start; /* keep rows tight at top */
}

.asset-thumbnail {
    width: 100%;
    height: 0;               /* enforce square cells */
    padding-bottom: 100%;    /* 1:1 ratio */
    background: #404040;
    border-radius: 4px;
    display: block;
    position: relative;      /* for absolute img */
    overflow: hidden;
    cursor: grab;
    min-height: 64px; /* ensure thumbnails render reasonably small */
}

.asset-thumbnail:active {
    cursor: grabbing;
}

.asset-thumbnail img {
    position: absolute;
    inset: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    object-fit: contain;
    display: block;
    z-index: 1; /* Ensure image is below the delete button */
}

/* Timeline */
.timeline-container {
    background: #2a2a2a;
    border-top: 1px solid #404040;
    height: 200px;
    display: flex;
    flex-direction: column;
    transition: height 0.12s ease, opacity 0.12s ease;
}

/* New style for hidden timeline */
.timeline-container.hidden {
    height: 0;
    opacity: 0;
    overflow: hidden;
}

.timeline-controls {
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #404040;
    justify-content: space-between; /* To push duration input to the right */
}

.timeline-duration-input {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto; /* Push to the right */
}

.timeline-duration-input label {
    font-size: 14px;
    color: #ccc;
    user-select: none;
}

.timeline-duration-input input {
    width: 60px;
    padding: 4px 6px;
    user-select: text; /* Allow selection within input */
}

.timeline-content {
    flex: 1;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    scrollbar-width: none;
}
.timeline-content::-webkit-scrollbar { display: none; }

.time-ruler {
    height: 30px;
    background: #333;
    border-bottom: 1px solid #404040;
    position: relative;
    min-width: 100%; /* Ensure ruler doesn't shrink */
    flex-shrink: 0;
}

/* New: Audio Track Container */
.audio-track-container {
    height: 60px; /* Corresponds to wavesurfer height */
    background: #222;
    border-bottom: 1px solid #404040;
    position: relative;
    min-width: 100%;
    flex-shrink: 0;
}

.tracks-container {
    flex: 1;
    background: #1a1a1a;
    min-width: 100%; /* Ensure tracks container doesn't shrink */
    overflow-y: auto;
}

.playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ff4757;
    left: 0;
    pointer-events: none;
    z-index: 10;
}

.track {
    height: 40px;
    border-bottom: 1px solid #333;
    position: relative;
    display: flex;
    align-items: center;
    padding-left: 130px; /* Make space for object label and button */
    font-size: 12px;
    min-width: fit-content; /* Allow tracks to extend horizontally */
}

.track-label-container { /* New container for label and button */
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 120px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    gap: 8px; /* Space between label and button */
}

.track span { /* Object label */
    user-select: none;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Renamed from .timeline-change-indicator to reflect new purpose */
.timeline-keyframe-marker { 
    position: absolute;
    width: 8px; /* Bigger markers */
    height: 8px;
    background: #ffa502; /* Default linear interpolation color */
    border-radius: 50%; /* Circle shape */
    cursor: grab;
    transform: translate(-50%, 10px); /* Move lower, 10px from track top to avoid text overlap */
    z-index: 5; /* Ensure markers are above track background */
}

/* State change markers (distinct shape/color) */
.timeline-state-marker {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 10px solid #00d1ff; /* cyan for state change */
    transform: translate(-50%, 0px);
    cursor: default;
    z-index: 6;
}

/* Context menus share base style */
.context-menu {
    position: fixed;
    background: #2a2a2a;
    border: 1px solid #404040;
    border-radius: 8px;
    z-index: 1400;
    min-width: 180px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.context-menu ul { list-style: none; padding: 6px; }
.context-menu li {
    padding: 8px 10px;
    font-size: 13px;
    color: #ddd;
    cursor: pointer;
    border-radius: 6px;
}
.context-menu li:hover { background: #3a3a3a; }

/* States list items include inline thumbnails */
#states-context-menu ul {
    max-height: 240px;
    overflow-y: auto;
}
#states-context-menu li {
    display: flex;
    align-items: center;
    gap: 8px;
}
#states-context-menu img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1f1f1f;
}

/* Optional: Style for 'hold' keyframes */
.timeline-keyframe-marker.keyframe-hold {
    background: #6c5ce7; /* Different color for hold interpolation */
    border-radius: 2px; /* Square shape for hold */
    transform: translate(-50%, 10px) rotate(45deg); /* Diamond shape */
}

/* New: Style for 'none' keyframes */
.timeline-keyframe-marker.keyframe-none {
    background: #ff6b81; /* Distinct color for none interpolation */
    border-radius: 0; /* Square shape */
    transform: translate(-50%, 10px); /* Regular square */
}

/* New: timeline resize handle */
.timeline-resize-handle {
    height: 6px;
    background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.12));
    cursor: ns-resize;
    width: 100%;
    position: relative;
    z-index: 8;
}

.timeline-container.hidden .timeline-resize-handle {
    display: none;
}

/* New: Layers panel styles */
.layers-panel {
    position: absolute;
    right: 12px;
    bottom: 220px; /* above timeline */
    width: 320px;
    max-height: 48vh;
    background: #2a2a2a;
    border: 1px solid #404040;
    border-radius: 8px;
    z-index: 1300;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

.layers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #404040;
}

.layers-list {
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column; /* top-most layer shown at the top */
    gap: 8px;
}

.layers-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px 10px;
    border-top: 1px solid #404040;
}

/* Shown when there are no layers in the panel */
.layers-empty {
    padding: 8px;
    font-size: 13px;
    color: #bbb;
    text-align: center;
}

.layer-item {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #1f1f1f;
    border: 1px solid #333;
    padding: 6px;
    border-radius: 6px;
    cursor: grab;
}

.layer-item:active {
    cursor: grabbing;
}

.layer-thumb {
    width: 52px;
    height: 32px;
    background: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 4px;
    flex-shrink: 0;
}

.layer-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.layer-meta {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.layer-filename {
    font-size: 13px;
    color: #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* Small arrow buttons */
.layer-btn {
    background: #404040;
    color: #fff;
    border: none;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* Buttons */
.btn, .modal-content, .sidebar, .timeline-container, .floating-controls {
    border-radius: 10px;
}

.btn {
    background: #404040;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background 0.2s;
    user-select: none;
}

.btn:hover {
    background: #505050;
}

.btn-primary {
    background: #ffffff;
    color: #1a1a1a;
}

.btn-primary:hover {
    background: #ffffff;
    opacity: 0.9;
}

.btn-secondary {
    background: #636e72;
}

.btn-secondary:hover {
    background: #707a7e;
}

.btn.record-btn.recording {
    background-color: #e74c3c;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
    }
}

.full-width {
    width: 100%;
}

/* This class is now used differently, see .sidebar.hidden and .timeline-container.hidden */
#properties-panel.hidden {
    width: 0;
    padding: 20px 0;
    opacity: 0;
    overflow: hidden;
}

/* New: Dropdown for viewport settings */
.dropdown-container {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #333;
    min-width: 240px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.5);
    z-index: 1;
    border-radius: 4px;
    padding: 12px 16px;
    border: 1px solid #404040;
}

/* Re-using property-group styles for consistency */
.dropdown-content .property-group {
    margin-bottom: 10px;
}
.dropdown-content .property-group label {
    font-size: 14px;
    color: #ccc;
    display: block;
    margin-bottom: 5px;
}
.dropdown-content .input-group {
    display: flex;
    gap: 8px;
}
.dropdown-content .input-group input {
    width: 100%;
    background: #404040;
    border: 1px solid #555;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
}

.modal-content {
    background: #2a2a2a;
    margin: 10% auto;
    width: 500px;
    border-radius: 8px;
    border: 1px solid #404040;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #404040;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #404040;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.close {
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: white;
}

.export-option {
    margin-bottom: 15px;
}

.export-option label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 500;
    user-select: none;
}

.export-option select,
.export-option input {
    background: #404040;
    border: 1px solid #555;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    width: 100%;
    user-select: text;
}

/* Progress */
.progress-container {
    padding: 20px;
    border-top: 1px solid #404040;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #404040;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: #ffffff;
    width: 0%;
    transition: width 0.3s;
}

.progress-text {
    text-align: center;
    font-size: 14px;
    color: #ccc;
    user-select: none;
}

/* New style for the tiny clear frames button */
.btn-tiny.clear-frames-btn {
    background: #444;
    color: #ccc;
    border: 1px solid #555;
    padding: 2px 5px;
    font-size: 12px;
    border-radius: 3px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.5; /* Hidden by default */
    transition: background 0.2s, opacity 0.2s;
}

.track:hover .btn-tiny.clear-frames-btn {
    opacity: 1; /* Show on track hover */
}

.btn-tiny.clear-frames-btn:hover {
    background: #e74c3c;
    color: white;
    border-color: #c0392b;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar-left {
        width: 200px;
    }
    .sidebar-right {
        width: 240px;
    }
}

/* New: Floating persistent controls */
.floating-controls {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 1200;
    background: rgba(40,40,40,0.95);
    border: 1px solid #404040;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
    box-shadow: 0 6px 18px rgba(0,0,0,0.6);
}

/* Ensure small buttons look good in floating panel */
.floating-controls .btn {
    padding: 6px 10px;
    font-size: 14px;
}

/* Make the floating controls draggable via the time label */
#floating-current-time {
    cursor: move;
    user-select: none;
}

/* New: Timeline scrubber styles */
.timeline-scrubber {
    height: 24px;
    padding: 6px 16px 10px;
    background: #26262a;
    border-top: 1px solid #3a3a3a;
}

.scrubber-track {
    position: relative;
    height: 6px;
    background: #3a3a3a;
    border-radius: 999px;
}

.scrubber-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    cursor: grab;
}

.asset-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    color: #1a1a1a;
    font-size: 14px;
    cursor: pointer;
    z-index: 2; /* Place button above the image */
}