/* ============================================
   CUBIUS - Children's Cube Game Styles
   ============================================ */

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

:root {
    --bg: #0f0e17;
    --surface: #1a1932;
    --surface2: #232145;
    --surface3: #2d2b55;
    --primary: #7f5af0;
    --primary-light: #a78bfa;
    --accent: #ffbd39;
    --success: #2cb67d;
    --danger: #e53170;
    --text: #fffffe;
    --text-muted: #94a1b2;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Nunito', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
}

#help-overlay {
    position: fixed;
    top: 72px;
    left: 16px;
    z-index: 25;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(10, 10, 18, 0.68);
    border: 1px solid rgba(148, 161, 178, 0.22);
    color: rgba(255, 255, 255, 0.96);
    font-size: 11px;
    line-height: 1.55;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(10px);
    pointer-events: none;
    max-width: 270px;
}

#help-overlay p + p {
    margin-top: 3px;
}

#help-overlay strong {
    color: #ffffff;
}

/* ---- Header ---- */
#app-header {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 2px solid var(--surface2);
    gap: 20px;
    z-index: 10;
    flex-shrink: 0;
}

#app-header h1 {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #ff6b6b, #ffbd39, #2cb67d, #7f5af0, #4d96ff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 4s ease infinite;
    white-space: nowrap;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% center; }
    50% { background-position: 200% center; }
}

#mode-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    transition: all var(--transition);
    white-space: nowrap;
}

.tab:hover {
    background: var(--surface3);
    color: var(--text);
}

.tab.active {
    background: var(--primary);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(127, 90, 240, 0.35);
}

.tab-icon {
    font-size: 16px;
}

/* ---- Main Layout ---- */
#app-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

#app-signature {
    position: absolute;
    left: 14px;
    bottom: 12px;
    z-index: 6;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(15, 14, 23, 0.42);
    border: 1px solid rgba(148, 161, 178, 0.16);
    color: rgba(255, 255, 254, 0.55);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    backdrop-filter: blur(8px);
    pointer-events: none;
}

/* ---- Side Panel ---- */
#side-panel {
    width: 250px;
    background: var(--surface);
    border-left: 2px solid var(--surface2);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    flex-shrink: 0;
}

.controls-panel h2 {
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Color picker */
#color-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.color-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.color-btn:hover {
    transform: scale(1.12);
}

.color-btn.active {
    border-color: white;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
    transform: scale(1.12);
}

/* Buttons */
.controls-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-action {
    flex: 1;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-action:hover {
    background: var(--surface3);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-primary {
    background: var(--primary);
    color: white;
    font-size: 16px;
    padding: 14px 24px;
}

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

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

.hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid var(--surface2);
}

.hint p {
    margin-bottom: 2px;
}

.hint strong {
    color: var(--primary-light);
}

/* ---- Mode 2: Figure select ---- */
#figure-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text);
    border: 2px solid var(--surface3);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color var(--transition);
}

#figure-select:focus {
    border-color: var(--primary);
    outline: none;
}

#figure-select option {
    background: var(--surface2);
    color: var(--text);
}

/* Progress bar */
#figure-progress {
    margin-bottom: 10px;
}

.progress-bar {
    width: 100%;
    height: 22px;
    background: var(--surface2);
    border-radius: 11px;
    overflow: hidden;
    margin-bottom: 6px;
    border: 1px solid var(--surface3);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #4d96ff, var(--primary));
    border-radius: 11px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 0%;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

#progress-text {
    font-size: 14px;
    text-align: center;
    display: block;
    color: var(--text-muted);
    font-weight: 700;
}

/* ---- Mode 3: Count ---- */
.count-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--surface2), var(--surface3));
    border-radius: var(--radius);
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 10px;
    border: 1px solid var(--surface3);
}

.count-total span:first-child {
    color: var(--text-muted);
}

#total-count {
    color: var(--accent);
    font-size: 32px;
}

#view-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.view-btn {
    flex: 1;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--surface3);
    background: var(--surface2);
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    transition: all var(--transition);
}

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

.view-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#level-breakdown {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.level-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    gap: 10px;
}

.level-color {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.level-label {
    flex: 1;
}

.level-count {
    color: var(--accent);
    font-size: 18px;
}

/* ---- Blocks Tray (Mode 2) ---- */
#blocks-tray {
    padding: 10px 20px;
    background: var(--surface);
    border-top: 2px solid var(--surface2);
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 76px;
    flex-shrink: 0;
}

#blocks-tray h3 {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#tray-blocks {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tray-block {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    cursor: grab;
    transition: all var(--transition);
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.tray-block::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 4px;
    right: 4px;
    height: 40%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.25), transparent);
    border-radius: 6px 6px 50% 50%;
}

.tray-block:hover {
    transform: scale(1.18) translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.3);
}

.tray-block:active {
    cursor: grabbing;
}

.tray-block.used {
    opacity: 0.2;
    pointer-events: none;
    transform: scale(0.85);
}

/* ---- Drag Ghost ---- */
#drag-ghost {
    position: fixed;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    transform: translate(-50%, -50%) scale(1.2);
    transition: opacity 0.15s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

#drag-ghost.visible {
    opacity: 0.9;
}

/* ---- Completion Modal ---- */
#completion-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 24px;
    padding: 36px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(255, 189, 57, 0.15);
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 8px;
}

.modal-content p {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

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

/* ---- Responsive ---- */
@media (max-width: 900px) {
    #help-overlay {
        top: 104px;
        left: 12px;
        font-size: 10px;
        max-width: 220px;
    }

    #app-header {
        flex-direction: column;
        padding: 8px 12px;
        gap: 8px;
    }

    #mode-tabs {
        width: 100%;
        justify-content: center;
    }

    .tab span:not(.tab-icon) {
        display: none;
    }

    .tab-icon {
        font-size: 20px;
    }

    #side-panel {
        width: 180px;
        padding: 10px;
    }

    .color-btn {
        border-radius: 8px;
    }
}

@media (max-width: 600px) {
    #help-overlay {
        top: 96px;
        left: 10px;
        max-width: 190px;
        padding: 8px 10px;
    }

    #app-signature {
        left: 10px;
        bottom: 86px;
        font-size: 9px;
        padding: 4px 8px;
    }

    #side-panel {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 200px;
        z-index: 20;
        transform: translateX(100%);
        transition: transform var(--transition);
        box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
    }

    #side-panel.open {
        transform: translateX(0);
    }
}
