* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #282828; color: #ddd; font: 13px/1.4 system-ui, "Noto Sans Thai", "Segoe UI", sans-serif; user-select: none; }
button, select, input { font: inherit; color: #ddd; background: #3a3a3a; border: 1px solid #555; border-radius: 3px; }
button { cursor: pointer; padding: 3px 9px; }
button:hover { background: #4a4a4a; }
button.primary { background: #2f7de1; border-color: #2f7de1; color: #fff; }
input[type=number] { width: 58px; padding: 2px 4px; }
input[type=text], textarea { background: #1f1f1f; color: #eee; border: 1px solid #555; border-radius: 3px; padding: 4px 6px; font: inherit; }
textarea { width: 100%; resize: vertical; }
.hidden { display: none !important; }
#app { display: flex; flex-direction: column; height: 100%; }
#menubar { display: flex; align-items: center; background: #3c3c3c; height: 30px; border-bottom: 1px solid #222; }
.logo { font-weight: 700; color: #6aa8ff; padding: 0 12px; }
#menus { display: flex; height: 100%; }
.menu { position: relative; padding: 0 10px; display: flex; align-items: center; cursor: default; }
.menu:hover, .menu.open { background: #505050; }
.menu .items { display: none; position: absolute; top: 100%; left: 0; background: #3a3a3a; border: 1px solid #222; min-width: 240px; z-index: 50; box-shadow: 0 6px 16px #0008; padding: 3px 0; }
.menu.open > .items { display: block; }
.mi { padding: 4px 14px 4px 22px; display: flex; justify-content: space-between; gap: 20px; white-space: nowrap; position: relative; }
.mi:hover { background: #2f7de1; color: #fff; }
.mi .k { color: #999; font-size: 12px; }
.mi:hover .k { color: #fff; }
.mi.sub > .items { display: none; position: absolute; left: 100%; top: -3px; }
.mi.sub:hover > .items { display: block; }
.sep { border-top: 1px solid #555; margin: 3px 0; }
.spacer { flex: 1; }
#conn { padding: 0 12px; color: #c44; }
#conn.on { color: #4c4; }
#optionsbar { height: 34px; background: #333; border-bottom: 1px solid #222; display: flex; align-items: center; gap: 12px; padding: 0 10px; white-space: nowrap; overflow-x: auto; }
#optionsbar label { display: flex; align-items: center; gap: 4px; }
#optionsbar input[type=range] { width: 90px; }
#optionsbar .tname { font-weight: 600; color: #fff; min-width: 90px; }
#main { flex: 1; display: flex; min-height: 0; }
#toolbar { width: 44px; background: #333; border-right: 1px solid #222; display: flex; flex-direction: column; align-items: center; padding-top: 4px; gap: 2px; overflow-y: auto; }
#toolbar button { width: 36px; height: 32px; padding: 0; border: none; background: transparent; font-size: 17px; border-radius: 4px; }
#toolbar button.on { background: #2f7de1; }
#toolbar button:hover:not(.on) { background: #4a4a4a; }
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#tabs { display: flex; background: #2b2b2b; height: 26px; overflow-x: auto; }
.tab { padding: 3px 8px 3px 12px; border-right: 1px solid #222; display: flex; gap: 8px; align-items: center; cursor: pointer; color: #aaa; white-space: nowrap; }
.tab.on { background: #474747; color: #fff; }
.tab .x { opacity: .6; } .tab .x:hover { opacity: 1; color: #f66; }
#viewport { flex: 1; position: relative; background: #202020; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: #252525; overflow: auto; }
#empty h1 { margin: 0; color: #6aa8ff; font-size: 40px; }
.empty-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px; }
.empty-btns button { padding: 10px 16px; }
#recent { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 900px; }
.rdoc { width: 140px; background: #333; border-radius: 4px; padding: 6px; cursor: pointer; text-align: center; font-size: 12px; position: relative; }
.rdoc:hover { background: #3f3f3f; }
.rdoc img { width: 128px; height: 96px; object-fit: contain; background: repeating-conic-gradient(#555 0 25%, #444 0 50%) 0 0/12px 12px; display: block; margin: 0 auto 4px; }
.rdoc .del { position: absolute; top: 2px; right: 6px; color: #f77; display: none; }
.rdoc:hover .del { display: block; }
#panels { width: 260px; background: #333; border-left: 1px solid #222; display: flex; flex-direction: column; min-height: 0; }
.panel { border-bottom: 1px solid #222; padding: 6px; }
.panel.grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ptitle { font-weight: 600; color: #fff; margin-bottom: 4px; }
.swatches { position: relative; height: 46px; width: 52px; flex: none; }
.swatches input { position: absolute; width: 34px; height: 34px; padding: 0; border: 2px solid #ddd; }
#fg { left: 0; top: 0; z-index: 2; } #bg { left: 16px; top: 12px; }
#colorpanel { display: flex; gap: 14px; align-items: center; }
#hexes { font-family: monospace; font-size: 12px; color: #aaa; }
.lrow1 { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.lrow1 select { flex: 1; }
#layers { flex: 1; overflow-y: auto; background: #2a2a2a; border: 1px solid #222; min-height: 80px; }
.layer { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-bottom: 1px solid #222; cursor: pointer; }
.layer.on { background: #2f5d99; }
.layer .eye { width: 18px; text-align: center; opacity: .9; }
.layer .eye.off { opacity: .25; }
.layer canvas { width: 40px; height: 30px; background: repeating-conic-gradient(#888 0 25%, #666 0 50%) 0 0/8px 8px; object-fit: contain; flex: none; border: 1px solid #111; }
.layer .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .badge { font-size: 10px; color: #9cf; }
.layer.drag-over { border-top: 2px solid #6aa8ff; }
.lbtns { display: flex; gap: 3px; margin-top: 5px; }
.lbtns button { flex: 1; padding: 2px 0; }
#histpanel { height: 170px; display: flex; flex-direction: column; }
#history { flex: 1; overflow-y: auto; background: #2a2a2a; border: 1px solid #222; }
.hi { padding: 2px 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hi:hover { background: #3c3c3c; }
.hi.on { background: #2f5d99; }
.hi.future { color: #777; }
#statusbar { height: 22px; background: #333; border-top: 1px solid #222; display: flex; gap: 18px; padding: 0 10px; align-items: center; font-size: 12px; color: #aaa; }
#modal { position: fixed; inset: 0; background: #0008; display: flex; align-items: center; justify-content: center; z-index: 100; }
.dlg { background: #3a3a3a; border: 1px solid #222; border-radius: 6px; min-width: 340px; max-width: 92vw; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px #000a; }
.dlg-title { padding: 8px 12px; font-weight: 600; background: #444; border-radius: 6px 6px 0 0; cursor: move; }
.dlg-body { padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 8px; user-select: text; }
.dlg-btns { padding: 8px 12px; display: flex; justify-content: flex-end; gap: 8px; }
.frow { display: flex; align-items: center; gap: 8px; }
.frow > label:first-child { min-width: 110px; color: #bbb; }
.frow input[type=range] { flex: 1; }
.frow input[type=text] { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 60vh; overflow: auto; width: min(820px, 85vw); }
.grid .it { background: #2a2a2a; padding: 4px; border-radius: 4px; cursor: pointer; font-size: 11px; color: #aaa; }
.grid .it:hover { outline: 2px solid #2f7de1; }
.grid img { width: 100%; height: 120px; object-fit: contain; display: block; }
pre.code { background: #1e1e1e; padding: 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-all; font-size: 12px; margin: 0; user-select: all; }
#toasts { position: fixed; bottom: 30px; right: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 200; }
.toast { background: #444; border-left: 4px solid #2f7de1; padding: 8px 12px; border-radius: 4px; box-shadow: 0 4px 12px #0008; max-width: 420px; }
.toast.err { border-color: #e04040; }
#busy { position: fixed; inset: 0; background: #0006; z-index: 150; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #fff; }
.spinner { width: 42px; height: 42px; border: 4px solid #fff3; border-top-color: #6aa8ff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 800px) { #panels { width: 190px; } }
