:root {
  --bg: #0f1115;
  --card: #1a1e26;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b8def;
  --accent2: #3ecf8e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.wrap {
  max-width: 1480px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* 업로드 전: 입력 패널 최대, 페이지 전체 클릭·드롭 */
body.mode-upload {
  min-height: 100vh;
  overflow: hidden;
}

body.mode-upload .wrap {
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.mode-upload header {
  flex-shrink: 0;
  padding: 1rem 1.25rem 0.5rem;
}

body.mode-upload #upload-section.upload-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
  padding: 0 1.25rem 1rem;
  cursor: pointer;
}

body.mode-upload #upload-section.upload-hero.dragover .drop,
body.mode-upload #upload-section.upload-hero:hover .drop {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.08);
}

body.mode-upload #upload-section .drop {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 12px;
  margin: 0;
}

body.mode-upload #upload-section .drop-title {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
}

body.mode-upload #upload-section .meta {
  flex-shrink: 0;
  text-align: center;
  margin: 0.75rem 0 0;
  pointer-events: none;
}

body:not(.mode-upload) #upload-section.upload-hero {
  margin-top: 0.6rem;
}

body:not(.mode-upload) #upload-section .drop {
  min-height: 100px;
}

/* 영상 등록 후: 드롭존 숨기고 한 줄 요약 + 변경 버튼 */
#upload-section.has-video .drop,
#upload-section.has-video .upload-idle-hint {
  display: none;
}

#upload-section.has-video #upload-status {
  display: none;
}

#upload-section.has-video.upload-hero {
  padding: 0.35rem 0.75rem;
}

.upload-compact-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: nowrap;
}

#upload-section.has-video .upload-compact-bar {
  display: flex;
}

.upload-compact-text {
  flex: 1;
  min-width: 0;
}

.upload-compact-label {
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
  margin-right: 0.5rem;
}

.upload-compact-bar .meta {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.25;
  word-break: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-change-video {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.88rem;
  padding: 0.45rem 0.75rem;
}

#preview-section.card {
  padding: 1rem;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-areas:
    "main tools"
    "thumbs tools";
  gap: 1rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "tools"
      "main"
      "thumbs";
  }

  .tools-panel {
    order: -1;
  }
}

.workspace-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  grid-area: main;
}

.tools-panel {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  grid-area: tools;
}

.preview-thumbs {
  grid-area: thumbs;
}

/* 프레임 미리보기 헤더 */
.thumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.thumbs-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.15;
  overflow: visible;
  word-break: keep-all;
}

/* 제목 최대 2줄까지 표시 (가능한 한 노출) */
.thumbs-title {
  display: block;
  white-space: normal;
}

.thumbs-toggle {
  flex: 0 0 auto;
  padding: 0.28rem 0.45rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

body.thumbs-hidden .preview-thumbs {
  display: none;
}

/* 숨김은 어떤 위치 클래스보다 우선되도록 더 구체적으로 처리 */
body.thumbs-hidden .workspace,
body.thumbs-hidden.thumbs-left .workspace,
body.thumbs-hidden.thumbs-right .workspace,
body.thumbs-hidden.thumbs-bottom .workspace {
  grid-template-columns: 1fr 300px;
  grid-template-areas: "main tools";
}

/* 프레임 미리보기 위치 토글 (좌/우/하단) */
body.thumbs-bottom .workspace {
  grid-template-columns: 1fr 300px;
  grid-template-areas:
    "main tools"
    "thumbs tools";
}

body.thumbs-left .workspace {
  grid-template-columns: 128px 1fr 300px;
  grid-template-areas: "thumbs main tools";
}

body.thumbs-right .workspace {
  grid-template-columns: 1fr 128px 300px;
  grid-template-areas: "main thumbs tools";
}

body.thumbs-left .preview-thumbs,
body.thumbs-right .preview-thumbs {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding-right: 0.25rem;
}

body.thumbs-left .preview-thumbs .grid,
body.thumbs-right .preview-thumbs .grid {
  grid-template-columns: 1fr;
  --frame-thumb-side: 88px;
}

body.thumbs-bottom .preview-thumbs {
  position: static;
  max-height: none;
  overflow: visible;
}

.seg {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.seg-btn {
  flex: 1;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  color: var(--accent2);
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.1);
}

/* 출력 탭 (GIF/시트) */
.output-tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0 0 0.65rem;
}

.output-tab {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.output-tab:hover {
  color: var(--text);
}

.output-tab.active {
  color: var(--accent2);
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.1);
}

.output-pane.hidden {
  display: none;
}

.download-meta {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.25;
}

/* 진행상황 모달 (업로드/프리뷰/다운로드 등) */
.busy-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
}

.busy-modal.hidden {
  display: none;
}

.busy-modal-card {
  width: min(520px, calc(100vw - 2rem));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: 0 14px 60px rgba(0, 0, 0, 0.55);
}

.busy-modal-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

#busy-modal-msg {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}

/* 플로팅 패널: 크기(이미지/캔버스) */
.float-panel {
  position: fixed;
  top: 120px;
  left: 320px;
  width: min(380px, calc(100vw - 2rem));
  max-height: min(80vh, 860px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 60px rgba(0, 0, 0, 0.55);
  z-index: 90;
}

.float-panel.hidden {
  display: none;
}

.float-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  cursor: move;
  user-select: none;
}

.float-panel__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.float-panel__body {
  padding: 0.65rem;
  overflow: auto;
}

/* 팝업 안에서는 size-tool-block가 tool-block 테두리를 중복하지 않게 */
.float-panel__body .tool-block.size-tool-block {
  border-bottom: none;
  padding-bottom: 0;
}

.tool-block {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.tool-block:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.tool-block-title {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tool-block-title--sub {
  margin-top: 0.85rem;
}

.tool-field--divider {
  border-top: 1px solid var(--border);
  margin: 0.85rem 0;
  padding: 0;
  height: 0;
}

.sheet-preview-wrap--top {
  margin-bottom: 0.65rem;
}

.tool-field {
  margin-bottom: 0.75rem;
}

.tool-field:last-child {
  margin-bottom: 0;
}

.tool-field > label {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.tool-field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tool-field-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.tool-field-row--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
}

.frame-count-controls input[type="number"] {
  width: 100%;
}

.frame-count-slider-wrap {
  width: 100%;
}

.frame-count-controls input[type="range"] {
  width: 100%;
  flex: none;
}

.frame-count-range-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.tool-field input[type="number"] {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.tool-hint {
  margin: -0.35rem 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.tool-field select {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

#default-max-side-val {
  min-width: 3.2rem;
  font-size: 0.85rem;
  color: var(--accent2);
  text-align: right;
}

.default-size-fixed.hidden {
  display: none;
}

.tool-field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.frame-layout-field .tool-hint {
  margin-top: 0;
  margin-bottom: 0.4rem;
}

.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 2.1rem);
  gap: 0.2rem;
  width: max-content;
}

.anchor-btn {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.anchor-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.anchor-btn.active {
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.15);
  color: var(--accent2);
}

.size-tool-block {
  padding-top: 0.35rem;
}

.size-subtabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.size-subtab {
  flex: 1;
  padding: 0.35rem 0.3rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}

.size-subtab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.size-subtab.active {
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.12);
  color: var(--accent2);
}

.size-subtab-pane.hidden {
  display: none;
}

.image-size-meta,
.canvas-edit-meta,
.sheet-cell-size-meta {
  font-size: 0.8rem;
  color: var(--accent2);
  margin: 0 0 0.45rem;
}

.frame-layout-details {
  margin: 0.35rem 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.frame-layout-details-summary {
  padding: 0.4rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.frame-layout-details-body {
  padding: 0.35rem 0.55rem 0.55rem;
  border-top: 1px solid var(--border);
}

.frame-layout-tweak-row {
  align-items: center;
}

.frame-layout-tweak-row input[type="range"] {
  flex: 1;
  min-width: 4rem;
}

/* .tool-field input[type=number] { width:100% } 보다 우선 */
.frame-layout-tweak-row .frame-layout-num {
  width: 3.25rem;
  max-width: 3.25rem;
  flex: 0 0 3.25rem;
  padding: 0.2rem 0.25rem;
  text-align: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.8rem;
  box-sizing: border-box;
}

.frame-layout-num::-webkit-outer-spin-button,
.frame-layout-num::-webkit-inner-spin-button {
  opacity: 1;
}

.sheet-auto-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.sheet-grid-row {
  align-items: flex-end;
  gap: 0.35rem;
}

.sheet-grid-field {
  flex: 1;
  min-width: 0;
}

.sheet-grid-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.sheet-grid-field input[type="number"] {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.sheet-grid-field input:disabled {
  opacity: 0.55;
}

.sheet-grid-x {
  padding-bottom: 0.55rem;
  color: var(--muted);
  font-weight: 600;
}

.sheet-mode-hint {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.8rem;
}

.sheet-layout-meta {
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  color: var(--accent2);
}

.frame-size-meta,
.canvas-auto-meta {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  color: var(--accent2);
  font-weight: 500;
}

.sheet-preview-wrap {
  position: relative;
  width: 100%;
  max-height: 160px;
  margin-bottom: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background-color: #12151c;
  background-image:
    linear-gradient(45deg, #1c2129 25%, transparent 25%),
    linear-gradient(-45deg, #1c2129 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1c2129 75%),
    linear-gradient(-45deg, transparent 75%, #1c2129 75%);
  background-size: 12px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
}

.canvas-crop-preview-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.canvas-crop-preview-overlay.hidden {
  display: none;
}

.sheet-preview-img {
  max-width: 100%;
  max-height: 160px;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sheet-preview-img.hidden {
  display: none;
}

.sheet-preview-placeholder {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.5rem;
  text-align: center;
}

.sheet-preview-placeholder.hidden {
  display: none;
}

.tool-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

button.full-width {
  width: 100%;
}

.gif-player-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background-color: #12151c;
  background-image:
    linear-gradient(45deg, #1c2129 25%, transparent 25%),
    linear-gradient(-45deg, #1c2129 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1c2129 75%),
    linear-gradient(-45deg, transparent 75%, #1c2129 75%);
  background-size: 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gif-play-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.gif-play-img.hidden {
  display: none;
}

.gif-player-placeholder {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 0.5rem;
}

.gif-player-placeholder.hidden {
  display: none;
}

.gif-play-meta {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--accent2);
  text-align: center;
  font-weight: 500;
}

.gif-play-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.gif-play-actions button {
  flex: 1;
}


header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  font-weight: 600;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-top: 1.25rem;
}

.hidden {
  display: none !important;
}

.card.hidden {
  display: none;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 140px;
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.drop:hover,
.drop.dragover {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.06);
}

.drop-title {
  font-weight: 500;
}

.drop-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.upload-status {
  margin: 0.5rem 0 0;
  min-height: 1.25em;
}

.upload-status--error {
  color: #f07070;
}

.upload-status--busy {
  color: var(--accent);
}

.meta {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.row label {
  min-width: 140px;
  font-size: 0.9rem;
}

.row input[type="range"] {
  flex: 1;
  min-width: 120px;
}

.row input[type="number"] {
  width: 88px;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

button {
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 500;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--border);
  color: var(--text);
}

button.primary:hover:not(:disabled) {
  background: #3a4458;
}

button.accent {
  background: var(--accent2);
  color: #0a120c;
}

button.accent:hover:not(:disabled) {
  filter: brightness(1.08);
}

.screen-block {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.screen-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 0.45rem;
}

.toolbar-band {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
}

.toolbar-band--view {
  align-items: center;
}

.toolbar-band--view {
  justify-content: space-between;
}

.toolbar-band--view .row.compact {
  flex: 0 1 auto;
  min-width: 0;
}

.toolbar-band--view #tool-bar-actions {
  margin-left: auto;
}

.toolbar-band--nukki {
  align-items: center;
}

.tool-bar-actions--prominent {
  border-left: 3px solid rgba(62, 207, 142, 0.65);
  background: rgba(62, 207, 142, 0.07);
}

.apply-all-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(232, 90, 90, 0.55);
  background: rgba(232, 90, 90, 0.12);
  color: #ffd1d1;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.apply-all-badge.hidden {
  display: none;
}

/* 2안: 박스는 활성 톤(초록), '전체 적용' 배지는 경고 톤 */
body.apply-all-on #tool-bar-actions {
  border-color: rgba(62, 207, 142, 0.75);
  background: rgba(62, 207, 142, 0.12);
  box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.14);
}

.tool-bar-actions--prominent .apply-all-label {
  font-size: 0.82rem;
}

.tool-bar-actions--prominent .apply-all-label span {
  color: var(--text);
}
.frame-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent2);
  padding: 0.2rem 0.55rem;
  background: rgba(62, 207, 142, 0.12);
  border-radius: 6px;
}

.frame-badge.hidden {
  display: none;
}

.row.compact {
  margin-bottom: 0;
  flex: 1;
  min-width: 200px;
}

.row.compact label {
  min-width: 90px;
}

#panel-resolution-val {
  min-width: 52px;
  font-size: 0.88rem;
  color: var(--muted);
}

#panel-fit {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.nukki-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  flex: 1 1 auto;
  width: 100%;
  min-width: min(100%, 280px);
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 0;
}

.nukki-primary,
.nukki-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.55rem;
}

.nukki-options {
  padding-left: 0.15rem;
}

.nukki-bar label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.nukki-bar select {
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

#nukki-engine {
  min-width: 12.5rem;
  max-width: 100%;
}

#nukki-orphan-area-val {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 1.5rem;
}

.nukki-tol-label + input[type="range"] {
  width: 100px;
}

#nukki-tolerance-val,
#nukki-inner-dark-val,
#nukki-alpha-threshold-val {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 1.5rem;
}

.nukki-engine-hint {
  display: none;
}

.toolbar-band--nukki #nukki-bar {
  display: none;
}

.nukki-bar.mode-color .nukki-engine-hint {
  flex: 1 1 auto;
}

.nukki-engine-hint.warn {
  color: #e8a84a;
}

.nukki-protect-clear-btn,
.nukki-protect-clear-all-btn {
  font-size: 0.78rem;
  padding: 0.3rem 0.45rem;
}

.nukki-protect-clear-all-btn {
  margin-left: auto;
}

.nukki-preview-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  width: 100%;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 0.25rem;
}

.nukki-details {
  width: 100%;
  padding: 0.25rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nukki-details-summary {
  cursor: pointer;
  user-select: none;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.25rem 0;
}

.nukki-details[open] .nukki-details-summary {
  color: var(--text);
}

.nukki-details-body {
  padding-top: 0.25rem;
}

.nukki-preview-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.nukki-preview-btn,
.nukki-preview-clear-btn {
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
}

.nukki-preview-live-label,
.nukki-preview-two-step-label,
.nukki-preview-scope-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}

.nukki-preview-scope-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.nukki-preview-live-label input,
.nukki-preview-two-step-label input,
.nukki-preview-scope-opt input {
  accent-color: var(--accent2);
}

.nukki-apply-inner-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  user-select: none;
}

.nukki-apply-inner-label input {
  accent-color: var(--accent2);
}

#edit-canvas.tool-nukki-protect {
  cursor: cell;
}

.nukki-two-step-btn {
  font-size: 0.82rem;
  padding: 0.35rem 0.55rem;
}

.nukki-from-source-label {
  font-size: 0.82rem;
  padding: 0.3rem 0.5rem;
  flex: 0 0 auto;
}

.nukki-check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.nukki-check-label input {
  accent-color: var(--accent2);
}

.nukki-correction-note {
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1 1 12rem;
  min-width: 8rem;
}

.status-strip {
  margin: 0;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: rgba(91, 141, 239, 0.14);
  border: 1px solid rgba(91, 141, 239, 0.4);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.status-strip:empty {
  display: none;
}

#status-msg {
  flex: 1 1 auto;
  min-width: 0;
}

.status-canvas-meta {
  flex: 0 0 auto;
  font-size: 0.86rem;
  font-weight: 600;
  opacity: 0.92;
  white-space: nowrap;
  color: inherit;
}

.status-strip.error {
  background: rgba(232, 90, 90, 0.12);
  border-color: rgba(232, 90, 90, 0.45);
  color: #f0a0a0;
}

.status-strip.busy {
  background: rgba(62, 207, 142, 0.12);
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--accent2);
}

.tool-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  flex: 1 1 100%;
  min-width: min(100%, 280px);
}

.tool-bar-tabs {
  display: flex;
  gap: 0.35rem;
}

.tool-bar-tab {
  padding: 0.32rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.tool-bar-tab:hover {
  color: var(--text);
}

.tool-bar-tab.active {
  color: var(--accent2);
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.1);
}

.tool-bar {
  width: 100%;
}

.tool-bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.35rem;
}

.tool-bar-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
  padding: 0.1rem 0.25rem 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  border-left: 2px solid rgba(62, 207, 142, 0.45);
}

.tool-bar-pane {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  width: auto;
  flex: 0 1 auto;
}

.tool-bar-pane.hidden {
  display: none;
}

.tool-bar-nukki-hint {
  font-size: 0.72rem;
  color: var(--muted);
  flex: 0 1 auto;
  max-width: 11rem;
  line-height: 1.25;
}

.brush-size-control {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
  padding: 0.12rem 0.25rem 0.12rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  border-left: 2px solid rgba(91, 141, 239, 0.45);
}

.frame-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.frame-nav-btn {
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  border-radius: 8px;
}

.brush-size-control__label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: 0.1rem;
}

.brush-size-control__bounds {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

.brush-size-step {
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.brush-size-step:hover:not(:disabled) {
  border-color: var(--accent);
}

.brush-size-step:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.brush-size-control input[type="number"] {
  width: 2.75rem;
  padding: 0.2rem 0.25rem;
  text-align: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.82rem;
  -moz-appearance: textfield;
}

.brush-size-control input[type="number"]::-webkit-outer-spin-button,
.brush-size-control input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tool-btn {
  --tool-accent: var(--border);
  width: auto;
  min-width: 3.1rem;
  height: auto;
  min-height: 2.75rem;
  padding: 0.28rem 0.38rem 0.22rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.tool-btn__icon {
  font-size: 1.05rem;
  line-height: 1;
}

.tool-btn__label {
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.tool-btn:hover:not(:disabled) {
  border-color: var(--tool-accent);
  background: color-mix(in srgb, var(--tool-accent) 10%, var(--bg));
}

.tool-btn.active {
  border-color: var(--tool-accent);
  background: color-mix(in srgb, var(--tool-accent) 22%, var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--tool-accent) 35%, transparent);
}

.tool-btn.active .tool-btn__label {
  color: var(--text);
}

.tool-btn--brush {
  --tool-accent: #5b8def;
}

.tool-btn--eraser {
  --tool-accent: #9aa3b5;
}

.tool-btn--fill {
  --tool-accent: #b07ce8;
}

.tool-btn--picker {
  --tool-accent: #3ecf8e;
}

.tool-btn--protect {
  --tool-accent: #e87ad0;
}

.tool-btn--protect-fill {
  --tool-accent: rgba(91, 141, 239, 0.35);
}

.tool-btn--protect-erase {
  --tool-accent: #c98bb8;
}

.tool-btn--undo {
  --tool-accent: #5b8def;
}

.tool-btn--reset {
  --tool-accent: #e88a5a;
}

.tool-btn--protect .tool-btn__icon,
.tool-btn--protect-erase .tool-btn__icon {
  font-size: 0.95rem;
}

.color-swatch-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.35rem 0.15rem 0.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.color-swatch input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}

.tool-color-hex {
  width: 5.5rem;
  padding: 0.28rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.78rem;
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.02em;
}

.fill-options {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
  padding: 0.15rem 0.4rem 0.15rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  border-left: 2px solid rgba(91, 141, 239, 0.45);
}

.fill-options.hidden {
  display: none;
}

.fill-opt-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.fill-options input[type="range"] {
  width: 4.5rem;
  vertical-align: middle;
}

.fill-opt-val {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 1.6rem;
  text-align: right;
}

.fill-opt-check {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  margin-left: 0.15rem;
  padding-left: 0.35rem;
  border-left: 1px solid var(--border);
}

.fill-opt-check input {
  margin: 0;
}

.tool-color-hex:focus {
  outline: none;
  border-color: var(--accent);
}

.tool-color-hex.tool-color-hex--invalid {
  border-color: #e85a5a;
}

.brush-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.brush-label input[type="range"] {
  width: 72px;
}

.apply-all-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.25rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.apply-all-label:has(input:checked) {
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.12);
}

.apply-all-label input {
  accent-color: var(--accent2);
}

.panel-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.panel-tab {
  flex: 1;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}

.panel-tab:hover {
  color: var(--text);
}

.panel-tab.active {
  color: var(--accent2);
  border-color: var(--accent2);
  background: rgba(62, 207, 142, 0.1);
}

.panel-tab-pane.hidden {
  display: none;
}

.layer-frame-meta {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--accent2);
}

.apply-all-layers-label {
  margin: 0 0 0.65rem;
  width: 100%;
  justify-content: center;
}

.layer-tab-block {
  display: flex;
  flex-direction: column;
}

.layer-list {
  list-style: none;
  margin: 0 0 0.65rem;
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.layer-list-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.88rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.layer-list-item:last-child {
  border-bottom: none;
}

.layer-list-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.layer-list-item.active {
  background: rgba(62, 207, 142, 0.12);
  color: var(--accent2);
}

.layer-list-item.hidden-layer {
  opacity: 0.55;
}

.layer-vis-toggle {
  flex-shrink: 0;
  min-width: 2.35rem;
  padding: 0.2rem 0.35rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  line-height: 1.2;
}

.layer-vis-toggle.on {
  background: rgba(62, 207, 142, 0.2);
  border-color: var(--accent2);
  color: var(--accent2);
}

.layer-vis-toggle.off {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.layer-vis-toggle:hover {
  filter: brightness(1.1);
}

.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.layer-actions button {
  flex: 1;
  min-width: 3.5rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
}

.layer-margin-test {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.layer-margin-test-label {
  font-size: 0.82rem;
  color: var(--muted);
  flex: 1 1 100%;
}

.layer-margin-test button {
  flex: 1;
  min-width: 4rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
}

.layer-outline-refine {
  margin-bottom: 0.65rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.layer-outline-refine-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.layer-outline-refine .tool-field {
  margin-bottom: 0.45rem;
}

.layer-outline-refine > #btn-outline-feather {
  width: 100%;
  margin-bottom: 0.45rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
}

.layer-outline-refine-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

.layer-outline-refine-actions button {
  flex: 1;
  min-width: 4.5rem;
  padding: 0.4rem 0.35rem;
  font-size: 0.78rem;
}

.layer-outline-hint {
  margin-top: 0.35rem;
  margin-bottom: 0;
  font-size: 0.78rem;
}

.outline-feather-spread {
  margin: 0.2rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
}

#outline-feather-val,
#outline-feather-kernel-val,
#outline-alpha-threshold-val {
  min-width: 1.5rem;
  font-size: 0.85rem;
  color: var(--accent2);
}

.layer-visible-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

#layer-opacity-val {
  min-width: 2.5rem;
  font-size: 0.85rem;
  color: var(--accent2);
}

.panel-stage {
  position: relative;
  width: 100%;
  height: min(72vh, calc(100vh - 220px));
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background-color: #12151c;
  background-image:
    linear-gradient(45deg, #1c2129 25%, transparent 25%),
    linear-gradient(-45deg, #1c2129 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1c2129 75%),
    linear-gradient(-45deg, transparent 75%, #1c2129 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.viewport-zoom-hint {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  z-index: 2;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
}

.panel-stage.viewport-zoomed {
  overflow: hidden;
}

.panel-stage.viewport-zoomed .canvas-wrap {
  flex-shrink: 0;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
  cursor: none;
}

.canvas-stack {
  position: absolute;
  left: 0;
  top: 0;
  line-height: 0;
  overflow: hidden;
  transform-origin: 0 0;
  will-change: transform;
}

.layer-underlay,
.layer-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.layer-underlay {
  z-index: 0;
}

.layer-overlay {
  z-index: 2;
}

.nukki-protect-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.nukki-protect-overlay.hidden {
  display: none;
}

.nukki-preview-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.nukki-preview-overlay.hidden {
  display: none;
}

.brush-cursor-overlay {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  pointer-events: none;
  box-sizing: border-box;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.85),
    0 0 6px rgba(0, 0, 0, 0.35);
  background: rgba(91, 141, 239, 0.12);
  border-radius: 1px;
}

.brush-cursor-overlay.hidden {
  display: none;
}

.brush-cursor-overlay.brush-cursor--brush {
  background: color-mix(in srgb, var(--brush-preview, #000000) 42%, transparent);
  border-color: rgba(255, 255, 255, 0.98);
}

.brush-cursor-overlay.brush-cursor--eraser {
  border-color: rgba(200, 210, 225, 0.98);
  background:
    repeating-conic-gradient(#555 0% 25%, #888 0% 50%) 50% / 8px 8px,
    rgba(154, 163, 181, 0.2);
}

.brush-cursor-overlay.brush-cursor--protect {
  border-color: rgba(255, 180, 235, 0.98);
  background: rgba(232, 122, 208, 0.35);
}

.brush-cursor-overlay.brush-cursor--protect-erase {
  border-color: rgba(255, 180, 235, 0.95);
  background: rgba(201, 139, 184, 0.2);
  border-style: dashed;
}

.canvas-wrap.tool-brush-cursor-active,
#edit-canvas.tool-brush-cursor-active {
  cursor: none;
}

#edit-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: none;
}

/* 스포이드/채우기는 OS 커서 사용 */
#edit-canvas.tool-picker,
#edit-canvas.tool-fill {
  cursor: crosshair;
}

#edit-canvas.hidden {
  display: none;
}

/** 표시는 underlay 합성만, 편집 캔버스는 입력·픽셀 동기화용 */
#edit-canvas.layer-edit-overlay {
  opacity: 0;
}

.preview-thumbs h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}

#preview-count {
  color: var(--muted);
  font-weight: 400;
}

/* 프레임 미리보기: 셀·썸네일 표시 크기 고정 (창 너비·종횡비와 무관하게 동일 박스) */
.grid {
  --frame-thumb-side: 112px;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--frame-thumb-side));
  gap: 0.65rem;
  justify-content: start;
}

.frame-cell {
  width: var(--frame-thumb-side);
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.frame-cell:hover {
  border-color: var(--accent);
}

.frame-cell.selected {
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.35);
}

.frame-cell img {
  display: block;
  width: var(--frame-thumb-side);
  height: var(--frame-thumb-side);
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
  background: var(--card);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.frame-cell .label {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.25rem 0.35rem 0.4rem;
}
