* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; font-size: 14px; color: #1d1d1f; background: #f5f5f7; overflow: hidden; }
button { font: inherit; cursor: pointer; border: 1px solid #d2d2d7; background: #fff; border-radius: 6px; padding: 4px 10px; color: inherit; }
button:hover { background: #f0f0f2; }
button.active { background: #ffd60a; border-color: #e6bf00; }
input, select { font: inherit; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.hint { color: #86868b; font-size: 12px; }
.sep { width: 1px; height: 18px; background: #d2d2d7; margin: 0 4px; }

#app { display: grid; grid-template-columns: 220px 280px 1fr; height: 100vh; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid #d2d2d7; }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px; font-weight: 700; font-size: 15px; }
.pane-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-head button { border: none; background: none; font-size: 18px; color: #e6a800; padding: 0 6px; }

/* 폴더 */
#folders { background: #ececee; }
#folder-tree { flex: 1; overflow-y: auto; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; }
.folder-row { display: flex; align-items: center; gap: 4px; padding: 6px 10px; margin: 1px 6px; border-radius: 6px; cursor: pointer; user-select: none; }
.folder-row:hover { background: #dcdce0; }
.folder-row.sel { background: #ffd60a; }
.folder-row.drop { outline: 2px dashed #e6a800; }
.folder-row .tw { width: 14px; font-size: 10px; color: #86868b; text-align: center; }
.folder-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row .ct { color: #86868b; font-size: 12px; }
.folder-row input { width: 100%; }

/* 웹툰 미리보기 카드 (폴더 영역 아래) */
.wt-card, .wt-card.active { position: relative; margin: 10px; height: 130px; padding: 0; border: none; border-radius: 14px; overflow: hidden; color: #fff; text-align: left; background: linear-gradient(135deg, #00c73c, #009a2e); flex-shrink: 0; }
.wt-card:hover { background: linear-gradient(135deg, #00d442, #00a834); }
.wt-card.active { outline: 3px solid #ffd60a; outline-offset: -3px; }
.wt-card-bg { position: absolute; inset: 0; background-size: cover; background-position: top center; opacity: .35; }
.wt-card-body { position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; height: 100%; padding: 14px; }
.wt-card-icon { font-size: 28px; }
.wt-card b { font-size: 16px; }
.wt-card small { font-size: 12px; opacity: .9; }

/* 글목록 */
#notes { background: #fafafa; }
#search { margin: 0 10px 8px; padding: 6px 10px; border: 1px solid #d2d2d7; border-radius: 8px; background: #fff; }
#note-list { list-style: none; margin: 0; padding: 0 6px; overflow-y: auto; flex: 1; }
.note-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid #ececee; }
.note-item:hover { background: #f0f0f2; }
.note-item.sel { background: #ffd60a; }
.note-item .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item .s { font-size: 12px; color: #6e6e73; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.note-item .s b { font-weight: 400; color: #1d1d1f; margin-right: 6px; }

/* 에디터 */
#editor { background: #fff; border-right: none; }
#editor-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.empty { margin: auto; color: #86868b; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #ececee; }
.tabs, .tools { display: flex; gap: 6px; align-items: center; }
.tools { margin-left: auto; }
#save-state { color: #86868b; font-size: 12px; white-space: nowrap; }
#save-state.unsaved { color: #d97706; }
#opacity { width: 80px; vertical-align: middle; }
.tab-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.text-tools, .board-tools, .wt-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 12px; border-bottom: 1px solid #ececee; }
.text-tools button, .board-tools button, .wt-tools button { padding: 3px 8px; font-size: 12px; }
.wt-tools label { font-size: 12px; display: flex; gap: 4px; align-items: center; }
.wt-tools input[type=number] { width: 60px; }
#char-count { color: #86868b; font-size: 12px; }

/* 펜 도구 모음 */
.ink-tools { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ink-tools .swatch { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #d2d2d7; }
.ink-tools .swatch.active { box-shadow: 0 0 0 2px #1d1d1f; }
.ink-tools input[type=color] { width: 26px; height: 22px; padding: 0; border: none; background: none; cursor: pointer; }
.ink-tools select { font-size: 12px; }
.edit-btn.active { background: #e53935; border-color: #c62828; color: #fff; }

/* 시나리오 종이: 글자(textarea) 위에 필기(svg) */
#paper { flex: 1; position: relative; min-height: 0; display: flex; }
#body { flex: 1; overflow: auto; outline: none; padding: 24px 40px 50vh; font-size: 12pt; line-height: 1.8; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; cursor: text; }
#body:empty::before { content: attr(data-placeholder); color: #aeaeb2; pointer-events: none; }
#body div, #body p { margin: 0; }
#paper.pen #body { touch-action: none; cursor: crosshair; }

/* 서식 도구 */
.fmt-btn { min-width: 28px; display: inline-flex; align-items: center; justify-content: center; }
.fmt-btn svg { width: 14px; height: 14px; }
#font-size { font-size: 12px; padding: 1px 2px; }
#board-zoom { position: absolute; right: 10px; bottom: 10px; padding: 2px 8px; border-radius: 10px; background: rgba(0,0,0,.55); color: #ddd; font-size: 12px; pointer-events: none; }
#body-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* 레퍼런스 보드 */
#board { flex: 1; position: relative; overflow: hidden; background-color: #d6d6da; cursor: default; }
#board[data-tool="pen"] { cursor: crosshair; }
#board[data-tool="text"] { cursor: text; }
#board[data-tool="eraser"] { cursor: cell; }
.board-items, .board-texts { position: absolute; left: 0; top: 0; }
.board-ink { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.board-text { position: absolute; white-space: pre; line-height: 1.3; font-weight: 600; user-select: none; cursor: move; }
#board[data-tool="pen"] .board-text { pointer-events: none; }
#board[data-tool="text"] .board-text { cursor: text; outline: 1px dashed rgba(0,0,0,.25); }
.board-text-input { position: absolute; min-width: 8em; border: 1px dashed currentColor; background: rgba(255,255,255,.92); outline: none; resize: both; font-weight: 600; line-height: 1.3; padding: 0 2px; font-family: inherit; }

/* 빈 폴더 안내 */
#editor-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#editor-empty p { margin: 0; }

/* 스티커 메모 */
.sticker-view { position: relative; }
.sticker-tools { display: flex; gap: 6px; align-items: center; padding: 6px 12px; border-bottom: 1px solid #ececee; }
.sticker-tools button { padding: 3px 8px; font-size: 12px; }
#sticker-wrap { flex: 1; min-height: 0; overflow: auto; background: #efeae0; }
#sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; padding: 20px; }
.sticker { aspect-ratio: 1; display: flex; flex-direction: column; min-width: 0; padding: 6px 12px 12px; border-radius: 4px; box-shadow: 0 2px 6px rgba(0,0,0,.15); cursor: grab; user-select: none; }
.sticker.dragging { opacity: .45; outline: 2px dashed #8a7f66; cursor: grabbing; }
.st-head { display: flex; align-items: center; gap: 4px; height: 22px; font-size: 12px; color: rgba(0,0,0,.45); }
.st-head .st-num { font-weight: 700; }
.st-head .st-grip { letter-spacing: -2px; }
.st-head button { border: none; background: none; padding: 0 3px; font-size: 13px; color: rgba(0,0,0,.45); }
.st-head button:hover { color: #000; background: none; }
.st-title { border: none; border-bottom: 1px solid rgba(0,0,0,.12); background: transparent; font: inherit; font-weight: 800; font-size: 16px; outline: none; padding: 4px 0; min-width: 0; }
.st-body { flex: 1; border: none; background: transparent; resize: none; outline: none; font: inherit; font-size: 13px; line-height: 1.6; padding: 6px 0 0; min-height: 0; }
.sticker-add-tile { aspect-ratio: 1; border: 2px dashed #c9c2b2; border-radius: 4px; background: transparent; color: #9a917d; font-size: 15px; }
.sticker-add-tile:hover { background: rgba(255,255,255,.4); }
#sticker-modal { position: absolute; inset: 0; z-index: 5; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 24px; }
.st-big { width: min(720px, 100%); aspect-ratio: 1; max-height: 100%; display: flex; flex-direction: column; padding: 14px 24px 24px; border-radius: 6px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.st-big-head { display: flex; align-items: center; gap: 10px; font-size: 13px; color: rgba(0,0,0,.55); }
.st-big-head button#st-big-close { font-size: 12px; background: rgba(255,255,255,.6); }
#st-big-title { border: none; border-bottom: 1px solid rgba(0,0,0,.15); background: transparent; font: inherit; font-weight: 800; font-size: 24px; outline: none; padding: 10px 0 8px; }
#st-big-body { flex: 1; border: none; background: transparent; resize: none; outline: none; font: inherit; font-size: 16px; line-height: 1.8; padding-top: 10px; }
#board.panning { cursor: grabbing; }
#board.dragover { outline: 3px dashed #ffd60a; outline-offset: -3px; }
#board-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ref { position: absolute; user-select: none; }
.ref img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.ref.flip img { transform: scaleX(-1); }
.ref.sel { outline: 2px solid #ffd60a; }
.ref .hdl { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; background: #ffd60a; border-radius: 3px; cursor: nwse-resize; display: none; }
.ref.sel .hdl { display: block; }
.board-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #777; pointer-events: none; font-size: 15px; }

/* 웹툰 미리보기 */
#webtoon-view { grid-column: 2 / 4; grid-row: 1; background: #fff; border-right: none; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.wt-stage { flex: 1; display: flex; min-height: 0; background: #e8e8ed; }
.wt-list-wrap { width: 240px; border-right: 1px solid #d2d2d7; background: #fafafa; display: flex; flex-direction: column; flex-shrink: 0; }
.wt-list-head { padding: 8px 10px; font-size: 12px; color: #6e6e73; line-height: 1.6; }
#wt-list { list-style: none; margin: 0; padding: 0 6px 10px; overflow-y: auto; flex: 1; }
#wt-list li { display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 6px; background: #fff; margin-bottom: 4px; border: 1px solid #ececee; cursor: grab; font-size: 12px; }
#wt-list li.drag-over { border-color: #e6a800; box-shadow: 0 -3px 0 #e6a800; }
#wt-list li img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; pointer-events: none; -webkit-user-drag: none; }
#wt-list li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#wt-list li .sz { font-size: 11px; color: #86868b; }
#wt-list li .sz.warn { color: #d97706; }
#wt-list li button { padding: 0 6px; border: none; background: none; color: #c00; }
.wt-phone-wrap { flex: 1; display: flex; justify-content: center; align-items: stretch; padding: 16px; min-width: 0; overflow: auto; }
#wt-phone { height: 100%; border: 10px solid #1d1d1f; border-radius: 28px; background: #fff; overflow: hidden; flex-shrink: 0; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
#wt-phone.orig, #wt-phone.edit { border: none; border-radius: 0; }
#wt-phone.dragover { outline: 3px dashed #ffd60a; }
#wt-scroll { height: 100%; overflow: auto; cursor: grab; user-select: none; }
#wt-scroll.grabbing { cursor: grabbing; }
#wt-phone:not(.orig):not(.edit) #wt-scroll { scrollbar-width: none; }
#wt-phone:not(.orig):not(.edit) #wt-scroll::-webkit-scrollbar { display: none; }
.wt-sheet { position: relative; overflow: hidden; }
.wt-strip img { display: block; pointer-events: none; -webkit-user-drag: none; }
.wt-strip .wt-empty { padding: 40px 20px; text-align: center; color: #86868b; line-height: 1.7; }
.wt-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.wt-texts { position: absolute; inset: 0; pointer-events: none; }
.wt-note { position: absolute; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; line-height: 1.3; font-weight: 600; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; }

/* 수정 모드: 원고 둘레 여백 + 펜 */
#wt-phone.edit .wt-sheet { background: #f4f4f6; background-image: linear-gradient(#e3e3e8 1px, transparent 1px); background-size: 100% 24px; }
#wt-phone.edit #wt-scroll { cursor: crosshair; touch-action: none; }
#wt-phone.edit[data-tool="text"] #wt-scroll { cursor: text; }
#wt-phone.edit[data-tool="eraser"] #wt-scroll { cursor: cell; }
#wt-phone.edit[data-tool="hand"] #wt-scroll { cursor: grab; touch-action: auto; }
#wt-phone.edit .wt-strip { box-shadow: 0 0 0 1px #c7c7cc; }
#wt-phone.edit[data-tool="text"] .wt-note, #wt-phone.edit[data-tool="eraser"] .wt-note { pointer-events: auto; outline: 1px dashed rgba(0,0,0,.2); }
/* 수정 표시 보기: 수정 모드가 아니어도 여백과 표시를 보여줌 */
#wt-phone.marked { border: none; border-radius: 0; }
#wt-phone.marked .wt-sheet { background: #fafafa; }
#wt-phone.marked .wt-strip { box-shadow: 0 0 0 1px #c7c7cc; }
#wt-show-marks-wrap input { margin: 0; }
.wt-text-input { position: absolute; min-width: 140px; border: 1px dashed currentColor; background: rgba(255,255,255,.92); outline: none; resize: both; font-weight: 600; line-height: 1.3; padding: 0 2px; font-family: inherit; pointer-events: auto; user-select: text; }
