:root {
    --accent: #10b981;
    --accent-hover: #059669;
    --bg-dark: #0f0f1a;
    --bg-sidebar: #1a1a2e;
    --bg-input: #252540;
    --border: #2d2d44;
    --border-light: #3d3d5c;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --text-muted: #666;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ==================== SIDEBAR ==================== */

#sidebar {
    width: 340px;
    min-width: 340px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#sidebar h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    color: #fff;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.site-logo {
    display: inline-block;
    margin-bottom: 12px;
}

.site-logo img {
    height: 24px;
    width: auto;
}

/* ==================== DROP ZONE ==================== */

.drop-zone {
    border: 2px dashed #4a4a6a;
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
    position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(16, 185, 129, 0.1);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone svg {
    color: var(--accent);
    margin-bottom: 10px;
}

.drop-zone p {
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.drop-zone .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ==================== FILE LIST ==================== */

.file-list {
    margin-bottom: 20px;
}

.file-list h3,
.anim-panel h3,
#controls h3,
.anim-info h3,
.export-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.file-label {
    color: var(--text-muted);
}

.file-name {
    color: #fff;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==================== TOOLBAR ==================== */

.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar .btn {
    flex: 1;
}

/* ==================== SEARCH ==================== */

.search-container {
    margin-bottom: 12px;
}

.search-container input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-container input:focus {
    border-color: var(--accent);
}

.search-container input::placeholder {
    color: var(--text-muted);
}

/* ==================== ANIMATION LIST ==================== */

.anim-panel {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.anim-panel h3 {
    display: flex;
    justify-content: space-between;
}

.anim-panel h3 span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

#anim-items {
    list-style: none;
    overflow-y: auto;
    max-height: 280px;
    background: var(--bg-input);
    border-radius: 8px;
}

#anim-items li {
    padding: 8px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#anim-items li:last-child {
    border-bottom: none;
}

#anim-items li:hover {
    background: #2d2d50;
}

#anim-items li.active {
    background: var(--accent);
    color: #000;
}

#anim-items li.active .anim-badges span {
    background: rgba(0, 0, 0, 0.2);
    color: #000;
}

.anim-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.anim-badges {
    display: flex;
    gap: 4px;
    margin-left: 8px;
    flex-shrink: 0;
}

.anim-badges span {
    font-size: 0.65rem;
    padding: 2px 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ==================== ACTION BUTTONS BAR ==================== */

.anim-actions {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.btn-icon {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.7rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.btn-icon:hover:not(:disabled) {
    background: #2d2d50;
    border-color: var(--border-light);
}

.btn-icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-icon.danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-icon svg {
    flex-shrink: 0;
}

/* Inline rename input */
.anim-name-input {
    background: var(--bg-dark);
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: var(--text-primary);
    font-size: 0.8rem;
    padding: 1px 4px;
    width: 100%;
    outline: none;
}

/* ==================== SECTIONS ==================== */

.section {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ==================== ANIMATION INFO ==================== */

.anim-info {
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
}

.anim-info h3 {
    margin-bottom: 10px;
}

.anim-info .btn-sm {
    margin-top: 10px;
    padding: 7px 12px;
    font-size: 0.8rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.85rem;
}

.info-label {
    color: var(--text-muted);
}

.info-row input[type="text"] {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 2px 6px;
    width: 140px;
    text-align: right;
    outline: none;
    transition: border-color 0.2s;
}

.info-row input[type="text"]:focus {
    border-color: var(--accent);
}

/* ==================== CONTROLS ==================== */

#controls h3 {
    margin-top: 16px;
}

#controls h3:first-child {
    margin-top: 0;
}

.current-anim {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.current-anim span {
    color: var(--accent);
    font-weight: 500;
}

.playback-controls {
    margin-bottom: 12px;
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.control-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.control-group input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    cursor: pointer;
    margin-top: 4px;
    background: var(--bg-input);
    padding: 4px;
}

.control-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.control-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.control-group input[type="range"] {
    width: calc(100% - 40px);
    margin-top: 4px;
    accent-color: var(--accent);
}

.control-group span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ==================== WEAPON PICKER ==================== */

.weapon-select {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.weapon-select:focus {
    border-color: var(--accent);
}

.weapon-select option,
.weapon-select optgroup {
    background: var(--bg-input);
    color: var(--text-primary);
}

.weapon-select optgroup {
    font-weight: 600;
    color: var(--accent);
}

.weapon-custom-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px dashed var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.weapon-custom-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.weapon-custom-hint {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.weapon-group-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.85rem;
}

.weapon-group-tag {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: 'SF Mono', Menlo, monospace;
}

.weapon-offsets {
    margin-top: 8px;
}

.weapon-offset-group {
    margin-bottom: 6px;
}

/* ==================== EXPORT SECTION ==================== */

.export-section {
    margin-bottom: 20px;
}

.export-section .control-group input[type="text"] {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    margin-top: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.export-section .control-group input[type="text"]:focus {
    border-color: var(--accent);
}

/* ==================== BUTTONS ==================== */

.btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn.secondary {
    background: var(--border-light);
    color: #fff;
    margin-top: 8px;
}

.btn.secondary:hover:not(:disabled) {
    background: #4d4d6c;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 2px 4px;
}

.btn-link:hover {
    text-decoration: underline;
}

/* ==================== CONTEXT MENU ==================== */

.context-menu {
    position: fixed;
    background: #252540;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 0;
    min-width: 160px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.context-menu button:hover {
    background: #2d2d50;
}

.context-menu button.danger {
    color: var(--danger);
}

.context-menu button.danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

.context-menu hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

/* ==================== MODALS ==================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 480px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-sm {
    width: 400px;
}

.modal h2 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.modal p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.import-subtitle {
    color: var(--accent);
    font-weight: 500;
}

.import-warnings {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    color: var(--warning);
    margin-bottom: 12px;
}

.modal-actions-top {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.import-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    max-height: 300px;
    background: var(--bg-input);
    border-radius: 8px;
    margin-bottom: 16px;
}

.import-list li {
    padding: 8px 12px;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.import-list li:last-child {
    border-bottom: none;
}

.import-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.import-list input[type="checkbox"] {
    accent-color: var(--accent);
    flex-shrink: 0;
}

.import-list .conflict {
    font-size: 0.7rem;
    color: var(--warning);
    margin-left: auto;
    flex-shrink: 0;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.modal-actions .btn {
    flex: 1;
    margin-top: 0;
}

.warnings-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.warnings-list li {
    padding: 6px 0;
    font-size: 0.8rem;
    color: var(--warning);
    border-bottom: 1px solid var(--border);
}

.warnings-list li:last-child {
    border-bottom: none;
}

/* ==================== VIEWPORT ==================== */

#viewport {
    flex: 1;
    position: relative;
    background: var(--bg-sidebar);
    min-height: 0;
}

#canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 26, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#stats {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(26, 26, 46, 0.9);
    padding: 8px 12px;
    border-radius: 6px;
}

/* ==================== EDITOR MODE ==================== */

.btn.accent {
    background: var(--accent);
    color: #000;
    font-weight: 600;
    border: none;
}

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

.btn.accent:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: default;
}

.btn.accent svg {
    vertical-align: -1px;
    margin-right: 2px;
}

.edit-mode-badge {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(245, 158, 11, 0.9);
    color: #000;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 3px 12px;
    border-radius: 4px;
    z-index: 10;
    pointer-events: none;
}

.bone-tooltip {
    position: fixed;
    background: rgba(26, 26, 46, 0.95);
    color: var(--text-primary);
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

/* Editor closed: hide timeline */
.timeline-panel.hidden {
    display: none !important;
}

.tl-close-btn {
    margin-left: 4px;
    color: var(--text-muted);
}

.tl-close-btn:hover {
    color: var(--danger);
}

/* ==================== KEYFRAME PROPERTIES ==================== */

.keyframe-props {
    padding: 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 8px 0;
}

.keyframe-props h3 {
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: #fff;
}

.kf-group {
    margin-top: 6px;
}

.kf-group-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: block;
    margin-bottom: 4px;
}

.kf-row {
    display: flex;
    gap: 4px;
}

.kf-row label {
    flex: 1;
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 3px;
}

.kf-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 3px 5px;
    font-size: 0.75rem;
    font-family: 'SF Mono', Menlo, monospace;
}

.kf-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ==================== TIMELINE ==================== */

.timeline-panel {
    height: 200px;
    min-height: 100px;
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tl-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 30px;
}

.tl-btn {
    font-size: 0.7rem;
    padding: 2px 6px;
    gap: 3px;
}

.tl-separator {
    width: 1px;
    height: 16px;
    background: var(--border);
    flex-shrink: 0;
}

.tl-time {
    font-size: 0.75rem;
    color: var(--accent);
    font-family: 'SF Mono', Menlo, monospace;
    min-width: 60px;
    text-align: center;
}

.tl-zoom-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    margin-left: auto;
}

.tl-zoom-label input[type="range"] {
    width: 80px;
    height: 14px;
    cursor: pointer;
}

.tl-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Labels are rendered on canvas — no separate DOM elements needed */

.tl-canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-width: 0;
}

.tl-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ==================== CREDITS ==================== */

.credits {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.credits a {
    color: var(--text-secondary);
    text-decoration: none;
}

.credits a:hover {
    color: var(--accent);
}

.credits a.author {
    color: var(--accent);
    font-weight: 500;
}

/* ==================== SCROLLBARS ==================== */

#sidebar::-webkit-scrollbar {
    width: 8px;
}

#sidebar::-webkit-scrollbar-track {
    background: var(--bg-sidebar);
}

#sidebar::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

#anim-items::-webkit-scrollbar,
.import-list::-webkit-scrollbar {
    width: 6px;
}

#anim-items::-webkit-scrollbar-thumb,
.import-list::-webkit-scrollbar-thumb {
    background: #4d4d6c;
    border-radius: 3px;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

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

    #main-area {
        min-height: 0;
    }

    #sidebar {
        width: 100%;
        min-width: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 16px;
    }

    #sidebar h1 {
        font-size: 1.25rem;
    }

    #anim-items {
        max-height: 200px;
    }

    #viewport {
        min-height: 40vh;
        height: 40vh;
    }

    .timeline-panel {
        height: 150px;
        min-height: 80px;
    }

    /* timeline labels rendered on canvas */

    .credits {
        display: none;
    }

    .modal {
        width: 95vw;
    }
}

@media (max-width: 640px) {
    #sidebar {
        padding: 12px;
    }

    #sidebar h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        font-size: 0.8rem;
        margin-bottom: 12px;
    }

    .drop-zone {
        padding: 20px 16px;
        margin-bottom: 12px;
    }

    .drop-zone svg {
        width: 36px;
        height: 36px;
    }

    .toolbar {
        flex-direction: column;
    }

    #anim-items {
        max-height: 160px;
    }

    #viewport {
        min-height: 35vh;
        height: 35vh;
    }

    .timeline-panel {
        height: 130px;
    }

    /* timeline labels rendered on canvas */

    #stats {
        bottom: 12px;
        left: 12px;
        font-size: 0.7rem;
    }
}

@media (max-width: 380px) {
    #sidebar {
        padding: 10px;
    }

    .site-logo img {
        height: 20px;
    }

    #anim-items {
        max-height: 120px;
    }
}
