/* ==========================================================================
   APP SHELL STYLES
   ========================================================================== */

:root {
  --gnb-height: 52px;
  --panel-height: 200px;
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --surface-hover: #333;
  --border: #3a3a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #4f8cff;
  --accent-hover: #3a7aee;
  --danger: #e94560;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ===== GNB ===== */
.gnb {
  height: var(--gnb-height);
  background: #111;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}
.gnb-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.gnb-logo {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
}
.btn-lang {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s;
}
.btn-lang:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-new {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-new:hover {
  border-color: var(--text-muted);
  color: var(--text);
}
.gnb-center {
  display: flex;
  align-items: center;
  gap: 16px;
}
/* Ratio Picker */
.ratio-picker-wrap {
  position: relative;
}
.ratio-trigger {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 12px 5px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Space Mono', monospace;
}
.ratio-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.ratio-trigger .ratio-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.ratio-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  z-index: 500;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  min-width: 280px;
}
.ratio-popover-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}
.ratio-grid {
  display: flex;
  gap: 6px;
}
.ratio-option {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
}
.ratio-option:hover {
  background: rgba(255,255,255,0.06);
}
.ratio-option.active {
  background: rgba(255,255,255,0.1);
}
.ratio-option svg {
  color: var(--text-muted);
  transition: color 0.15s;
}
.ratio-option.active svg {
  color: var(--text);
}
.ratio-option-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Space Mono', monospace;
  letter-spacing: -0.5px;
}
.ratio-option.active .ratio-option-label {
  color: var(--text);
  font-weight: 700;
}
.gnb-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.gnb-ad {
  max-width: 200px;
  height: 36px;
  overflow: hidden;
  border-radius: 4px;
}
.undo-redo-group {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border-radius: 8px;
  padding: 2px;
}
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover:not(:disabled) {
  background: var(--surface-hover);
  color: #fff;
}
.btn-icon:disabled {
  color: #666;
  cursor: default;
}
.btn-feedback {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  color: var(--text-muted, #999);
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-feedback:hover {
  color: var(--text);
  background: var(--surface);
}
.btn-save {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-save:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-save.saved {
  border-color: #22c55e;
  color: #22c55e;
}
.save-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #666;
  margin-left: 4px;
  transition: background 0.2s;
}
.btn-save.saving .save-dot {
  background: #eab308;
}
.btn-save.saved .save-dot {
  background: #22c55e;
}
.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-export:hover {
  background: var(--accent-hover);
}
.btn-export svg {
  transform: rotate(180deg);
}

/* ===== WORKSPACE ===== */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* ===== CANVAS AREA (all artboards side by side) ===== */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 40px;
  overflow: auto;
  background: #222;
  background-image:
    radial-gradient(circle, #2a2a2a 1px, transparent 1px);
  background-size: 20px 20px;
  padding: 60px 40px 240px 40px;
  min-height: 0;
}

/* ===== ARTBOARD WRAPPER ===== */
.artboard-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  cursor: default;
}

.artboard-header {
  display: flex;
  align-items: center;
  padding: 0 0 10px 0;
}
.artboard-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px 4px 10px;
  cursor: grab;
  transition: all 0.15s;
  user-select: none;
}
.artboard-badge:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}
.artboard-badge:active {
  cursor: grabbing;
}
.artboard-wrap.active .artboard-badge {
  border-color: var(--accent);
  background: rgba(79,140,255,0.12);
}
.artboard-badge-index {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 1px 5px;
  letter-spacing: 0.5px;
}
.artboard-wrap.active .artboard-badge-index {
  color: var(--accent);
  background: rgba(79,140,255,0.15);
}
.artboard-badge-name {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.artboard-wrap.active .artboard-badge-name {
  color: var(--accent);
  font-weight: 600;
}
.artboard-badge-duration {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: #f59e0b;
  background: rgba(245,158,11,0.12);
  border-radius: 8px;
  padding: 1px 6px;
  letter-spacing: 0.3px;
}

.card-canvas {
  position: relative;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  flex-shrink: 0;
  transition: box-shadow 0.15s;
}
.artboard-wrap.active .card-canvas {
  box-shadow: 0 0 0 2px var(--accent), 0 8px 32px rgba(0,0,0,0.4);
}

.card-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #bbb;
  font-size: 14px;
}

/* Drag indicator for artboard reorder */
.artboard-wrap.drag-over-left {
  border-left: 3px solid var(--accent);
  padding-left: 4px;
}
.artboard-wrap.drag-over-right {
  border-right: 3px solid var(--accent);
  padding-right: 4px;
}
.artboard-add-btn.drag-over {
  border-color: var(--accent);
  background: rgba(59,130,246,0.1);
  transform: scale(1.05);
}
.template-item[draggable="true"] {
  cursor: grab;
}
.template-item[draggable="true"]:active {
  cursor: grabbing;
}

/* Editable elements highlight */
.card-canvas [data-editable-text]:hover {
  outline: 1px dashed rgba(79, 140, 255, 0.5);
  outline-offset: 2px;
  cursor: text;
}
.card-canvas [data-editable-text]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  cursor: text;
}
.card-canvas [data-editable-color]:hover {
  outline: 1px dashed rgba(255, 140, 79, 0.5);
  outline-offset: 2px;
  cursor: pointer;
}

/* Add artboard button (inline, after last artboard) */
.artboard-add-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  border: 2px dashed var(--border);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.artboard-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79,140,255,0.1);
  transform: scale(1.08);
}

/* ===== ARTBOARD ACTION BUTTONS ===== */
.artboard-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.artboard-wrap:hover .artboard-actions,
.artboard-wrap.active .artboard-actions {
  opacity: 1;
}
.artboard-action-btn {
  width: 26px;
  height: 26px;
  min-width: 26px;
  min-height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s;
  line-height: 0;
}
.artboard-action-btn svg {
  flex-shrink: 0;
}
.artboard-action-btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
  color: var(--text);
}
.artboard-action-delete:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(233,69,96,0.1);
}

/* ===== TEMPLATE PANEL ===== */
.template-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #111;
  border-top: 1px solid var(--border);
  z-index: 90;
  transition: transform 0.3s ease;
}
.template-panel.collapsed {
  transform: translateY(calc(100% - 38px));
}
.template-panel-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  height: 38px;
}
.template-panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 1px;
}
.template-panel-tabs {
  display: flex;
  gap: 4px;
}
.tpl-tab {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}
.tpl-tab:hover {
  border-color: var(--text-muted);
  color: var(--text);
}
.tpl-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.template-panel-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: transform 0.3s;
}
.template-panel.collapsed .template-panel-toggle {
  transform: rotate(180deg);
}

.template-grid {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  height: 162px;
}
.template-grid::-webkit-scrollbar { height: 6px; }
.template-grid::-webkit-scrollbar-track { background: transparent; }
.template-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.template-item {
  flex-shrink: 0;
  width: 130px;
  height: 130px;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  position: relative;
  background: #222;
}
.template-item:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.template-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.template-item .preview {
  width: 100%;
  height: 100%;
  transform-origin: top left;
  pointer-events: none;
}
.template-item .tpl-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  background: rgba(0,0,0,0.7);
  color: #ccc;
  font-size: 9px;
  text-align: center;
  letter-spacing: 0.5px;
}

/* ===== EXPORT MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal {
  background: #222;
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}
.modal-close:hover { color: #fff; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
}
.export-options {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.export-options label {
  font-size: 13px;
  color: var(--text-muted);
}
.export-options select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  outline: none;
}
.export-preview {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.export-preview-item {
  flex-shrink: 0;
  text-align: center;
}
.export-preview-item img {
  width: 160px;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.export-preview-item .download-single {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
}
.export-preview-item .download-single:hover {
  text-decoration: underline;
}
.export-actions {
  margin-top: 16px;
  text-align: center;
}
.btn-download-all {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-download-all:hover {
  background: var(--accent-hover);
}

/* ===== VIDEO EXPORT SECTION ===== */
.video-export-section {
  margin-top: 16px;
}
.video-export-info {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.video-export-tag {
  background: rgba(245,158,11,0.12);
  color: #f59e0b;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  letter-spacing: 0.3px;
}
.video-export-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.video-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}
.video-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s;
}
.video-progress-text {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== ARTBOARD ACTION BUTTONS (overlay on active artboard) ===== */
.artboard-btns-group {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 10;
}
.artboard-btns-group > button {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  font-size: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.artboard-btns-group > button svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.artboard-btns-group > button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79,140,255,0.08);
}

/* ===== DRAGGABLE IMAGE ===== */
.card-image {
  position: absolute;
  cursor: move;
  user-select: none;
  touch-action: none;
  z-index: 1;
}
.card-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.card-image.selected {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
/* Resize handles */
.card-image .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  z-index: 10;
  display: none;
}
.card-image.selected .resize-handle { display: block; }
.card-image .resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.card-image .resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.card-image .resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.card-image .resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
/* Rotate handle */
.card-image .rotate-handle {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  display: none;
  z-index: 10;
}
.card-image .rotate-handle::after {
  content: '↻';
  font-size: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  line-height: 1;
}
.card-image.selected .rotate-handle { display: block; }
.card-image .rotate-line {
  position: absolute;
  top: -18px;
  left: 50%;
  width: 1px;
  height: 18px;
  background: var(--accent);
  display: none;
}
.card-image.selected .rotate-line { display: block; }

/* ===== DRAGGABLE TEXT BOX ===== */
.card-text {
  position: absolute;
  cursor: move;
  user-select: none;
  touch-action: none;
  z-index: 1;
  min-width: 40px;
  min-height: 20px;
}
.card-text .card-text-content {
  width: 100%;
  min-height: 1em;
  font-size: 24px;
  font-family: 'Noto Sans KR', sans-serif;
  color: #333;
  line-height: 1.4;
  word-break: keep-all;
  outline: none;
  pointer-events: auto;
}
.card-text.selected {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
.card-text .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  z-index: 10;
  display: none;
}
.card-text.selected .resize-handle { display: block; }
.card-text .resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.card-text .resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.card-text .resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.card-text .resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.card-text .rotate-handle {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  display: none;
  z-index: 10;
}
.card-text .rotate-handle::after {
  content: '\21BB';
  font-size: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  line-height: 1;
}
.card-text.selected .rotate-handle { display: block; }
.card-text .rotate-line {
  position: absolute;
  top: -18px;
  left: 50%;
  width: 1px;
  height: 18px;
  background: var(--accent);
  display: none;
}
.card-text.selected .rotate-line { display: block; }

/* ===== DRAGGABLE VIDEO ===== */
.card-video {
  position: absolute;
  cursor: move;
  user-select: none;
  touch-action: none;
  z-index: 1;
}
.card-video video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  border-radius: 2px;
}
.card-video.selected {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
.card-video .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  z-index: 10;
  display: none;
}
.card-video.selected .resize-handle { display: block; }
.card-video .resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.card-video .resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.card-video .resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.card-video .resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.card-video .rotate-handle {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  display: none;
  z-index: 10;
}
.card-video .rotate-handle::after {
  content: '\21BB';
  font-size: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  line-height: 1;
}
.card-video.selected .rotate-handle { display: block; }
.card-video .rotate-line {
  position: absolute;
  top: -18px;
  left: 50%;
  width: 1px;
  height: 18px;
  background: var(--accent);
  display: none;
}
.card-video.selected .rotate-line { display: block; }

/* ===== TEXT FORMATTING TOOLBAR ===== */
.text-toolbar {
  position: fixed;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 1200;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.text-toolbar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 11px;
  outline: none;
  cursor: pointer;
}
.text-toolbar select#tbFontFamily { width: 110px; }
.text-toolbar select#tbFontSize { width: 56px; }
.tb-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}
.tb-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}
.tb-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tb-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}
.text-toolbar input[type="color"] {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}

/* ===== COLOR PICKER POPOVER ===== */
.color-picker-popover {
  position: fixed;
  background: #222;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.color-picker-popover input[type="color"] {
  width: 100%;
  height: 36px;
  border: none;
  cursor: pointer;
  background: none;
  padding: 0;
}
.color-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  max-width: 180px;
}
.color-preset {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.1s;
}
.color-preset:hover {
  border-color: #fff;
}

/* ===== BACKGROUND PANEL ===== */
.bg-panel {
  position: fixed;
  background: #222;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  width: 240px;
}
.bg-panel-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
  background: var(--surface);
  border-radius: 6px;
  padding: 2px;
}
.bg-tab {
  all: unset;
  box-sizing: border-box;
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  padding: 5px 0;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}
.bg-tab:hover { color: var(--text); }
.bg-tab.active {
  background: var(--border);
  color: var(--text);
}
.bg-tab-content input[type="color"] {
  width: 100%;
  height: 36px;
  border: none;
  cursor: pointer;
  background: none;
  padding: 0;
}
.bg-tab-content .color-presets {
  margin-top: 8px;
  max-width: 216px;
}
.color-preset-transparent {
  background: repeating-conic-gradient(#808080 0% 25%, #fff 0% 50%) 50% / 10px 10px;
  position: relative;
}
.color-preset-transparent::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 45%, #e94560 45%, #e94560 55%, transparent 55%);
  border-radius: 4px;
}
.bg-gradient-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.bg-gradient-row label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 24px;
}
.bg-gradient-row input[type="color"] {
  width: 32px;
  height: 28px;
  border: none;
  cursor: pointer;
  background: none;
  padding: 0;
  flex-shrink: 0;
}
.bg-gradient-row select {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
}
.bg-gradient-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bg-gradient-preset {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.1s;
}
.bg-gradient-preset:hover {
  border-color: #fff;
}
.bg-img-upload-btn {
  all: unset;
  box-sizing: border-box;
  display: block;
  width: 100%;
  text-align: center;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
}
.bg-img-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.bg-img-fit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.bg-img-fit-row label {
  font-size: 11px;
  color: var(--text-muted);
}
.bg-img-fit-row select {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
}
.bg-img-remove-btn {
  all: unset;
  box-sizing: border-box;
  font-size: 11px;
  font-family: 'Noto Sans KR', sans-serif;
  color: var(--danger);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}
.bg-img-remove-btn:hover {
  background: rgba(233,69,96,0.1);
}
.bg-reset-btn {
  all: unset;
  box-sizing: border-box;
  display: block;
  width: 100%;
  text-align: center;
  font-size: 11px;
  font-family: 'Noto Sans KR', sans-serif;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 10px;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
}
.bg-reset-btn:hover {
  color: var(--text);
  background: var(--surface);
}

/* ===== MOBILE BLOCK ===== */
.mobile-block {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #0a0a0a;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
}
.mobile-block-content {
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.mobile-block-icon {
  font-size: 48px;
  margin-bottom: 20px;
}
.mobile-block h2 {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 12px;
}
.mobile-block p {
  font-size: 14px;
  color: #888;
  line-height: 1.7;
  margin-bottom: 28px;
}
.mobile-block-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #111;
  color: #fff;
  text-decoration: none;
  border-radius: 999px;
  padding: 14px 32px;
  font-size: 14px;
  font-weight: 600;
  border: 2px solid #fff;
  cursor: pointer;
  font-family: inherit;
}
.mobile-share-btn {
  background: #fff;
  color: #111;
  border-color: #ddd;
  margin-top: 10px;
}

/* ===== RESPONSIVE — MOBILE EDITOR ===== */

/* Mobile nav bar (artboard pagination + actions) */
.mobile-nav {
  display: none;
  height: calc(48px + env(safe-area-inset-bottom, 0px));
  background: #111;
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 12px env(safe-area-inset-bottom, 0px);
  flex-shrink: 0;
  z-index: 100;
}
.mobile-nav-pager {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mobile-nav-pager button {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}
.mobile-nav-pager button:disabled {
  color: #666;
  cursor: default;
}
.mobile-nav-pager .mobile-page-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  min-width: 44px;
  text-align: center;
}
.mobile-nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mobile-nav-actions button {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
}
.mobile-nav-actions button svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Mobile Toast */
.mobile-toast {
  display: none;
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #fff;
  color: #111;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  pointer-events: none;
}
.mobile-toast.show {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Mobile Artboard List Sheet */
.mobile-list-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 299;
}
.mobile-list-backdrop.active { display: block; }
.mobile-list-sheet {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: #1a1a1a;
  border-radius: 16px 16px 0 0;
  z-index: 300;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.mobile-list-sheet.open {
  display: flex;
  transform: translateY(0);
}
.mobile-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mobile-list-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.mobile-list-close {
  all: unset;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}
.mobile-list-body {
  overflow-y: auto;
  padding: 8px 0;
  flex: 1;
  min-height: 0;
}
.mobile-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.mobile-list-item:active {
  background: var(--surface);
}
.mobile-list-item.active {
  background: rgba(79,140,255,0.1);
}
.mobile-list-item.drag-over {
  border-top: 2px solid var(--accent);
}
.mobile-list-drag {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  cursor: grab;
  padding: 4px;
  touch-action: none;
  flex-shrink: 0;
}
.mobile-list-drag:active { cursor: grabbing; }
.mobile-list-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: #222;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.mobile-list-thumb .card {
  transform-origin: top left;
  pointer-events: none;
}
.mobile-list-info {
  flex: 1;
  min-width: 0;
}
.mobile-list-num {
  font-size: 10px;
  font-family: 'Space Mono', monospace;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.mobile-list-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-list-item.active .mobile-list-name {
  color: var(--accent);
  font-weight: 600;
}
.mobile-list-empty {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
  padding: 2px 8px;
}
.mobile-list-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}
.mobile-list-action-btn {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.mobile-list-action-btn:active {
  background: var(--surface-hover);
  color: var(--text);
}
.mobile-list-action-delete:active {
  color: var(--danger);
  background: rgba(233,69,96,0.1);
}

@media (max-width: 768px) {
  /* Hide mobile block overlay — we now support mobile */
  .mobile-block { display: none !important; }

  /* === GNB compact === */
  .gnb {
    height: 44px;
    padding: 0 10px;
  }
  .gnb-left {
    gap: 6px;
  }
  .gnb-logo {
    font-size: 0;
  }
  .gnb-logo img {
    width: 22px;
    height: 22px;
  }
  .btn-new,
  .btn-feedback,
  .gnb-ad {
    display: none;
  }
  .gnb-center {
    gap: 8px;
  }
  .ratio-trigger {
    padding: 4px 8px 4px 6px;
    font-size: 11px;
  }
  .ratio-trigger .ratio-icon {
    width: 14px;
    height: 14px;
  }
  .ratio-popover {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    min-width: 240px;
    padding: 12px;
  }
  .btn-lang {
    padding: 3px 8px;
    font-size: 10px;
  }
  .gnb-right {
    gap: 6px;
  }
  .undo-redo-group {
    gap: 1px;
    padding: 1px;
  }
  .btn-icon {
    width: 28px;
    height: 28px;
  }
  .btn-save {
    padding: 6px 10px;
    font-size: 12px;
  }
  .btn-save svg { display: none; }
  .btn-export {
    padding: 6px 10px;
    font-size: 12px;
  }
  .btn-export svg { display: none; }

  /* === Workspace — single artboard centered === */
  .workspace {
    --gnb-height: 44px;
  }
  .canvas-area {
    padding: 16px 16px 16px 16px;
    gap: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  .artboard-wrap {
    display: none;
    width: 100%;
    align-items: center;
  }
  .artboard-wrap.active {
    display: flex;
  }
  .artboard-header {
    padding: 0 0 8px 0;
  }
  .artboard-badge {
    padding: 3px 10px 3px 8px;
    gap: 4px;
  }
  .artboard-badge-index {
    font-size: 8px;
  }
  .artboard-badge-name {
    font-size: 10px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .artboard-actions {
    opacity: 1;
    gap: 3px;
    margin-left: 4px;
  }
  .artboard-action-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
  }
  /* Scale card canvas to fit mobile viewport */
  .card-canvas {
    transform-origin: top center;
  }
  /* Hide desktop "+" add button (mobile nav handles this) */
  .artboard-add-btn:not(.artboard-btns-group .artboard-add-btn) {
    display: none;
  }
  /* Artboard action buttons — below card */
  .artboard-btns-group {
    position: static !important;
    transform: none !important;
    bottom: auto !important;
    left: auto !important;
    justify-content: center;
    margin-top: 8px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .artboard-btns-group > button {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 6px;
  }

  /* === Template panel — full-screen modal on mobile === */
  .template-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }
  .template-panel.mobile-open {
    transform: translateY(0);
  }
  .template-panel.collapsed {
    transform: translateY(100%);
  }
  .template-panel-header {
    padding: 10px 12px;
    gap: 6px;
  }
  .template-panel-title {
    display: none;
  }
  .template-panel-tabs {
    gap: 6px;
    overflow-x: auto;
    flex-shrink: 1;
    min-width: 0;
    flex: 1;
  }
  .tpl-tab {
    font-size: 13px;
    padding: 7px 14px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .template-grid {
    height: auto;
    max-height: calc(50vh - 46px);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 10px 20px;
    gap: 8px;
  }
  .template-item {
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    position: relative;
  }
  .template-item .preview {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
  }
  .template-item .preview .card {
    width: 600px !important;
    height: 600px !important;
    transform-origin: top left !important;
  }
  .template-item .tpl-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    font-size: 8px;
    padding: 3px 4px;
  }

  /* Template panel backdrop */
  .template-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  .template-backdrop.active {
    display: block;
  }

  /* === Text toolbar — above selected text on mobile === */
  .text-toolbar {
    position: fixed !important;
    z-index: 9999;
    border-radius: 8px;
    padding: 4px 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 16px);
  }
  .text-toolbar::-webkit-scrollbar { display: none; }
  .text-toolbar select#tbFontFamily { width: 90px; flex-shrink: 0; }
  .text-toolbar select#tbFontSize { width: 48px; flex-shrink: 0; }
  .text-toolbar .tb-btn { flex-shrink: 0; }
  .text-toolbar input[type="color"] { flex-shrink: 0; }

  /* === Background panel — bottom sheet on mobile === */
  .bg-panel {
    position: fixed !important;
    bottom: 48px !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 12px 12px 0 0;
    z-index: 150;
  }

  /* === Context menu — centered on mobile === */
  .context-menu {
    position: fixed !important;
    bottom: 48px !important;
    left: 50% !important;
    top: auto !important;
    transform: translateX(-50%) !important;
    min-width: 200px;
  }

  /* === Export modal — better on mobile === */
  .modal {
    width: 95%;
    max-height: 90vh;
  }
  .export-preview {
    flex-direction: column;
    gap: 0;
    overflow-x: hidden;
  }
  .export-preview-item {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .export-preview-item img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    flex-shrink: 0;
  }
  .export-preview-item .download-single {
    margin-top: 0;
    margin-left: auto;
    flex-shrink: 0;
    font-size: 20px;
    padding: 8px;
  }

  /* === Bigger touch targets for handles === */
  .resize-handle {
    width: 20px !important;
    height: 20px !important;
    touch-action: none;
  }
  .card-image .resize-handle.nw,
  .card-text .resize-handle.nw { top: -10px; left: -10px; }
  .card-image .resize-handle.ne,
  .card-text .resize-handle.ne { top: -10px; right: -10px; }
  .card-image .resize-handle.sw,
  .card-text .resize-handle.sw { bottom: -10px; left: -10px; }
  .card-image .resize-handle.se,
  .card-text .resize-handle.se { bottom: -10px; right: -10px; }
  .rotate-handle {
    width: 28px !important;
    height: 28px !important;
    touch-action: none;
  }

  /* === Mobile nav visible === */
  .mobile-nav { display: flex; }
}

/* Loading spinner */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
