:root {
    --primary: #7fb432;
    --primary-dark: #6a962a;
    --accent: #ffb35e;
    --bg-dark: #020617;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

.hidden {
    display: none !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    color-scheme: light;
    /* Force light mode at root */
}

html,
body {
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--bg-dark) !important;
    font-family: 'Outfit', sans-serif;
    position: fixed;
    /* Prevent mobile pull-to-refresh */
    inset: 0;
    color: #f3f4f6 !important;
}

#app-container {
    width: 100%;
    max-width: 100rem;
    margin: 0 auto;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    position: relative;
    background: #020617 !important;
    display: flex;
    flex-direction: column;
}

/* PC 환경(가로 > 480px)에서 스마트폰 베젤 형상으로 고정 및 중앙 정렬 */
@media (min-width: 481px) {
    body {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background: #090d16 !important;
    }
    #app-container {
        width: calc(96vh * (9 / 19.5)) !important;
        height: 96vh !important;
        max-width: 480px !important;
        max-height: 96vh !important;
        border-radius: 36px !important;
        border: 12px solid #1e293b !important;
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8) !important;
        margin: auto !important;
        position: relative !important;
    }
}

@media (max-width: 480px) {
    #app-container {
        width: 100% !important;
        height: 100% !important;
        height: calc(var(--vh, 1vh) * 100) !important;
        max-width: none !important;
        max-height: none !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        margin: 0 !important;
    }
}

#coloring-screen.active {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: calc(var(--vh, 1vh) * 100) !important;
    display: block !important;
    overflow: hidden !important;
    background: #020617;
    z-index: 1000;
}

.main-header {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: calc(95px + env(safe-area-inset-top, 0px)) !important;
    display: flex;
    align-items: flex-end;
    padding-bottom: 15px !important;
    background: #0f172a;
    z-index: 1100;
}

#coloring-screen .tool-footer.phablet {
    position: absolute !important;
    bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 85% !important;
    max-width: 700px !important;
    height: 155px !important;
    background: #0f172a !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 24px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
    z-index: 2000;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: visible !important;
    padding: 0 15px !important;
    cursor: grab !important;
    touch-action: none !important;
    transition: bottom 0.3s ease, box-shadow 0.2s, border-color 0.2s;
}

/* Moved dragging-active to Tablet Media Query */

.footer-drag-handle {
    width: 60px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    margin: 6px auto 4px;
    flex-shrink: 0;
    cursor: grab;
    transition: background 0.2s;
}

.footer-drag-handle:hover {
    background: rgba(255, 255, 255, 0.4);
}

.dragging-active .footer-drag-handle {
    background: var(--primary);
    cursor: grabbing;
}

#coloring-screen #editor-area {
    position: absolute !important;
    top: calc(95px + env(safe-area-inset-top, 0px)) !important;
    bottom: 0px !important;
    /* FILL BACKGROUND TO BOTTOM */
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    padding-bottom: 120px !important;
    /* REDUCED BUFFER FOR MOBILE */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #000 !important;
    overflow: hidden !important;
    z-index: 1050;
}

#paper-layer {
    position: relative;
    transform-origin: 0 0 !important;
    /* IMMUTABLE TOP-LEFT AXIS v3.7.6 */
}

/* Standardized tablet behavior in v3.2.0 */

.screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-dark) !important;
    z-index: 10;
}

.screen.active {
    display: flex;
}

#coloring-screen {
    padding: 0 !important;
}

/* Center login card specifically */
#login-screen {
    justify-content: center;
    align-items: center;
}

/* --- HEADER --- */
.main-header {
    height: auto;
    min-height: 48px;
    padding: 2px 10px 4px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: rgba(15, 23, 42, 0.9) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    flex-shrink: 0;
    user-select: none;
    -webkit-touch-callout: none;
}

.header-cluster {
    display: flex;
    gap: 12px;
    align-items: center;
    width: 100%;
}

#btn-settings-gallery,
#btn-settings-coloring {
    margin-left: auto;
}

#user-display {
    display: none;
    /* Hide 'Artist' text to match editor screen's icon-only header */
}

.icon-btn {
    width: 42px;
    /* Slightly wider for better touch area on tablets */
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--primary) !important;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transform: none !important;
    /* Instant appearance */
    transition: none !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 0 var(--primary-dark);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    display: block;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn .fa-fw {
    font-size: 16px;
}

.icon-btn::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    right: 1px;
    height: 45%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), transparent);
    border-radius: 11px 11px 4px 4px;
    pointer-events: none;
}

.icon-btn:active {
    transform: perspective(800px) rotateX(20deg) translateY(3px);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.3),
        0 1px 0 var(--primary-dark),
        0 4px 10px rgba(0, 0, 0, 0.2);
}

/* --- MASTER 3D HEADER BUTTONS --- */
.header-icon-btn-3d {
    width: 46px !important;
    height: 46px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 50% !important;
    cursor: pointer;
    padding: 8px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    pointer-events: auto;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2) !important;
}

.header-icon-btn-3d:active {
    transform: scale(0.9);
}

.header-ico-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.icon-btn.secondary {
    background: #4b5563 !important;
    color: #fff;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 4px 0 #1f2937,
        0 8px 15px rgba(0, 0, 0, 0.2);
}

.header-cluster {
    display: flex;
    gap: 4px;
    /* Very tight gap */
    align-items: center;
}

.icon-btn.exit {
    background: #4B5563 !important;
    /* Steel Gray for Exit */
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 0 #1f2937;
}

.icon-btn.warning {
    background: #F59E0B !important;
    /* Amber for Undo */
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 0 #B45309;
}

.icon-btn.danger {
    background: #ef4444 !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 3px 0 #991b1b;
}

.icon-btn.danger:active {
    box-shadow: 0 1px 0 #991b1b;
}

.icon-btn.success {
    background: #22c55e !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 4px 0 #166534,
        0 8px 15px rgba(0, 0, 0, 0.2);
}

.icon-btn.success:active {
    box-shadow: 0 1px 0 #166534;
}

.icon-btn.accent {
    background: #f59e0b !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 4px 0 #92400e,
        0 8px 15px rgba(0, 0, 0, 0.2);
}

.icon-btn.accent:active {
    box-shadow: 0 1px 0 #92400e;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 16px 30px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
}

/* --- LOGIN --- */
/* --- LOGIN (PUZZLE PREMIUM STYLE) --- */

.login-card {
    background: linear-gradient(145deg, #1e1b4b 0%, #312e81 100%) !important;
    color: #f3f4f6;
    border: 2px solid rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 340px;
    padding: 15px 20px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(255, 255, 255, 0.1);
    max-height: 92vh;
    overflow-y: auto;
}

/* Compact Login Overrides */
.login-compact {
    padding: 10px 20px !important;
}

.login-compact .login-logo-mini img {
    height: 60px !important;
    width: auto;
    margin-bottom: 2px !important;
}

.login-compact .login-title {
    margin: 2px 0 10px 0 !important;
    font-size: 1.1rem !important;
    letter-spacing: 2px;
}

.login-compact .input-group {
    margin-bottom: 8px !important;
    text-align: left;
}

.login-compact .input-group label {
    font-size: 0.6rem !important;
    margin-bottom: 2px !important;
    display: block;
    opacity: 0.8;
}

.login-compact input {
    height: 38px !important;
    font-size: 0.85rem !important;
    padding: 0 12px !important;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    width: 100%;
}

.login-compact .login-submit {
    margin-top: 10px !important;
    margin-bottom: 10px !important;
    padding: 12px 10px !important;
    font-size: 0.95rem !important;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    width: 100%;
}

.login-compact .login-policy-note {
    font-size: 0.6rem !important;
    margin-top: 5px;
    opacity: 0.6;
}

.login-compact .login-policy-note span {
    text-decoration: underline;
    cursor: pointer;
}

.logo {
    width: 70px;
    height: 70px;
    /* Fixed height to prevent layout shift/jumping */
    object-fit: contain;
    margin: 0 auto 2px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
    display: block;
    opacity: 1 !important;
    /* Always visible to avoid entrance motion */
    transform: none !important;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#user-name {
    width: 100%;
    padding: 18px;
    border-radius: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    font-size: 1.15rem;
    color: #444;
    text-align: center;
}

.btn-primary {
    background: #ffffff;
    color: var(--primary);
    border: none;
    padding: 20px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
    transition: 0.3s;
}

.btn-primary:active {
    transform: scale(0.95);
    background: #f8f8f8;
}

/* Glassmorphism & Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    z-index: 10000;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 10000;
    overflow-y: auto;
    padding: 40px 15px;
}

.glass {
    background: #ffffff;
    /* Solid white for better readability in modals */
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.info-card {
    width: 90%;
    max-width: 380px;
    max-height: 90vh;
    /* Prevent overflowing screen */
    overflow-y: auto;
    background: #ffffff !important;
    border-radius: 25px;
    padding: 15px 20px;
    /* Reduced vertical padding */
    text-align: center;
    position: relative;
    overflow: hidden;
    color: #333333;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* --- MODAL CARD (Standard) --- */
.modal-card {
    width: 90%;
    max-width: 400px;
    background: #ffffff;
    border-radius: 30px;
    padding: 30px 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    color: #333;
    z-index: 10001;
}

.modal-card h3 {
    margin-bottom: 25px;
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--primary);
}

.paper-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px 12px;
    /* Further reduced row gap and col gap */
    margin-bottom: 12px;
    /* Further reduced margin */
}

.paper-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    /* Minimal gap between icon and text */
    cursor: pointer;
    transition: transform 0.2s;
}

.paper-opt:active {
    transform: scale(0.95);
}

.paper-opt .preview {
    width: 46px;
    /* Even smaller to maximize vertical space */
    height: 46px;
    border-radius: 10px;
    border: 2px solid #eee;
    background: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.paper-opt.active .preview {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(127, 180, 50, 0.2);
}

.paper-opt span {
    font-size: 0.75rem;
    /* Slightly smaller text */
    font-weight: 800;
    color: #666;
}

.paper-opt.active span {
    color: var(--primary);
}

/* Texture Previews (User Assets) */
.preview.plain {
    background: #fff;
}

.preview.canvas {
    background-image: url('../assets/thumbs/papers/canvas.png');
    background-size: cover;
}

.preview.rough {
    background-image: url('../assets/thumbs/papers/rough%20paper.png');
    background-size: cover;
}

.preview.emboss {
    background-image: url('../assets/thumbs/papers/embossing.png');
    background-size: cover;
}

.preview.emboss2 {
    background-image: url('../assets/Embossing2.png');
    background-size: cover;
}

.preview.emboss3 {
    background-image: url('../assets/Embossing3.png');
    background-size: cover;
}

.preview.recycled {
    background-image: url('../assets/thumbs/papers/recycled_paper1.png');
    background-size: cover;
}

.preview.recycled2 {
    background-image: url('../assets/thumbs/papers/recycled_paper2.png');
    background-size: cover;
}

.preview.parchment {
    background-image: url('../assets/thumbs/papers/parchment.png');
    background-size: cover;
}

.preview.linen {
    background-image: url('../assets/thumbs/papers/linen.png');
    background-size: cover;
}

.preview.wood1 {
    background-image: url('../assets/thumbs/papers/wood1.png');
    background-size: cover;
}

.preview.wood2 {
    background-image: url('../assets/thumbs/papers/wood2.png');
    background-size: cover;
}

.preview.wood3 {
    background-image: url('../assets/thumbs/papers/wood3.png');
    background-size: cover;
}

.preview.rice {
    background-image: url('../assets/thumbs/papers/rice.png');
    background-size: cover;
}

.preview.marble {
    background-image: url('../assets/thumbs/papers/marble1.png');
    background-size: cover;
}

.preview.marble2 {
    background-image: url('../assets/thumbs/papers/marble2.png');
    background-size: cover;
}

.preview.postcard {
    background-image: url('../assets/thumbs/papers/postcard.png');
    background-size: cover;
}

.preview.blackboard {
    background-image: url('../assets/blackboard.png');
    background-size: cover;
}

.preview.beige {
    background-image: url('../assets/beige.png');
    background-size: cover;
}


/* --- GALLERY --- */
/* --- GALLERY (DENSE GRID) --- */
.gallery-wrapper {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    position: relative;
    padding-top: calc(95px + env(safe-area-inset-top, 0px)) !important;
}

.scroll-area {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    width: 100%;
}

.stage-card {
    background: #fff;
    border-radius: 12px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.stage-card:active {
    transform: scale(0.96);
}

.stage-img-box {
    width: 100%;
    display: block;
    overflow: hidden;
}

.stage-img-box img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    border-radius: 6px;
}

.stage-img-box img.placeholder-img {
    width: 60%;
    height: auto;
    opacity: 0.2;
    filter: grayscale(1);
}

/* --- EDITOR Area --- */
.editor-container {
    flex: 1;
    position: relative;
    background: var(--bg-dark) !important;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10px;
    touch-action: none;
    min-height: 0;
}

#paper-layer {
    position: relative;
    background-color: #ffffff;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
    transform-origin: center center;
    forced-color-adjust: none !important;
    filter: none !important;
    color-scheme: light !important;
}

/* Texture Styles (User Grains) */
.editor-container.plain #paper-layer {
    background: #ffffff !important;
}

.editor-container.canvas #paper-layer {
    background-image: url('../assets/thumbs/papers/canvas.png') !important;
    background-size: cover;
}

.editor-container.rough #paper-layer {
    background-image: url('../assets/thumbs/papers/rough%20paper.png') !important;
    background-size: cover;
}

.editor-container.emboss #paper-layer {
    background-image: url('../assets/thumbs/papers/embossing.png') !important;
    background-size: cover;
}

.editor-container.emboss2 #paper-layer {
    background-image: url('../assets/Embossing2.png') !important;
    background-size: cover;
}

.editor-container.emboss3 #paper-layer {
    background-image: url('../assets/Embossing3.png') !important;
    background-size: cover;
}

.editor-container.recycled #paper-layer {
    background-image: url('../assets/thumbs/papers/recycled_paper1.png') !important;
    background-size: cover;
}

.editor-container.recycled2 #paper-layer {
    background-image: url('../assets/thumbs/papers/recycled_paper2.png') !important;
    background-size: cover;
}

.editor-container.parchment #paper-layer {
    background-image: url('../assets/thumbs/papers/parchment.png') !important;
    background-size: cover;
}

.editor-container.linen #paper-layer {
    background-image: url('../assets/thumbs/papers/linen.png') !important;
    background-size: cover;
}

.editor-container.wood1 #paper-layer {
    background-image: url('../assets/thumbs/papers/wood1.png') !important;
    background-size: cover;
}

.editor-container.wood2 #paper-layer {
    background-image: url('../assets/thumbs/papers/wood2.png') !important;
    background-size: cover;
}

.editor-container.wood3 #paper-layer {
    background-image: url('../assets/thumbs/papers/wood3.png') !important;
    background-size: cover;
}

.editor-container.rice #paper-layer {
    background-image: url('../assets/thumbs/papers/rice.png') !important;
    background-size: cover;
}

.editor-container.marble #paper-layer {
    background-image: url('../assets/thumbs/papers/marble1.png') !important;
    background-size: cover;
}

.editor-container.marble2 #paper-layer {
    background-image: url('../assets/thumbs/papers/marble2.png') !important;
    background-size: cover;
}

.editor-container.postcard #paper-layer {
    background-image: url('../assets/thumbs/papers/postcard.png') !important;
    background-size: cover;
}

.editor-container.blackboard #paper-layer {
    background-image: url('../assets/blackboard.png') !important;
    background-size: cover;
}

.editor-container.beige #paper-layer {
    background-image: url('../assets/beige.png') !important;
    background-size: cover;
}

.editor-container.stone #paper-layer {
    background-color: #ddd !important;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)' opacity='0.3'/%3E%3C/svg%3E") !important;
}

#paint-canvas,
#wet-canvas {
    position: absolute;
    inset: 0;
    z-index: 5;
    mix-blend-mode: normal !important;
    background: transparent;
    touch-action: none;
}

#wet-canvas {
    z-index: 6;
    /* Slightly above paint canvas */
    pointer-events: none;
    /* Let events pass to paper-layer */
}

#line-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
    mix-blend-mode: multiply !important;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    filter: none !important;
    color-scheme: light !important;
}

#template-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    mix-blend-mode: normal;
    display: block;
    background: transparent !important;
}

/* --- FOOTER Layout --- */
.tool-footer {
    width: 100%;
    padding: 4px 8px 6px;
    background: rgba(15, 23, 42, 0.98) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 10000;
    flex-shrink: 0;
    position: relative;
    display: block;
    min-height: auto;
}

.footer-up-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    padding: 0;
}


/* Existing Swatch List (Standard) */
.swatch-list {
    flex: 1;
    display: grid;
    grid-template-rows: repeat(2, 34px);
    grid-auto-flow: column;
    grid-auto-columns: 34px;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px;
    -webkit-overflow-scrolling: touch;
    background: #ffffff !important;
    border-radius: 12px;
    border: 1.5px solid #dddddd;
    min-height: 80px;
}

/* NEW: Phablet Optimized Mini Palette */
.swatch-list-mini {
    display: flex;
    gap: 6px;
    padding: 6px;
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-sizing: border-box;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    max-width: 100%;
}

.swatch-list-mini::-webkit-scrollbar {
    display: none;
}

.swatch-list-mini .swatch {
    width: 30px !important;
    height: 30px !important;
}

.swatch-list::-webkit-scrollbar {
    display: none;
}

.swatch {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
    overflow: hidden;
    background-color: var(--swatch-color, #ffffff) !important;
    border: none !important;
}

.swatch::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('../assets/color_swatch_frame.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 2;
}

.swatch.active {
    transform: scale(1.15);
    z-index: 5;
    filter: brightness(1.05);
    outline: 2px solid #7fb432;
    outline-offset: 2px;
}

.wheel-trigger {
    width: 72px;
    height: 72px;
    background-image: url('../assets/color_wheel.png');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
    touch-action: none;
    align-self: center;
    /* Prevent top-clipping in flex-start layout */
}

.wheel-trigger:active {
    transform: scale(0.9);
}

/* Styled Native Picker (Color Box Preview) */
#native-picker {
    width: 48px;
    height: 48px;
    border: 2px solid #dddddd;
    border-radius: 12px;
    background: var(--current-color, #ff5e5e);
    cursor: pointer;
    box-shadow: none;
    /* Removed shadow */
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
    padding: 0;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

#native-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#native-picker::-webkit-color-swatch {
    border: none;
}

/* Center circle removed per user request */
.wheel-trigger::after {
    display: none;
}


.footer-down-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.sliders-container {
    display: flex;
    gap: 10px;
    width: 100%;
}

.size-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.label {
    font-size: 11px;
    font-weight: 800;
    color: #cbd5e1;
    /* Brighter for readability on dark footer */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.range-input {
    width: 100%;
    height: 8px;
    /* Slimmer, more modern track */
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    appearance: none;
    cursor: pointer;
    margin: 8px 0;
}

.range-input::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border: 3px solid var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(127, 180, 50, 0.5);
    /* Glowing effect */
}

.tools-grid {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    /* Restore centered position as requested */
    align-items: center;
    gap: 4px;
    /* Balanced spacing */
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 8px;
    z-index: 1;
}

.tools-grid::-webkit-scrollbar {
    display: none;
}

/* Phablet Layout Overrides */
.tool-footer.phablet {
    padding: 6px 10px;
    background: rgba(15, 23, 42, 1.0) !important;
    /* Opaque background for visibility */
    overflow: visible;
    /* Prevent clipping */
}

.footer-layout {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100%;
    margin: 0 auto;
    height: 100% !important;
}

.footer-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px !important;
    /* BALANCED VERTICAL GAP */
}

.controls-top {
    display: flex;
    align-items: center;
    justify-content: center;
    /* CENTERED */
    gap: 12px;
}

.compact-sliders {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 15px;
    /* MORE VERTICAL GAP BETWEEN SLIDERS */
}

.mini-slider {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mini-slider input {
    flex: 1;
    height: 4px;
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
}

.mini-slider input::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid var(--primary);
    border-radius: 50%;
}

.tiny-label {
    font-size: 9px;
    font-weight: 1000;
    color: #fff;
    width: 10px;
}

.controls-bottom {
    display: flex;
    width: 100%;
}

.tools-grid-compact {
    display: flex;
    width: 100%;
    gap: 6px;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px;
}

@media screen and (min-width: 641px) {
    .tools-grid-compact {
        justify-content: center;
    }
}

.tools-grid-compact::-webkit-scrollbar {
    display: none;
}

.tools-grid-compact .tool-btn {
    flex: 1;
    max-width: 60px;
    /* ENLARGED */
    height: 54px;
    /* ENLARGED */
    border-radius: 10px !important;
    background: #f8fafc !important;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tools-grid-compact .tool-btn.active {
    background: var(--primary) !important;
    color: white;
    border-color: #7fb432;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.tools-grid-compact .tool-btn img {
    width: 32px;
    /* ENLARGED */
    height: 32px;
    /* ENLARGED */
}

.tool-btn.active {
    border: 3px solid var(--primary) !important;
    transform: scale(1.1) translateY(-2px);
    z-index: 10;
}

/**
 * Mellow Fruit Rabbit - Stable Coloring Engine v3.1.2
 * [STATUS: UNIVERSAL RESPONSIVE LAYOUT ENABLED]
 */
#start-screen {
    background: radial-gradient(circle at center, #312e81 0%, #020617 100%);
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.tool-btn.active::after {
    display: none;
}

/* START SCREEN STYLES */
#start-screen {
    background: radial-gradient(circle at center, #312e81 0%, #020617 100%);
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.start-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.start-logo-container {
    width: 150px;
    height: 150px;
    margin-bottom: 30px;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}

.start-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.start-title {
    font-size: 2.5rem;
    font-weight: 900;
    line-height: 1.1;
    margin-bottom: 10px;
    background: linear-gradient(to bottom, #fff, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.start-desc {
    color: #94a3b8;
    margin-bottom: 40px;
    font-size: 0.95rem;
}

.start-btn-main {
    width: 100%;
    max-width: 280px;
    padding: 16px 30px;
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
    border: none;
    border-radius: 40px;
    color: white;
    font-size: 1.3rem;
    font-weight: 900;
    box-shadow: 0 10px 25px rgba(219, 39, 119, 0.4);
    cursor: pointer;
}

.start-footer {
    position: absolute;
    bottom: 25px;
    text-align: center;
    color: #475569;
    font-size: 0.75rem;
}

/* V25: 3D VOLUMETRIC LOGIN & SETTINGS */
#login-screen {
    background: radial-gradient(circle at center, #1e1b4b 0%, #020617 100%);
}

.login-card {
    background: linear-gradient(145deg, rgba(30, 27, 75, 0.85) 0%, rgba(49, 46, 129, 0.85) 100%) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #f3f4f6;
    width: 85%;
    max-width: 340px;
    padding: 25px 25px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.1);
}

.login-title {
    font-size: 1.0rem;
    font-weight: 1000;
    color: #ffffff;
    background: linear-gradient(to bottom, #4f46e5, #3730a3);
    padding: 2px 10px;
    border-radius: 8px;
    display: table;
    margin: 0 auto 2px;
    position: relative;
    letter-spacing: 1px;
    width: fit-content;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 2px 0 #1f2937, 0 4px 6px rgba(0, 0, 0, 0.4);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.settings-title {
    font-size: 1.4rem;
    /* Significantly bigger as requested */
    font-weight: 1000;
    color: #ffffff;
    background: linear-gradient(to bottom, #db2777, #9d174d);
    padding: 8px 30px;
    margin: 15px auto 25px;
    border-radius: 12px;
    display: table;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.login-title::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    height: 45%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.15), transparent);
    border-radius: 18px 18px 5px 5px;
}

.social-login-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    /* Increased for better spacing */
    margin-bottom: 15px;
    /* Added breathing room */
}

.social-btn {
    padding: 10px 12px;
    /* Bigger buttons */
    font-size: 0.85rem;
    /* Larger text */
    font-weight: 800;
    border-radius: 12px;
    /* More rounded */
    border: none;
    color: white;
    cursor: pointer;
    transform: none !important;
    position: relative;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.social-btn::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    right: 1px;
    height: 40%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), transparent);
    border-radius: 17px 17px 5px 5px;
}

.social-btn:active {
    transform: none;
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.3),
        0 2px 0 rgba(0, 0, 0, 0.2);
}

.gmail {
    background: #ea4335;
    border-bottom-color: #b31412;
}

.naver {
    background: #03c75a;
    border-bottom-color: #028e40;
}

.kakao {
    background: #fee500;
    color: #3c1e1e;
    border-bottom-color: #d1bc00;
}

.yahoo {
    background: #6001d2;
    border-bottom-color: #430193;
}

.divider {
    margin: 1px 0;
    /* Minimal */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 0.65rem;
    font-weight: 700;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 2px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 10px;
}

.input-group {
    text-align: left;
    margin-bottom: 1px;
    /* Minimal */
}

.input-group label {
    font-size: 9px;
    font-weight: 900;
    color: #cbd5e1;
    margin-left: 8px;
    margin-bottom: 1px;
    display: block;
}

.input-group input {
    width: 100%;
    padding: 8px 12px;
    /* Thinner input */
    border: none;
    border-radius: 10px;
    background: #1e293b;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.8rem;
    color: #f8fafc;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    outline: none;
}

.login-submit {
    width: 100%;
    margin-top: 4px;
}

.start-btn {
    padding: 8px 30px;
    font-size: 1.0rem;
    font-weight: 1000;
    background: linear-gradient(to bottom, #ec4899, #db2777);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transform: none !important;
    /* Flattened */
    box-shadow: 0 4px 0 #9d174d;
    transition: transform 0.1s;
    letter-spacing: 1px;
}

.start-btn::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    right: 1px;
    height: 45%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), transparent);
    border-radius: 24px 24px 8px 8px;
}

.start-btn:active {
    transform: perspective(800px) rotateX(25deg) translateY(4px);
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.5),
        0 2px 0 #9d174d,
        0 6px 15px rgba(219, 39, 119, 0.4);
}

/* SETTINGS SPECIFIC 3D */
.settings-section {
    margin-bottom: 25px;
    text-align: left;
}

.settings-section h3 {
    font-size: 0.85rem;
    font-weight: 900;
    color: #ffffff;
    background: #db2777;
    padding: 4px 10px;
    border-radius: 8px;
    display: inline-flex;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.settings-options {
    display: flex;
    gap: 10px;
}

.option-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 2px 0 #e2e8f0;
}

.option-btn.active {
    background: #db2777;
    border-color: #9d174d;
    color: white;
    box-shadow: 0 2px 0 #9d174d;
}

.policy-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 5px;
}

.policy-btn {
    width: 100%;
    padding: 12px 20px;
    border-radius: 10px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    color: #334155 !important;
    /* Visible dark text on white card */
    font-weight: 800;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.policy-btn:active {
    background: #f1f5f9;
}

.policy-btn::after {
    content: '▶';
    opacity: 0.5;
    font-size: 0.75rem;
}

.contact-box {
    background: #111827;
    padding: 12px;
    border-radius: 15px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.contact-email {
    color: #fbbf24;
    font-weight: 900;
    text-decoration: none;
    display: block;
}

.fruit-btn {
    width: 100%;
    padding: 14px;
    font-weight: 900;
    background: linear-gradient(to bottom, #ec4899, #db2777);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 0 #9d174d, 0 8px 15px rgba(219, 39, 119, 0.3);
    transition: all 0.2s;
    font-family: inherit;
    display: block;
    text-decoration: none;
    text-align: center;
}

.hidden {
    display: none !important;
}

/* Mobile Uniformity - Removed previous absolute picker logic */
body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

html {
    height: -webkit-fill-available;
}

/* --- CUSTOM PREMIUM COLOR PICKER --- */
.color-picker-card {
    width: 90%;
    max-width: 320px;
    padding: 20px;
    border-radius: 25px;
    text-align: center;
    color: white;
    transform: perspective(1000px) rotateX(5deg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.picker-title {
    font-weight: 900;
    letter-spacing: 1px;
    font-size: 0.9rem;
    background: #db2777;
    padding: 4px 12px;
    border-radius: 8px;
    box-shadow: 0 3px 0 #9d174d;
}

.close-icon {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    font-weight: 900;
}

.sv-container {
    position: relative;
    width: 100%;
    height: 200px;
    /* Fixed height for consistency */
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: crosshair;
}

/* Remove old native picker styles */
#native-picker {
    display: none;
}

/* POLICY DISPLAY (Fruit Rabbit Puzzle Style) */
.policy-display {
    position: absolute;
    inset: 15px;
    background: #ffffff;
    /* Solid white background */
    border-radius: 25px;
    padding: 25px 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    color: #334155;
    /* Dark slate text */
    text-align: left;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.policy-display h4 {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    /* Use theme pink/primary color */
    margin-bottom: 20px;
    text-align: center;
}

.policy-body {
    flex: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #475569;
    /* Medium dark text */
    padding-bottom: 20px;
}

.policy-section h4 {
    color: #1e293b;
    margin-top: 15px;
    margin-bottom: 8px;
    font-size: 1rem;
    font-weight: 700;
    text-align: left;
}

.policy-body p {
    margin-bottom: 12px;
}

.mini-btn {
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: #475569;
    color: white;
    font-weight: 800;
    cursor: pointer;
    margin-top: 10px;
}

body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

html {
    height: -webkit-fill-available;
}

/* --- CUSTOM PREMIUM COLOR PICKER --- */
.color-picker-card {
    width: 90%;
    max-width: 320px;
    padding: 20px;
    border-radius: 25px;
    text-align: center;
    color: white;
    transform: perspective(1000px) rotateX(5deg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.picker-title {
    font-weight: 900;
    letter-spacing: 1px;
    font-size: 0.9rem;
    background: #db2777;
    padding: 4px 12px;
    border-radius: 8px;
    box-shadow: 0 3px 0 #9d174d;
}

.close-icon {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    font-weight: 900;
}

.sv-container {
    position: relative;
    width: 100%;
    height: 200px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: crosshair;
}

#sv-canvas {
    width: 100%;
    height: 100%;
}

#sv-cursor {
    position: absolute;
    width: 18px;
    height: 18px;
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
    transform: translate(-50%, -50%);
    pointer-events: none;
    mix-blend-mode: difference;
    top: 0;
    left: 100%;
}

.hue-container {
    margin-bottom: 20px;
}

#hue-slider {
    width: 100%;
    height: 15px;
    border-radius: 10px;
    appearance: none;
    background: linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

#hue-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 22px;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.picker-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.color-preview-large {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-radius: 15px;
    flex: 1;
}

#final-color-preview {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 2px solid #fff;
    background: #ff0000;
}

#hex-label {
    font-family: monospace;
    font-weight: 800;
    font-size: 0.9rem;
}

#native-picker {
    display: none;
}

.policy-display {
    position: absolute;
    inset: 15px;
    background: #ffffff;
    border-radius: 25px;
    padding: 25px 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    color: #334155;
    text-align: left;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.policy-display h4 {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 20px;
    text-align: center;
}

.policy-body {
    flex: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #475569;
    padding-bottom: 20px;
}

.policy-section h4 {
    color: #1e293b;
    margin-top: 15px;
    margin-bottom: 8px;
    font-size: 1rem;
    font-weight: 700;
    text-align: left;
}

.policy-body p {
    margin-bottom: 12px;
}

/* Unified Login UI Classes */
.start-btn-primary {
    width: 240px;
    height: 68px;
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
    color: white !important;
    border: none !important;
    border-radius: 34px !important;
    font-size: 1.5rem !important;
    font-weight: 950 !important;
    cursor: pointer;
    box-shadow: 0 8px 0 #9d174d, 0 15px 30px rgba(236, 72, 153, 0.4) !important;
    transition: transform 0.1s;
    margin-bottom: 25px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
}

.start-btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #9d174d, 0 10px 20px rgba(236, 72, 153, 0.3) !important;
}

.start-secondary-row {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
}

.start-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 12px 24px;
    border-radius: 15px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.start-btn-secondary:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
}

.login-compact {
    padding: 20px 30px !important;
    max-width: 320px;
    width: 90%;
}

.login-compact .login-title {
    margin: 5px 0 20px 0 !important;
    font-size: 1.5rem !important;
}

.login-compact .input-group {
    margin-bottom: 12px !important;
    text-align: left;
}

.login-compact .input-group label {
    font-size: 0.7rem !important;
    margin-bottom: 4px !important;
    display: block;
    opacity: 0.8;
}

.login-compact input {
    width: 100%;
    height: 44px !important;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: white;
    padding: 0 15px !important;
    font-size: 0.95rem !important;
}

.login-compact .login-submit {
    width: 100%;
    height: 54px !important;
    margin-top: 20px !important;
    font-size: 1.1rem !important;
}

/* LAYER MANAGEMENT UI */
.layer-item {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 15px;
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.2s, background-color 0.2s;
    color: #334155;
    position: relative;
}

.layer-item.active {
    border-color: #4f46e5;
    background-color: #f8fafc;
}

.layer-item-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.layer-visibility-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
}

.layer-item-name {
    flex: 1;
    border: none;
    background: none;
    font-weight: 800;
    font-size: 0.9rem;
    color: inherit;
    padding: 4px;
    border-radius: 4px;
}

.layer-item-name:focus {
    background: #fff;
    outline: 2px solid #94a3b8;
}

.layer-opacity-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layer-opacity-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.6;
}

.layer-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-top: 5px;
}

.layer-ctrl-btn {
    padding: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: white;
    cursor: pointer;
}

.layer-ctrl-btn:active {
    background: #f1f5f9;
}

/* UNIVERSAL RESPONSIVE ADJUSTMENTS v3.7.0 */
.footer-layout {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 20px !important;
    width: 100% !important;
    height: 100% !important;
}

.footer-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
}

.layer-ctrl-btn.danger {
    color: #ef4444;
}

/* --- DEVICE SPECIFIC OPTIMIZATIONS (Phone & Pad) --- */

/* 1. Mobile Phone Layout (Portrait) */
@media screen and (max-width: 640px) {
    #coloring-screen .main-header {
        height: 50px !important;
        /* Slimmer header on mobile */
    }

    #editor-area {
        top: 50px !important;
        /* Start immediately after the header */
        padding-top: 4px !important;
        /* Minimized gap */
    }

    #coloring-screen .tool-footer.phablet {
        width: 100% !important;
        border-radius: 0 !important;
        bottom: env(safe-area-inset-bottom, 0px) !important;
        left: 0 !important;
        transform: none !important;
        padding: 6px 8px !important;
        height: auto !important;
        min-height: 110px !important;
        cursor: default !important;
        box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.2) !important;
        border: none !important;
        touch-action: pan-y !important;
    }

    .footer-drag-handle {
        display: none !important;
    }

    .footer-layout {
        display: grid !important;
        grid-template-areas:
            "swatches swatches"
            "sliders sliders"
            "wheel tools";
        grid-template-columns: auto 1fr;
        gap: 8px !important;
        padding: 0 !important;
        justify-items: start;
        align-items: center;
    }

    .footer-controls {
        display: contents !important;
    }

    .controls-top {
        display: contents !important;
    }

    #palette-list {
        grid-area: swatches;
        width: 100% !important;
        margin-bottom: 2px !important;
        justify-self: stretch;
    }

    .compact-sliders {
        grid-area: sliders;
        width: 100% !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 4px 12px !important;
        margin-bottom: 4px;
    }

    #color-wheel-btn {
        grid-area: wheel;
        width: 50px !important;
        height: 50px !important;
        margin: 0 !important;
    }

    .controls-bottom {
        grid-area: tools;
        width: 100% !important;
        margin-left: 0 !important;
        display: flex !important;
        align-items: center !important;
        overflow-x: auto;
    }

    .tools-grid-compact {
        padding: 0 !important;
        gap: 4px !important;
    }

    .tools-grid-compact .tool-btn {
        height: 44px !important;
        max-width: 48px !important;
    }

    .tools-grid-compact .tool-btn img {
        width: 24px !important;
        height: 24px !important;
    }

    .tiny-label {
        width: auto !important;
        min-width: 55px !important;
        /* Fixed width for alignment of full labels */
        font-size: 8px !important;
        text-align: left;
    }

    .main-header {
        padding: 4px 8px;
        gap: 6px;
    }

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

    .mini-slider input {
        height: 12px !important;
    }
}

/* 2. Tablet / Pad Layout (Larger Screen) - FIXED FOR PHABLET VIEW */
@media screen and (min-width: 641px) and (max-width: 1200px) {
    .main-header {
        padding: 6px 15px;
        min-height: 52px;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    /* Safe area and height management for iPad Safari */
    .tool-footer.phablet {
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
        height: auto !important;
        min-height: 130px !important;
        /* Ensure enough room for wheel + 2 rows */
        max-height: none !important;
        /* Remove restrictive limit */
    }

    .footer-layout {
        gap: 15px;
        /* More space on tablet */
    }

    .footer-controls {
        gap: 8px;
    }

    .swatch {
        width: 32px;
        height: 32px;
    }

    /* iPad-Only Dragging Feedback (Green Border) */
    /* Moved dragging-active to iPad Media Query v3.8.1 */
    #coloring-screen .tool-footer.phablet.dragging-active {
        border-color: var(--primary) !important;
        box-shadow: 0 0 25px var(--primary), 0 15px 50px rgba(0, 0, 0, 0.6) !important;
        z-index: 2001;
    }

    /* Support Free Horizontal Movement */
    #coloring-screen .tool-footer.phablet {
        left: 50%;
        transform: translateX(-50%);
    }
}

/* Custom Picker Modal Styling */
.custom-picker-content {
    width: 95%;
    max-width: 320px;
    background: #fff;
    border-radius: 20px;
    padding: 20px;
    color: #333;
    pointer-events: auto;
}

.sv-canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #eee;
    margin-bottom: 15px;
    border-radius: 10px;
    overflow: hidden;
}

.sv-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.sv-cursor {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.picker-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

#hue-slider {
    width: 100%;
    height: 15px;
    border-radius: 10px;
    background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
    -webkit-appearance: none;
    appearance: none;
}

#hue-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #fff;
    border: 2px solid #333;
    border-radius: 50%;
    cursor: pointer;
}

.picker-preview-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

#hex-label {
    font-family: monospace;
    font-weight: bold;
    font-size: 1.1rem;
}