:root {
  --bg: #0e1013;
  --panel: #16191e;
  --panel-2: #1d2127;
  --line: #2a2f37;
  --text: #e7eaef;
  --muted: #8d96a5;
  --accent: #7cc6ff;
  --accent-ink: #0b1620;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
          "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

/* ---------- panel ---------- */

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel__head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel__head h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.panel__head h1 span {
  color: var(--accent);
  font-weight: 400;
}

.panel__head .sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.panel__body {
  overflow-y: auto;
  padding: 4px 18px 40px;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.panel__body::-webkit-scrollbar { width: 9px; }
.panel__body::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 9px;
  border: 3px solid var(--panel);
}

.group {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.group:last-child { border-bottom: 0; }

.group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- dropzone ---------- */

.drop {
  display: block;
  position: relative;
  border: 1px dashed #39404a;
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}

.drop:hover, .drop.is-over {
  border-color: var(--accent);
  background: #1b232b;
}

.drop__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
}

.drop__inner b { color: var(--text); font-size: 12.5px; font-weight: 600; }
.drop__inner span { font-size: 11px; }
.drop svg { color: var(--accent); margin-bottom: 4px; }

.drop img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: cover;
}

.drop img:not([hidden]) + .drop__inner,
.drop img:not([hidden]) ~ .drop__inner { display: none; }

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

.hint b { color: #c3ccd8; font-weight: 600; }

/* ---------- controls ---------- */

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

.field label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 6px;
  color: #c9d1dc;
}

.field output {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-size: 11px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: #333a44;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: #333a44;
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

select {
  width: 100%;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--panel-2);
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 13px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 2px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.segmented button:hover { color: var(--text); }

.segmented button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #c9d1dc;
  margin-top: 9px;
  cursor: pointer;
  user-select: none;
}

.check input { accent-color: var(--accent); margin: 0; }
.check--inline { margin: 0; }

.colors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--muted);
  cursor: pointer;
}

.swatch input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }

.colors--2 { grid-template-columns: repeat(2, 1fr); }

.colors + .field,
.colors + .palettes,
.palettes + .field,
.field + .colors { margin-top: 12px; }

.is-off { opacity: .3; pointer-events: none; }

/* ---------- palette chips ---------- */

.palettes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-family: inherit;
  font-size: 10.5px;
  padding: 5px;
  border-radius: 7px;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}

.chip i {
  display: block;
  height: 16px;
  border-radius: 4px;
}

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

.row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 7px;
  margin-bottom: 7px;
}

.row:last-child { margin-bottom: 0; }

/* display:grid 가 hidden 속성의 기본값을 덮어쓰므로 되돌린다 */
.row[hidden] { display: none; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:hover { background: #262c34; border-color: #3b434e; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn--primary:hover { background: #9ad4ff; border-color: #9ad4ff; }

.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.stage__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.stage__canvas {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 26px;
  position: relative;
  background:
    repeating-conic-gradient(#151820 0 25%, #12151b 0 50%) 0 0 / 22px 22px;
}

.stage__canvas.is-over::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .55);
  display: block;
}

canvas[hidden] { display: none; }

/* 투명 배경일 때만 캔버스 뒤에 체커를 깔아 '비어 있음'을 눈으로 보여준다. */
canvas.is-alpha {
  background: repeating-conic-gradient(#454d5c 0 25%, #333a46 0 50%) 0 0 / 14px 14px;
}

/* ---------- crop overlay ---------- */

.crop {
  position: absolute;
  overflow: hidden;             /* 바깥을 덮는 그림자를 이미지 안으로 가둔다 */
  border-radius: 4px;
  cursor: crosshair;
  touch-action: none;
}

.crop[hidden] { display: none; }

.crop__box {
  position: absolute;
  cursor: move;
  outline: 1px solid rgba(255, 255, 255, .95);
  box-shadow: 0 0 0 9999px rgba(8, 10, 14, .62);
}

/* 삼분할 가이드 */
.crop__box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent 33.33%, rgba(255,255,255,.32) 33.33%,
      rgba(255,255,255,.32) calc(33.33% + 1px), transparent calc(33.33% + 1px),
      transparent 66.66%, rgba(255,255,255,.32) 66.66%,
      rgba(255,255,255,.32) calc(66.66% + 1px), transparent calc(66.66% + 1px)),
    linear-gradient(to bottom, transparent 33.33%, rgba(255,255,255,.32) 33.33%,
      rgba(255,255,255,.32) calc(33.33% + 1px), transparent calc(33.33% + 1px),
      transparent 66.66%, rgba(255,255,255,.32) 66.66%,
      rgba(255,255,255,.32) calc(66.66% + 1px), transparent calc(66.66% + 1px));
}

.crop__h {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
  z-index: 1;
}

.crop__h[data-h="nw"] { left: 0;    top: 0;    cursor: nwse-resize; }
.crop__h[data-h="n"]  { left: 50%;  top: 0;    cursor: ns-resize; }
.crop__h[data-h="ne"] { left: 100%; top: 0;    cursor: nesw-resize; }
.crop__h[data-h="e"]  { left: 100%; top: 50%;  cursor: ew-resize; }
.crop__h[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.crop__h[data-h="s"]  { left: 50%;  top: 100%; cursor: ns-resize; }
.crop__h[data-h="sw"] { left: 0;    top: 100%; cursor: nesw-resize; }
.crop__h[data-h="w"]  { left: 0;    top: 50%;  cursor: ew-resize; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #4c5563;
  font-size: 13px;
  pointer-events: none;
}

.empty[hidden] { display: none; }

@media (max-width: 820px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .stage__canvas { min-height: 60vh; }
}
