:root {
  --bg: #f2f2ef;
  --surface: #ffffff;
  --line: #cfcfca;
  --text: #151515;
  --muted: #666660;
  --accent: #1f4c8f;
  --accent-strong: #173a6d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 30px;
  padding: 0 10px;
  border: 1px solid #b8b8b2;
  background: #fff;
  color: #111;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  background: #f7f7f5;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
}

input,
select {
  width: 100%;
  height: 30px;
  border: 1px solid #bdbdb7;
  border-radius: 6px;
  background: #fff;
  padding: 0 9px;
}

.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.header-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 230px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  font-size: 11px;
  color: var(--muted);
}

.header-actions,
.row-actions,
.segmented {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header {
  flex-wrap: nowrap;
  overflow-x: auto;
}

.app-header button {
  white-space: nowrap;
  flex-shrink: 0;
}

.context-bar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
}

.context-bar[hidden] {
  display: none;
}

.ctx-section {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.ctx-section[hidden] {
  display: none;
}

.ctx-section button {
  flex-shrink: 0;
  white-space: nowrap;
}

.ctx-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.ctx-hint {
  font-size: 12px;
  color: var(--muted);
}

.ctx-range {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 12px;
  color: var(--text);
}

.ctx-range input[type="range"] {
  width: 130px;
  height: auto;
}

.ctx-range select {
  width: auto;
  height: 28px;
  padding: 0 6px;
}

.ctx-range span {
  min-width: 22px;
  font: 700 12px Consolas, monospace;
}

.ctx-divider {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.ctx-divider[hidden] {
  display: none;
}

.ctx-text-btn {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.ctx-section .icon-button {
  width: 30px;
  height: 28px;
  font-size: 15px;
}

.label-row.anchor {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr) 340px;
}

.panel {
  overflow: hidden;
  background: #fafafa;
  border-right: 1px solid var(--line);
}

.layers {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel section {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 4px;
  margin: 7px 0;
  font-size: 11px;
  color: var(--muted);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin: 8px 0;
}

.preset-grid button {
  padding: 0;
}

.preset-grid button.active,
.toggle-button.active,
input.active-input {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.formula {
  padding: 16px 18px 18px;
  display: grid;
  gap: 12px;
}

.formula header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.formula h2 {
  margin: 0;
  font-size: 18px;
}

.formula-preview-wrap {
  display: grid;
  place-items: center;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f4f1;
}

#formulaPreview {
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  max-width: 100%;
}

.formula-keys {
  display: grid;
  gap: 7px;
}

.key-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.key-row .key-label {
  flex: 0 0 auto;
  width: 38px;
  font-size: 11px;
  color: var(--muted);
}

.key-row button {
  height: 28px;
  min-width: 34px;
  padding: 0 7px;
}

.formula-ref {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

.formula-ref code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #ececea;
  color: #222;
  font-family: Consolas, monospace;
}

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

.field-grid label {
  min-width: 0;
  margin: 0;
}

.range-label {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.range-label input {
  grid-column: 1 / -1;
}

.range-label span {
  color: #111;
  font-size: 12px;
}

.range-label .num-inline {
  grid-column: 2;
  width: 60px;
  height: 26px;
  justify-self: end;
  padding: 0 6px;
  text-align: right;
}

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

.toggle-button {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shape-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1.25fr);
  gap: 7px;
  margin: 7px 0;
}

.shape-grid.shape-tools {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.style-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 9px 2px;
}

.style-checks .check {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.style-checks input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.shape-grid input[type="color"] {
  width: 44px;
  padding: 2px;
}

.shape-grid button {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-toggle {
  margin: 0 0 8px;
}

.span-2 {
  grid-column: span 2;
}

button.wide {
  width: 100%;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #f8f8f6;
}

#status {
  color: var(--muted);
  font-size: 12px;
}

.canvas-shell {
  position: relative;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #e8e8e3;
}

.canvas-shell.add-mode,
.canvas-shell.shape-mode,
.canvas-shell.picker-mode,
.canvas-shell.knockout-mode,
.canvas-shell.add-mode #canvas,
.canvas-shell.shape-mode #canvas,
.canvas-shell.picker-mode #canvas,
.canvas-shell.knockout-mode #canvas {
  cursor: crosshair;
}

#knockoutBtn.active,
#canvasResizeBtn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.resize {
  padding: 16px 18px 18px;
  display: grid;
  gap: 12px;
}

.resize header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.resize h2 {
  margin: 0;
  font-size: 18px;
}

.resize-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.resize-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.resize-grid label {
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--text);
}

.resize-bg {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.resize-bg > span {
  font-size: 12px;
  color: var(--muted);
}

.resize-bg label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  font-size: 13px;
  color: var(--text);
}

.resize-bg input[type="radio"] {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

#canvas {
  display: none;
  background: transparent;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.18);
  transform-origin: center center;
}

.drop-empty {
  position: relative;
  width: min(880px, 100%);
  min-height: min(620px, calc(100vh - 210px));
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  border: 2px dashed #b8b8b2;
  background: #f7f7f3;
  color: var(--muted);
}

.drop-empty strong {
  color: #222;
  font-size: 18px;
}

.drop-empty span {
  font-size: 13px;
}

.label-list {
  display: grid;
  gap: 6px;
  max-height: min(220px, 28vh);
  overflow: auto;
}

.label-list:empty {
  display: none;
}

.label-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #d1d1cc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.label-row.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.label-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-pos {
  color: var(--muted);
  font-size: 11px;
  flex: 0 0 auto;
}

.leader-badge {
  flex: 0 0 auto;
  height: 18px;
  padding: 1px 5px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8c8c2;
  border-radius: 999px;
  color: var(--muted);
  background: #f7f7f4;
  font-size: 10px;
}

.leader-badge.on {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.leader-badge.group {
  border-color: #7a5cff;
  color: #fff;
  background: #7a5cff;
}

.row-actions {
  margin-top: 8px;
}

.row-actions button {
  flex: 1;
}

.drag-over .drop-empty {
  border-color: var(--accent);
  color: var(--accent);
}

.magnifier {
  position: fixed;
  z-index: 20;
  width: 260px;
  padding: 8px;
  border: 1px solid #1b1b1b;
  background: #111;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.magnifier canvas {
  display: block;
  width: 240px;
  height: 150px;
  image-rendering: pixelated;
  background: #fff;
  border: 1px solid #555;
}

.magnifier-size,
.magnifier-meta {
  height: 20px;
  display: flex;
  align-items: center;
  font: 700 13px Consolas, monospace;
}

.magnifier-size {
  color: #ddd;
}

.magnifier-meta {
  color: #f5f5f5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 48px));
  padding: 10px 16px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  font-size: 14px;
}

.update-progress {
  position: fixed;
  left: 50%;
  bottom: 54px;
  z-index: 40;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 48px));
  padding: 10px 16px 12px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  font-size: 13px;
}

.update-progress[hidden] {
  display: none;
}

.update-progress-track {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

.update-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: #4c9aff;
  transition: width 0.15s ease;
}

.app-footer {
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.footer-copy {
  flex-shrink: 0;
  margin-left: auto;
  max-width: 28%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 32px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

dialog {
  width: min(560px, calc(100vw - 48px));
  border: 1px solid #b8b8b2;
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.28);
}

.help {
  padding: 16px 18px 18px;
}

.help header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.help h2 {
  margin: 0;
  font-size: 18px;
}

.help ol {
  margin: 0;
  padding-left: 22px;
  line-height: 1.65;
}

.help li {
  margin: 6px 0;
}

.help-pages {
  min-height: 224px;
}

.help-page {
  display: none;
}

.help-page.active {
  display: block;
}

.help-page ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.7;
}

.help-page li {
  margin: 8px 0;
}

.help-page code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #ececea;
  color: #222;
  font-family: Consolas, monospace;
  font-size: 0.92em;
}

.help-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

/* 일러스트 박물관 바로가기 버튼 (오른쪽 패널 하단 여백) */
.layers { display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; }
.museum-btn {
  margin: auto 12px 12px;
  display: flex; align-items: center; gap: 11px;
  padding: 13px 15px; border-radius: 12px;
  background: var(--accent); color: #fff; text-decoration: none;
  box-shadow: 0 6px 16px rgba(31,76,143,.28);
  transition: transform .15s, box-shadow .15s, background .15s;
  flex: none;
}
.museum-btn:hover { background: var(--accent-strong); transform: translateY(-2px); box-shadow: 0 10px 24px rgba(31,76,143,.34); }
.museum-btn:active { transform: translateY(0); }
.museum-btn .mb-ic { font-size: 22px; line-height: 1; }
.museum-btn .mb-tx { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.museum-btn .mb-tx b { font-size: 14px; font-weight: 700; }
.museum-btn .mb-tx small { font-size: 11px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.museum-btn .mb-arr { margin-left: auto; font-size: 16px; opacity: .9; }
