:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f5f7f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #172026;
  --muted: #65717c;
  --subtle: #89949e;
  --line: #d9e0e5;
  --line-strong: #c7d0d7;
  --teal: #09999a;
  --teal-strong: #078183;
  --teal-soft: #e7f7f7;
  --coral: #ff5b62;
  --lemon: #f8c534;
  --shadow: 0 18px 45px rgba(24, 38, 48, 0.08);
  --radius-sm: 6px;
  --radius: 8px;
  --sidebar: 248px;
  --inspector: 310px;
  --topbar: 64px;
  --mobile-tabbar: 64px;
  --font: "Pretendard", "Noto Sans KR", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0;
  /* Korean wraps at word boundaries, never character-by-character, even when squeezed. */
  word-break: keep-all;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(9, 153, 154, 0.22);
  outline-offset: 2px;
}

input:focus {
  border-color: var(--teal) !important;
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.09);
  outline: none;
}

select:focus,
textarea:focus {
  border-color: var(--teal) !important;
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.09);
  outline: none;
}

.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(9, 153, 154, 0.03), transparent 32%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar);
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  color: var(--text);
  text-decoration: none;
  font-size: 25px;
  font-weight: 800;
  line-height: 1;
}

.brand strong {
  color: var(--teal);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 2px;
  flex: none;
}

.lang-select-top {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.theme-toggle-top .icon {
  width: 20px;
  height: 20px;
}

.desktop-panel-toggle[aria-pressed="true"] {
  border-color: rgba(9, 153, 154, 0.36);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.autosave {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(248, 197, 52, 0.72);
  border-radius: var(--radius-sm);
  color: #8a6400;
  background: #fff8db;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--lemon);
  box-shadow: 0 0 0 3px rgba(248, 197, 52, 0.22);
}

.icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.icon svg,
.drop-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button,
.soft-button,
.danger-button,
.primary-button,
.mode-button,
.seg-button,
.bg-option,
.tool-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button.labelled {
  width: auto;
  gap: 7px;
  padding: 0 12px;
  border-color: transparent;
}

.icon-button:hover,
.soft-button:hover,
.mode-button:hover,
.seg-button:hover,
.bg-option:hover {
  border-color: var(--line-strong);
  background: var(--bg-soft);
}

.primary-download {
  color: var(--text);
}

.primary-button {
  min-height: 40px;
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(9, 153, 154, 0.18);
}

.primary-button:hover {
  border-color: var(--teal-strong);
  background: var(--teal-strong);
}

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

.soft-button {
  min-height: 36px;
  gap: 8px;
  color: var(--text);
}

.soft-button.full {
  width: 100%;
  min-height: 34px;
  margin-top: 8px;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 8px 0 12px;
}

.preset-chip {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.preset-chip:hover,
.preset-chip.active {
  border-color: rgba(9, 153, 154, 0.36);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.danger-button {
  min-height: 36px;
  border-color: #ffd7d9;
  color: var(--coral);
  background: #fffafa;
}

.danger-button:hover {
  border-color: #ffb8bc;
  background: #fff1f2;
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--inspector);
  height: calc(100vh - var(--topbar));
}

body.sidebar-collapsed .app-body {
  grid-template-columns: 0 minmax(0, 1fr) var(--inspector);
}

body.inspector-collapsed .app-body {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) 0;
}

body.sidebar-collapsed.inspector-collapsed .app-body {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px 10px;
  overflow: hidden;
}

body.sidebar-collapsed .sidebar,
body.inspector-collapsed .inspector {
  width: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.tool-nav {
  display: grid;
  gap: 7px;
}

.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--muted);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 850;
}

.category-chip.active,
.category-chip:hover {
  border-color: rgba(9, 153, 154, 0.36);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.tool-library {
  position: relative;
  display: grid;
  z-index: 18;
}

.all-tools-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 42px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 900;
}

.all-tools-trigger:hover,
.all-tools-trigger:focus-visible,
.tool-library:focus-within .all-tools-trigger,
.tool-library:hover .all-tools-trigger {
  border-color: rgba(9, 153, 154, 0.42);
  background: var(--teal-soft);
  color: var(--teal-strong);
}

.all-tools-popover {
  position: fixed;
  left: 14px;
  top: 116px;
  z-index: 34;
  width: min(720px, calc(100vw - 28px));
  max-height: min(74vh, 660px);
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 70px rgba(24, 38, 48, 0.18);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  overflow: auto;
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.tool-library:hover .all-tools-popover,
.tool-library:focus-within .all-tools-popover,
.all-tools-popover.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.all-tools-popover .tool-nav {
  display: none;
}

.tool-menu-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.tool-menu-group {
  display: grid;
  gap: 8px;
}

.tool-menu-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.tool-menu-group-title {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tool-menu-card {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.tool-menu-open {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  height: 100%;
  gap: 9px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 850;
  text-align: left;
}

.tool-menu-open:hover {
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.tool-menu-favorite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--subtle);
  font-size: 16px;
  font-weight: 900;
}

.tool-menu-favorite.active,
.tool-menu-favorite:hover {
  color: #d9a700;
  background: rgba(248, 197, 52, 0.12);
}

.tool-tab.filtered-out {
  display: none;
}

.tool-list {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: 18px;
  min-height: 0;
  overflow: auto;
}

.tool-nav-section {
  display: grid;
  gap: 8px;
}

.nav-section-title {
  padding: 0 10px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.favorite-tools {
  display: grid;
  gap: 7px;
}

.favorite-empty {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
  font-size: 13px;
  line-height: 1.4;
}

.tool-tab {
  justify-content: flex-start;
  width: 100%;
  min-height: 46px;
  gap: 11px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  white-space: nowrap;
}

.tool-tab.active {
  background: linear-gradient(135deg, var(--teal), #11a9a6);
  color: #ffffff;
  box-shadow: 0 12px 25px rgba(9, 153, 154, 0.22);
}

.tool-tab:not(.active):hover {
  background: #eef4f5;
}

.favorite-tab {
  border-color: rgba(248, 197, 52, 0.58);
  background: #fffdf2;
}

.favorite-tab.active {
  border-color: transparent;
}

.favorite-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 36px;
  min-width: 82px;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.favorite-toggle .icon {
  width: 18px;
  height: 18px;
}

.favorite-toggle .icon svg {
  fill: none;
}

.favorite-toggle:hover {
  border-color: rgba(248, 197, 52, 0.75);
  color: #7d5a00;
  background: #fff8db;
}

.favorite-toggle.active {
  border-color: rgba(248, 197, 52, 0.88);
  color: #7d5a00;
  background: #fff8db;
  box-shadow: 0 0 0 3px rgba(248, 197, 52, 0.16);
}

.favorite-toggle.active .icon svg {
  fill: currentColor;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.preset-list-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.preset-list-button:hover,
.preset-list-button.active {
  border-color: rgba(9, 153, 154, 0.42);
  background: var(--teal-soft);
  color: var(--teal-strong);
}

.ai-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 13px 14px;
}

.ai-status div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ai-status strong {
  color: var(--text);
  font-size: 14px;
}

.ai-status span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.ai-status progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--line);
}

.ai-status progress::-webkit-progress-bar {
  background: var(--line);
}

.ai-status progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--teal), #f8c534);
  border-radius: 999px;
}

.ai-status progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--teal), #f8c534);
  border-radius: 999px;
}

.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(12, 18, 22, 0.56);
  padding: 18px;
}

.editor-modal[hidden] {
  display: none !important;
}

.editor-dialog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: min(1120px, calc(100vw - 36px));
  height: min(760px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(24, 38, 48, 0.30);
  overflow: hidden;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.editor-head h2 {
  font-size: 18px;
  font-weight: 900;
}

.editor-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  overflow-x: auto;
}

.editor-size,
.editor-preview-bg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.editor-size input {
  width: 150px;
  accent-color: var(--teal);
}

.editor-size strong {
  min-width: 42px;
  color: var(--text);
  text-align: right;
}

.editor-preview-bg select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 850;
  padding: 0 30px 0 10px;
}

.editor-preview-bg input[type="color"] {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 3px;
}

.editor-canvas-wrap {
  --preview-bg: #16d8d2;
  --brush-cursor-size: 34px;
  display: grid;
  position: relative;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.editor-canvas-wrap[data-preview-bg="checker"] {
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f3 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f3 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.editor-canvas-wrap[data-preview-bg="white"] {
  background: #ffffff;
}

.editor-canvas-wrap[data-preview-bg="black"] {
  background: #05080a;
}

.editor-canvas-wrap[data-preview-bg="custom"] {
  background: var(--preview-bg);
}

.mask-brush-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 95;
  display: none;
  width: var(--brush-cursor-size);
  height: var(--brush-cursor-size);
  border: 2px solid rgba(22, 216, 210, 0.95);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 0 1px rgba(7, 12, 16, 0.70),
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    0 0 14px rgba(22, 216, 210, 0.32);
}

.mask-brush-cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.editor-canvas-wrap.mask-brush-visible .mask-brush-cursor {
  display: block;
}

.editor-canvas-wrap[data-mask-mode="restore"] .mask-brush-cursor {
  color: #16d8d2;
  border-color: rgba(22, 216, 210, 0.96);
}

.editor-canvas-wrap[data-mask-mode="erase"] .mask-brush-cursor {
  color: #ff5b62;
  border-color: rgba(255, 91, 98, 0.96);
  box-shadow:
    0 0 0 1px rgba(7, 12, 16, 0.72),
    inset 0 0 0 1px rgba(255, 255, 255, 0.44),
    0 0 14px rgba(255, 91, 98, 0.34);
}

#maskEditorCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 36px rgba(24, 38, 48, 0.18);
  touch-action: none;
  cursor: none;
}

.side-footer {
  display: grid;
  gap: 12px;
}

.mode-button {
  justify-content: space-between;
  width: 100%;
  min-height: 40px;
  gap: 10px;
  color: var(--text);
}

.version {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  position: relative;
  min-width: 0;
  overflow: auto;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 72%, #ffffff 100%);
}

.tool-panel {
  display: none;
  min-height: 100%;
  padding: 18px 24px 20px;
}

.tool-panel.active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 850;
  line-height: 1.15;
}

.panel-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.panel-tools,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.seg-button {
  min-height: 36px;
  min-width: 56px;
  padding: 0 12px;
  color: var(--muted);
}

.seg-button.active {
  border-color: rgba(9, 153, 154, 0.35);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 126px;
  padding: 18px;
  border: 1.5px dashed rgba(9, 153, 154, 0.55);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(9, 153, 154, 0.035), transparent 46%, rgba(255, 91, 98, 0.035)),
    #ffffff;
  color: var(--muted);
  text-align: center;
  outline: none;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.drop-zone.compact {
  min-height: 88px;
  margin-bottom: 14px;
}

.drop-zone.drag-over,
.drop-zone:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(9, 153, 154, 0.12);
}

.drop-icon {
  width: 40px;
  height: 40px;
  color: var(--teal);
}

.drop-zone strong {
  margin-top: 8px;
  color: var(--teal);
  font-size: 18px;
  font-weight: 850;
  white-space: nowrap;
}

.drop-zone span:not(.drop-icon) {
  margin-top: 4px;
  font-size: 13px;
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 0 10px;
}

.preview-heading > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-heading h2,
.preview-card h2,
.palette-panel h2,
.inspector h2 {
  font-size: 16px;
  font-weight: 850;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid rgba(9, 153, 154, 0.35);
  border-radius: var(--radius-sm);
  color: var(--teal-strong);
  background: var(--teal-soft);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.canvas-stage {
  position: relative;
  min-height: 282px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(24, 38, 48, 0.02);
}

.canvas-scroll {
  width: 100%;
  height: 100%;
  min-height: 282px;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #eef2f4 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f4 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f4 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#alignCanvas {
  display: block;
  max-width: 100%;
  max-height: 360px;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 26px rgba(25, 38, 49, 0.10);
}

.canvas-stage.actual #alignCanvas {
  max-width: none;
  max-height: none;
}

/* Compact centered hint chip — does NOT cover the whole preview area. */
.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 28px);
  padding: 9px 16px;
  border-radius: 999px;
  text-align: center;
  color: #eef3f5;
  background: rgba(26, 33, 38, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
}

.empty-state.hidden,
.empty-state[hidden] {
  display: none;
}

.thumb-rail-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.rail-hint {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 800;
}

.add-button {
  flex: 0 0 auto;
  min-width: 126px;
  color: var(--teal-strong);
  border-color: rgba(9, 153, 154, 0.4);
}

.plus-mark {
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
}

.thumb-rail {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 2px 6px;
}

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  flex: 0 0 62px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: #eef3f4;
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.16);
}

.thumb::before {
  content: "";
  position: absolute;
  top: 5px;
  width: 18px;
  height: 4px;
  border-top: 2px solid rgba(23, 32, 38, 0.45);
  border-bottom: 2px solid rgba(23, 32, 38, 0.45);
}

.thumb.dragging {
  opacity: 0.55;
}

.inspector {
  min-width: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #fbfcfd;
}

.inspector-panel {
  display: none;
  padding: 18px 16px 20px;
}

.inspector-panel.active {
  display: block;
}

.inspector h2 {
  margin: 0 0 10px;
}

.inspector h2:not(:first-child) {
  margin-top: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  margin-bottom: 7px;
  color: var(--text);
  font-weight: 750;
}

.field-row input[type="number"],
.field-row input[type="color"],
.field-row select,
.field-row em {
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.field-row input[type="number"] {
  padding: 0 9px;
  color: var(--text);
  text-align: right;
  font-weight: 750;
}

.field-row select {
  padding: 0 9px;
  color: var(--text);
  font-weight: 750;
}

.field-row input[type="color"] {
  padding: 4px;
}

.field-row em {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
}

.color-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
  margin: -1px 0 10px 87px;
}

.color-action-row.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.eyedropper-button {
  min-width: 0;
  font-size: 13px;
}

.eyedropper-button::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--subtle);
  opacity: 0.5;
}

.eyedropper-button.active,
.eyedropper-button[aria-pressed="true"] {
  border-color: rgba(9, 153, 154, 0.55);
  background: var(--teal-soft);
  color: var(--teal-strong);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.10);
}

.eyedropper-button.active::before,
.eyedropper-button[aria-pressed="true"]::before {
  background: var(--teal);
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(9, 153, 154, 0.16);
}

.range {
  width: 100%;
  accent-color: var(--teal);
  margin: -4px 0 9px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  margin-top: 2px;
  color: var(--text);
  font-weight: 800;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.bg-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.bg-option {
  justify-content: flex-start;
  width: 100%;
  min-height: 34px;
  gap: 7px;
  padding: 0 8px;
  font-size: 13px;
}

.bg-option.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.09);
}

.swatch {
  width: 26px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--swatch, #ffffff);
}

.checker {
  background-color: #0d0d0d;
  background-image:
    linear-gradient(45deg, #1c1c1c 25%, transparent 25%),
    linear-gradient(-45deg, #1c1c1c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1c1c1c 75%),
    linear-gradient(-45deg, transparent 75%, #1c1c1c 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.custom-bg {
  position: relative;
}

.custom-bg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.output-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.output-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.output-list dt {
  color: var(--muted);
  font-weight: 700;
}

.output-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 800;
  text-align: right;
}

.output-list.tight {
  gap: 7px;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 10px;
  margin-top: 16px;
}

.tool-action-stack {
  display: grid;
  gap: 8px;
}

.split-preview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.preview-card,
.palette-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 1px 0 rgba(24, 38, 48, 0.02);
}

.preview-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.preview-card-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.canvas-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 276px;
  padding: 14px;
}

.canvas-box canvas,
.color-image-frame canvas {
  display: block;
  max-width: 100%;
  max-height: 360px;
  width: auto;
  height: auto;
  aspect-ratio: var(--canvas-aspect, auto);
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.color-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 14px;
}

.sprite-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 14px;
  min-height: 0;
}

.sprite-preview-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
}

.sprite-canvas-box {
  min-height: 420px;
}

.sprite-preview-box {
  min-height: 260px;
}

.sprite-canvas-box canvas,
.sprite-preview-box canvas {
  max-height: 420px;
  background: transparent;
}

.sprite-frame-card {
  min-height: 150px;
}

.sprite-frame-strip {
  display: flex;
  gap: 8px;
  min-height: 104px;
  padding: 12px;
  overflow-x: auto;
}

.sprite-frame-button {
  position: relative;
  display: grid;
  grid-template-rows: 72px 20px;
  place-items: center;
  width: 78px;
  flex: 0 0 78px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 11px;
  font-weight: 850;
}

.sprite-frame-button canvas {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background-color: #eef3f4;
  background-image:
    linear-gradient(45deg, rgba(180, 191, 199, 0.45) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(180, 191, 199, 0.45) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(180, 191, 199, 0.45) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(180, 191, 199, 0.45) 75%);
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
}

.sprite-frame-button.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.15);
}

.sprite-frame-button.disabled {
  opacity: 0.5;
}

/* Sprite-sheet maker layout + frame thumbnails */
.sprite-layout {
  display: grid;
  grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}
@media (max-width: 760px) {
  .sprite-layout {
    grid-template-columns: 1fr;
  }
}
.frame-thumb {
  position: relative;
  flex: 0 0 78px;
  width: 78px;
  height: 88px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-soft);
  cursor: grab;
  overflow: hidden;
  padding: 0;
}
.frame-thumb.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.15);
}
.frame-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.frame-thumb-index {
  position: absolute;
  left: 4px;
  bottom: 3px;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  padding: 0 4px;
}
.frame-thumb-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  cursor: pointer;
}
.frame-thumb-remove:hover {
  background: #d6455a;
}

.sprite-frame-button.disabled::after {
  content: "";
  position: absolute;
  inset: 8px 8px 26px;
  background:
    linear-gradient(45deg, transparent 46%, rgba(255, 91, 98, 0.9) 48%, rgba(255, 91, 98, 0.9) 52%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, rgba(255, 91, 98, 0.9) 48%, rgba(255, 91, 98, 0.9) 52%, transparent 54%);
  pointer-events: none;
}

.text-tool-panel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.text-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.text-workbench.single {
  grid-template-columns: minmax(0, 1fr);
}

.text-pane {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.text-pane span {
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.text-pane textarea {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  padding: 14px;
  color: var(--text);
  background: #ffffff;
  font-family: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.utility-panel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.utility-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.55fr);
  gap: 14px;
  min-height: 0;
}

.utility-card,
.maker-preview,
.ad-map,
.ad-plan-cards article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.utility-card {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 330px;
  padding: 26px;
}

.utility-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.utility-card strong {
  max-width: 420px;
  font-size: 28px;
  line-height: 1.12;
}

.utility-card p {
  max-width: 420px;
  color: currentColor;
  font-size: 14px;
  line-height: 1.45;
  opacity: 0.72;
}

.utility-output {
  min-height: 330px;
}

.maker-preview {
  min-height: 330px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.26);
}

.ad-plan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  align-items: start;
  gap: 14px;
  min-height: 0;
}

.ad-map {
  position: relative;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) 150px;
  gap: 10px;
  height: min(420px, calc(100vh - 220px));
  min-height: 320px;
  padding: 14px;
  background: #f8fafb;
}

.ad-map-sidebar,
.ad-map-work,
.ad-map-inspector {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.ad-map-work {
  color: var(--teal-strong);
  background:
    linear-gradient(135deg, rgba(9, 153, 154, 0.06), rgba(255, 255, 255, 0.72)),
    #ffffff;
}

.ad-pin {
  position: absolute;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px dashed rgba(9, 153, 154, 0.42);
  border-radius: var(--radius-sm);
  background: #fff8db;
  color: #7b5b00;
  font-size: 12px;
  font-weight: 850;
  box-shadow: 0 10px 28px rgba(24, 38, 48, 0.08);
}

.pin-sidebar {
  left: 24px;
  bottom: 28px;
}

.pin-inspector {
  right: 24px;
  bottom: 28px;
}

.pin-mobile {
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
}

.ad-plan-cards {
  display: grid;
  gap: 10px;
}

.ad-plan-cards article {
  display: grid;
  gap: 7px;
  padding: 16px;
}

.ad-plan-cards strong {
  font-size: 15px;
  font-weight: 850;
}

.ad-plan-cards p,
.inspector-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.color-image-frame {
  display: grid;
  place-items: center;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.palette-panel {
  padding-bottom: 12px;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.palette-swatch {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 6px;
  text-align: left;
}

.palette-swatch.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(9, 153, 154, 0.10);
}

.palette-chip,
.mini-swatch,
.selected-swatch {
  border: 1px solid rgba(23, 32, 38, 0.12);
  background: var(--swatch, #000000);
}

.palette-chip {
  width: 42px;
  height: 36px;
  border-radius: 5px;
}

.palette-swatch strong,
.palette-swatch span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-swatch strong {
  color: var(--text);
  font-size: 13px;
}

.palette-swatch span {
  color: var(--muted);
  font-size: 12px;
}

.selected-color-card {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 10px;
  margin-bottom: 16px;
}

.selected-swatch {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-sm);
}

.selected-color-card strong,
.selected-color-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-color-card strong {
  margin-bottom: 4px;
  font-size: 18px;
}

.selected-color-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.swatch-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-swatch {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
}

.harmony-list {
  display: grid;
  gap: 12px;
}

.harmony-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.harmony-row strong {
  color: var(--muted);
  font-size: 13px;
}

.harmony-row .swatch-line {
  flex-wrap: nowrap;
  overflow: hidden;
}

.mobile-sheet-head,
.mobile-tabbar,
.mobile-scrim,
.mobile-action-sheet {
  display: none;
}

.mirror-warning {
  position: fixed;
  left: 50%;
  top: 12px;
  z-index: 50;
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: 10px;
  max-width: min(860px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 91, 98, 0.32);
  border-radius: var(--radius);
  background: rgba(255, 250, 250, 0.98);
  color: #6f2328;
  box-shadow: 0 18px 45px rgba(24, 38, 48, 0.14);
  transform: translateX(-50%);
}

.mirror-warning strong,
.mirror-warning span,
.mirror-warning a {
  font-size: 13px;
  line-height: 1.35;
}

.mirror-warning a {
  color: var(--teal-strong);
  font-weight: 850;
  white-space: nowrap;
}

.ad-slot,
.ad-dock,
.ad-float {
  min-width: 0;
  border: 1px dashed rgba(9, 153, 154, 0.34);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(9, 153, 154, 0.045), rgba(248, 197, 52, 0.08)),
    #ffffff;
  color: var(--muted);
}

.ad-slot[hidden],
.ad-dock[hidden],
.ad-float[hidden],
.save-overlay[hidden] {
  display: none !important;
}

.ad-slot {
  display: grid;
  place-items: center;
  gap: 5px;
  text-align: center;
}

.ad-slot .ad-label,
.ad-dock .ad-label,
.ad-float .ad-label {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.ad-slot strong,
.ad-dock strong,
.ad-float strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ad-slot-sidebar {
  min-height: 74px;
  padding: 10px;
}

.ad-slot-inspector {
  min-height: 96px;
  margin: 0 16px 16px;
  padding: 12px;
}

.ad-slot-save {
  width: 100%;
  min-height: 88px;
  padding: 12px;
}

.ad-float {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 13;
  display: none;
  width: min(320px, calc(100vw - 36px));
  min-height: 76px;
  padding: 10px 14px;
  place-items: center;
  text-align: center;
  box-shadow: 0 18px 42px rgba(24, 38, 48, 0.13);
}

body.ads-enabled .ad-float[data-ad-active="true"] {
  display: grid;
}

.ad-dock {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 14;
  display: none;
  min-height: 58px;
  padding: 8px 12px;
  place-items: center;
  text-align: center;
  box-shadow: 0 12px 34px rgba(24, 38, 48, 0.13);
}

body.ads-enabled .ad-dock[data-ad-active="true"] {
  display: grid;
}

body.ads-enabled:has(.ad-dock[data-ad-active="true"]) {
  padding-bottom: 78px;
}

body[data-ad-surface="mobile-web"] .ad-dock[data-ad-active="true"] {
  position: static;
  margin: 14px 12px;
  box-shadow: none;
}

body[data-ad-surface="mobile-web"].ads-enabled:has(.ad-dock[data-ad-active="true"]) {
  padding-bottom: 0;
}

.save-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(246, 248, 249, 0.72);
  backdrop-filter: blur(10px);
}

.save-overlay-card {
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 70px rgba(24, 38, 48, 0.20);
}

.save-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(9, 153, 154, 0.16);
  border-top-color: var(--teal);
  border-radius: 999px;
  animation: saveSpin 800ms linear infinite;
}

.save-copy {
  display: grid;
  gap: 5px;
}

.save-copy strong {
  color: var(--text);
  font-size: 17px;
}

.save-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@keyframes saveSpin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%) translateY(24px);
  min-width: 220px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 13px 16px;
  border: 1px solid rgba(9, 153, 154, 0.22);
  border-radius: var(--radius);
  background: rgba(23, 32, 38, 0.94);
  color: #ffffff;
  box-shadow: var(--shadow);
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.dark {
  color-scheme: dark;
  --bg: #0c1216;
  --bg-soft: #121b20;
  --surface: #172126;
  --surface-raised: #1f2b31;
  --text: #f4fbfc;
  --muted: #c2d0d7;
  --subtle: #9eacb4;
  --line: #3a4a52;
  --line-strong: #52646d;
  --teal-soft: rgba(32, 190, 188, 0.22);
  --teal-strong: #55d6d1;
  --yellow-soft: #4d3d12;
}

body.dark .app-shell,
body.dark .workspace,
body.dark .topbar,
body.dark .sidebar,
body.dark .inspector,
body.dark .drop-zone,
body.dark .ad-slot,
body.dark .ad-dock,
body.dark .ad-float,
body.dark .save-overlay-card,
body.dark .preview-card,
body.dark .palette-panel,
body.dark .selected-color-card,
body.dark .soft-button,
body.dark .icon-button,
body.dark .mode-button,
body.dark .seg-button,
body.dark .category-chip,
body.dark .bg-option,
body.dark .field-row input,
body.dark .field-row select,
body.dark .field-row em,
body.dark .text-pane,
body.dark .text-pane textarea,
body.dark .canvas-stage,
body.dark .utility-card,
body.dark .maker-preview,
body.dark .editor-dialog,
body.dark .ad-map,
body.dark .ad-plan-cards article,
body.dark .ad-map-sidebar,
body.dark .ad-map-work,
body.dark .ad-map-inspector {
  background: var(--surface);
}

body.dark .all-tools-popover {
  background: rgba(23, 33, 38, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

body.dark .all-tools-trigger,
body.dark .tool-menu-card,
body.dark .preset-list-button {
  background: #1b272d;
}

body.dark .tool-tab {
  color: var(--text);
}

body.dark .tool-tab:not(.active):hover,
body.dark .tool-menu-open:hover {
  background: rgba(32, 190, 188, 0.16);
}

body.dark .editor-preview-bg select,
body.dark .editor-preview-bg input[type="color"] {
  background: #121a1f;
  color: var(--text);
}

body.dark .editor-canvas-wrap[data-preview-bg="checker"] {
  background-color: #151d22;
  background-image:
    linear-gradient(45deg, #202a30 25%, transparent 25%),
    linear-gradient(-45deg, #202a30 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #202a30 75%),
    linear-gradient(-45deg, transparent 75%, #202a30 75%);
}

body.dark .category-chip.active,
body.dark .category-chip:hover,
body.dark .preset-list-button:hover,
body.dark .preset-list-button.active {
  color: #7ff0eb;
}

body.dark .field-row input,
body.dark .field-row select,
body.dark .text-pane textarea {
  color: var(--text);
}

body.dark .field-row,
body.dark .check-row {
  color: #e8f2f4;
}

body.dark .field-row em {
  color: #d2e0e6;
}

body.dark .range {
  accent-color: #20bebc;
}

body.dark .preview-card-head span,
body.dark .panel-subtitle,
body.dark .output-list dt,
body.dark .ad-plan-cards p,
body.dark .inspector-note {
  color: var(--muted);
}

body.dark .save-overlay {
  background: rgba(10, 14, 17, 0.72);
}

body.dark .drop-zone {
  background: #11191d;
}

body.dark .canvas-scroll,
body.dark .checker,
body.dark .color-image-frame {
  background-color: #151d22;
  background-image:
    linear-gradient(45deg, #202a30 25%, transparent 25%),
    linear-gradient(-45deg, #202a30 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #202a30 75%),
    linear-gradient(-45deg, transparent 75%, #202a30 75%);
}

body.dark .sprite-frame-button {
  background: #11191d;
  color: var(--text);
}

body.dark .sprite-frame-button canvas {
  background-color: #151d22;
  background-image:
    linear-gradient(45deg, #202a30 25%, transparent 25%),
    linear-gradient(-45deg, #202a30 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #202a30 75%),
    linear-gradient(-45deg, transparent 75%, #202a30 75%);
}

body.dark .palette-swatch {
  background: #141c21;
}

body.dark .favorite-empty,
body.dark .favorite-tab {
  background: #151d22;
}

body.dark .favorite-toggle.active,
body.dark .favorite-toggle:hover {
  color: #ffd66a;
  background: rgba(248, 197, 52, 0.10);
}

body.dark .mirror-warning {
  border-color: rgba(255, 91, 98, 0.42);
  background: rgba(42, 24, 27, 0.98);
  color: #ffd9dc;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
  }

  .app-body {
    grid-template-columns: 88px minmax(0, 1fr);
    height: auto;
    min-height: calc(100vh - var(--topbar));
  }

  .sidebar {
    position: sticky;
    top: var(--topbar);
    height: calc(100vh - var(--topbar));
  }

  .tool-list {
    gap: 14px;
  }

  .nav-section-title,
  .favorite-empty {
    display: none;
  }

  .all-tools-popover {
    left: 10px;
    right: 10px;
    top: 76px;
    width: auto;
    max-height: min(74dvh, 560px);
  }

  .tool-menu-grid {
    grid-template-columns: 1fr;
  }

  .ai-status {
    grid-template-columns: 1fr;
  }

  .tool-tab {
    justify-content: center;
    padding: 0;
    font-size: 0;
  }

  .tool-tab .icon {
    width: 23px;
    height: 23px;
  }

  .side-footer {
    display: none;
  }

  .inspector {
    grid-column: 2;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .ad-slot-inspector {
    display: none !important;
  }
}

/* Narrow desktop / tablet-landscape: keep all topbar actions but make them
   icon-only so they never overflow. */
@media (min-width: 861px) and (max-width: 1120px) {
  .autosave {
    display: none;
  }
  .top-actions {
    gap: 6px;
  }
  .top-actions .icon-button.labelled {
    width: 40px;
    padding: 0;
    gap: 0;
    font-size: 0;
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: var(--topbar);
    min-height: var(--topbar);
    padding: 0 14px;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
  }

  .brand {
    font-size: 22px;
  }

  .top-actions {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    overflow-x: auto;
    gap: 4px;
  }

  .autosave {
    display: none;
  }

  .top-actions .icon-button.labelled {
    width: 38px;
    min-height: 38px;
    padding: 0;
    font-size: 0;
  }

  .top-actions #openFileBtn,
  .top-actions #globalDownloadBtn,
  .desktop-panel-toggle {
    display: none;
  }

  .mirror-warning {
    grid-template-columns: 1fr;
    top: 8px;
    text-align: left;
  }

  .app-body {
    grid-template-columns: 1fr;
    height: calc(100dvh - var(--topbar) - var(--mobile-tabbar));
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0;
  }

  body.sidebar-collapsed .app-body,
  body.inspector-collapsed .app-body,
  body.sidebar-collapsed.inspector-collapsed .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-tabbar) + 10px + env(safe-area-inset-bottom, 0px));
    z-index: 32;
    display: flex;
    max-height: min(74dvh, 560px);
    height: auto;
    border: 1px solid var(--line);
    border-radius: 14px 14px var(--radius) var(--radius);
    padding: 0;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(24, 38, 48, 0.22);
    overflow: hidden;
    transform: translate3d(0, 110dvh, 0);
    transition: transform 180ms ease;
  }

  body.sidebar-collapsed .sidebar {
    width: auto;
    min-width: 0;
    padding: 0;
    border: 1px solid var(--line);
    opacity: 1;
    pointer-events: auto;
    overflow: hidden;
  }

  body.mobile-tools-open .sidebar {
    transform: translateY(0);
  }

  .sidebar .tool-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 0 12px 12px;
    gap: 14px;
  }

  .all-tools-popover {
    position: fixed;
    left: 12px;
    right: 12px;
    top: calc(var(--topbar) + 12px);
    width: auto;
    max-height: min(74dvh, 560px);
  }

  .nav-section-title,
  .favorite-empty {
    display: block;
  }

  .tool-nav,
  .favorite-tools {
    grid-template-columns: 1fr;
  }

  .tool-tab {
    min-height: 46px;
    justify-content: flex-start;
    padding: 0 14px;
    font-size: 15px;
  }

  .tool-tab .icon {
    width: 21px;
    height: 21px;
  }

  .side-footer {
    display: none;
  }

  .workspace,
  .inspector {
    grid-column: 1;
  }

  .workspace {
    height: 100%;
    overflow: hidden;
  }

  .tool-panel {
    height: 100%;
    min-height: 0;
    padding: 12px 14px;
    overflow: hidden;
  }

  .tool-panel.active {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    gap: 10px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 0;
  }

  h1 {
    font-size: 22px;
  }

  .panel-subtitle {
    display: -webkit-box;
    margin-top: 4px;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .panel-tools {
    flex: 0 0 auto;
    width: 100%;
    gap: 6px;
  }

  .favorite-toggle {
    min-width: 42px;
    width: 42px;
    padding: 0;
    font-size: 0;
  }

  .panel-tools,
  .inline-actions {
    flex-wrap: wrap;
  }

  .color-action-row {
    margin-left: 0;
  }

  .color-action-row.two {
    grid-template-columns: 1fr;
  }

  .seg-button {
    min-width: 52px;
    padding: 0 10px;
  }

  .split-preview,
  .color-workbench,
  .sprite-workbench,
  .text-workbench,
  .utility-grid,
  .ad-plan-layout {
    grid-template-columns: 1fr;
    min-height: 0;
    overflow: auto;
  }

  .text-tool-panel.active,
  .utility-panel.active {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .utility-card,
  .utility-output,
  .maker-preview,
  .ad-map {
    min-height: 220px;
  }

  .utility-card {
    padding: 18px;
  }

  .utility-card strong {
    font-size: 22px;
  }

  .ad-map {
    grid-template-columns: 1fr;
    height: 250px;
    min-height: 250px;
  }

  .ad-map-sidebar,
  .ad-map-inspector,
  .pin-sidebar,
  .pin-inspector {
    display: none;
  }

  .ad-pin {
    min-height: 28px;
    padding: 0 8px;
    font-size: 11px;
  }

  .drop-zone {
    min-height: 96px;
    padding: 12px;
  }

  .drop-zone.compact {
    min-height: 76px;
  }

  .drop-icon {
    width: 32px;
    height: 32px;
  }

  .drop-zone strong {
    margin-top: 6px;
    font-size: 16px;
  }

  .drop-zone span:not(.drop-icon) {
    font-size: 12px;
  }

  .preview-heading {
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
  }

  .preview-heading > div:first-child {
    min-width: 0;
  }

  .preview-heading h2 {
    font-size: 15px;
    white-space: nowrap;
  }

  .inline-actions {
    justify-content: flex-start;
  }

  .inline-actions .soft-button,
  .inline-actions .danger-button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
  }

  .canvas-stage,
  .canvas-scroll,
  .canvas-box,
  .color-image-frame,
  .sprite-canvas-box,
  .sprite-preview-box {
    min-height: 0;
  }

  .canvas-stage {
    height: 100%;
  }

  .canvas-scroll {
    padding: 10px;
  }

  #alignCanvas,
  .canvas-box canvas,
  .color-image-frame canvas,
  .sprite-canvas-box canvas,
  .sprite-preview-box canvas {
    max-height: 100%;
  }

  .sprite-preview-stack {
    grid-template-rows: auto auto;
  }

  .sprite-frame-strip {
    min-height: 90px;
    padding: 10px;
  }

  .sprite-frame-button {
    width: 68px;
    flex-basis: 68px;
    grid-template-rows: 60px 18px;
  }

  .sprite-frame-button canvas {
    width: 54px;
    height: 54px;
  }

  .thumb-rail-wrap {
    align-items: center;
    gap: 8px;
    margin-top: 0;
  }

  .add-button {
    min-width: 112px;
    min-height: 36px;
  }

  .rail-hint {
    display: none;
  }

  .thumb {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
  }

  .inspector {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-tabbar) + 10px + env(safe-area-inset-bottom, 0px));
    z-index: 32;
    display: flex;
    flex-direction: column;
    max-height: min(78dvh, 620px);
    border: 1px solid var(--line);
    border-radius: 14px 14px var(--radius) var(--radius);
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(24, 38, 48, 0.22);
    overflow: hidden;
    transform: translate3d(0, 110dvh, 0);
    transition: transform 180ms ease;
  }

  body.inspector-collapsed .inspector {
    width: auto;
    min-width: 0;
    padding: 0;
    border: 1px solid var(--line);
    opacity: 1;
    pointer-events: auto;
    overflow: hidden;
  }

  body.mobile-options-open .inspector {
    transform: translateY(0);
  }

  .inspector-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 14px 14px 18px;
  }

  .mobile-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    min-height: 48px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .mobile-sheet-head strong {
    font-size: 15px;
    font-weight: 850;
  }

  .mobile-sheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
  }

  .mobile-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 34;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    height: calc(var(--mobile-tabbar) + env(safe-area-inset-bottom, 0px));
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .mobile-tab {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
  }

  .mobile-tab .icon {
    width: 20px;
    height: 20px;
  }

  .mobile-tab.active {
    color: var(--teal-strong);
    background: var(--teal-soft);
  }

  .mobile-scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    background: rgba(17, 26, 32, 0.36);
  }

  .mobile-scrim[hidden] {
    display: none;
  }

  .mobile-action-sheet {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-tabbar) + 10px + env(safe-area-inset-bottom, 0px));
    z-index: 32;
    display: block;
    border: 1px solid var(--line);
    border-radius: 14px 14px var(--radius) var(--radius);
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(24, 38, 48, 0.22);
    overflow: hidden;
    transform: translate3d(0, 110dvh, 0);
    transition: transform 180ms ease;
  }

  body.mobile-actions-open .mobile-action-sheet {
    transform: translateY(0);
  }

  .mobile-action-sheet[hidden] {
    display: none;
  }

  .mobile-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 14px;
  }

  .mobile-action-grid .soft-button,
  .mobile-action-grid .primary-button {
    min-height: 44px;
  }

  body.dark .mobile-tabbar,
  body.dark .mobile-sheet-head,
  body.dark .mobile-sheet-close,
  body.dark .mobile-action-sheet {
    background: var(--surface);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}

/* ============================================================
   Install button, flow tab, tool chain + presets
   ============================================================ */
.install-button {
  border-color: var(--teal) !important;
  color: var(--teal-strong);
  background: var(--teal-soft);
  font-weight: 800;
}
.install-button:hover {
  border-color: var(--teal-strong) !important;
  background: var(--teal-soft);
}

.tool-tab-flow {
  justify-content: flex-start;
  gap: 10px;
}
.tab-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: var(--coral);
  border-radius: 999px;
  padding: 2px 7px;
  line-height: 1.4;
}
.category-chip[data-category="flow"].active {
  border-color: rgba(9, 153, 154, 0.36);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

/* ---- Chain layout ---- */
.chain-drop strong {
  margin-top: 2px;
}
/* Once an input image is loaded, hide the drop zone (it returns on "새 작업"). */
.chain-drop.has-image {
  display: none;
}
.chain-run-button.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.chain-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.05fr) minmax(300px, 0.95fr);
  gap: 18px;
  margin-top: 16px;
  align-items: start;
}
/* Pipeline lives in the right inspector now → the center is a single, prominent preview. */
.chain-layout.chain-layout-single {
  grid-template-columns: 1fr;
}
.chain-layout-single .chain-output-box {
  min-height: clamp(340px, 52vh, 680px);
}
/* The chain inspector hosts the pipeline editor, so give it more room. */
body[data-tool="chain"] {
  --inspector: 384px;
}
/* Pipeline editor inside the (scrolling) inspector */
.inspector-panel .chain-builder {
  margin-bottom: 16px;
}
.inspector-panel .chain-add-popover {
  max-height: 60vh;
  overflow-y: auto;
}

.chain-builder,
.chain-result {
  min-width: 0;
}

.chain-builder-head,
.chain-result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.chain-builder-head h2,
.chain-result-head h2 {
  font-size: 16px;
}
.chain-add {
  position: relative;
  margin-left: auto;
}
.chain-add-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--teal);
  border-radius: var(--radius-sm);
  background: var(--teal);
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 8px 18px rgba(9, 153, 154, 0.18);
}
.chain-add-trigger:hover {
  background: var(--teal-strong);
  border-color: var(--teal-strong);
}
.chain-add-trigger .plus-mark {
  font-size: 16px;
  line-height: 1;
}
.chain-add-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 260px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}
.chain-add-popover.open {
  display: flex;
}
.chain-add-popover button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  color: var(--text);
}
.chain-add-popover button:hover {
  background: var(--teal-soft);
}
.chain-add-popover button strong {
  font-size: 14px;
  font-weight: 800;
}
.chain-add-popover button span {
  font-size: 12px;
  color: var(--muted);
}

.chain-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chain-empty {
  padding: 22px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.chain-empty strong {
  color: var(--teal-strong);
}

.chain-step {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.chain-step:hover {
  border-color: var(--line-strong);
}
.chain-step.disabled {
  opacity: 0.58;
}
.chain-step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}
.chain-step-index {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-strong);
  font-size: 12px;
  font-weight: 900;
}
.chain-step-glyph {
  flex: none;
}
.chain-step-glyph .icon {
  width: 22px;
  height: 22px;
  color: var(--muted);
}
.chain-step-titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-right: auto;
}
.chain-step-titles strong {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.chain-step-summary {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.chain-step-status {
  font-size: 11px;
  font-weight: 800;
  color: var(--subtle);
  white-space: nowrap;
}
.chain-step-status[data-kind="running"] {
  color: var(--lemon);
}
.chain-step-status[data-kind="done"] {
  color: var(--teal-strong);
}
.chain-step-status[data-kind="off"] {
  color: var(--subtle);
}

/* toggle switch */
.switch {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 160ms ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 160ms ease;
}
.switch input:checked + .switch-track {
  background: var(--teal);
}
.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.chain-step-move {
  display: flex;
  gap: 3px;
  flex: none;
}
.icon-mini {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}
.icon-mini:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--bg-soft);
}
.icon-mini:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.icon-mini.danger {
  color: var(--coral);
}
.icon-mini.danger:hover {
  border-color: #ffb8bc;
  background: #fff1f2;
}

.chain-step-body {
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}
.chain-step-body > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 8px 12px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-strong);
}
.chain-step-body > summary:hover {
  border-color: rgba(9, 153, 154, 0.36);
  background: var(--teal-soft);
}
.chain-step-body > summary::-webkit-details-marker {
  display: none;
}
.chain-step-body > summary::before {
  content: "▸ ";
}
.chain-step-body[open] > summary::before {
  content: "▾ ";
}
.chain-step-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  padding: 4px 12px 12px;
}
.chain-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
}
.chain-field.check {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  grid-column: 1 / -1;
}
.chain-field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}
.chain-field-value {
  color: var(--teal-strong);
  font-weight: 800;
}
.chain-field.select,
.chain-field.keycolor {
  grid-column: 1 / -1;
}
.chain-field select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}
.chain-field .range {
  width: 100%;
}
.chain-keycolor-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chain-keycolor-row input[type="color"] {
  width: 42px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 2px;
}
.chip-toggle {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.chip-toggle.active {
  border-color: rgba(9, 153, 154, 0.4);
  color: var(--teal-strong);
  background: var(--teal-soft);
}

.chain-step-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 12px;
}
.chain-step-presets select {
  flex: 1 1 130px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font-size: 12px;
}
.soft-button.mini {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}
.soft-button.mini.danger {
  color: var(--coral);
  border-color: #ffd7d9;
}

/* ---- Chain result ---- */
.chain-output-box {
  min-height: 240px;
  position: relative;
}
.chain-output-box canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(560px, 52vh);
  aspect-ratio: var(--canvas-aspect, auto);
  object-fit: contain;
}
.chain-stages-wrap {
  margin-top: 16px;
}
.chain-stages-wrap h3 {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  margin: 0 0 8px;
}
.chain-stages {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.stage-card {
  flex: none;
  width: 132px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stage-card.final {
  border-color: rgba(9, 153, 154, 0.5);
  box-shadow: 0 0 0 1px rgba(9, 153, 154, 0.18);
}
.stage-thumb {
  align-self: center;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 88px;
  aspect-ratio: var(--canvas-aspect, auto);
  border-radius: var(--radius-sm);
  display: block;
}
.stage-caption {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-dims {
  font-size: 10px;
  color: var(--subtle);
}
.stage-arrow {
  flex: none;
  color: var(--subtle);
  font-size: 18px;
  font-weight: 700;
}

/* ---- Reusable preset bar on tool inspectors ---- */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 14px;
}
.preset-bar .preset-select {
  flex: 1 1 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
}
.preset-bar .soft-button.mini {
  flex: 1 1 0;
}

/* ---- Name dialog ---- */
.name-dialog {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 18, 22, 0.5);
  backdrop-filter: blur(3px);
}
.name-dialog[hidden] {
  display: none;
}
.name-dialog-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.name-dialog-card strong {
  font-size: 16px;
}
.name-dialog-card span {
  font-size: 13px;
  color: var(--muted);
}
.name-dialog-card input {
  min-height: 40px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
}
.name-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

body.dark .chain-add-popover,
body.dark .name-dialog-card,
body.dark .chain-step,
body.dark .stage-card,
body.dark .chain-field select,
body.dark .chain-step-presets select,
body.dark .preset-bar .preset-select,
body.dark .name-dialog-card input,
body.dark .icon-mini,
body.dark .chip-toggle {
  background: var(--surface);
  color: var(--text);
}
body.dark .chain-step-body,
body.dark .chain-empty {
  background: var(--bg-soft);
}

/* ---- Simple op tools: auto-generated inspector fields ---- */
.simple-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}
.simple-range {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.simple-range-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-weight: 750;
  color: var(--text);
}
.simple-range-top em {
  font-style: normal;
  font-weight: 800;
  color: var(--teal-strong);
}
.simple-range .range {
  width: 100%;
}
.simple-fields .text-field {
  grid-template-columns: 80px minmax(0, 1fr);
}
.simple-fields .text-field input[type="text"] {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}
body.dark .simple-range-top {
  color: var(--text);
}
body.dark .simple-fields .text-field input[type="text"] {
  background: var(--surface);
  color: var(--text);
}

/* ---- Crop tool ---- */
.crop-ratio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0;
}
.crop-ratio-row .preset-chip {
  min-width: 56px;
}
.crop-stage .canvas-scroll {
  display: grid;
  place-items: center;
  padding: 14px;
  min-height: 320px;
}
#cropCanvas,
#censorCanvas,
#unwmCanvas {
  max-width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
  border-radius: var(--radius-sm);
}

/* ---- EXIF tool ---- */
.exif-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 16px;
  align-items: start;
}
.exif-meta-card {
  min-width: 0;
}
.exif-tags {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 460px;
  overflow: auto;
}
.exif-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.exif-row dt {
  color: var(--muted);
  font-weight: 750;
  margin: 0;
}
.exif-row dd {
  margin: 0;
  font-weight: 700;
  word-break: break-word;
}
.exif-none {
  padding: 16px 4px;
  color: var(--muted);
  font-size: 13px;
}
@media (max-width: 900px) {
  .exif-workbench {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Safety net: dynamic text (file names, preset names, values, long URLs)
   must wrap instead of pushing the layout. Elements that already use
   white-space:nowrap + ellipsis are intentionally excluded. */
.toast,
.drop-zone span,
.output-list dd,
.qr-info,
.exif-row dd,
.panel-subtitle,
.inspector-note,
.name-dialog-card span {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.panel-head,
.panel-head > div,
.preview-card-head,
.chain-builder-head,
.chain-result-head,
.chain-step-titles,
.field-row {
  min-width: 0;
}

.footer-controls {
  display: flex;
  gap: 7px;
  margin-top: 6px;
}
.lang-select {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
}
.mode-toggle-mini {
  width: 40px;
  flex: none;
  padding: 0;
  justify-content: center;
}
.mode-toggle-mini .icon {
  width: 20px;
  height: 20px;
}

.inspector-actions.tight {
  gap: 6px;
  flex-wrap: wrap;
}

/* Click-to-zoom previews */
.canvas-box canvas {
  cursor: zoom-in;
}
.canvas-box canvas[data-no-zoom] {
  cursor: grab;
  touch-action: none;
}
.canvas-box canvas[data-no-zoom].grabbing {
  cursor: grabbing;
}
.hint-text {
  margin-left: auto;
  margin-right: 8px;
  color: var(--teal-strong);
  font-size: 11px;
  font-weight: 600;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(8, 14, 17, 0.86);
  backdrop-filter: blur(6px);
  cursor: zoom-out;
}
.lightbox[hidden] {
  display: none;
}
.lightbox-stage {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.lightbox-stage canvas {
  display: block;
  max-width: 94vw;
  max-height: 88vh;
}
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.26);
}
.lightbox-close .icon {
  width: 22px;
  height: 22px;
}

/* Multi-image batch dock (parametric tools) */
.batch-dock {
  margin: 14px 24px 0;
  padding: 12px 14px;
  border: 1px solid rgba(9, 153, 154, 0.36);
  border-radius: var(--radius);
  background: var(--teal-soft);
}
.batch-dock[hidden] {
  display: none;
}
.batch-dock-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}
.batch-dock-head strong {
  font-size: 14px;
  color: var(--text);
}
.batch-dock-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.frame-strip-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-bottom: 4px;
  overflow-x: auto;
}

/* Chain batch bar — apply the pipeline to many images, export a ZIP */
.chain-batch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin: 10px 0 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--teal-soft);
}
.chain-batch-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chain-batch-info strong {
  font-size: 14px;
  color: var(--text);
}
.muted-text {
  color: var(--muted);
  font-size: 12px;
}
.chain-batch-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.mini-select {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 700;
}

/* Panel collapse/expand controls (replaces topbar 도구/옵션 toggles) */
.panel-collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-bottom: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.panel-collapse:hover {
  color: var(--teal-strong);
  border-color: rgba(9, 153, 154, 0.36);
  background: var(--teal-soft);
}
.panel-collapse .icon {
  width: 18px;
  height: 18px;
}
.panel-collapse-left {
  align-self: flex-end;
}
.panel-collapse-right {
  align-self: flex-start;
}

.edge-expand {
  position: absolute;
  top: 14px;
  z-index: 9;
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--teal-strong);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15, 32, 39, 0.1);
}
.edge-expand .icon {
  width: 18px;
  height: 18px;
}
.edge-expand-left {
  left: 0;
  border-left: 0;
  border-radius: 0 10px 10px 0;
}
.edge-expand-right {
  right: 0;
  border-right: 0;
  border-radius: 10px 0 0 10px;
}
body.sidebar-collapsed .edge-expand-left {
  display: inline-flex;
}
body.inspector-collapsed .edge-expand-right {
  display: inline-flex;
}
/* The collapse handles only make sense on the wide (3-pane) desktop layout */
@media (max-width: 860px) {
  .panel-collapse,
  .edge-expand {
    display: none !important;
  }
}
.footer-meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 5px;
  margin-top: 8px;
  white-space: nowrap;
  overflow: hidden;
}
.footer-meta a {
  color: var(--subtle);
  font-size: 11px;
  text-decoration: none;
}
.footer-meta a:hover {
  color: var(--teal-strong);
  text-decoration: underline;
}
.footer-meta .dot {
  color: var(--line-strong);
}
.footer-meta .version {
  color: var(--muted);
  font-size: 11px;
}
.footer-mail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  flex: none;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.footer-mail:hover {
  color: var(--teal-strong);
  border-color: rgba(9, 153, 154, 0.36);
  background: var(--teal-soft);
}
.footer-mail .icon {
  width: 16px;
  height: 16px;
}

/* ---- Pixel art ---- */
.pixelart-preview-box canvas,
#pixelartPreviewCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.pixel-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 14px;
}
.pixel-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.18);
}

/* ---- QR generator ---- */
.qr-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  gap: 18px;
  align-items: start;
  margin-top: 8px;
}
.qr-input-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 750;
  color: var(--muted);
}
.qr-input-pane textarea {
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  font-size: 15px;
  line-height: 1.5;
}
.qr-preview-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.qr-canvas-box {
  display: grid;
  place-items: center;
  padding: 18px;
  width: 100%;
  min-height: 240px;
}
.qr-canvas-box canvas {
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 6px;
}
.qr-info {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
}
body.dark .qr-input-pane textarea {
  background: var(--surface);
  color: var(--text);
}
@media (max-width: 860px) {
  .qr-workbench {
    grid-template-columns: minmax(0, 1fr);
  }
}

.qr-logo-row {
  display: flex;
  gap: 7px;
  margin: 6px 0 12px;
}
.qr-logo-row .soft-button {
  flex: 1 1 0;
}

/* ---- Favicon generator ---- */
.favicon-stage {
  min-height: 200px;
}
.favicon-editor {
  display: grid;
  grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 760px) {
  .favicon-editor {
    grid-template-columns: 1fr;
  }
}
.favicon-edit-box {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
}
.favicon-edit-box canvas {
  width: 100%;
  height: 100%;
}
.favicon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  padding: 20px;
}
.favicon-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.favicon-cell canvas {
  border-radius: 6px;
  border: 1px solid var(--line);
}
.favicon-cell span {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
}
.favicon-list {
  margin: 6px 0 12px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}
.favicon-list li {
  font-weight: 700;
}

/* ---- Drop anywhere: global file-drag affordance ---- */
body.file-dragging .workspace {
  outline: 2px dashed var(--teal);
  outline-offset: -12px;
  background: var(--teal-soft);
}
body.file-dragging .workspace::after {
  content: "여기에 이미지를 놓으면 현재 도구로 불러옵니다";
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  z-index: 30;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--teal);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(9, 153, 154, 0.28);
  pointer-events: none;
}

@media (max-width: 1080px) {
  .chain-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 680px) {
  .chain-step-fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .chain-add-popover {
    right: auto;
    left: 0;
    width: min(280px, calc(100vw - 48px));
  }
}
