@font-face {
  font-family: "Pretendard";
  src: url("./fonts/Pretendard-Light.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Pretendard";
  src: url("./fonts/Pretendard-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Pretendard";
  src: url("./fonts/Pretendard-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #17211a;
  --muted: #667064;
  --line: #d8ded2;
  --accent: #20735e;
  --accent-strong: #165744;
  --accent-soft: #dfeee8;
  --canvas: #e8ece3;
  --shadow: 0 18px 45px rgba(23, 33, 26, 0.12);
  --input-bg: #ffffff;
  --empty-bg: rgba(245, 247, 242, 0.86);
  --checker: rgba(255, 255, 255, 0.72);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101411;
    --panel: #171c18;
    --ink: #edf4ef;
    --muted: #a6b2aa;
    --line: #313a34;
    --accent: #58c7a3;
    --accent-strong: #8de1c4;
    --accent-soft: #1f3a32;
    --canvas: #121713;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.38);
    --input-bg: #101511;
    --empty-bg: rgba(16, 20, 17, 0.86);
    --checker: rgba(255, 255, 255, 0.05);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

.is-hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  min-height: calc(100vh - 48px);
}

.editor-nav {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-title {
  display: grid;
  gap: 2px;
  min-width: 0;
  text-align: center;
}

.editor-title strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-title span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--accent-strong);
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.icon-button span {
  display: none;
}

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

.save-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.preview-pane.is-empty {
  grid-template-rows: auto minmax(0, 1fr);
}

.thumbnail-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.thumbnail-bar.is-empty {
  grid-template-columns: 70px minmax(0, 1fr);
}

.thumbnail-bar.is-empty .thumbnail-list {
  order: 2;
  padding: 0;
}

.thumbnail-bar.is-empty .thumbnail-add {
  order: 1;
  width: 70px;
  height: 70px;
}

.thumbnail-list {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 6px;
  scrollbar-width: thin;
}

.thumbnail-item {
  position: relative;
  flex: 0 0 70px;
  width: 70px;
  aspect-ratio: 1;
}

.thumbnail-button {
  display: block;
  width: 100%;
  height: 100%;
  padding: 2px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--input-bg);
  cursor: pointer;
}

.thumbnail-button img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  object-fit: cover;
}

.thumbnail-item.is-active .thumbnail-button {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 115, 94, 0.16);
}

.thumbnail-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.thumbnail-add {
  display: inline-grid;
  place-items: center;
  width: 70px;
  height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--accent-strong);
  cursor: pointer;
}

.thumbnail-add:hover,
.thumbnail-remove:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.thumbnail-button:focus,
.thumbnail-remove:focus,
.thumbnail-add:focus {
  outline: 3px solid rgba(32, 115, 94, 0.2);
  outline-offset: 2px;
}

.thumbnail-add svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.canvas-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%),
    var(--canvas);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.canvas-frame.is-upload-target {
  cursor: pointer;
}

canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 50px);
  width: auto;
  height: auto;
  object-fit: contain;
  touch-action: none;
}

.image-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.canvas-frame.is-ready canvas {
  cursor: grab;
}

.canvas-frame.is-dragging canvas {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: transparent;
}

.empty-state-content {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.empty-state svg {
  width: 72px;
  height: 72px;
  padding: 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.empty-state strong {
  color: var(--ink);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
}

.controls {
  align-self: stretch;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-form {
  display: grid;
  gap: 18px;
}

.control-panel {
  display: grid;
  gap: 18px;
}

.control-sheet {
  display: grid;
  gap: 18px;
}

.sheet-backdrop,
.sheet-handle,
.sheet-header {
  display: none;
}

.mobile-menu-tabs {
  display: none;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field.is-disabled {
  opacity: 0.45;
}

.field.is-disabled input {
  cursor: not-allowed;
}

.watermark-text-field {
  padding-bottom: 2px;
}

.switch-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
}

.switch-field span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.switch-field strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.switch-field small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.switch-field i {
  position: relative;
  display: block;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
}

.switch-field i::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 2px 7px rgba(23, 33, 26, 0.22);
  transition: transform 0.18s ease;
}

.switch-field input:checked + i {
  background: var(--accent);
}

.switch-field input:checked + i::after {
  transform: translateX(24px);
}

.switch-field input:focus + i {
  outline: 3px solid rgba(32, 115, 94, 0.2);
  outline-offset: 2px;
}

.field input[type="text"],
.field select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--input-bg);
}

.field input[type="text"]:focus,
.field select:focus,
.field input[type="range"]:focus,
.color-swatch:focus,
.color-custom-button:focus {
  outline: 3px solid rgba(32, 115, 94, 0.2);
  outline-offset: 2px;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field output {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.color-tools {
  display: grid;
  gap: 18px;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: center;
  width: 100%;
  max-width: 100%;
}

.color-swatch,
.color-custom-button {
  min-width: 0;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.color-swatch {
  position: relative;
  justify-self: center;
  width: 100%;
  max-width: 56px;
  min-height: 0;
  aspect-ratio: 1;
  background: var(--input-bg);
}

.color-swatch::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(34px, calc(100% - 18px));
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 50%;
  background: var(--swatch-color);
  transform: translate(-50%, -50%);
}

.color-swatch.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 115, 94, 0.16);
}

.color-custom-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  grid-column: 1 / -1;
  padding: 0 12px;
  background: var(--input-bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.color-custom-button:focus-within {
  outline: 3px solid rgba(32, 115, 94, 0.2);
  outline-offset: 2px;
}

.native-color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.alpha-field output {
  text-align: right;
}

@media (max-width: 840px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    inset: 0;
  }

  .app-shell {
    height: 100svh;
    padding: 10px;
    overflow: hidden;
  }

  .workspace {
    grid-template-rows: auto minmax(240px, 1fr) auto;
    grid-template-columns: 1fr;
    gap: 10px;
    height: calc(100svh - 20px);
    min-height: 0;
    overflow: hidden;
  }

  .editor-nav {
    min-height: 48px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(23, 33, 26, 0.1);
  }

  .editor-nav {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .editor-title span {
    display: none;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .save-button {
    width: 38px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #d77b86;
  }

  .save-button svg {
    display: block;
  }

  .save-button span {
    display: none;
  }

  .preview-pane {
    min-height: 0;
    overflow: hidden;
  }

  .preview-pane.is-empty {
    overflow: hidden;
  }

  .controls {
    align-self: end;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 0 2px 8px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .mobile-menu-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    padding: 0;
    background: transparent;
  }

  .mobile-menu-tab {
    position: relative;
    min-height: 46px;
    padding: 0 6px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    font-weight: 850;
    cursor: pointer;
  }

  .mobile-menu-tab::after {
    content: "";
    position: absolute;
    right: 22%;
    bottom: 0;
    left: 22%;
    height: 4px;
    border-radius: 999px;
    background: transparent;
  }

  .mobile-menu-tab.is-active {
    color: #d77b86;
  }

  .mobile-menu-tab.is-active::after {
    background: #d77b86;
  }

  .control-form {
    gap: 12px;
  }

  .watermark-text-field {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .control-panel {
    display: none;
    gap: 12px;
  }

  .control-panel.is-active {
    display: grid;
  }

  .sheet-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(0, 0, 0, 0.42);
  }

  .control-sheet {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    gap: 18px;
    max-height: min(520px, 68svh);
    padding: 12px 24px calc(28px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-radius: 28px 28px 0 0;
    background: var(--panel);
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.28);
    transform: translateY(110%);
    transition: transform 0.22s ease;
  }

  .control-sheet.is-open {
    transform: translateY(0);
  }

  .sheet-handle {
    display: block;
    justify-self: center;
    width: 48px;
    height: 5px;
    border-radius: 999px;
    background: var(--line);
  }

  .sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
  }

  .sheet-header strong {
    color: var(--ink);
    font-size: 24px;
    line-height: 1.2;
  }

  .sheet-close {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
  }

  .canvas-frame {
    height: 100%;
    min-height: 0;
  }

  .empty-state {
    padding: 20px;
  }

  .empty-state svg {
    width: 64px;
    height: 64px;
  }

  .empty-state strong {
    font-size: clamp(20px, 5vw, 30px);
  }

  canvas {
    max-height: 100%;
  }

  .field input[type="text"],
  .field select {
    min-height: 44px;
  }

  .color-swatches {
    gap: 10px;
  }

  .color-swatch {
    max-width: 54px;
  }
}
