* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --accent: #f97316;
    --accent-light: #fb923c;
    --accent-dark: #ea580c;
    --bg-dark: #0f0f1a;
    --bg-mid: #1a1a2e;
    --bg-light: #16213e;
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 50%, var(--bg-light) 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Layout */
#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 360px;
    min-width: 360px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.site-logo {
    display: inline-block;
    margin-bottom: 8px;
}

.site-logo img {
    height: 24px;
    width: auto;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* TXD Button Loaded State */
#loadTxdBtn.loaded {
    background: rgba(74, 222, 128, 0.15);
    border-color: #4ade80;
    color: #4ade80;
}

#loadTxdBtn.loaded:hover {
    background: rgba(74, 222, 128, 0.25);
}

/* Search */
.search-box {
    flex: 1;
    min-width: 120px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.search-box::placeholder {
    color: var(--text-muted);
}

.search-box:focus {
    outline: none;
    border-color: var(--accent);
}

/* Systems List */
.systems-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-bottom: 1px solid var(--border);
}

.section-header {
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header .count {
    background: rgba(249, 115, 22, 0.2);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
}

.systems-list {
    flex: 1;
    overflow-y: auto;
    min-height: 150px;
    max-height: 300px;
}

.system-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.system-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.system-item.active {
    background: rgba(249, 115, 22, 0.15);
    border-left: 3px solid var(--accent);
}

.system-item .name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.system-item .prims {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Properties Panel */
.properties-section {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.property-group {
    border-bottom: 1px solid var(--border);
}

.property-group-header {
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.15);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.property-group-header:hover {
    background: rgba(0, 0, 0, 0.25);
}

.property-group-header .toggle {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.property-group.collapsed .toggle {
    transform: rotate(-90deg);
}

.property-group.collapsed .property-group-content {
    display: none;
}

.property-group-content {
    padding: 8px 16px;
}

.property-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.8rem;
}

.property-row .label {
    color: var(--text-secondary);
}

.property-row .value {
    color: var(--text-primary);
    font-family: monospace;
}

.property-input {
    width: 80px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: monospace;
    text-align: right;
}

.property-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Primitive Tabs */
.primitive-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.prim-tab {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.prim-tab:hover {
    background: rgba(255, 255, 255, 0.1);
}

.prim-tab.active {
    background: rgba(249, 115, 22, 0.2);
    border-color: var(--accent);
    color: var(--accent);
}

/* Info Blocks */
.info-block {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.info-header {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-light);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-header:hover {
    background: rgba(0, 0, 0, 0.3);
}

.info-content {
    padding: 8px 12px;
}

.info-block.collapsed .info-content {
    display: none;
}

/* Keyframe List */
.keyframe-list {
    margin-top: 4px;
}

.keyframe-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.75rem;
}

.keyframe-item .time {
    color: var(--text-muted);
    font-family: monospace;
    min-width: 50px;
}

.keyframe-item .key-input {
    width: 60px;
    padding: 3px 6px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: monospace;
}

.keyframe-item .key-input:focus {
    outline: none;
    border-color: var(--accent);
}

.add-key-btn {
    padding: 4px 8px;
    font-size: 0.7rem;
    margin-top: 4px;
}

/* Viewport */
.viewport {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0a0a12;
    position: relative;
}

.viewport-header {
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viewport-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.viewport-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.viewport-canvas {
    flex: 1;
    position: relative;
}

.viewport-canvas canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Playback Controls */
.playback-controls {
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.5);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.time-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    cursor: pointer;
}

.time-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.time-display {
    font-size: 0.8rem;
    font-family: monospace;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: right;
}

/* Playback Options */
.playback-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}

.repeat-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.repeat-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

.repeat-interval {
    width: 50px;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: monospace;
    text-align: center;
}

.repeat-interval:focus {
    outline: none;
    border-color: var(--accent);
}

.repeat-interval:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.interval-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: -4px;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

.speed-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.speed-slider {
    width: 60px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.speed-value {
    font-size: 0.7rem;
    font-family: monospace;
    color: var(--accent);
    min-width: 32px;
}

/* Trigger button highlight */
#triggerBtn {
    background: rgba(74, 222, 128, 0.15);
    border-color: #4ade80;
    color: #4ade80;
}

#triggerBtn:hover:not(:disabled) {
    background: rgba(74, 222, 128, 0.25);
}

#triggerBtn:disabled {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-light);
    color: var(--text-primary);
}

/* Drop Zone */
.drop-zone {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 18, 0.95);
    z-index: 10;
}

.drop-zone.hidden {
    display: none;
}

.drop-zone-content {
    text-align: center;
    padding: 40px;
    border: 2px dashed var(--border-light);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.drop-zone-content:hover,
.drop-zone.drag-over .drop-zone-content {
    border-color: var(--accent);
    background: rgba(249, 115, 22, 0.05);
}

.drop-zone h3 {
    margin: 16px 0 8px;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.drop-zone p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.drop-zone p.hint {
    font-size: 0.75rem;
    margin-top: 12px;
    padding: 6px 12px;
    background: rgba(249, 115, 22, 0.1);
    border-radius: 4px;
    color: var(--accent-light);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Utility */
.hidden {
    display: none !important;
}

/* Channel Row */
.channel-row {
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.channel-row:last-child {
    border-bottom: none;
}

.channel-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: capitalize;
}

/* Stats Bar */
.stats-bar {
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stats-bar span {
    color: var(--accent);
    font-weight: 600;
}

/* Blend Mode Labels */
.blend-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
}

/* Texture Preview */
.texture-preview {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--text-muted);
}

@media (max-width: 900px) {
    #app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .viewport {
        height: 50vh;
    }

    .systems-list {
        max-height: 150px;
    }
}
