:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --secondary: #334155;
    --secondary-hover: #475569;
    --accent: #22D3EE;

    --bg-dark: #0F172A;
    --bg-panel: #1E293B;
    --bg-input: #0F172A;
    --bg-stage: #0B1121;

    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    --border: #334155;
    --danger: #EF4444;

    --radius-sm: 6px;
    --radius-md: 10px;
    --font-sans: 'Inter', system-ui, sans-serif;
}

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

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

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

/* Header */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    height: 64px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
}

.global-actions {
    display: flex;
    gap: 1rem;
}

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
    color: white;
}

.btn.primary {
    background: var(--primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn.secondary {
    background: var(--secondary);
    border: 1px solid var(--border);
}

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

.btn.danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn.danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn.sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
}

.w-full {
    width: 100%;
}

/* Workspace */
.workspace {
    display: flex;
    flex-grow: 1;
    height: calc(100vh - 64px - 260px);
    /* Subtract Header and Timeline */
}

/* Sidebar Properties */
.properties-panel {
    width: 320px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

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

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.badge {
    background: var(--secondary);
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-family: monospace;
    color: var(--accent);
}

.panel-content {
    padding: 1.25rem;
}

.empty-state {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.num-input,
.select-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.num-input:focus,
.select-input:focus {
    outline: none;
    border-color: var(--primary);
}

.select-input {
    width: 100%;
    font-family: var(--font-sans);
}

.select-input.sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
}

.input-with-value {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.input-with-value input[type="range"] {
    flex-grow: 1;
    accent-color: var(--primary);
}

.val-display {
    font-family: monospace;
    font-size: 0.85rem;
    width: 40px;
    text-align: right;
}

.hidden {
    display: none !important;
}

.pb-border {
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.mt-md {
    margin-top: 1.25rem;
}

/* Stage Preview Area */
.preview-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-stage);
    background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
}

.preview-toolbar {
    padding: 1rem 1.5rem;
    display: flex;
    gap: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tool-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.canvas-stage {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    perspective: 1000px;
}

/* The Animated Target */
.target-element {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--primary), #D946EF);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Will be manipulated via JS / CSS */
    position: absolute;
}

.inner-shape {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    backdrop-filter: blur(4px);
}

/* Timeline UI */
.timeline-section {
    height: 260px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.timeline-header {
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: var(--bg-input);
}

.timeline-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.tracks-container {
    display: flex;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

.track-labels {
    width: 220px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    z-index: 10;
    position: sticky;
    left: 0;
}

.track-label {
    height: 80px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.timeline-grid {
    flex-grow: 1;
    position: relative;
    overflow-x: auto;
    min-width: 800px;
}

.ticks-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: linear-gradient(to right, var(--border) 1px, transparent 1px);
    background-size: 50px 100%;
    opacity: 0.5;
    z-index: 1;
    pointer-events: none;
}

.keyframe-track {
    height: 80px;
    position: relative;
    border-bottom: 1px solid var(--border);
    z-index: 5;
    margin: 0 40px;
    /* Paddings so diamonds don't clip */
}

/* Keyframe Nodes */
.kf-node {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    background: var(--accent);
    transform: translate(-50%, -50%) rotate(45deg);
    cursor: pointer;
    transition: transform 0.1s;
    border: 2px solid var(--bg-panel);
    z-index: 10;
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.5);
}

.kf-node:hover {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.2);
}

.kf-node.selected {
    background: white;
    border-color: var(--primary);
    z-index: 11;
    transform: translate(-50%, -50%) rotate(45deg) scale(1.3);
    box-shadow: 0 0 15px white;
}

/* Playhead */
.playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--danger);
    left: 40px;
    z-index: 20;
    pointer-events: none;
    display: none;
}

.playhead::before {
    content: '';
    position: absolute;
    top: 0;
    left: -5px;
    width: 12px;
    height: 12px;
    background: var(--danger);
    border-radius: 50%;
}

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

.modal-content {
    background: var(--bg-panel);
    width: 600px;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    overflow: hidden;
}

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

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

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.icon-btn:hover {
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body textarea {
    width: 100%;
    height: 300px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--accent);
    padding: 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    resize: none;
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.toast.show {
    transform: translateY(0);
}