:root{
  --bg0:#070f1c;
  --bg1:#0b1220;
  --panel:#0f1a30;
  --line:rgba(255,255,255,.10);
  --text:#eaf2ff;
  --muted:rgba(233,242,255,.68);
  --primary:#2aa6ff;
  --shadow:0 14px 40px rgba(0,0,0,.45);
  --radius:18px;
}

/* ========== LOCAL THAI FONTS (assets/font) ========== */

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
   font-family: "Kanit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color:var(--text);
  background:linear-gradient(180deg,var(--bg0),var(--bg1));
  -webkit-text-size-adjust:100%;
  overscroll-behavior:none;
}

.app{
  min-height:100svh;
  min-height:100dvh;
  display:flex;
  gap:12px;
  padding:12px;
  padding-bottom:calc(12px + env(safe-area-inset-bottom));
}

/* ===== PANEL ===== */
.panel{
  width:380px;
  min-width:340px;
  max-width:420px;
  background:rgba(15,26,48,.92);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}
.panelHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 14px 10px;
  border-bottom:1px solid var(--line);
}
.brand{font-weight:900;font-size:16px}
.sub{font-size:12px;color:var(--muted);margin-top:2px}
.panelBody{
  padding:12px 14px 14px;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
}
h3{margin:0 0 8px;font-size:14px;letter-spacing:.2px}
label{display:block;font-size:13px;color:var(--muted);margin:10px 0 6px}
input{
  width:100%;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  color:var(--text);
  outline:none;
}
input[type="range"]{padding:8px 0}
.inline{display:flex;align-items:center;gap:8px;margin:0}
.inline input{width:auto}
.hint{margin-top:8px;font-size:12px;color:rgba(233,242,255,.62);line-height:1.45}
.hint.small{font-size:11.5px}
hr{border:none;border-top:1px solid rgba(255,255,255,.10);margin:14px 0;}

.fieldWrap{
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  border-radius:16px;
  padding:12px;
  margin-bottom:12px;
}
.fieldHead{display:flex;align-items:center;justify-content:space-between;gap:10px}
.inputRow{display:flex;gap:10px;align-items:center}
.inputRow input:not([type="color"]){flex:1}
.inputRow input[type="color"]{
  width:44px;height:42px;padding:0;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);background:rgba(255,255,255,.06);
}

.iconBtn{
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:9px 10px;
  border-radius:12px;
  cursor:pointer;
  font-weight:900;
}
.btn{
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.07);
  color:var(--text);
  padding:11px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:800;
  width:100%;
  text-align:center;
  user-select:none;
}
.btn.primary{background:rgba(42,166,255,.18);border-color:rgba(42,166,255,.45)}
.btn.ghost{background:transparent}
.fileBtn{position:relative;overflow:hidden}
.fileBtn input{position:absolute;inset:0;opacity:0;cursor:pointer}
.btnRow{display:flex;gap:10px;margin-top:10px}
.btnRow .btn{flex:1}

.plusInline{
  width:44px;height:42px;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.06);
  color:var(--text);
  cursor:pointer;
  font-weight:900;
  display:inline-flex;align-items:center;justify-content:center;
}
.plusInline:active{transform:scale(.98)}

.toolRow{display:flex;gap:8px;align-items:center;margin-top:10px}
.toolBtn{
  width:44px;height:42px;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.06);
  color:var(--text);
  cursor:pointer;
  font-weight:900;
}
.toolBtn.active{
  outline:2px solid rgba(42,166,255,.65);
  box-shadow:0 0 0 6px rgba(42,166,255,.12);
}
.toolSelect{
  flex:1;height:42px;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:0 10px;outline:none;
}

.sizeRow{display:flex;gap:10px;align-items:center;margin-top:6px}
.sizeRow input[type="range"]{flex:1}

.extraWrap{margin-top:10px;display:flex;flex-direction:column;gap:10px}
.extraRow{display:flex;gap:10px;align-items:center}
.extraRow input:not([type="color"]){
  flex:1;padding:10px 10px;border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);color:var(--text);
}
.extraRow input[type="color"]{
  width:44px;height:42px;padding:0;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);background:rgba(255,255,255,.06);
}
.delBtn{
  width:44px;height:42px;border-radius:12px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.06);
  color:var(--text);
  cursor:pointer;
  font-weight:900;
}

/* ===== MAIN ===== */
.main{flex:1;min-width:0;display:flex;flex-direction:column;gap:12px}
.topbar{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:12px;background:rgba(255,255,255,.03);
  border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow);
}
.topbarTitle .t1{font-weight:900}
.topbarTitle .t2{font-size:12px;color:var(--muted)}
.stageWrap{
  flex:1;min-height:0;background:rgba(255,255,255,.03);
  border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow);overflow:auto;-webkit-overflow-scrolling:touch;
}
.stage{
  min-height:100%;
  display:grid;
  place-items:start center; /* lift poster up */
  padding:14px;padding-top:20px;
}
.posterBase{
  position:relative;
  width:860px;
  max-width:92vw;
  aspect-ratio:1/1.414;
  overflow:hidden;
  touch-action:none;
  background:#000;
  border-radius:18px;
  border:1px solid rgba(255,255,255,.10);
}

/* ===== Layer order (Mode B) =====
   bgBase   z=0
   overlay  z=3
   grid     z=4
   bgUser   z=5  (on top of overlay/grid)
   box      z=10
   decor    z=11
*/
.bgBase{
  position:absolute;inset:0;width:100%;height:100%;
  object-fit:cover;z-index:0;pointer-events:none;
}
.overlay{
  position:absolute;inset:0;width:100%;height:100%;
  object-fit:contain;z-index:3;pointer-events:none;opacity:.98;
}
.grid{
  position:absolute;inset:0;z-index:4;pointer-events:none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.10) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.10) 1px, transparent 1px);
  background-size:40px 40px;opacity:.45;
}
.bgUser{
  position:absolute;inset:0;width:100%;height:100%;
  object-fit:cover;z-index:5;pointer-events:none;
}

.box{
  position:absolute;
  z-index:10;
  color:#fff;
  font-weight:800;
  text-shadow:0 4px 16px rgba(0,0,0,.55);
  user-select:none;
  touch-action:none;
  cursor:grab;
  padding:6px 10px;
  border-radius:12px;
  outline:1px dashed rgba(255,255,255,.0);
}
.box:active{cursor:grabbing}
.box.selected{
  outline:1px dashed rgba(42,166,255,.95);
  box-shadow:0 0 0 6px rgba(42,166,255,.14);
}
.boxTitle{left:60px;top:70px;font-size:56px}
.boxDesc{left:60px;top:160px;font-size:32px}
.boxPlace{left:60px;top:220px;font-size:30px}

.decor{
  position:absolute;
  z-index:11;
  width:240px;
  height:auto;
  user-select:none;
  -webkit-user-drag:none;
  touch-action:none;
  cursor:grab;
  border-radius:12px;
  filter:drop-shadow(0 10px 18px rgba(0,0,0,.45));
}
.decor:active{cursor:grabbing}
.decor.selected{
  outline:1px dashed rgba(42,166,255,.95);
  box-shadow:0 0 0 6px rgba(42,166,255,.14);
}

@media (max-width: 980px){
  .app{padding:10px;}
  .panel{
    position:fixed;
    left:10px; right:10px;
    bottom:10px;
    width:auto;
    max-width:none;
    min-width:0;
    height:72vh;
    transform:translateY(110%);
    transition:transform .25s ease;
    z-index:50;
  }
  .panel.open{transform:translateY(0);}
}
