html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
overscroll-behavior: none;
} 
.main {
padding: 0;
margin: 0;
} 
#app {
display: flex;
flex-direction: column;
height: 100vh;              /* 🔑 Full viewport height - allows flex: 1 to work on wrapper */
height: 100dvh;             /* 🔑 Dynamic viewport height (fallback for mobile) */
} 
#header {
padding: 5px 10px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
border-bottom: 1px solid var(--border);
background: var(--bg);
font-size: 75%;
line-height: 1em;
} 
#header .domain-name {
font-weight: bold;
} 
#header .icon {
width: 20px;
height: 20px;
color:var(--link);
} 
#canvasWrapper {
flex: 1;
position: relative;
display: flex;
flex-direction: row;
justify-content: flex-start;       /* 🔑 ALIGN TO TOP-LEFT */
align-items: flex-start;           /* 🔑 ALIGN TO TOP-LEFT */
overflow: auto;                    /* Allow scrolling */
gap: 0;
padding: 0;                        /* No padding - canvas controls all positioning */
-webkit-user-select: none;
overflow: auto;              /* Wrapper can scroll if needed */
touch-action: manipulation;  /* Wrapper allows natural panning */
min-width: 100%;             /* 🔑 Zoom support: prevent clipping when scaled */
min-height: 100%;            /* 🔑 Zoom support: prevent clipping when scaled */

}

/* 🔑 ALL CANVAS PROPERTIES CONTROLLED BY JAVASCRIPT */
#canvas { touch-action:none;
/* Do NOT set display, size, position, borders, margins, or any visual properties here */
/* Everything is controlled by JavaScript */
}

.error {
padding: 20px;
background: #d32f2f;
color: white;
margin: 10px;
border-radius: 4px;
}
.w{white-space:nowrap} 

/* ====== CROP OVERLAY STYLES (FIXED) ====== */
#cropOverlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.85);
display: none;
align-items: center;
justify-content: center;
z-index: 10000;
flex-direction: column;
padding: 10px;
} 
#cropArea {
position: relative;
width: 90vw;
height: 90vw;
max-width: 600px;
max-height: 600px;
background: #111;
overflow: hidden;
border: 1px solid #555;
touch-action: pinch-zoom; 
} 
#cropImage {
position: absolute;
top: 0; 
left: 0;
max-width: none;
user-select: none;
touch-action: none;
pointer-events: none; 
} 
#cropBox {
position: absolute;
border: 2px solid #4CAF50;
box-sizing: border-box;
cursor: move;
width: 200px;
height: 200px;
touch-action: none; 
min-width: 60px;
min-height: 60px;
} 
@media (pointer: coarse) {
#cropBox {
border-width: 3px;
}
} 
.resize-handle {
width: 40px;
height: 40px;
position: absolute;
touch-action: none;
border-radius: 50%;
background-color: rgba(76, 175, 80, 0.6);
border: 2px solid #4CAF50;
cursor: nwse-resize;
} 
.corner-br { bottom: -20px; right: -20px; cursor: nwse-resize; }
.corner-bl { bottom: -20px; left: -20px; cursor: nesw-resize; }
.corner-tr { top: -20px; right: -20px; cursor: nesw-resize; }
.corner-tl { top: -20px; left: -20px; cursor: nwse-resize; } 

#cropDarkMask {
position: absolute;
inset: 0;
background: rgba(0,0,0,0.65);
pointer-events: none; 
/* performance hints */
will-change: clip-path; 
/* Firefox flicker fix */
contain: strict;
transform: translateZ(0);
} 

#cropActions {
margin-top: 10px;
} 
#stickerScrollable{margin-top:10px}
/* ---------- FONT ITEM ---------- */ 
.font-item {
background: #333;
margin:5px;
border-radius: 8px;
cursor: pointer;
text-align: center;
color: #fff;
position: relative;
display: flex;
justify-content: center;
min-height: 60px; /* stable height */
flex-direction: column;
} 
.svg-shape-item {
width: 160px;
height: 160px;
display: inline-block;
cursor: pointer;
overflow: hidden;
}
.svg-shape-item img {
width: 100%;
height: 100%;
object-fit: cover;
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-position: center;
mask-position: center;
}
.sticker-item {
width: 160px;
height: 200px;

display: inline-block;
cursor: pointer;
overflow: hidden;
text-align:center;
font-size:60%;
overflow:hidden;
position:relative;
} 
.sticker-item, .frame-item{ border:solid 1px var(--border);
border-radius:var(--radius);
}
.frame-item {
width: 160px;
height: 160px;
margin:2px; 
display: inline-block;
cursor: pointer;
overflow: hidden;
text-align:center;
font-size:60%;
overflow:hidden;
position:relative;
}
.frame-item img{max-width: 160px;
max-height: 160px;}
.frame-item .likeBtn,.sticker-item .likeBtn, .wallpaper-item .likeBtn{position:absolute;top:0;left:0;margin:0}
.frame-item .deleteFrameBtn, .sticker-item .deleteStickerBtn, .wallpaper-item .deleteWallpaperBtn {position:absolute;top:0;right:0;margin:0} 

.svg-shape-item .deleteSvgShapeBtn{position:absolute;bottom:0;right:0;margin:0}
.frame-item{background-repeat: no-repeat;
background-position: center;
background-size: cover;
} 
.sticker-item img{ max-width: 160px;
max-height: 160px;
}

/* SVG Shapes Grid Styling */
.svg-shape-item {
width: 160px;
height: 200px;
display: inline-block;
cursor: pointer;
overflow: hidden;
text-align: center;
font-size: 60%;
position: relative;
border: solid 1px var(--border);
border-radius: var(--radius);
margin: 2px;
}

.svg-shape-preview {
width: 100%;
height: 120px;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--bg-light);
}

.svg-shape-preview svg {
width: 80px;
height: 80px;
}

.svg-shape-item span {
display: block;
padding: 8px 4px 4px;
font-size: 11px;
font-weight: bold;
}

.svg-shape-item .likeBtn, .svg-shape-item .deleteSvgShapeBtn {
position: absolute;
margin: 0;
font-size: 12px;
}

.svg-shape-item .likeBtn {
top: 0;
left: 0;
}


.shape-item {
width: 160px;
height: 160px;
display: inline-block;
cursor: pointer;
overflow: hidden;
}
.shape-item img {
width: 100%;
height: 100%;
object-fit: cover;
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-position: center;
mask-position: center;
}

.sticker-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: 1px;
padding: 1px;
justify-items: center;
} 
input[type="color"]{width:2em;height:26px;border:solid 2px var(--border2)} 

.mainbtn{background:#05f !important;color:#fff !important} 
.btnpad{padding:0 9px;}
input[type="range"]{width:4em} 
#scaleSlider, #rotationSlider{width:7em}

.toggle-switch {
display: inline-flex;
align-items: center;
gap: .5rem;
cursor: pointer;
user-select: none;
margin:0 4px;
vertical-align:middle;
} 
.toggle-switch input {
display: none;
} 
.toggle-switch .slider {
width: 42px;
height: 22px;
background: #666;
border-radius: 999px;
position: relative;
transition: background .2s;
} 
.toggle-switch .slider::before {
content: "";
width: 18px;
height: 18px;
background: #fff;
border-radius: 50%;
position: absolute;
top: 2px;
left: 2px;
transition: transform .2s;
} 
.toggle-switch input:checked + .slider {
background: #4caf50;
} 
.toggle-switch input:checked + .slider::before {
transform: translateX(20px);
} 
/* one item per row */
.texture-grid {
display: flex;
flex-direction: column;
} 
/* row container */
.texture-item {
padding: 8px 10px;
border-bottom: 1px solid var(--border);
cursor: pointer;
} 

/* LEFT: thumbnail */
.texture-bg {
width: 56px;
height: 56px;
border-radius: 6px;
background-size: cover;
background-position: center;
border: 1px solid var(--border3);
float:left;
}
.texturename{font-size:70%} 
.texture-preview {
flex: 1;
height: 56px;
display: flex;
align-items: center;
justify-content: flex-start;
font-size: 69px;
font-weight: 800;
letter-spacing: -0.04em;
color: transparent;
background-repeat: repeat; /* ✅ Critical - allows tiling */
background-position: center;
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
cursor: pointer;
/* background-size set dynamically via JS */
}
#texturePreviewBgWrap{white-space:nowrap} 
/* Shared template grid base styles */
#canvasTemplateGrid,
#textTemplateGrid,
#photoTemplateGrid {
display: grid;
gap: 10px;
padding: 10px;
justify-content: center;
} 
/* Grid column widths */
#canvasTemplateGrid,
#photoTemplateGrid {
grid-template-columns: repeat(auto-fill, 230px);
} 
#textTemplateGrid {
grid-template-columns: repeat(auto-fill, 360px);
} 
/* Shared template-item base styles */
#canvasTemplateGrid .template-item,
#textTemplateGrid .template-item,
#photoTemplateGrid .template-item {
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 8px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
overflow: hidden;
} 
/* Template-item dimensions */
#canvasTemplateGrid .template-item,
#photoTemplateGrid .template-item {
width: 230px;
height: 240px;
} 
#textTemplateGrid .template-item {
width: 360px;
height: auto;
min-height: 160px;
} 
/* Shared canvas base styles */
#canvasTemplateGrid .template-item canvas,
#textTemplateGrid .template-item canvas,
#photoTemplateGrid .template-item canvas {
display: block;
margin-bottom: 5px;
cursor: pointer;
} 
/* Canvas max dimensions */
#canvasTemplateGrid .template-item canvas,
#photoTemplateGrid .template-item canvas {
max-width: 220px;
max-height: 160px;
} 
#textTemplateGrid .template-item canvas {
max-width: 350px;
max-height: 120px;
} 
/* Default template grid for other template types */
.template-grid {
display: inline-flex;
flex-wrap: wrap;
gap: 10px;
padding: 5px;
width: 100%;
} 
.template-item {
border-bottom: 1px solid var(--border);
padding: 5px;
line-height: 0.8em;
min-height: 50px;
} 
.template-item canvas {
display: block;
cursor: pointer;
} 
.template-name {
font-size: 60%;
line-height: 1.2em;
text-align: center;
width: 100%;
display: flex;
flex-wrap: wrap;
gap: 4px;
align-items: center;
justify-content: center;
} 
.template-name > span:first-child {
flex-basis: 100%;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
} 
.template-name svg.icon {
width: 30px;
height: 30px;
} 
.checkered {
width: 32px;
height: 32px;
background-color: #ccc;
background-image: 
linear-gradient(45deg, #808080 25%, transparent 25%, transparent 75%, #808080 75%),
linear-gradient(45deg, #808080 25%, transparent 25%, transparent 75%, #808080 75%);
background-size: 8px 8px;
background-position: 0 0, 4px 4px;
display:inline-block;
vertical-align:middle;
}
.closemenu{display:none;color:#c00;float:right;margin-right:10px}
.backmenu{color:#c00;margin-left:6px;margin-right:2px;float:right}
.backmenu svg {width:40px;height:36px}
.plus{font-size: 1.5em;
vertical-align: middle;
font-weight: bold;
}
.big{color:#080}
[data-theme="dark"] .big{color:#ffa} 

.redtext{color:#c00;}
.greentext{color:#0a0;} 
.template-item.active .template-actions {
display: flex;
flex-direction: column;
} 
.template-item.active {
outline: 2px solid #4a90e2;
border-radius: 6px;
} 
.val{width:2em;text-align:left;display:inline-block;overflow:hidden;font-weight:normal;font-size:16px;vertical-align:middle;} 
#wallpaperGrid {
display: grid;
grid-template-columns: repeat(auto-fill, 200px);
gap: 1px;
padding: 2px;
justify-content: center;
} 
.wallpaper-item {
border: solid 1px var(--border);
border-radius: var(--radius);
padding: 0;
cursor: pointer;
overflow: hidden;
text-align: center;
font-size: 65%;
position: relative;
display: flex;
flex-direction: column;
} 
.wallpaper-item img {
width: 100%;
height: auto;
max-height: 200px;
object-fit: contain;
display: block;
} 
.wallpaper-item .frame-title {
padding: 8px 5px;
background: var(--background);
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 5px;
min-height: 35px;
line-height: 1em;
} 
.frame,.border{display:inline-block;width:24px;height:32px;margin:1px;vertical-align:middle;}
.border{border:solid 4px var(--border3);}
.frame{border:double 4px var(--border3);} 
.template-name svg{margin-left:20px}
.modalsearch{width:8em;border-radius:var(--radius);margin-bottom:5px}
.liked{color:green !important} 



/* ===== MENU STYLING (fixed positioning) ===== */


:root{--menu-maxheight:99.9%;--menu-maxwidth:99.9%;--topmenu-height:50px;--transparentBG:rgba(255, 255, 255, 0.5);}
[data-theme="dark"] {--transparentBG:rgba(0, 0, 0, 0.5);}
.menu{z-index:2;border: solid 1px var(--border3);border-radius:var(--radius);}
.landscapeMode .menu {
bottom:auto;
top:var(--topmenu-height);
left:auto;
right:0;
}

.portraitMode .menu{
bottom:var(--topmenu-height);
top:auto;
left:0;
right:auto;
}

.landscapeMode .menu{max-height:var(--menu-maxheight);max-width:var(--menu-maxwidth);}
/*
.landscapeMode .modal, .landscapeMode .modal-content{max-width:var(--menu-maxwidth);}
.landscapeMode .modal-content{right:0;top:0;left:auto;}
.landscapeMode .modal{background:none}
*/

.landscapeMode #topmenu{
bottom:auto;left:auto;
top:0;right:0;
max-width:var(--menu-maxwidth);
}
.portraitMode  #topmenu{
bottom:0;left:0;
top:auto;right:auto;
}
#topmenu{height:32px;overflow:hidden;line-height:0.6em;z-index:1;padding:0;border-top:1px solid var(--border2);}
#topmenu,.menu{
position: fixed;
width: 99.9%;
height: auto;
max-height: 99%;
;background:var(--transparentBG);
line-height: 0.9em;
font-size: 90%;
text-align: center;
padding:0;
overflow: visible;
}
.menu button,.menu .btn{font-size:80%;margin:2px}

#topmenu {
  display: flex;z-index:1;
}

#topmenu button { 
  min-width: 0;          /* prevents overflow */
  font-size: clamp(12px, 3vw, 24px);
  line-height:0.8em;
}
#topmenu .icon{flex-shrink: 0;}


.menu .icon,#topmenu .icon {
width: 32px;
height: 32px;
margin:1px;
} 


.frame-shareBtn, .sticker-shareBtn {
position: absolute;
bottom: 0;
left: 0;
} 
.backmenu .icon {
width: 32px !important;
height: 32px !important;
}

/* Menu Drag Handle */
.menu-drag-handle {
width: 36px;
height: 36px;
padding: 4px;
cursor: grab;
margin-right: 8px;
margin-bottom: 4px;
float:left;
}

/* Menu Resize Handle */
.menu-resize-handle {
position: absolute;
bottom: 0;
right: 0;
width: 28px;
height: 28px;
cursor: nwse-resize;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
background: linear-gradient(135deg, transparent 50%, var(--bg2) 50%);
border-top-left-radius: var(--radius);
transition: background 0.2s ease;
z-index: 1001;
}

.menu-resize-handle:hover {
background: linear-gradient(135deg, transparent 50%, var(--border) 50%);
}

.menu-resize-handle .icon {
width: 18px;
height: 18px;
}

.layer-item {
margin-bottom: 5px;
background:var(--bg);
border: 2px solid transparent;
border-radius: 4px;
border:solid 2px var(--border);
line-height:1em;
} 
.layer-item.hidden {
opacity: 0.4;
}
.layer-item.active{border:solid 2px #900}
.layer-item.hidden{display:block}

.layer-item.locked {
opacity: 0.6;
background:#c00;
}

.layer-thumb {
font-size:50%;
width: 100px;
height: 100px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--bg);
overflow: hidden;
float:right;
}

/* ====== DIALOG BUTTON STYLES (SHARED) ====== */

.btn-primary { background: #337ab7; }
.btn-success { background: #5cb85c; }
.btn-danger { background: #d9534f; }

.svg-shape-shareBtn{position:absolute;top:0;right:0}

/* ====== TERMS OF SERVICE NOTIFICATION ====== */
#tosNotification {
position: fixed;
top: 10px;
left: 10px;
background: var(--bg);
border: 1px solid var(--border);
padding: 10px 12px;
max-width: 300px;
font-size: 90%;
z-index: 3;
display: none;
}
.red{color:#900}
/* ====== FILTER TARGET MODAL ====== */
.filterTargetList {
    display: flex;
    flex-direction: column;
    gap: 12px;
    line-height:1em;
    font-size:60%;
}

.filterTargetItem {
    cursor: pointer;
    padding: 1px;
    border: 2px solid var(--border);
    border-radius: 6px;
    text-align: center;
}

.filterTargetItem canvas {
    max-width: 100%;
    border: 1px solid var(--border);
    margin-bottom: 8px;
}


/* Wallpaper options dialog */
.wallpaperOptionsContainer {
    text-align: center;
    padding: 20px;
}

.wallpaperOptionBtn {
    margin: 10px;
    padding: 10px 20px;
}

/* Share link input container - structural only */
.templateShareLinkContainer {
    display: flex;
    gap: 8px;
    align-items: center;
}

.templateShareInput {
    flex: 1;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-family: monospace;
}

.filterPhotosGrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}

#wallpaperFilterOption{width:100px;font-size:60%}