/**
 * 2D Rigging Tool V2 - Stylesheet
 * Ver.0.001 20260120-15:03
 *
 * Mobile-first responsive design
 */

/* ============================================================
   CSS Variables
   ============================================================ */
:root {
    /* Colors */
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --bg-elevated: #2a2a4a;

    --text-primary: #f0f0f0;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;

    --accent-primary: #4a9eff;
    --accent-secondary: #ff6b6b;
    --accent-success: #4ade80;
    --accent-warning: #fbbf24;

    --border-color: #3a3a5a;
    --border-light: #4a4a6a;

    /* Spacing */
    --header-height: 44px;
    --toolbar-height: 56px;
    --status-height: 28px;

    /* Touch targets */
    --touch-min: 44px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* ============================================================
   Reset & Base
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
}

/* ============================================================
   App Container (Mobile-first)
   ============================================================ */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height for mobile */
}

/* ============================================================
   Header
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.mode-tabs {
    display: flex;
    gap: 2px;
}

.mode-tab {
    min-width: var(--touch-min);
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.mode-tab:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.mode-tab.active {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.header-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ============================================================
   Canvas Area
   ============================================================ */
.canvas-area {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    background: var(--bg-tertiary);
    /* Checkerboard pattern */
    background-image:
        linear-gradient(45deg, var(--bg-secondary) 25%, transparent 25%),
        linear-gradient(-45deg, var(--bg-secondary) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--bg-secondary) 75%),
        linear-gradient(-45deg, transparent 75%, var(--bg-secondary) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    overflow: hidden;
}

#canvas-2d,
#canvas-webgl {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Drop Overlay */
.drop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 15, 26, 0.9);
    pointer-events: none;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.drop-overlay.hidden {
    opacity: 0;
}

.drop-overlay.drag-over {
    background: rgba(74, 158, 255, 0.2);
}

.drop-content {
    text-align: center;
    padding: 40px;
    border: 2px dashed var(--border-light);
    border-radius: 16px;
}

.drop-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.drop-content p {
    font-size: 16px;
    color: var(--text-secondary);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 15, 26, 0.9);
    z-index: 100;
}

.loading-overlay.hidden {
    display: none;
}

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

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

.loading-overlay p {
    margin-top: 12px;
    color: var(--text-secondary);
}

/* ============================================================
   Side Panel (Hidden on mobile)
   ============================================================ */
.side-panel {
    display: none;
}

/* ============================================================
   Context Toolbar
   ============================================================ */
.context-toolbar {
    height: var(--toolbar-height);
    padding: 8px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.toolbar-content {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    min-width: max-content;
}

.toolbar-content.hidden {
    display: none;
}

/* Tool Buttons */
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-min);
    height: 40px;
    padding: 4px 12px;
    font-size: 11px;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.tool-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-light);
}

.tool-btn:active {
    transform: scale(0.96);
}

.tool-btn.primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.tool-btn.primary:hover {
    background: #3d8ae6;
}

.tool-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.btn-icon {
    font-size: 16px;
    line-height: 1;
}

.btn-label {
    font-size: 10px;
    margin-top: 2px;
}

/* Tool Select */
.tool-select {
    height: 40px;
    padding: 0 12px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
}

.tool-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* File Input */
.file-input-wrapper {
    display: block;
    cursor: pointer;
}

.file-input-wrapper input[type="file"] {
    display: none;
}

/* Slider Group */
.slider-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
}

.slider-group label {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.slider-group input[type="range"] {
    width: 80px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    -webkit-appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}

.slider-value {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 28px;
    text-align: right;
}

/* Tool Divider */
.tool-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

/* ============================================================
   Status Bar
   ============================================================ */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--status-height);
    padding: 0 12px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

#status-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-info {
    display: flex;
    gap: 12px;
}

.status-info span {
    white-space: nowrap;
}

/* ============================================================
   Modals
   ============================================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    padding: 16px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content h2 {
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.modal-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}

.modal-btn {
    min-width: var(--touch-min);
    height: 40px;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.modal-btn:hover {
    background: var(--bg-elevated);
}

.modal-btn.primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.modal-btn.primary:hover {
    background: #3d8ae6;
}

/* Option Rows */
.option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.option-row label {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
}

.option-row input[type="range"] {
    width: 120px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
}

.checkbox-row label {
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

/* Export Options */
.export-option {
    margin-bottom: 12px;
}

.export-btn {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.export-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
}

.export-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.export-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.export-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Help Content */
.help-content {
    font-size: 13px;
}

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

.help-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 8px;
}

.help-section p {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.help-section ul {
    list-style: none;
    padding-left: 0;
}

.help-section li {
    padding: 4px 0;
    color: var(--text-secondary);
}

.help-section li strong {
    color: var(--text-primary);
}

/* ============================================================
   Placeholder
   ============================================================ */
.placeholder {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================================
   Tablet/Desktop Responsive
   ============================================================ */
@media (min-width: 768px) {
    .side-panel {
        display: flex;
        flex-direction: column;
        width: 240px;
        background: var(--bg-secondary);
        border-left: 1px solid var(--border-color);
        overflow-y: auto;
    }

    .panel-section {
        border-bottom: 1px solid var(--border-color);
    }

    .panel-section h3 {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 12px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        cursor: pointer;
        user-select: none;
    }

    .panel-section h3:hover {
        background: var(--bg-tertiary);
    }

    .collapse-icon {
        font-size: 10px;
        transition: transform var(--transition-fast);
    }

    .panel-section.collapsed .collapse-icon {
        transform: rotate(-90deg);
    }

    .panel-section.collapsed .panel-content {
        display: none;
    }

    .panel-content {
        padding: 0 12px 12px;
    }

    /* Bone Tree */
    .bone-tree {
        font-size: 12px;
    }

    .bone-item {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px 8px;
        border-radius: 4px;
        cursor: pointer;
    }

    .bone-item:hover {
        background: var(--bg-tertiary);
    }

    .bone-item.selected {
        background: var(--accent-primary);
        color: white;
    }

    .bone-icon {
        width: 8px;
        height: 8px;
        background: var(--accent-secondary);
        border-radius: 50%;
    }

    .bone-item.physics .bone-icon {
        background: var(--accent-warning);
    }

    .bone-children {
        padding-left: 16px;
    }

    /* Properties */
    .property-row {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
    }

    .property-row label {
        width: 50px;
        font-size: 11px;
        color: var(--text-secondary);
    }

    .property-row input {
        flex: 1;
        padding: 6px 8px;
        font-size: 12px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: 4px;
        color: var(--text-primary);
    }

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

    /* Wider toolbar */
    .context-toolbar {
        overflow-x: visible;
    }

    .toolbar-content {
        justify-content: center;
    }

    /* Show labels */
    .btn-label {
        display: block;
    }
}

/* Large Desktop */
@media (min-width: 1024px) {
    .side-panel {
        width: 280px;
    }

    .tool-btn {
        flex-direction: row;
        gap: 6px;
        padding: 8px 16px;
    }

    .btn-label {
        font-size: 12px;
        margin-top: 0;
    }
}

/* ============================================================
   Utility Classes
   ============================================================ */
.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
