@import url("https://fonts.googleapis.com/css2?family=Hanuman:wght@400;700;900&family=Koulen&family=Moul&family=Noto+Sans+Khmer:wght@400;500;700;900&family=Noto+Serif+Khmer:wght@400;700&family=Siemreap&display=swap");

:root{--bg:#0b1020;--panel:#111827;--panel2:#0f172a;--stage:#080d18;--border:#263247;--border2:#334155;--text:#e5e7eb;--muted:#94a3b8;--blue:#2563eb;--blue2:#60a5fa}
*{box-sizing:border-box}
html,body{width:100%;height:100%;margin:0;overflow:hidden}
body{font-family:"Noto Sans Khmer",system-ui,sans-serif;background:var(--bg);color:var(--text)}
.hidden{display:none!important}

/* Login */
.lock-screen{position:fixed;inset:0;display:grid;place-items:center;background:radial-gradient(circle at 50% 20%,#243b72,#0b1020 60%);z-index:100}
.login-card{width:min(430px,92vw);padding:36px;border:1px solid #334155;border-radius:24px;background:#111827ee;box-shadow:0 25px 80px #0008;text-align:center}
.brand-mark,.logo{display:inline-grid;place-items:center;background:var(--blue);color:#fff;font-weight:800;border-radius:12px}.brand-mark{width:64px;height:64px;font-size:22px}.login-card h1{margin:16px 0 8px}.login-card input{width:100%;padding:15px;border-radius:12px;border:1px solid #475569;background:#0f172a;color:#fff;font-size:18px;margin:14px 0}.error{color:#f87171;min-height:24px;margin:8px}

/* App shell */
.app{height:100vh;min-height:0;display:flex;flex-direction:column;overflow:hidden}
.topbar{flex:0 0 68px;height:68px;display:flex;align-items:center;justify-content:space-between;padding:8px 14px;background:#111827;border-bottom:1px solid #334155;gap:10px;min-width:0}
.brand{display:flex;align-items:center;gap:10px;min-width:190px}.logo{width:42px;height:42px;flex:0 0 42px}.brand small{display:block;color:var(--muted)}
.top-actions{display:flex;gap:7px;flex-wrap:wrap;justify-content:flex-end;min-width:0}button,select,input,textarea{font:inherit}button{border:1px solid #475569;background:#182235;color:var(--text);border-radius:9px;padding:9px 11px;cursor:pointer}button:hover{background:#24324a}button.active{background:var(--blue);border-color:var(--blue2)}button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{outline:2px solid var(--blue2);outline-offset:1px}.primary{background:var(--blue)!important;border-color:var(--blue2)!important;color:#fff}.danger{background:#7f1d1d}

/* Three-pane desktop layout */
.workspace{flex:1 1 auto;min-height:0;display:grid;grid-template-columns:minmax(260px,300px) minmax(0,1fr) minmax(260px,300px);overflow:hidden}
.sidebar{min-width:0;min-height:0;overflow:auto;padding:10px;background:var(--panel2);scrollbar-width:thin;scrollbar-color:#475569 transparent}.left{border-right:1px solid #334155}.right{border-left:1px solid #334155}
.sidebar::-webkit-scrollbar{width:7px}.sidebar::-webkit-scrollbar-track{background:transparent}.sidebar::-webkit-scrollbar-thumb{background:#475569;border-radius:10px}
section{background:var(--panel);border:1px solid var(--border);border-radius:13px;padding:12px;margin-bottom:10px}section h3{margin:0 0 10px;font-size:15px}.grid2{display:grid;grid-template-columns:1fr 1fr;gap:8px}.grid3{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}label{display:block;font-size:12px;color:#aeb9ca;margin:8px 0}input[type=text],input[type=number],input[type=tel],select,textarea{width:100%;background:#0b1220;border:1px solid #334155;color:#fff;border-radius:8px;padding:8px}input[type=color]{width:100%;height:35px;border:0;background:transparent;padding:0}textarea{resize:vertical}.full{width:100%;margin-top:8px}.hint{font-size:11px;color:#94a3b8;line-height:1.5}

/* Central editor: exactly 3 rows = toolbar / image / thumbnails */
.canvas-area{min-width:0;min-height:0;height:100%;display:grid;grid-template-rows:38px minmax(0,1fr) 92px;background:var(--stage);overflow:hidden}
.canvas-toolbar{min-width:0;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 12px;background:#0f172a;border-bottom:1px solid var(--border);font-size:12px;overflow:hidden}.canvas-toolbar span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.canvas-toolbar span:last-child{text-align:right;color:#cbd5e1}
.canvas-wrap{position:relative;min-width:0;min-height:0;width:100%;height:100%;padding:6px;overflow:hidden;display:flex;align-items:flex-start;justify-content:center;background:var(--stage)}
.canvas-wrap canvas{display:block;flex:0 0 auto;width:auto;height:auto;max-width:100%;max-height:100%;margin:0;box-shadow:0 8px 28px #0008;background:#000}
.thumbnails{min-width:0;width:100%;height:92px;display:flex;align-items:center;gap:7px;padding:5px 8px;overflow-x:auto;overflow-y:hidden;border-top:1px solid var(--border);background:#0f172a;scrollbar-width:thin;scrollbar-color:#475569 transparent}.thumbnails::-webkit-scrollbar{height:7px}.thumbnails::-webkit-scrollbar-thumb{background:#475569;border-radius:10px}
.thumb{height:80px;width:102px;flex:0 0 102px;object-fit:cover;border:2px solid #334155;border-radius:8px;cursor:pointer;background:#111827}.thumb.active{border-color:#60a5fa;box-shadow:0 0 0 2px #2563eb55}

/* Controls */
.color-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:5px;margin:6px 0}.gradient-editor{display:flex;flex-direction:column;gap:7px;margin:7px 0}.gradient-row{display:grid;grid-template-columns:20px 38px 54px minmax(70px,1fr) 42px;align-items:center;gap:6px}.gradient-row input[type=color]{width:38px;height:30px}.gradient-row input[type=range]{width:100%}.gradient-row span{font-size:11px;color:#cbd5e1}.gradient-row output{font-size:11px;text-align:right;color:#94a3b8}.center-align-note{padding:8px 10px;border:1px solid #334155;border-radius:8px;background:#0b1220;color:#cbd5e1;font-size:12px;text-align:center;margin:8px 0}

.note a{color:#60a5fa;text-decoration:none}footer{flex:0 0 26px;height:26px;text-align:center;padding:6px;background:#111827;color:#64748b;font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* Crop / dialogs */
.modal{position:fixed;inset:0;display:grid;place-items:center;background:#0009;z-index:90}.modal-card{width:min(520px,94vw);background:#111827;border:1px solid #475569;border-radius:18px;padding:20px}.modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}

/* Tablet: keep all functions, reduce side widths */
@media(max-width:1200px){
  .workspace{grid-template-columns:minmax(230px,270px) minmax(0,1fr) minmax(230px,270px)}
  .topbar{padding-inline:10px}.top-actions{gap:5px}
}

/* Small tablet: stack right panel below editor instead of hiding features */
@media(max-width:950px){
  html,body{overflow:auto}
  .app{height:auto;min-height:100vh;overflow:visible}
  .topbar{height:auto;min-height:68px;align-items:center;flex-wrap:wrap}
  .workspace{height:auto;min-height:0;display:grid;grid-template-columns:1fr;overflow:visible}
  .canvas-area{order:1;height:min(72vh,760px);min-height:520px;grid-template-rows:38px minmax(0,1fr) 92px}
  .left{order:2;border-right:0;border-top:1px solid #334155;max-height:none;overflow:visible}
  .right{order:3;border-left:0;border-top:1px solid #334155;max-height:none;overflow:visible}
  footer{height:26px}
}

/* Mobile */
@media(max-width:600px){
  body{overflow:auto}
  .topbar{padding:8px;gap:8px;align-items:flex-start}
  .brand{min-width:0;flex:1}.brand b{font-size:14px}.brand small{font-size:10px}.logo{width:36px;height:36px;flex-basis:36px}
  .top-actions{width:100%;justify-content:flex-start;overflow-x:auto;flex-wrap:nowrap;padding-bottom:2px}.top-actions button{flex:0 0 auto;padding:8px 10px}
  .canvas-area{height:68vh;min-height:400px;grid-template-rows:36px minmax(0,1fr) 86px}
  .canvas-toolbar{font-size:10px;padding:0 8px}.canvas-toolbar span:last-child{display:none}
  .canvas-wrap{padding:3px;align-items:flex-start}
  .thumbnails{height:86px;padding:5px 6px;gap:6px}.thumb{height:74px;width:94px;flex-basis:94px}
  .sidebar{padding:8px}.grid3{grid-template-columns:1fr 1fr}.gradient-row{grid-template-columns:18px 34px 48px minmax(50px,1fr) 38px}.gradient-row input[type=color]{width:34px}
  section{padding:10px;margin-bottom:8px}
  footer{font-size:10px}
}

/* Very small phones */
@media(max-width:380px){
  .canvas-area{height:64vh;min-height:360px}
  .grid2{grid-template-columns:1fr}
  .grid3{grid-template-columns:1fr 1fr}
}

@keyframes pop{from{opacity:0;transform:translateX(-50%) scale(.7) rotate(-3deg)}to{opacity:1;transform:translateX(-50%) scale(1) rotate(0)}}
@keyframes stickerPop{from{transform:scale(.75) rotate(-3deg);opacity:.2}to{transform:scale(1) rotate(0);opacity:1}}
@keyframes stickerFade{from{opacity:0}to{opacity:1}}

.glow-box{margin:9px 0;padding:10px;border:1px solid #334155;border-radius:10px;background:linear-gradient(135deg,#0b1220,#111827)}.glow-box>b{display:block;margin-bottom:7px;color:#dbeafe}.checkline{display:flex;align-items:center;gap:8px;color:#cbd5e1;margin:6px 0}.checkline input{width:auto}.glow-presets{display:grid;grid-template-columns:repeat(4,1fr);gap:5px;margin-top:7px}.glow-presets button{padding:6px 4px;font-size:11px}

.object-context-menu{position:fixed;z-index:99999;min-width:230px;padding:8px;background:#111827;border:1px solid #334155;border-radius:12px;box-shadow:0 18px 50px rgba(0,0,0,.45);display:flex;flex-direction:column;gap:6px}.object-context-menu .context-title{padding:6px 9px;font-weight:700;color:#cbd5e1;font-size:13px}.object-context-menu button{border:1px solid #334155;background:#1e293b;color:#f8fafc;border-radius:8px;padding:9px 10px;text-align:left;cursor:pointer}.object-context-menu button:hover{background:#334155}.object-context-menu button.danger{background:#7f1d1d;border-color:#991b1b}.object-context-menu button.danger:hover{background:#991b1b}

/* Brush & Sticker library */
.brush-library{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px;margin-top:9px;max-height:330px;overflow:auto;padding:2px}
.brush-card{padding:5px;background:#0b1220;border:1px solid #334155;border-radius:10px;cursor:pointer;display:flex;flex-direction:column;gap:4px;align-items:stretch;min-width:0}
.brush-card:hover{background:#182235;border-color:#64748b}.brush-card.active{border-color:#60a5fa;box-shadow:0 0 0 2px #2563eb55;background:#172554}
.brush-card img{display:block;width:100%;height:52px;object-fit:contain;background:repeating-conic-gradient(#e5e7eb 0 25%,#fff 0 50%) 50%/14px 14px;border-radius:7px}
.brush-card span{text-align:center;font-size:11px;color:#cbd5e1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@media(max-width:600px){.brush-library{grid-template-columns:repeat(2,minmax(0,1fr));max-height:420px}.brush-card img{height:60px}}
