:root {
  --bg: #f3f4f6; --panel: #ffffff; --line: #e5e7eb; --text: #111827; --muted: #6b7280;
  --primary: #2563eb; --primary-ink: #ffffff; --danger: #dc2626; --stage: #e5e7eb;
}
* { box-sizing: border-box; }
/* display 를 지정한 요소도 hidden 속성이 먹게(팝업·설정 항목이 안 숨겨지던 버그, 2026-09-16~17) */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 4px 8px; }
.right { margin-left: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; margin-top: 6px; }
.row.right-align { justify-content: flex-end; margin-top: 12px; }
.grow { flex: 1; min-width: 180px; }
input[type=text], input:not([type]), input[type=number], input[type=password], select {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0;
}
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f3f4f6; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.tiny { padding: 1px 6px; font-size: 11px; }
.btn.wide { width: 100%; justify-content: center; }
.error { background: #fef2f2; color: #991b1b; padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; }

/* 로그인 */
.login-body { display: grid; place-items: center; }
.login-card { background: var(--panel); padding: 28px; border-radius: 12px; width: min(380px, 92vw); box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card label { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; }
.login-card .btn { margin-top: 18px; }

/* 목록 */
.topnav { display: flex; gap: 12px; align-items: center; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.tile .thumb { display: grid; place-items: center; height: 150px; background: #f9fafb; overflow: hidden; }
.tile .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tile-body { padding: 10px; }
.tile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 편집기 레이아웃 */
.editor-body { display: grid; grid-template-rows: 52px 1fr; grid-template-columns: 230px 1fr 290px; grid-template-areas: "top top top" "left stage right"; height: 100vh; overflow: hidden; }
.toolbar { grid-area: top; display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.name-input { border: 1px solid transparent; padding: 6px 8px; border-radius: 6px; font-weight: 600; width: 260px; }
.name-input:hover, .name-input:focus { border-color: var(--line); background: #fff; }
.zoom-label { min-width: 48px; text-align: center; cursor: pointer; font-variant-numeric: tabular-nums; }
.toolbar input[type=color] { width: 22px; height: 22px; border: none; padding: 0; background: none; vertical-align: middle; cursor: pointer; }
.dropdown { position: relative; }
.menu { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.1); display: none; flex-direction: column; min-width: 180px; z-index: 20; }
.menu.open { display: flex; }
.menu button { text-align: left; padding: 9px 12px; border: none; background: none; cursor: pointer; }
.menu button:hover { background: #f3f4f6; }

.panel { background: var(--panel); overflow-y: auto; padding: 10px; }
.panel.left { grid-area: left; border-right: 1px solid var(--line); }
.panel.right { grid-area: right; border-left: 1px solid var(--line); }
.panel-title { font-size: 12px; color: var(--muted); margin: 12px 4px 6px; display: flex; justify-content: space-between; align-items: center; }
.tool { display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; margin-bottom: 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; text-align: left; }
.tool:hover { background: #f3f4f6; }
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tool-grid .tool { justify-content: center; font-size: 18px; padding: 8px 0; }
.file-tool { cursor: pointer; }
.assets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.assets .asset { position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #f9fafb; cursor: pointer; }
.assets .asset img { width: 100%; height: 100%; object-fit: cover; }
.assets .asset .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.55); color: #fff; border: none; border-radius: 4px; font-size: 10px; padding: 1px 4px; cursor: pointer; display: none; }
.assets .asset:hover .x { display: block; }

.stage { grid-area: stage; overflow: auto; background: var(--stage); position: relative; }
.canvas-wrap { position: relative; margin: 40px auto; width: max-content; box-shadow: 0 6px 24px rgba(0,0,0,.15); background: #fff; }
.canvas-wrap.dragover { outline: 3px dashed var(--primary); }
.guide { position: absolute; background: #f43f5e; pointer-events: none; z-index: 5; }
.guide.v { top: 0; bottom: 0; width: 1px; }
.guide.h { left: 0; right: 0; height: 1px; }

/* 속성 패널 */
.props-body .group { border-top: 1px solid var(--line); padding: 10px 2px; }
.props-body .group:first-child { border-top: none; }
.props-body .g-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.props-body .f { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; }
.props-body .f input, .props-body .f select { width: 100%; padding: 5px 7px; }
.props-body .f input[type=color] { padding: 0; height: 28px; border: 1px solid var(--line); border-radius: 6px; }
.props-body .f input[type=range] { padding: 0; }
.props-body .two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.props-body .btns { display: flex; flex-wrap: wrap; gap: 4px; }
.props-body .btns .btn { padding: 5px 8px; font-size: 12px; }
.props-body .btn.on { background: #dbeafe; border-color: #93c5fd; }

/* 1:1 이미지 제작 */
.sq-drop { border: 2px dashed #b9c4c9; border-radius: 12px; padding: 26px 20px; text-align: center; background: #f9fafb; }
.sq-drop.over { border-color: var(--primary); background: #eff6ff; }
.sq-opt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 150px; }
.sq-opt select, .sq-opt input[type=range] { width: 100%; }
.sq-opt input[type=range] { accent-color: var(--primary); }
.sq-card .sq-outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 12px; }
.sq-tile { display: flex; flex-direction: column; gap: 6px; }
.sq-tile canvas { width: 100%; height: auto; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ── 편집기 확장(2026-09-16): 페이지 띠·레이어·격자·문맥메뉴·색 팔레트 ── */
.editor-body { grid-template-rows: 52px 1fr 92px; grid-template-areas: "top top top" "left stage right" "left pages right"; }
.pages { grid-area: pages; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); overflow-x: auto; }
.pages-list { display: flex; gap: 8px; flex: 1; overflow-x: auto; }
.pg { position: relative; flex: 0 0 auto; width: 96px; height: 72px; border: 2px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; display: grid; place-items: center; overflow: hidden; }
.pg img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pg.on { border-color: var(--primary); box-shadow: 0 0 0 2px #bfdbfe; }
.pg .no { position: absolute; left: 4px; top: 2px; font-size: 11px; color: var(--muted); background: rgba(255,255,255,.85); padding: 0 4px; border-radius: 3px; }
.pg .acts { position: absolute; right: 2px; top: 2px; display: none; gap: 2px; }
.pg:hover .acts { display: flex; }
.pg .acts button { border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; border-radius: 3px; padding: 1px 4px; cursor: pointer; }
.pg.dragover { outline: 2px dashed var(--primary); }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab { flex: 1; padding: 6px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
.tab.on { background: #dbeafe; border-color: #93c5fd; }
.layers-body .ly { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 12px; border: 1px solid transparent; }
.layers-body .ly:hover { background: #f3f4f6; }
.layers-body .ly.on { background: #dbeafe; border-color: #93c5fd; }
.layers-body .ly .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layers-body .ly .ic { width: 18px; text-align: center; color: var(--muted); }
.layers-body .ly button { border: none; background: none; cursor: pointer; padding: 0 3px; font-size: 12px; opacity: .6; }
.layers-body .ly button:hover { opacity: 1; }
.layers-body .ly.hidden-obj .nm { opacity: .45; text-decoration: line-through; }
.layers-body .ly.dragover { border-top: 2px solid var(--primary); }
.tool-grid.two-col { grid-template-columns: 1fr 1fr; }
.tool-grid.two-col .tool { font-size: 13px; }
.tiny-input { width: 80px; padding: 2px 6px; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; }
.btn.tog.on { background: #dbeafe; border-color: #93c5fd; }
.grid-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background-image: linear-gradient(to right, rgba(37,99,235,.18) 1px, transparent 1px), linear-gradient(to bottom, rgba(37,99,235,.18) 1px, transparent 1px); }
#guides .guide { position: absolute; background: #f43f5e; pointer-events: none; z-index: 5; }
#guides .guide.v { top: 0; bottom: 0; width: 1px; }
#guides .guide.h { left: 0; right: 0; height: 1px; }
#guides .dist { position: absolute; background: #f43f5e; color: #fff; font-size: 10px; padding: 0 4px; border-radius: 3px; pointer-events: none; z-index: 6; transform: translate(-50%, -50%); }
.ctx { position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.14); min-width: 170px; padding: 4px; }
.ctx button { display: flex; justify-content: space-between; width: 100%; text-align: left; padding: 7px 10px; border: none; background: none; cursor: pointer; border-radius: 5px; font-size: 13px; }
.ctx button:hover { background: #f3f4f6; }
.ctx button span { color: var(--muted); font-size: 11px; }
.ctx hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.palette .sw { width: 20px; height: 20px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
.palette .sw.add { display: grid; place-items: center; font-size: 12px; color: var(--muted); background: #fff; }
.props-body .f.color-f { grid-template-columns: 64px 36px 1fr; }
.props-body .f.color-f .btn.tiny { justify-self: start; }
.modal-card.wide { width: min(560px, 94vw); }
.two-col-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.two-col-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.two-col-form input, .two-col-form select { width: 100%; }
.versions { max-height: 50vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.versions .ver { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.versions .ver .btn { margin-left: auto; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-size: 13px; }
.keys b { display: inline-block; min-width: 120px; font-weight: 600; color: var(--primary); }
.crop-hint { background: #eff6ff; border: 1px solid #bfdbfe; padding: 6px 8px; border-radius: 6px; font-size: 12px; margin-bottom: 6px; }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: rgba(17,24,39,.92); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 70; pointer-events: none; transition: opacity .3s; }

.icons { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; max-height: 190px; overflow-y: auto; padding: 2px; }
.icons button { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; display: grid; place-items: center; padding: 4px; }
.icons button:hover { background: #eff6ff; border-color: #93c5fd; }
.icons button img { width: 20px; height: 20px; }
.emojis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 96px; overflow-y: auto; }
.emojis button { border: 1px solid transparent; background: none; font-size: 18px; cursor: pointer; border-radius: 5px; padding: 2px 0; }
.emojis button:hover { background: #f3f4f6; border-color: var(--line); }
.tb-grid { display: grid; gap: 3px; max-height: 40vh; overflow: auto; }
.tb-grid input { width: 100%; padding: 5px 6px; font-size: 12px; min-width: 0; }
.tb-grid input.head { font-weight: 600; background: #f3f4f6; }
.fx-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 4px; }
.fx-grid .btn { justify-content: center; font-size: 12px; padding: 5px 4px; }

/* GIF 최적화 */
.gf-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.gf-side img { width: 100%; height: auto; max-height: 420px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; display: block; margin-top: 4px; }
.gf-result { min-height: 60px; display: flex; flex-direction: column; gap: 6px; }
.gf-result .ok { color: #15803d; font-weight: 600; }
.gf-tl { position: relative; height: 64px; margin-top: 8px; border-radius: 6px; overflow: hidden; background: #111; user-select: none; touch-action: none; cursor: crosshair; }
.gf-tl canvas { width: 100%; height: 100%; display: block; opacity: .85; }
.gf-sel { position: absolute; top: 0; bottom: 0; background: rgba(37,99,235,.28); box-shadow: 0 0 0 1px #2563eb inset; pointer-events: none; }
.gf-ph { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; pointer-events: none; opacity: .9; }
.gf-h { position: absolute; top: 0; bottom: 0; width: 14px; margin-left: -7px; background: #2563eb; border-radius: 4px; cursor: ew-resize; box-shadow: 0 0 0 1px #fff; }
.gf-h::after { content: ''; position: absolute; left: 5px; right: 5px; top: 22px; bottom: 22px; border-left: 1px solid #fff; border-right: 1px solid #fff; opacity: .8; }
@media (max-width: 760px) { .gf-compare { grid-template-columns: 1fr; } }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; }
/* display:grid 가 브라우저 기본 [hidden]{display:none} 을 덮어써서 팝업이 안 닫혔다(2026-09-16 사장님 발견) */
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; padding: 20px; width: 340px; }
.modal-card h3 { margin: 0 0 12px; }
.modal-card input[type=number] { width: 110px; }
