:root {
    --bg-color: #1a1a1e;
    --panel-bg: rgba(20, 20, 22, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-color: #f0f0f0;
    --text-color-muted: #a0a0a0;
    --accent-color: #007aff;
    --danger-color: #ff3b30;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
}

#c {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#c.selectable {
    cursor: pointer;
}

.ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    padding: 20px;
    z-index: 20;
}

.panel {
    position: absolute;
    background: var(--panel-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 16px;
    pointer-events: all;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.panel-header {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-content button {
    width: 100%;
}

#scene-controls {
    /* From absolute to fixed for dialog positioning */
    position: fixed;
    top: 50%;
    left: 50%;
    width: 320px;
    /* Hidden by default */
    transform: translate(-50%, -50%) scale(0.95);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s;
    z-index: 20;
}

#scene-controls.visible {
    transform: translate(-50%, -50%) scale(1);
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0s;
}

div.dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 320px;
    transform: translate(-50%, -50%) scale(0.95);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s;
    z-index: 20;
}

div.dialog.visible {
    transform: translate(-50%, -50%) scale(1);
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0s;
}

#right-panels {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    pointer-events: none;
}

#right-panels .panel {
    position: relative;
    width: 100%;
    pointer-events: all;
}

#animation-controls {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    max-width: calc(100% - 40px);
    padding: 12px;
}

/* Dialog Backdrop */
#dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 19;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s 0.2s;
}

#dialog-backdrop.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0s 0s;
}

/* Menu Button */
.menu-button {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    padding: 0;
    line-height: 44px;
    text-align: center;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    color: var(--text-color);
    z-index: 10;
    pointer-events: all;
}

.close-button {
    background: transparent;
    border: none;
    color: var(--text-color-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 30px;
    height: 30px;
}

.close-button:hover {
    color: var(--text-color);
    transform: none; /* override default button hover */
    background-color: transparent;
}

hr {
    border: none;
    height: 1px;
    background-color: var(--panel-border);
    margin: 4px 0;
}

/* Form Elements */
label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: var(--text-color-muted);
}

input[type="text"],
input[type="file"],
select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1em;
}

input[type="file"] {
    padding: 4px;
}

input[type="file"]::file-selector-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

input[type="file"]::file-selector-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

button {
    padding: 8px 16px;
    background: var(--accent-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

button:hover {
    transform: scale(1.05);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-color-muted);
    cursor: not-allowed;
    transform: none;
}

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

.input-row {
    display: flex;
    gap: 8px;
}

.input-row input {
    flex-grow: 1;
}

/* Model List */
#model-list {
    max-height: 200px;
    overflow-y: auto;
}

.model-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
}

.model-item:not(:last-child) {
    margin-bottom: 6px;
}

.model-item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.instructions-text {
    color: var(--text-color-muted);
    font-size: 0.9em;
    text-align: center;
    padding: 5px;
    background-color: rgba(0,0,0,0.2);
    border-radius: 6px;
    margin: 0;
}

.ik-chain-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
}

.ik-chain-item:not(:last-child) {
    margin-bottom: 6px;
}

.ik-chain-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9em;
}

.ik-chain-item button {
    background: none;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 2px 8px;
    font-size: 0.8em;
    border-radius: 6px;
    opacity: 0.7;
}

.ik-chain-item button:hover {
    background: var(--danger-color);
    color: white;
    opacity: 1;
    transform: scale(1.05);
}

.empty-list-text {
    color: var(--text-color-muted);
    text-align: center;
    padding: 10px;
}


/* Toggles */
.toggle-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 34px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background-color 0.2s;
}

.toggle-switch:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch:checked {
  background-color: var(--accent-color);
}

.toggle-switch:checked:before {
  transform: translateX(20px);
}


/* Animation Controls */
#animation-controls .control-bar {
    display: flex;
    gap: 12px;
    align-items: center;
}

#animation-controls select {
    flex-grow: 1;
}

#play-pause-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    padding: 0;
    background-color: rgba(255, 255, 255, 0.2);
    font-size: 18px;
    line-height: 40px;
    text-align: center;
    color: var(--text-color);
}

#animation-controls .timeline-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

#timeline-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    outline: none;
}
#timeline-slider:disabled {
    background: rgba(255, 255, 255, 0.1);
}

#timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--text-color);
    cursor: pointer;
    border-radius: 50%;
}
#timeline-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--text-color);
    cursor: pointer;
    border-radius: 50%;
    border: none;
}
#timeline-slider:disabled::-webkit-slider-thumb {
    background: var(--text-color-muted);
    cursor: not-allowed;
}
#timeline-slider:disabled::-moz-range-thumb {
    background: var(--text-color-muted);
    cursor: not-allowed;
}


#animation-controls .timeline-bar span {
    font-size: 0.9em;
    color: var(--text-color-muted);
    min-width: 40px;
    text-align: center;
}


/* Loader */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s;
    pointer-events: none;
    opacity: 0;
}
#loader-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.loader-spinner {
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}