
:root{--bg:#0b0d10;--p:#15191f;--p2:#202630;--line:#303943;--gold:#d7ad55;--txt:#f4f1e9;--muted:#9ba5b1}
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--txt);font-family:system-ui,Tahoma,Arial}
header{position:sticky;top:0;background:#101318f2;padding:11px 12px;display:flex;justify-content:space-between;align-items:center;gap:8px;border-bottom:1px solid var(--line);z-index:5}
.brand{font-weight:900;color:#f1d58e}.brand small{display:block;color:var(--muted);font-size:10px}
main{max-width:1050px;margin:auto;padding:11px;display:grid;gap:11px}.panel{background:var(--p);border:1px solid var(--line);border-radius:14px;overflow:hidden}.head{padding:11px 13px;border-bottom:1px solid var(--line);color:#f1d58e;font-weight:800}.body{padding:12px}
button,select,input{font:inherit}button{background:var(--p2);color:var(--txt);border:1px solid var(--line);padding:9px 11px;border-radius:9px}button.primary{background:linear-gradient(135deg,#b58a3e,#e3c274);color:#17130b;border:0;font-weight:800}button.danger{color:#ffaaaa}
select,input{width:100%;background:#0e1217;color:var(--txt);border:1px solid var(--line);padding:9px;border-radius:8px;min-width:0}.toolbar,.actions{display:flex;gap:7px;flex-wrap:wrap}.toolbar select{flex:1;min-width:140px}
.work{display:grid;grid-template-columns:1fr 1fr;gap:11px}.preview{background:#080a0d;padding:10px;display:grid;place-items:center;align-content:start;gap:8px}
canvas{display:block;width:100%;max-height:58vh;object-fit:contain;background:#222;border-radius:7px;touch-action:none;user-select:none;-webkit-user-select:none}
.field{display:grid;gap:5px;margin-bottom:10px}.field label{font-size:12px;color:var(--muted)}.row{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.hint,.notice{font-size:12px;line-height:1.75;color:var(--muted)}.notice{padding:10px;background:#282315;border:1px solid #66512c;border-radius:9px;color:#e8d29d}
.empty{text-align:center;padding:14px;border:1px dashed var(--line);border-radius:9px;color:var(--muted);font-size:13px}
.sect{font-size:13px;color:#f1d58e;margin:12px 0 8px;font-weight:800}.variable{display:flex;align-items:center;gap:8px;padding:9px;background:#0e1217;border:1px solid var(--line);border-radius:9px;margin-bottom:7px}.variable.active{border-color:var(--gold)}.variable .vname{flex:1;font-size:13px}.variable small{display:block;color:var(--muted);font-size:10px}
.group{border:1px solid var(--line);border-radius:10px;padding:10px;margin:9px 0}.group-title{font-size:12px;font-weight:800;color:#e6c477;margin-bottom:9px}
footer{text-align:center;color:#78828e;font-size:11px;padding:8px}
@media(max-width:720px){.work{grid-template-columns:1fr}.preview{order:0}.editor{order:1}canvas{max-height:45vh}main{padding:8px}}

.app-shell{max-width:1450px;margin:auto;padding:12px;display:grid;grid-template-columns:220px minmax(0,1fr);gap:12px;align-items:start}
.sidebar{background:var(--p);border:1px solid var(--line);border-radius:14px;padding:10px;position:sticky;top:76px;max-height:calc(100vh - 90px);overflow:auto}
.sidebar-title{font-size:11px;color:var(--muted);padding:7px 9px 10px;font-weight:800}
.nav-list{display:grid;gap:5px}
.nav-item{width:100%;display:flex;align-items:center;gap:9px;text-align:right;background:transparent;border:1px solid transparent;padding:10px;border-radius:9px;color:var(--txt);cursor:pointer}
.nav-item.active{background:#292316;border-color:#80652f;color:#f1d58e}
.nav-item .nav-icon{width:23px;text-align:center;font-size:16px}
.nav-item small{display:block;color:var(--muted);font-size:10px;font-weight:400;margin-top:2px}
.nav-divider{height:1px;background:var(--line);margin:7px 3px}
.section-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.setting-card,.subpanel{background:#101419;border:1px solid var(--line);border-radius:10px;padding:11px;min-width:0;margin-bottom:10px}
.setting-card h3,.subpanel h3{font-size:12px;color:#e6c477;margin:0 0 10px}
.setting-fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}
.setting-field{display:grid;gap:5px;min-width:0;font-size:11px;color:var(--muted)}
.setting-field.full{grid-column:1/-1}
.setting-field input,.setting-field select,.setting-field textarea{width:100%;min-width:0;background:#0b0e12;color:var(--txt);border:1px solid var(--line);padding:9px;border-radius:7px}
.setting-field textarea{min-height:72px;resize:vertical;line-height:1.7}
.setting-field input[type=color]{height:36px;padding:3px}
.setting-field select[multiple]{min-height:115px}
.emoji-setting{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;align-items:center}
.emoji-preview{display:flex;align-items:center;gap:7px;min-width:0;padding:6px 9px;border:1px solid var(--line);border-radius:7px;background:#0b0e12;font-size:11px;color:var(--muted)}
.emoji-preview img{width:28px;height:28px;object-fit:contain;image-rendering:auto}
.emoji-preview span{max-width:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
@media(max-width:420px){.emoji-setting{grid-template-columns:1fr}.emoji-preview{justify-content:flex-start}}
.toolbar-line{display:flex;gap:7px;flex-wrap:wrap;align-items:center;margin:10px 0}
.data-row{display:flex;align-items:center;justify-content:space-between;gap:9px;padding:9px;border:1px solid var(--line);border-radius:8px;background:#0d1116;margin:7px 0}
.data-row strong{font-size:12px}.data-row small{display:block;color:var(--muted);font-size:10px;margin-top:3px;overflow-wrap:anywhere}
.chip{display:inline-block;border:1px solid #66512c;color:#e8d29d;border-radius:20px;padding:4px 8px;font-size:10px;margin:2px}
.inline-check{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--muted);margin:7px 0}
.inline-check input{width:auto}
.warning-note{padding:10px;background:#282315;border:1px solid #66512c;border-radius:9px;color:#e8d29d;font-size:11px;line-height:1.8;margin:9px 0}
@media(max-width:850px){.app-shell{grid-template-columns:175px minmax(0,1fr)}}
@media(max-width:720px){.app-shell{grid-template-columns:1fr;padding:8px}.sidebar{position:sticky;top:58px;z-index:8;max-height:none;overflow:visible}.nav-list{display:flex;overflow-x:auto;gap:5px;padding:4px 0}.nav-item{min-width:125px;flex:0 0 auto;margin:0}.nav-item small{display:none}.section-grid{grid-template-columns:1fr}.setting-fields{grid-template-columns:1fr}.setting-field.full{grid-column:auto}.work{grid-template-columns:1fr}.preview{order:0}.editor{order:1}canvas{max-height:45vh}main{padding:0}}
@media(max-width:720px){
 body{overflow-x:hidden}header{padding:9px 10px;gap:8px;flex-wrap:wrap}.brand{font-size:13px}.brand small{font-size:9px}.actions{margin-inline-start:auto}.actions button{padding:8px 9px;font-size:12px}
 .app-shell{gap:8px}.sidebar{top:64px;padding:7px;border-radius:10px}.sidebar-title{padding:4px 6px 7px}.nav-list{scroll-snap-type:x mandatory;-webkit-overflow-scrolling:touch}.nav-item{scroll-snap-align:start;min-width:112px;max-width:145px;padding:9px 8px;font-size:12px}.nav-item .nav-icon{width:19px;font-size:14px}
 #settingsPage .panel{border-radius:10px}#settingsPage .body{padding:10px}.toolbar-line{align-items:stretch}.toolbar-line>button{flex:1 1 135px;min-height:42px}.data-row{align-items:flex-start;flex-wrap:wrap}.data-row>button{flex:0 0 auto}
 .work{gap:8px}.preview{padding:8px}.preview .body{padding:7px!important}canvas{width:100%;max-height:42svh}.notice,.warning-note{font-size:11px;line-height:1.7}.field input,.field select,.setting-field input,.setting-field select,.setting-field textarea{font-size:16px;min-height:42px}
}
@media(max-width:420px){.sidebar{top:88px}header .actions{width:100%}header .actions button{flex:1}.app-shell{padding:6px}.nav-item{min-width:102px}.nav-item>span:last-child{font-size:11px}.toolbar{gap:6px}.toolbar>*{min-width:0}.section-grid{gap:7px}.setting-card,.subpanel{padding:9px}.row{grid-template-columns:1fr}}
@media(hover:none){button{min-height:40px}input,select,textarea{font-size:16px}}

/* Mobile overflow hardening: prevent grid children and intrinsic canvas sizes
   from widening the document beyond the actual phone viewport. */
html,body{width:100%;max-width:100%;min-width:0;overflow-x:hidden}
.app-shell, .app-shell > *, main, #imagePage, #settingsPage, #transferPage,
.work, .preview, .editor, .panel, .body, .section-grid, .setting-card,
.subpanel, .setting-fields {min-width:0;max-width:100%}
.app-shell{width:100%}
main{width:100%}
canvas{max-width:100%;height:auto}
img,video,iframe{max-width:100%}
input,select,textarea,button{max-width:100%;min-width:0}
@media(max-width:720px){
  .app-shell{display:grid;grid-template-columns:minmax(0,1fr);width:100%;overflow-x:clip}
  .app-shell>main{grid-column:1;grid-row:auto;width:100%;min-width:0}
  .work{display:grid;grid-template-columns:minmax(0,1fr);width:100%;min-width:0}
  .preview,.editor{width:100%;min-width:0}
  .preview canvas{width:100%;max-width:100%;height:auto}
  .toolbar{min-width:0;max-width:100%}
  .toolbar select{min-width:0}
  .data-row>*{min-width:0;max-width:100%}
}
@media(max-width:420px){
  .app-shell{padding:5px}
  main{padding:0}
  .preview,.editor{border-radius:9px}
  .body{padding:9px}
}


/* Real-device responsive fallback: mobile browsers may use a desktop-sized
   layout viewport when "Desktop site" is enabled, so max-width alone is not enough. */
@media (max-device-width: 900px) and (pointer: coarse) {
  html, body { width:100% !important; max-width:100% !important; overflow-x:hidden !important; }
  .app-shell { display:grid !important; grid-template-columns:minmax(0,1fr) !important; width:100% !important; max-width:100% !important; padding:6px !important; gap:8px !important; overflow-x:clip !important; }
  .app-shell > .sidebar, .app-shell > main { grid-column:1 / -1 !important; width:100% !important; min-width:0 !important; max-width:100% !important; }
  .sidebar { position:relative !important; top:auto !important; max-height:none !important; overflow:hidden !important; padding:7px !important; z-index:8 !important; }
  .nav-list { display:flex !important; flex-direction:row !important; flex-wrap:nowrap !important; overflow-x:auto !important; overflow-y:hidden !important; max-width:100% !important; gap:5px !important; -webkit-overflow-scrolling:touch; }
  .nav-item { flex:0 0 auto !important; min-width:105px !important; max-width:150px !important; }
  .nav-item small { display:none !important; }
  .section-grid, .setting-fields, .work { grid-template-columns:minmax(0,1fr) !important; }
  .setting-field.full { grid-column:auto !important; }
  #pageBody, #pageBody > *, #settingsPage, #imagePage, .panel, .body, .setting-card, .subpanel { min-width:0 !important; max-width:100% !important; }
  #pageBody { overflow-wrap:anywhere; }
  #pageBody pre, #pageBody code, #pageBody table { max-width:100%; overflow-x:auto; }
  canvas, img, video { max-width:100% !important; }
}


/* Explicit page switching: prevent responsive layout rules from overriding
   the active/inactive page state. */
.app-shell > main[hidden] { display:none !important; }
#imagePage:not([hidden]) { display:grid !important; }
#settingsPage:not([hidden]) { display:block !important; }
.nav-list .nav-item { pointer-events:auto; touch-action:manipulation; }
