:root {
    --white: #ffffff;
    --bg: #f3f0e9;
    --bg-dot: #e4dfd5;
    --surface: #ffffff;
    --surface-2: #faf8f4;
    --border: #e4dfd6;
    --border-lt: #efebe3;
    --text: #191816;
    --text2: #76716a;
    --text3: #a8a299;
    --accent: #e05a47;
    --red: #d64545;
    --blue: #3b82f6;
    --polaroid: #faf8f4;
    --pol-sh: rgba(25, 24, 22, 0.09);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --hw: 'Caveat', cursive;
    --mono: 'Space Mono', monospace;
    --r: 12px;
    --r-sm: 8px;
    --r-lg: 18px;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

body {
    background-image: radial-gradient(var(--bg-dot) 1px, transparent 1px);
    background-size: 20px 20px;
}

.dot-bg-sm {
    background-image: radial-gradient(var(--bg-dot) 1px, transparent 1px);
    background-size: 16px 16px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

.hidden { display: none !important; }

/* Interactive state classes toggled by app.js */
.text-btn.active { color: var(--text); background: var(--white); border-color: var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.tool-btn.active { background: var(--text); color: var(--white); border-color: var(--text); }
.lay-btn.active { background: var(--white); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.tab-btn.active { color: var(--white); background: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
.fit-btn.active { background: var(--white); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.sz-btn.active, .fn-btn.active { background: var(--text); color: var(--white); border-color: var(--text); }
.cdot.active { border-color: var(--text) !important; box-shadow: 0 0 0 2px var(--white), 0 0 0 3.5px var(--text); }

.modal-overlay.active { opacity: 1; pointer-events: all; }
.camera-box, .editor {
    transform: scale(0.94) translateY(14px);
    transition: transform 360ms var(--spring);
}
.modal-overlay.active .camera-box,
.modal-overlay.active .editor { transform: scale(1) translateY(0); }

/* Empty state animations */
.empty { animation: fadeUp 0.5s var(--ease); }
.empty-card-front { animation: float 4.5s ease-in-out infinite; }

/* Camera specifics */
.cam-live-dot { animation: pulseDot 1.6s infinite; }
.cam-view video.mirrored { transform: scaleX(-1); }
.cam-grid {
    background:
        linear-gradient(to right, transparent 33.33%, rgba(255,255,255,0.14) 33.33%, rgba(255,255,255,0.14) 33.6%, transparent 33.6%, transparent 66.66%, rgba(255,255,255,0.14) 66.66%, rgba(255,255,255,0.14) 66.9%, transparent 66.9%),
        linear-gradient(to bottom, transparent 33.33%, rgba(255,255,255,0.14) 33.33%, rgba(255,255,255,0.14) 33.6%, transparent 33.6%, transparent 66.66%, rgba(255,255,255,0.14) 66.66%, rgba(255,255,255,0.14) 66.9%, transparent 66.9%);
}
.shutter:active .shutter-dot { width: 44px; height: 44px; }

/* Film Tray (dynamically rendered by app.js) */
.gallery { animation: fadeUp 0.4s var(--ease); }
.preview { animation: fadeUp 0.4s var(--ease); }

.strip-item {
    flex-shrink: 0;
    position: relative;
    cursor: grab;
    transition: transform 250ms var(--spring), opacity 200ms;
    animation: dropIn 0.45s var(--spring);
}
.strip-item:active { cursor: grabbing; }
.strip-item.dragging { opacity: 0.35; transform: scale(0.92) !important; }
.strip-item.drag-over { transform: scale(1.06) !important; }

.strip-pol {
    width: 112px;
    background: var(--polaroid);
    border-radius: 2px;
    padding: 6px 6px 20px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 10px var(--pol-sh);
    transition: transform 240ms var(--spring), box-shadow 240ms;
    cursor: pointer;
}
.strip-item:hover .strip-pol { transform: translateY(-4px) rotate(0deg); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12); }
.strip-pol img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; border-radius: 1px; }
.strip-caption {
    font-family: var(--hw);
    font-size: 0.85rem;
    color: #9e9689;
    text-align: center;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 16px;
}
.strip-num {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 21px;
    height: 21px;
    background: var(--text);
    color: var(--white);
    font-size: 0.64rem;
    font-weight: 700;
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.strip-rm {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 21px;
    height: 21px;
    background: var(--red);
    color: var(--white);
    border: none;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.6);
    transition: all 150ms var(--spring);
    z-index: 2;
    line-height: 1;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.strip-item:hover .strip-rm,
.strip-item:focus-within .strip-rm { opacity: 1; transform: scale(1); }

.strip-badge {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.56rem;
    font-weight: 700;
    color: var(--text2);
    background: rgba(255, 255, 255, 0.92);
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 150ms;
    letter-spacing: 0.03em;
    pointer-events: none;
}
.strip-item:hover .strip-badge { opacity: 1; }

.strip-add-card {
    flex-shrink: 0;
    width: 112px;
    height: 136px;
    border: 1.5px dashed var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--text3);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 180ms var(--ease);
}
.strip-add-card:hover {
    border-color: var(--text2);
    color: var(--text);
    background: var(--white);
}

/* A4 Print Sheet Preview (dynamically rendered by app.js) */
.a4 {
    position: relative;
    background: var(--white);
    box-shadow: 0 8px 32px rgba(25, 24, 22, 0.08), 0 0 0 1px var(--border);
    border-radius: 4px;
    aspect-ratio: 210 / 297;
    width: 100%;
    max-width: 580px;
    overflow: hidden;
}

.a4-grid {
    position: absolute;
    inset: 0;
    padding: 4.8%;
    display: grid;
    align-items: center;
    justify-items: center;
}
.a4-grid.grid-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 2% 3%; }
.a4-grid.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 4% 5%; }
.a4-grid.grid-2 { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 5%; }
.a4-grid.grid-1 { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 0; }

.a4-grid.grid-6 .pol { height: 96%; width: auto; max-width: 100%; }
.a4-grid.grid-4 .pol { height: 92%; width: auto; max-width: 100%; }
.a4-grid.grid-2 .pol { height: 90%; width: auto; max-width: 100%; }
.a4-grid.grid-1 .pol { height: 84%; width: auto; max-width: 100%; }

.a4-num {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.62rem;
    color: var(--text3);
    font-weight: 600;
}

.pol {
    position: relative;
    width: 100%;
    aspect-ratio: 70 / 85;
    background: var(--polaroid);
    border-radius: 1.5px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: visible;
    cursor: pointer;
    transform: rotate(var(--tilt, 0deg));
    transition: transform 260ms var(--spring), box-shadow 260ms;
}
.pol:hover { transform: rotate(var(--tilt, 0deg)) scale(1.025); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); z-index: 2; }

.a4.show-cuts .pol::before {
    content: '';
    position: absolute;
    inset: -5px;
    pointer-events: none;
    border: 1px dashed rgba(25, 24, 22, 0.25);
}

.pol-img {
    flex: 1;
    margin: 5.7% 5.7% 0;
    border-radius: 1px;
    overflow: hidden;
    background: #eae6de;
}
.pol-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pol-bottom {
    height: 22.35%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8%;
}
.pol-cap {
    font-family: var(--hw);
    font-size: clamp(0.6rem, 1.5vw, 1rem);
    color: #9e9689;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Editor controls & dynamic items */
@media (min-width: 781px) and (min-height: 640px) {
    .editor-workspace { min-height: 456px; }
}

.tab-content { animation: fadeUp 160ms var(--ease); }

.filter-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 5px;
    border-radius: 10px;
    border: 1.5px solid var(--border-lt);
    background: var(--surface-2);
    transition: all 150ms var(--ease);
}
.filter-opt:hover { border-color: #c7c0b5; transform: translateY(-1px); }
.filter-opt.active { border-color: var(--text); background: var(--white); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.filter-thumb { width: 100%; aspect-ratio: 1; border-radius: 6px; object-fit: cover; }
.filter-name { font-size: 0.66rem; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }
.filter-opt.active .filter-name { color: var(--text); }

input[type="range"] {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 120ms var(--ease);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.toggle-pill[aria-pressed="true"] { border-color: var(--text); background: var(--text); color: var(--white); }
.toggle-pill[aria-pressed="true"] .toggle-knob { background: var(--accent); }

.topt::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--sw);
    border: 1px solid var(--swb);
    flex-shrink: 0;
}
.topt.active { border-color: var(--text); color: var(--text); background: var(--surface-2); }

/* Overlays */
.ov-item {
    position: absolute;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    transform: translate(-50%, -50%);
    padding: 4px 6px;
    border-radius: 4px;
    border: 2px solid transparent;
    transition: border-color 100ms;
}
.ov-item:hover { border-color: rgba(59, 130, 246, 0.35); }
.ov-item.selected { border-color: var(--blue); }
.ov-item[contenteditable="true"] {
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.5);
}
.ov-text { font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,0.4), 0 0 8px rgba(0,0,0,0.15); white-space: nowrap; min-width: 16px; outline: none; }
.ov-sticker { line-height: 1; pointer-events: auto; }

.ov-tools { animation: fadeUp 0.2s var(--ease); }

.cdot-picker-wrap {
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

/* Emoji Picker (dynamically rendered by app.js) */
.emoji-cat-btn {
    border: none;
    background: transparent;
    padding: 4px 7px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1.2;
    opacity: 0.6;
    transition: all 120ms;
    flex-shrink: 0;
}
.emoji-cat-btn:hover { opacity: 1; background: rgba(0,0,0,0.04); }
.emoji-cat-btn.active { opacity: 1; background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.emoji-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 18px 8px;
    font-size: 0.76rem;
    color: var(--text3);
}
.sk {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.35rem;
    border-radius: 8px;
    transition: transform 100ms, background 100ms;
}
.sk:hover { background: var(--white); transform: scale(1.15); }

.drop-zone { animation: fadeIn 0.2s var(--ease); }
.flash.on { opacity: 0.9; }
.toast { animation: toastIn 0.28s var(--spring); }
.context-menu { animation: ctxIn 120ms var(--ease); }

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dropIn { 0% { opacity: 0; transform: translateY(-16px) rotate(-3deg) scale(0.88); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-6px) rotate(-2deg); } }
@keyframes pulseDot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.85); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.92); } to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes ctxIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 600px) {
    .strip-pol, .strip-add-card { width: 92px; }
    .strip-add-card { height: 116px; }
    .a4 { max-width: 100%; }
}

@media print {
    @page { size: A4; margin: 0; }
    *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    body { background: white !important; margin: 0; padding: 0; }
    .header, .actions, .gallery, .bar, .hint, .footer, .modal-overlay, .flash, .empty, .a4-num, .drop-zone, .toast, .context-menu { display: none !important; }
    .app, .main, .studio-workspace, .preview, .pages { all: unset !important; display: block !important; }
    .a4 { width: 210mm !important; height: 297mm !important; max-width: none !important; aspect-ratio: auto !important; box-shadow: none !important; border-radius: 0 !important; page-break-after: always; break-after: page; position: relative !important; overflow: hidden !important; background: white !important; margin: 0 !important; }
    .a4:last-child { page-break-after: auto; break-after: auto; }

    .a4-grid { position: absolute !important; inset: 0 !important; padding: 10mm !important; display: grid !important; align-items: center !important; justify-items: center !important; }
    .a4-grid.grid-6 { grid-template-columns: 1fr 1fr !important; grid-template-rows: 1fr 1fr 1fr !important; gap: 3mm 5mm !important; }
    .a4-grid.grid-4 { grid-template-columns: 1fr 1fr !important; grid-template-rows: 1fr 1fr !important; gap: 6mm 8mm !important; }
    .a4-grid.grid-2 { grid-template-columns: 1fr !important; grid-template-rows: 1fr 1fr !important; gap: 8mm 8mm !important; }
    .a4-grid.grid-1 { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; gap: 0 !important; }

    .pol { aspect-ratio: auto !important; border-radius: 1px !important; box-shadow: 0 0 0 0.3mm #ddd !important; display: flex !important; flex-direction: column !important; overflow: visible !important; }
    .a4-grid.grid-6 .pol { width: 70mm !important; height: 85mm !important; }
    .a4-grid.grid-4 .pol { width: 85mm !important; height: 103mm !important; }
    .a4-grid.grid-2 .pol { width: 120mm !important; height: 145mm !important; }
    .a4-grid.grid-1 .pol { width: 150mm !important; height: 182mm !important; }

    .pol:hover { transform: none !important; box-shadow: 0 0 0 0.3mm #ddd !important; }
    .pol-img { margin: 5.7% 5.7% 0 !important; flex: 1 !important; height: auto !important; flex-shrink: 0 !important; }
    .pol-bottom { height: 22.35% !important; flex-shrink: 0 !important; display: flex !important; align-items: center !important; justify-content: center !important; }
}
