/* ========================================
   BalonPixel - Premium Dark Glassmorphism
   ======================================== */

/* ===== CSS Custom Properties ===== */
:root {
    --bg-deep: #06060e;
    --bg-surface: rgba(12, 12, 24, 0.75);
    --glass-bg: rgba(18, 18, 35, 0.65);
    --glass-bg-solid: rgba(18, 18, 35, 0.9);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-hover: rgba(255, 255, 255, 0.15);
    --glass-blur: 16px;

    --accent: #ff3366;
    --accent-glow: rgba(255, 51, 102, 0.4);
    --accent-soft: rgba(255, 51, 102, 0.15);
    --accent-hover: #ff5588;

    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;

    --text-primary: #f0f0f5;
    --text-secondary: rgba(224, 224, 240, 0.7);
    --text-muted: rgba(224, 224, 240, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 300ms cubic-bezier(0.175, 0.885, 0.32, 1.275);

    --toolbar-width: 56px;
    --topbar-height: 52px;
    --palette-height: 64px;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ===== Canvas ===== */
#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: crosshair;
}

/* ===== UI Layer ===== */
#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

#ui-layer > * {
    pointer-events: auto;
}

/* ===== Glass Panel Base ===== */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* ===== Top Bar ===== */
#topbar {
    position: absolute;
    top: 12px;
    left: calc(var(--toolbar-width) + 24px);
    right: 12px;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 20;
}

#topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

#logo {
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
    background: linear-gradient(135deg, #ff3366, #ff6b9d, #ff3366);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 4s ease infinite;
}

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

#info-group {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow: hidden;
}

.info-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.06);
    white-space: nowrap;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

#topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

#selected-color-wrapper {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 2px;
    transition: var(--transition-base);
    cursor: pointer;
}

#selected-color-wrapper:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

#selected-color {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #E50000;
}

/* ===== Toolbar ===== */
#toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    bottom: calc(var(--palette-height) + 24px);
    width: var(--toolbar-width);
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 20;
    scrollbar-width: none;
}

#toolbar::-webkit-scrollbar {
    display: none;
}

.toolbar-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.toolbar-label {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 4px 0 2px;
    text-align: center;
    width: 100%;
}

.toolbar-divider {
    width: 28px;
    height: 1px;
    background: var(--glass-border);
    margin: 4px auto;
}

/* ===== Tool Button ===== */
.tool-btn {
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-base);
    position: relative;
    flex-shrink: 0;
}

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

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--glass-border-hover);
    transform: translateY(-1px);
}

.tool-btn:active {
    transform: translateY(0px) scale(0.95);
}

.tool-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(255, 51, 102, 0.3);
    box-shadow: 0 0 12px rgba(255, 51, 102, 0.15);
}

.tool-btn.active:hover {
    background: rgba(255, 51, 102, 0.25);
}

/* ===== Pen Status Indicator ===== */
#pen-status {
    position: absolute;
    bottom: calc(var(--palette-height) + 24px);
    left: calc(var(--toolbar-width) + 24px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 20;
    transition: var(--transition-base);
    opacity: 0.85;
}

#pen-status.active {
    border-color: rgba(34, 197, 94, 0.3);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.15);
}

#pen-status:not(.active) {
    border-color: rgba(239, 68, 68, 0.3);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.1);
}

#pen-status-text {
    color: var(--text-secondary);
}

#pen-status.active #pen-status-text {
    color: var(--success);
}

#pen-status:not(.active) #pen-status-text {
    color: var(--danger);
}

/* ===== Color Palette ===== */
#palette-container {
    position: absolute;
    bottom: 12px;
    left: calc(var(--toolbar-width) + 24px);
    right: 12px;
    height: var(--palette-height);
    display: flex;
    align-items: center;
    padding: 8px 12px;
    z-index: 20;
}

#palette {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    align-items: center;
    width: 100%;
    padding: 4px 0;
    scrollbar-width: none;
}

#palette::-webkit-scrollbar {
    display: none;
}

.color-swatch {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    cursor: pointer;
    border: 2.5px solid transparent;
    transition: var(--transition-spring);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.2);
    z-index: 5;
    border-color: rgba(255, 255, 255, 0.5);
}

.color-swatch.active {
    border-color: #fff;
    transform: scale(1.25);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2), 0 0 16px rgba(255, 255, 255, 0.3);
    z-index: 10;
}

.color-swatch.active::after {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    animation: pulseRing 2s ease infinite;
}

@keyframes pulseRing {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 0.1; transform: scale(1.1); }
}

/* ===== Overlay Panel ===== */
#overlay-panel {
    position: absolute;
    top: calc(var(--topbar-height) + 24px);
    right: 12px;
    width: 280px;
    z-index: 25;
    transition: var(--transition-base);
    background: var(--glass-bg-solid);
}

/* ===== Admin Panel ===== */
#admin-panel {
    position: absolute;
    top: calc(var(--topbar-height) + 24px);
    left: calc(var(--toolbar-width) + 24px);
    width: 250px;
    z-index: 25;
    transition: var(--transition-base);
    background: var(--glass-bg-solid);
}

#overlay-panel.hidden, #admin-panel.hidden {
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
}

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

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: var(--transition-fast);
}

.panel-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.panel-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.btn-primary {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid rgba(255, 51, 102, 0.3);
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-base);
    text-align: center;
}

.btn-primary:hover {
    background: rgba(255, 51, 102, 0.25);
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-base);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-danger {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.08);
    color: rgba(239, 68, 68, 0.8);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-base);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--danger);
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.slider-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-wrapper input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

.slider-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 8px var(--accent-glow);
    transition: var(--transition-fast);
}

.slider-wrapper input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider-wrapper input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 8px var(--accent-glow);
}

.slider-wrapper span {
    font-size: 0.8rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
    color: var(--text-secondary);
}

.overlay-actions {
    display: flex;
    gap: 8px;
}

.btn-accent {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--radius-md);
    background: rgba(34, 197, 94, 0.12);
    color: #22c55e;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-base);
    text-align: center;
}

.btn-accent:hover {
    background: rgba(34, 197, 94, 0.22);
    border-color: #22c55e;
    box-shadow: 0 0 16px rgba(34, 197, 94, 0.2);
}

.overlay-info {
    padding-top: 4px;
    text-align: center;
}

.overlay-info small {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.overlay-info kbd {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.65rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    color: var(--text-secondary);
}

/* ===== Minimap ===== */
#minimap {
    position: absolute;
    bottom: calc(var(--palette-height) + 24px);
    right: 12px;
    width: 200px;
    height: 100px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    z-index: 20;
    cursor: pointer;
    transition: var(--transition-base);
    background: var(--glass-bg);
}

#minimap:hover {
    border-color: var(--glass-border-hover);
    box-shadow: var(--shadow-lg), 0 0 16px rgba(255, 51, 102, 0.1);
}

#minimap.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    pointer-events: none;
}

/* ===== Toast Container ===== */
#toast-container {
    position: absolute;
    top: calc(var(--topbar-height) + 24px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    background: var(--glass-bg-solid);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    text-align: center;
}

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

/* ===== Shortcuts Help ===== */
#shortcuts-help {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    z-index: 50;
    background: var(--glass-bg-solid);
    transition: var(--transition-base);
}

#shortcuts-help.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
    pointer-events: none;
}

.shortcuts-list {
    padding: 12px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.shortcut-item kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 3px 8px;
    font-size: 0.72rem;
    font-family: inherit;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-primary);
}

/* ===== Scrollbar (global) ===== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ============================================================
   RESPONSIVE - MOBILE (< 768px)
   ============================================================ */
@media (max-width: 768px) {
    :root {
        --toolbar-width: 100%;
        --topbar-height: 44px;
        --palette-height: 120px; /* Increased for multi-line wrapping */
    }

    /* Top bar adjustments */
    #topbar {
        left: 12px;
        right: 12px;
        top: 8px;
        height: var(--topbar-height);
        padding: 0 10px;
    }

    #logo {
        font-size: 0.95rem;
    }

    #info-group {
        gap: 4px;
    }

    .info-badge {
        font-size: 0.65rem;
        padding: 2px 6px;
    }

    /* Toolbar moves to bottom */
    #toolbar {
        position: absolute;
        top: auto;
        left: 8px;
        right: 8px;
        bottom: calc(var(--palette-height) + 16px);
        width: auto;
        height: auto;
        flex-direction: row;
        padding: 6px 8px;
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        border-radius: var(--radius-md);
    }

    .toolbar-section {
        flex-direction: row;
        gap: 2px;
    }

    .toolbar-label {
        display: none;
    }

    .toolbar-divider {
        width: 1px;
        height: 28px;
        margin: 0 4px;
    }

    .tool-btn {
        width: 36px;
        height: 36px;
    }

    .tool-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Pen Status */
    #pen-status {
        top: calc(var(--topbar-height) + 16px);
        left: 50%;
        bottom: auto;
        transform: translateX(-50%);
        padding: 4px 10px;
        font-size: 0.7rem;
        border-radius: var(--radius-sm);
    }

    /* Palette adjustments */
    #palette-container {
        left: 8px;
        right: 8px;
        bottom: 8px;
        height: auto;
        min-height: 60px;
        max-height: 140px;
        padding: 8px;
        border-radius: var(--radius-md);
    }

    #palette {
        flex-wrap: wrap;
        justify-content: center;
        overflow-y: auto;
        gap: 6px;
    }

    .color-swatch {
        width: 28px;
        height: 28px;
        min-width: 28px;
    }

    /* Overlay panel */
    #overlay-panel {
        top: auto;
        bottom: calc(var(--palette-height) + 60px);
        right: 8px;
        left: 8px;
        width: auto;
    }

    /* Admin panel */
    #admin-panel {
        top: calc(var(--topbar-height) + 16px);
        left: 8px;
        right: 8px;
        width: auto;
    }

    /* Minimap */
    #minimap {
        width: 140px;
        height: 70px;
        bottom: calc(var(--palette-height) + 60px);
        right: 8px;
        border-radius: var(--radius-md);
    }

    /* Toast */
    #toast-container {
        top: calc(var(--topbar-height) + 60px);
    }

    .toast {
        font-size: 0.75rem;
        padding: 6px 14px;
    }

    /* Shortcuts */
    #shortcuts-help {
        width: 280px;
    }
}

/* ===== Extra small mobile ===== */
@media (max-width: 400px) {
    #logo {
        font-size: 0.85rem;
    }

    .info-badge {
        font-size: 0.6rem;
        padding: 2px 4px;
    }

    #selected-color-wrapper {
        width: 26px;
        height: 26px;
    }

    .color-swatch {
        width: 24px;
        height: 24px;
        min-width: 24px;
    }

    .tool-btn {
        width: 32px;
        height: 32px;
    }

    .tool-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* ===== Print protection ===== */
@media print {
    #ui-layer { display: none; }
}

/* ===== Prefers reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
