@font-face {
    font-family: 'CrayonLibre';
    src: url('../assets/fonts/CrayonLibre.ttf') format('truetype');
    font-display: swap;
}

* {
    font-family: 'CrayonLibre', 'Comic Sans MS', cursive, sans-serif;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    scrollbar-color: #c4b4a0 transparent;
    scrollbar-width: thin;
}

img {
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

img[draggable="true"] {
    pointer-events: auto;
}

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #c4b4a0; border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: #a89888; }

:root {
    --bg: #faf6f0;
    --panel: #fff9e6;
    --pink: #ff6b9d;
    --green: #51cf66;
    --blue: #339af0;
    --yellow: #fcc419;
    --orange: #ff922b;
    --text: #5c4033;
    --border: #5c4033;
    --panel-w: 245px;

    --svg-dash-2-brown: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%235c4033' stroke-width='2' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
    --svg-dash-2-blue: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%23339af0' stroke-width='2' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
    --svg-dash-25-brown: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%235c4033' stroke-width='2.5' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
    --svg-dash-25-pink: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%23ff6b9d' stroke-width='2.5' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
    --svg-dash-25-green: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%2351cf66' stroke-width='2.5' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
    --svg-dash-25-yellow: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 200'><rect x='1' y='1' width='198' height='198' fill='none' stroke='%23fcc419' stroke-width='2.5' stroke-dasharray='6 7' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>");
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
}

body {
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(circle, transparent 0%, rgba(0,0,0,0.012) 100%);
}

/* ---------- HEADER ---------- */

#header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 0 6px;
    border-bottom: none;
    position: relative;
    z-index: 10;
    background:
        url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 200 4'><line x1='0' y1='2' x2='200' y2='2' stroke='%235c4033' stroke-width='3.5' stroke-dasharray='8 6' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") bottom / 100% 4px no-repeat,
        var(--panel);
}

#header-logo {
    height: 40px;
    width: auto;
    image-rendering: pixelated;
}

#header h1 {
    font-size: 2.3rem;
    color: #000;
    letter-spacing: 3px;
    transform: rotate(-1.5deg);
    display: inline-block;
    margin-bottom: 10px;
}

/* ---------- MAIN ---------- */

#app {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ---------- PANELS ---------- */

.panel {
    width: var(--panel-w);
    background: var(--panel);
    overflow-y: auto;
    padding: 12px 10px;
    flex-shrink: 0;
}

#layers-panel {
    border-right: none;
    background:
        url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 4 200'><line x1='2' y1='0' x2='2' y2='200' stroke='%235c4033' stroke-width='3.5' stroke-dasharray='8 6' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") right / 4px 100% no-repeat,
        var(--panel);
}

#decals-panel {
    border-left: none;
    background:
        url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 4 200'><line x1='2' y1='0' x2='2' y2='200' stroke='%235c4033' stroke-width='3.5' stroke-dasharray='8 6' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") left / 4px 100% no-repeat,
        var(--panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#decals-list {
    max-height: 75%;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 1;
}

.panel h2 {
    font-size: 1.4rem;
    text-align: center;
    margin-bottom: 10px;
    color: var(--text);
    transform: rotate(-1deg);
}

/* ---------- VIEWPORT ---------- */

#viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#canvas3d {
    width: 100%;
    height: 100%;
    display: block;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.6rem;
    color: var(--orange);
    pointer-events: none;
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: .5; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

.hint {
    font-size: 1rem;
    color: #b0a090;
    text-align: center;
    padding: 16px 8px;
}

/* ---------- TOOLBAR ---------- */

#toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 5;
}

.tool-btn {
    width: 40px;
    height: 40px;
    padding: 5px;
    background: var(--panel);
    border: none;
    cursor: pointer;
    transition: all .15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tool-btn::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.tool-btn:hover:not(:disabled)::after {
    background-image: var(--svg-dash-25-pink);
}

.tool-btn:hover:not(:disabled) {
    transform: scale(1.1) rotate(-2deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

.tool-btn:disabled {
    opacity: .35;
    cursor: default;
}

.tool-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#drag-hint {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    font-size: 1.05rem;
    color: rgba(92, 64, 51, 0.35);
    white-space: nowrap;
}

#viewport.drag-over {
    outline: 4px dashed var(--green);
    outline-offset: -4px;
}

/* ---------- FOLDERS ---------- */

.folder { margin-bottom: 14px; }

.folder-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 10px;
    border: none;
    border-radius: 10px 6px 12px 8px;
    transition: all .2s ease;
    user-select: none;
    position: relative;
}

.folder-header::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 11px 7px 13px 9px);
    pointer-events: none;
    background: transparent center / 100% 100% no-repeat;
}

.folder-header:hover::after {
    background-image: var(--svg-dash-25-yellow);
}

.folder-header:hover {
    background: rgba(252, 196, 25, .12);
    transform: scale(1.02) rotate(-.5deg);
}

.folder-icon {
    width: 36px;
    height: 36px;
}

.folder-title {
    font-size: 1.3rem;
    color: var(--text);
}

.folder-items {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 6px;
    justify-content: center;
}

.folder.open .folder-items { display: flex; }

/* ---------- DECAL THUMBNAILS ---------- */

.decal-thumb {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border: none;
    border-radius: 8px 4px 10px 6px;
    padding: 3px;
    background: #fff;
    cursor: pointer;
    transition: all .15s ease;
}

.decal-thumb[draggable="true"] {
    -webkit-user-drag: element;
}

.decal-thumb-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    position: relative;
    transform: rotate(var(--rot, 0deg));
    transition: all .15s ease;
}

.decal-thumb-wrapper::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: calc(2px + .75rem + 1px);
    clip-path: inset(0 round 9px 5px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.decal-thumb-wrapper:hover {
    transform: scale(1.12) rotate(calc(var(--rot, 0deg) - 2deg));
}

.decal-thumb-wrapper:hover .decal-thumb {
    box-shadow: 2px 3px 0 var(--yellow);
}

.decal-thumb-wrapper:hover::after {
    background-image: var(--svg-dash-25-pink);
}

.decal-thumb-wrapper.selected::after {
    background-image: var(--svg-dash-25-green);
}

.decal-thumb-wrapper.selected .decal-thumb {
    box-shadow: 0 0 0 3px rgba(81, 207, 102, .4);
}

.decal-thumb-wrapper.selected {
    transform: scale(1.15) rotate(0deg);
}

.decal-label {
    font-size: .75rem;
    color: var(--text);
    opacity: .7;
    text-align: center;
    white-space: nowrap;
}

/* ---------- LAYERS ---------- */

.layer-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 7px;
    margin-bottom: 6px;
    border: none;
    border-radius: 8px 5px 10px 6px;
    background: #fff;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, opacity .2s;
    position: relative;
}

.layer-item::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-2-brown) center / 100% 100% no-repeat;
}

.layer-handle {
    display: none;
    width: 16px;
    height: auto;
    flex-shrink: 0;
    opacity: .45;
    cursor: grab;
    touch-action: none;
}

.layer-item.slide-in {
    animation: slideIn .25s ease-out;
}

.layer-item.slide-out {
    animation: slideOut .2s ease-in forwards;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-16px) scale(.9); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes slideOut {
    to { opacity: 0; transform: translateX(-20px) scale(.85); }
}

.layer-item.bounce,
.layer-item.bounce .vis-btn {
    animation: bounce .35s ease;
}

@keyframes bounce {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.12); }
    50%  { transform: scale(.95); }
    70%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.layer-item:hover { background: #fff8e8; }

.layer-item.layer-selected {
    background: rgba(51, 154, 240, .08);
    box-shadow: 0 0 0 2px rgba(51, 154, 240, .2);
}

.layer-item.layer-selected::after {
    background-image: var(--svg-dash-2-blue);
}

.layer-item.layer-hidden { opacity: .45; }

.layer-item.layer-locked {
    cursor: default;
}

.layer-item.layer-locked .layer-thumb {
    opacity: .6;
}

.layer-item.layer-locked .layer-name {
    opacity: .6;
}

.layer-item.dragging {
    opacity: .3;
    pointer-events: none;
}

.layer-drop-indicator {
    height: 3px;
    background: var(--blue);
    border-radius: 2px;
    margin: -1.5px 4px;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(51, 154, 240, .5);
}

.layer-thumb {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}

.layer-name {
    flex: 1;
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.layer-btn {
    width: 22px;
    height: 22px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    opacity: .65;
    transition: all .15s;
    flex-shrink: 0;
}

.layer-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}

.layer-btn img {
    width: 100%;
    height: 100%;
}

.del-btn:hover { filter: brightness(1.2); }

/* ---------- MEOW ---------- */

.meow-btn {
    position: absolute;
    bottom: 62px;
    right: 12px;
    z-index: 6;
    width: 44px;
    height: 44px;
    padding: 6px;
    background: var(--panel);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s ease;
}

.meow-btn::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.meow-btn:hover::after {
    background-image: var(--svg-dash-25-pink);
}

.meow-btn:hover {
    transform: scale(1.1) rotate(-2deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

.meow-btn.hidden { display: none; }

.meow-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.meow-panel {
    position: absolute;
    bottom: 112px;
    right: 12px;
    z-index: 5;
    padding: 12px;
    background: var(--panel);
    border-radius: 10px 6px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 190px;
    animation: modalPop .2s ease;
}

.meow-panel::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 11px 7px 13px 9px);
    pointer-events: none;
    background: var(--svg-dash-2-brown) center / 100% 100% no-repeat;
}

.meow-panel.hidden { display: none; }

.meow-tones {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.meow-tone {
    width: 48px;
    height: 48px;
    padding: 4px;
    background: #fff;
    border: none;
    border-radius: 8px 5px 10px 6px;
    cursor: pointer;
    transition: all .15s;
    position: relative;
}

.meow-tone::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.meow-tone.selected::after {
    background-image: var(--svg-dash-25-green);
}

.meow-tone.selected {
    box-shadow: 0 0 0 3px rgba(81, 207, 102, .4);
}

.meow-tone:hover {
    transform: scale(1.1) rotate(-2deg);
}

.meow-tone img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.meow-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.meow-slider-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    image-rendering: pixelated;
}

/* ---------- CAPTURE ---------- */

.capture-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 6;
    width: 44px;
    height: 44px;
    padding: 6px;
    background: var(--panel);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s ease;
}

.capture-btn::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.capture-btn:hover::after {
    background-image: var(--svg-dash-25-pink);
}

.capture-btn:hover {
    transform: scale(1.1) rotate(-2deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

.capture-btn.hidden { display: none; }

.capture-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.capture-frame-wrap {
    position: absolute;
    z-index: 4;
    pointer-events: none;
    aspect-ratio: 1 / 1;
}

.capture-frame-wrap.hidden { display: none; }

.capture-frame-wrap img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.capture-shoot {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: var(--pink);
    color: #fff;
    border: none;
    border-radius: 10px 6px 12px 8px;
    cursor: pointer;
    font-size: 1.15rem;
    transition: all .15s ease;
}

.capture-shoot::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 11px 7px 13px 9px);
    pointer-events: none;
    background: var(--svg-dash-25-pink) center / 100% 100% no-repeat;
}

.capture-shoot:hover {
    transform: translateX(-50%) scale(1.06) rotate(-1deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

.capture-shoot img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.capture-shoot.hidden { display: none; }

.capture-flash {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: #fff;
    pointer-events: none;
}

.capture-flash.hidden { display: none; }

@keyframes flashBlink {
    0% { opacity: 0; }
    15% { opacity: 1; }
    100% { opacity: 0; }
}

.capture-flash.active {
    animation: flashBlink .5s ease-out forwards;
}

/* ---------- POLAROID PREVIEW ---------- */

.polaroid-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(92, 64, 51, .4);
    backdrop-filter: blur(3px);
    cursor: pointer;
}

.polaroid-card {
    animation: polaroidSlideUp 2.4s cubic-bezier(.15, .5, .25, 1) forwards;
}

@keyframes polaroidSlideUp {
    0% { transform: translateY(120vh) rotate(3deg); opacity: 0; }
    10% { opacity: 1; }
    40% { transform: translateY(20vh) rotate(-1deg); }
    70% { transform: translateY(-2vh) rotate(.5deg); }
    85% { transform: translateY(1vh) rotate(-.3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

.polaroid-canvas {
    display: block;
    max-width: 80vw;
    max-height: 75vh;
    image-rendering: pixelated;
}

.polaroid-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-top: 14px;
    animation: modalFadeIn .3s ease;
}

.polaroid-controls.hidden { display: none; }

.polaroid-btn-row {
    display: flex;
    gap: 10px;
}

.polaroid-btn-row.hidden { display: none; }

.book-glue-btn {
    background: var(--green);
}

.book-glue-btn::after {
    background: var(--svg-dash-25-green) center / 100% 100% no-repeat;
}

.polaroid-name-input {
    padding: 8px 14px;
    font-size: 1.15rem;
    font-family: 'CrayonLibre', 'Comic Sans MS', cursive;
    color: var(--text);
    background: #fff;
    border: none;
    border-radius: 8px 5px 10px 6px;
    outline: none;
    text-align: center;
    min-width: 180px;
    position: relative;
}

.polaroid-name-input::placeholder {
    color: #c0b0a0;
}

.polaroid-name-input:focus {
    box-shadow: 0 0 0 2.5px var(--blue);
}

/* ---------- LAYER ADJUSTMENTS ---------- */

.layer-adjustments {
    position: absolute;
    bottom: 12px;
    left: 12px;
    z-index: 5;
    padding: 10px 12px;
    background: var(--panel);
    border-radius: 10px 6px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 180px;
    transition: opacity .25s ease, transform .25s ease;
}

.layer-adjustments::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 11px 7px 13px 9px);
    pointer-events: none;
    background: var(--svg-dash-2-blue) center / 100% 100% no-repeat;
}

.layer-adjustments.hidden {
    display: none;
}

.adj-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.adj-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    image-rendering: pixelated;
}

.adj-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #f0e8d8;
    border-radius: 4px;
    outline: none;
    border: 1.5px solid #d4c8b8;
    cursor: pointer;
}

.adj-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--panel);
    border: 2.5px solid var(--blue);
    box-shadow: 1px 2px 0 var(--yellow);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}

.adj-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 2px 3px 0 var(--yellow);
}

.adj-slider::-webkit-slider-thumb:active {
    transform: scale(1.1);
    border-color: var(--pink);
}

.adj-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--panel);
    border: 2.5px solid var(--blue);
    box-shadow: 1px 2px 0 var(--yellow);
    cursor: pointer;
}

.adj-slider::-moz-range-track {
    height: 8px;
    background: #f0e8d8;
    border-radius: 4px;
    border: 1.5px solid #d4c8b8;
}

/* ---------- CONFIRM MODAL ---------- */

.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(92, 64, 51, .35);
    backdrop-filter: blur(3px);
    animation: modalFadeIn .2s ease;
}

.confirm-modal.hidden { display: none; }

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

.confirm-box {
    background: var(--panel);
    padding: 24px 32px;
    border-radius: 14px 8px 16px 10px;
    text-align: center;
    position: relative;
    animation: modalPop .25s ease;
    min-width: 220px;
}

@keyframes modalPop {
    from { transform: scale(.85) rotate(-2deg); opacity: 0; }
    to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.confirm-box::after {
    content: '';
    position: absolute;
    inset: -2px;
    clip-path: inset(0 round 15px 9px 17px 11px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.confirm-msg {
    font-size: 1.3rem;
    color: var(--text);
    margin-bottom: 18px;
    transform: rotate(-.5deg);
}

.confirm-btns {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-btn {
    padding: 8px 22px;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px 5px 10px 6px;
    cursor: pointer;
    transition: all .15s ease;
    position: relative;
}

.confirm-btn::after {
    content: '';
    position: absolute;
    inset: -1px;
    clip-path: inset(0 round 9px 6px 11px 7px);
    pointer-events: none;
}

.confirm-yes {
    background: var(--pink);
    color: #fff;
}

.confirm-yes::after {
    background: var(--svg-dash-25-pink) center / 100% 100% no-repeat;
}

.confirm-yes:hover {
    transform: scale(1.08) rotate(-1deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

.confirm-no {
    background: #fff;
    color: var(--text);
}

.confirm-no::after {
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.confirm-no:hover {
    transform: scale(1.08) rotate(1deg);
    box-shadow: 2px 3px 0 var(--yellow);
}

/* ---------- COLLAR EDITOR ---------- */

.collar-editor {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(92, 64, 51, .4);
    backdrop-filter: blur(3px);
    animation: modalFadeIn .2s ease;
    cursor: pointer;
    padding: 20px;
}

.collar-editor.hidden { display: none; }

.collar-editor-box {
    background: var(--panel);
    padding: 24px 28px;
    border-radius: 14px 8px 16px 10px;
    text-align: center;
    position: relative;
    animation: modalPop .25s ease;
    cursor: default;
    max-width: 320px;
    width: 100%;
}

.collar-editor-box::after {
    content: '';
    position: absolute;
    inset: -2px;
    clip-path: inset(0 round 15px 9px 17px 11px);
    pointer-events: none;
    background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
}

.collar-editor-title {
    font-size: 1.4rem;
    color: var(--pink);
    margin-bottom: 12px;
    transform: rotate(-1deg);
}

.collar-editor-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 14px;
}

.collar-editor-bg {
    max-width: 200px;
    width: 100%;
    image-rendering: pixelated;
    display: block;
}

.pendant-canvas {
    position: absolute;
    top: 14%;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    height: auto;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: crosshair;
    touch-action: none;
}

.collar-editor-colors {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.collar-color {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2.5px solid var(--border);
    cursor: pointer;
    transition: all .15s;
    padding: 0;
}

.collar-color:hover {
    transform: scale(1.2);
    box-shadow: 2px 3px 0 var(--yellow);
}

.collar-color.active {
    box-shadow: 0 0 0 3px var(--pink);
    transform: scale(1.15);
}

.collar-editor-tools {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 12px;
}

.collar-eraser {
    width: 34px;
    height: 34px;
    padding: 4px;
    background: #fff;
    border: 2.5px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition: all .15s;
}

.collar-eraser:hover {
    transform: scale(1.2);
    box-shadow: 2px 3px 0 var(--yellow);
}

.collar-eraser.active {
    box-shadow: 0 0 0 3px var(--pink);
    transform: scale(1.15);
}

.collar-eraser img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.collar-editor-btns {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ---------- TUTORIAL ---------- */

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(92, 64, 51, .45);
    backdrop-filter: blur(4px);
    animation: modalFadeIn .3s ease;
    padding: 20px;
}

.tutorial-box {
    background: var(--panel);
    padding: 28px 32px;
    border-radius: 14px 8px 16px 10px;
    position: relative;
    animation: modalPop .3s ease;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.tutorial-box::after {
    content: '';
    position: absolute;
    inset: -2px;
    clip-path: inset(0 round 15px 9px 17px 11px);
    pointer-events: none;
    background: var(--svg-dash-25-pink) center / 100% 100% no-repeat;
}

.tutorial-title {
    font-size: 1.6rem;
    color: var(--pink);
    margin-bottom: 6px;
    transform: rotate(-1deg);
}

.tutorial-body {
    font-size: 1.15rem;
    color: var(--text);
    margin-bottom: 16px;
}

.tutorial-steps {
    text-align: left;
    padding-left: 22px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tutorial-steps li {
    font-size: .95rem;
    color: var(--text);
    line-height: 1.35;
}

.tutorial-btn {
    font-size: 1.2rem;
    padding: 10px 36px;
}

/* ---------- C3B LOGO ---------- */

#c3b-logo {
    position: fixed;
    top: 17px;
    left: 25px;
    z-index: 50;
    height: 28px;
    width: auto;
    image-rendering: pixelated;
    transition: all .2s ease;
    cursor: pointer;
}

#c3b-logo:hover {
    transform: scale(1.15) rotate(-3deg);
    filter: drop-shadow(2px 3px 0 rgba(252, 196, 25, .7));
}

/* ---------- PHOTO BOOK ---------- */

.book-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform .2s ease;
    margin-top: 16px;
    padding: 10px 0;
}

.book-preview:hover {
    transform: scale(1.08);
}

.book-preview-scene {
    position: relative;
    width: 120px;
    height: 132px;
    perspective: 400px;
}

.book-preview-page {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
    border-radius: 2px;
}

.book-preview-cover {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
    transform-origin: left center;
    transition: transform .4s cubic-bezier(.4, 0, .2, 1);
}

.book-preview:hover .book-preview-cover {
    transform: rotateY(-30deg);
}

.book-preview-label {
    font-size: 1rem;
    color: var(--text);
    white-space: nowrap;
}


/* ---------- MOBILE ---------- */

.mob-btn,
.mob-tray,
.mob-backdrop { display: none; }

@media (max-width: 768px) {
    #header { display: none; }

    #layers-panel,
    #decals-panel { display: none !important; }

    #layers-panel.mob-visible {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 80vw;
        height: 100%;
        z-index: 50;
        box-shadow: 4px 0 20px rgba(0,0,0,.15);
        background:
            url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 4 200'><line x1='2' y1='0' x2='2' y2='200' stroke='%235c4033' stroke-width='3.5' stroke-dasharray='8 6' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") right / 4px 100% no-repeat,
            var(--panel);
    }

    #app { height: 100vh; }

    #viewport { width: 100%; }

    .mob-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 6px;
        background: var(--panel);
        border: none;
        cursor: pointer;
        position: absolute;
        z-index: 6;
        transition: all .15s ease;
    }
    .mob-btn::after {
        content: '';
        position: absolute;
        inset: -1px;
        clip-path: inset(0 round 9px 6px 11px 7px);
        pointer-events: none;
        background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
    }
    .mob-btn:hover::after,
    .mob-btn:active::after { background-image: var(--svg-dash-25-pink); }
    .mob-btn img { width: 100%; height: 100%; object-fit: contain; }

    .mob-folder-btn { bottom: 12px; left: 12px; }
    .mob-folder-btn.hidden { display: none; }
    .mob-layers-btn { top: 10px; left: 10px; }

    .mob-tray {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 40vh;
        background: var(--panel);
        z-index: 20;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,.1);
        padding: 12px 12px 16px;
    }
    .mob-tray:not(.hidden) { display: block; }
    .mob-tray.hidden { display: none; }

    @keyframes traySlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .tray-slide {
        animation: traySlideUp .3s ease;
    }

    .mob-tray-header {
        align-items: center;
        gap: 10px;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 2.5px dashed var(--border);
    }
    .mob-tray-header:not(.hidden) { display: flex; }
    .mob-tray-header.hidden { display: none; }

    .mob-tray-back {
        width: 32px;
        height: 32px;
        padding: 4px;
        background: none;
        border: none;
        cursor: pointer;
    }
    .mob-tray-back img { width: 100%; height: 100%; }

    .mob-tray-title {
        font-size: 1.3rem;
        color: var(--text);
    }

    .mob-tray-cats {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
        padding: 4px 0;
    }

    .mob-cat-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 10px 18px;
        background: #fff;
        border: none;
        border-radius: 10px 6px 12px 8px;
        cursor: pointer;
        transition: all .15s;
        position: relative;
    }
    .mob-cat-btn::after {
        content: '';
        position: absolute;
        inset: -1px;
        clip-path: inset(0 round 11px 7px 13px 9px);
        pointer-events: none;
        background: var(--svg-dash-25-brown) center / 100% 100% no-repeat;
    }
    .mob-cat-btn:active::after { background-image: var(--svg-dash-25-pink); }
    .mob-cat-btn:active { transform: scale(1.05); }
    .mob-cat-btn img { width: 44px; height: 44px; object-fit: contain; }
    .mob-cat-btn span { font-size: 1rem; color: var(--text); }

    .mob-tray-topbar {
        display: flex;
        justify-content: flex-end;
        margin-bottom: 4px;
    }

    .mob-tray-close {
        width: 32px;
        height: 32px;
        padding: 4px;
        background: none;
        border: none;
        cursor: pointer;
        opacity: .6;
        transition: all .15s;
    }
    .mob-tray-close:active { opacity: 1; transform: scale(1.15); }
    .mob-tray-close img { width: 100%; height: 100%; }

    .mob-tray-header .mob-tray-close { margin-left: auto; }

    .mob-layers-close {
        position: absolute;
        top: 8px;
        right: 8px;
        z-index: 51;
    }

    .mob-tray-items {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }

    .mob-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.25);
        z-index: 45;
    }
    .mob-backdrop:not(.hidden) { display: block; }
    .mob-backdrop.hidden { display: none; }

    #toolbar {
        top: unset;
        right: unset;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
    }
    .tool-btn { width: 36px; height: 36px; }

    #flip-h-btn,
    #flip-v-btn {
        position: absolute;
        z-index: 6;
        top: 10px;
    }
    #flip-h-btn { left: calc(50% - 39px); }
    #flip-v-btn { left: calc(50% + 3px); }

    .layer-adjustments {
        position: relative;
        bottom: unset;
        left: unset;
        right: unset;
        min-width: unset;
        z-index: 7;
        background: none;
        border-radius: 0;
        padding: 6px 0;
    }

    .layer-adjustments::after {
        display: none;
    }

    @keyframes trayBump {
        0%   { transform: translateY(0); }
        30%  { transform: translateY(6px); }
        60%  { transform: translateY(-3px); }
        100% { transform: translateY(0); }
    }

    .tray-bump {
        animation: trayBump .3s ease;
    }

    .meow-panel {
        right: 8px;
        left: 8px;
        min-width: unset;
    }

    #drag-hint { display: none; }

    .layer-item {
        padding: 10px 10px;
        margin-bottom: 8px;
        gap: 8px;
        min-height: 52px;
    }

    .layer-handle {
        display: block;
        width: 18px;
        padding: 8px 6px 8px 0;
        box-sizing: content-box;
    }
    .layer-item.layer-locked .layer-handle { opacity: .2; }

    .layer-thumb {
        width: 36px;
        height: 36px;
    }

    .layer-name { font-size: 1rem; }

    .layer-btn {
        width: 28px;
        height: 28px;
        padding: 2px;
    }

    #layers-panel.mob-visible #layers-list {
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    #c3b-logo {
        display: none;
    }

    .book-preview {
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 6;
        margin-top: 0;
        padding: 0;
        gap: 2px;
    }

    .book-preview-scene {
        width: 48px;
        height: 53px;
    }

    .book-preview-label {
        font-size: .7rem;
    }

}

/* ---------- BOOK OVERLAY ---------- */

.book-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    transform: translateY(100%);
    transition: transform .8s cubic-bezier(.25, .1, .25, 1);
    background: url('../assets/ui/table.png') center / cover no-repeat;
    image-rendering: pixelated;
}

.book-overlay.open {
    transform: translateY(0);
}

.book-overlay iframe {
    width: 100%;
    height: 100%;
    border: none;
}
