/* ─── Reset & Variables ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0F172A;
    --bg-panel: #1E293B;
    --bg-input: #0F172A;
    --border: #334155;
    --text: #E2E8F0;
    --text-dim: #94A3B8;
    --primary: #6366F1;
    --primary-hover: #818CF8;
    --accent: #22D3EE;
    --green: #10B981;
    --red: #EF4444;
    --orange: #F59E0B;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 200ms ease;
    --font: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
    --font-mono: 'SF Mono', 'JetBrains Mono', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ─── App Layout ──────────────────────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ─── Header ──────────────────────────────────────────────────────────── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn { padding: 6px 16px; border: none; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: #0F172A; }
.btn-accent:hover { opacity: 0.9; }
.btn-icon { background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); border-radius: var(--radius-sm); width: 34px; height: 34px; font-size: 1rem; cursor: pointer; transition: all var(--transition); display: flex; align-items: center; justify-content: center; }
.btn-icon:hover { border-color: var(--primary); color: var(--text); }
.btn-sm { padding: 4px 12px; background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); border-radius: 6px; font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-sm:hover, .btn-sm.active { border-color: var(--primary); color: var(--primary); }
.btn-danger { color: var(--red) !important; border-color: var(--red) !important; }

.select, .select-sm {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

.select-sm { padding: 4px 8px; font-size: 0.75rem; border-radius: 6px; }
.input-sm { width: 50px; padding: 3px 6px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 0.75rem; text-align: center; }

/* ─── Workspace ───────────────────────────────────────────────────────── */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.canvas-panel {
    flex: 3;
    border-right: 1px solid var(--border);
}

.canvas-tools { display: flex; gap: 4px; }

.canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at center, #1a2540 0%, var(--bg) 100%);
}

#canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
    filter: drop-shadow(0 4px 24px rgba(0,0,0,0.4));
}

#canvas .selected {
    outline: 2px dashed var(--accent);
    outline-offset: 4px;
}

/* ─── Properties Panel ────────────────────────────────────────────────── */
.props-panel {
    flex: 1;
    min-width: 240px;
    max-width: 300px;
    background: var(--bg-panel);
}

.props-content {
    padding: 14px;
    overflow-y: auto;
    flex: 1;
}

.placeholder {
    color: var(--text-dim);
    font-size: 0.8rem;
    text-align: center;
    padding: 40px 0;
}

.prop-group {
    margin-bottom: 14px;
}

.prop-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    display: block;
}

.prop-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.prop-input {
    flex: 1;
    padding: 5px 8px;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
    transition: border var(--transition);
}

.prop-input:focus { border-color: var(--primary); }

.prop-color {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background: none;
}

/* ─── Timeline ────────────────────────────────────────────────────────── */
.timeline-section {
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

.timeline-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.duration-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}

.timeline-track {
    position: relative;
    height: 80px;
    padding: 0 14px;
    overflow: hidden;
}

.timeline-ruler {
    position: absolute;
    top: 0;
    left: 14px;
    right: 14px;
    height: 20px;
    display: flex;
    align-items: flex-end;
}

.ruler-mark {
    position: absolute;
    font-size: 0.6rem;
    color: var(--text-dim);
    transform: translateX(-50%);
}

.ruler-tick {
    position: absolute;
    bottom: 0;
    width: 1px;
    height: 6px;
    background: var(--border);
}

.timeline-playhead {
    position: absolute;
    top: 0;
    left: 14px;
    width: 2px;
    height: 100%;
    background: var(--accent);
    z-index: 10;
    transition: left 50ms linear;
    pointer-events: none;
}

.timeline-playhead::before {
    content: '';
    position: absolute;
    top: 0;
    left: -5px;
    width: 12px;
    height: 12px;
    background: var(--accent);
    clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.timeline-keyframes {
    position: absolute;
    top: 24px;
    left: 14px;
    right: 14px;
    bottom: 8px;
}

.keyframe-dot {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border: 2px solid var(--accent);
    border-radius: 3px;
    transform: rotate(45deg) translate(-50%, -50%);
    cursor: pointer;
    z-index: 5;
    transition: all var(--transition);
}

.keyframe-dot:hover, .keyframe-dot.active {
    background: var(--accent);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
    transform: rotate(45deg) translate(-50%, -50%) scale(1.2);
}

/* ─── Modal ───────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(0,0,0,0.5);
}

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

.modal-header h2 {
    font-size: 1rem;
}

.export-output {
    flex: 1;
    padding: 16px 20px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre;
    color: var(--accent);
    max-height: 400px;
}

.modal-content > .btn {
    margin: 12px 20px 16px;
}

/* ─── Toast ───────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--green);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 300ms;
    z-index: 200;
    pointer-events: none;
}

.toast.visible { opacity: 1; transform: translateY(0); }
