/* 미니어처 스튜디오 — 어두운 편집실 톤. 사진 색을 방해하지 않는 무채색 위주. */

:root {
  --bg: #0e1013;
  --surface: #161a1f;
  --surface-2: #1d222a;
  --line: #2a3038;
  --text: #e6e9ee;
  --muted: #9aa3af;
  --accent: #f2b03d;
  --accent-ink: #241a06;
  --radius: 10px;
  --panel-w: 340px;
}

* { box-sizing: border-box; }

/*
 * [hidden] 은 브라우저 기본 스타일이라 작성자 규칙에 무조건 밀린다.
 * .btn { display:inline-flex } 같은 규칙 하나만 있어도 숨긴 요소가 그대로
 * 보인다. 선택자마다 예외를 다는 대신 여기서 한 번에 못 박는다.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

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

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
}

/* ------------------------------------------------------------------ 상단바 */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-text small { color: var(--muted); font-size: 11px; white-space: nowrap; }

.topbar-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background .13s, border-color .13s, transform .06s;
}
.btn:hover { background: #262c35; border-color: #3a424d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { background: #ffc258; }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; justify-content: center; }

:where(button, select, input, canvas, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ 작업창 */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  min-height: 0;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #16191e 0%, var(--bg) 70%);
}

.frame-wrap {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
}

.frame {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  background: #000;
  touch-action: none;
}

.frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#overlayCanvas { touch-action: none; }

.stage-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  user-select: none;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.stage-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.stage-tip { margin: 0; color: var(--muted); font-size: 12px; text-align: center; max-width: 60ch; }
.stage-tip b { color: #cdd4dd; font-weight: 600; }

/* 동영상 재생 막대 */

.video-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 820px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.video-bar[hidden] { display: none; }
.video-bar input[type="range"] { flex: 1 1 160px; min-width: 120px; }

.icon-btn {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { background: #2a313a; }

.video-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.video-speed { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.video-speed select { padding: 4px 7px; }

/* -------------------------------------------------------------- 오른쪽 패널 */

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

.panel-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.block { display: flex; flex-direction: column; gap: 10px; }

.block-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

/* 미니어처 강도 — 이 앱에서 가장 중요한 조작이라 눈에 띄게 둔다 */

.hero {
  padding: 13px 14px 12px;
  background: linear-gradient(160deg, #23292f, #1a1f25);
  border: 1px solid #333b45;
  border-radius: 12px;
  gap: 6px;
}
.hero-head { display: flex; justify-content: space-between; align-items: baseline; }
.hero-head label { font-size: 13.5px; font-weight: 700; cursor: pointer; }
.hero-val {
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.hero-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }

input[type="range"].big-range { height: 28px; }
input[type="range"].big-range::-webkit-slider-runnable-track { height: 7px; background: #39424e; border-radius: 999px; }
input[type="range"].big-range::-moz-range-track { height: 7px; background: #39424e; border-radius: 999px; }
input[type="range"].big-range::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -7.5px; background: var(--accent); }
input[type="range"].big-range::-moz-range-thumb { width: 22px; height: 22px; background: var(--accent); }

/* 접어 두는 고급 설정 */

.fold {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  gap: 0;
}
.fold > summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: #c6ccd5;
  list-style-position: inside;
}
.fold[open] > summary { margin-bottom: 10px; }
.fold > *:not(summary) { margin-top: 10px; }
.fold #controlGroups { display: flex; flex-direction: column; gap: 16px; }
.fold-note { margin-top: 0 !important; }

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

.preset {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-size: 12.5px;
  transition: border-color .13s, background .13s;
}
.preset:hover { background: #262c35; }
.preset.active { border-color: var(--accent); background: #2a2415; }
.preset-swatch { width: 20px; height: 20px; border-radius: 5px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.14); }
.preset-hint { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.5; min-height: 2.6em; }

.segmented { display: grid; grid-auto-flow: column; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.seg { padding: 7px 4px; background: transparent; border: 0; border-radius: 7px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.seg:hover:not(:disabled) { background: #2a313a; }
.seg.active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg:disabled { opacity: .38; cursor: not-allowed; }

/* 한방 변환 */

.gen-block { gap: 8px; }
.gen-go {
  background: linear-gradient(135deg, #7c5cff, #d946a8);
  border-color: transparent;
  color: #fff;
  font-weight: 700;
  padding: 12px 14px;
  font-size: 14px;
}
.gen-go:hover { filter: brightness(1.1); background: linear-gradient(135deg, #8b6dff, #e155b6); }
.gen-go:disabled { filter: grayscale(.6); }

.gen-status { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); }
.gen-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; flex: none; }
.gen-status .dot.ok { background: #35c07a; }
.gen-status .dot.bad { background: #e5484d; }
.gen-status .dot.busy { background: var(--accent); animation: recblink 1s steps(1,end) infinite; }

.gen-fold { background: transparent; }
.text-in {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
}
.field-row .text-in { width: auto; flex: 1; min-width: 0; }
.field-row select { max-width: 62%; }

/* AI 심도 메뉴 */

.ai-fold { border-color: #3a4150; background: linear-gradient(160deg, #1f242c, #1a1e24); }
.tag-beta {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: #3a4150;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #b9c2cf;
  vertical-align: 1px;
}
#depthPanel { display: flex; flex-direction: column; gap: 10px; }
#depthSliders { display: flex; flex-direction: column; gap: 10px; }
#btnDepthView { align-self: flex-start; }

/* 슬라이더 */

.slider { display: flex; flex-direction: column; gap: 5px; }
.slider[hidden] { display: none; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.slider-head label { font-size: 12.5px; color: #c6ccd5; cursor: pointer; }
.slider-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: #333b45; border-radius: 999px; }
input[type="range"]::-moz-range-track { height: 4px; background: #333b45; border-radius: 999px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px; margin-top: -5.5px;
  background: var(--text); border: 0; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.6);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border: 0; border-radius: 50%;
  background: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.6);
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]:hover::-moz-range-thumb { background: var(--accent); }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-row label { font-size: 12.5px; color: #c6ccd5; }
select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
}

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

.tips { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.tips summary { cursor: pointer; font-size: 12.5px; color: #c6ccd5; font-weight: 600; }
.tips ul { margin: 10px 0 2px; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.tips li + li { margin-top: 5px; }
.tips b { color: #cdd4dd; }

/* ------------------------------------------------------------------ 오버레이 */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 15, .82);
  backdrop-filter: blur(2px);
}
.dropzone[hidden] { display: none; }
.dropzone-inner {
  padding: 40px 56px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
}

.camera-dialog {
  width: min(92vw, 720px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
.camera-dialog::backdrop { background: rgba(0, 0, 0, .7); }
.camera-stage { background: #000; aspect-ratio: 4 / 3; position: relative; }

.rec-badge {
  position: absolute;
  top: 12px; left: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  background: rgba(0, 0, 0, .62);
  border-radius: 999px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: #fff;
}
.rec-badge[hidden] { display: none; }
.rec-badge i {
  width: 9px; height: 9px;
  background: #e5484d;
  border-radius: 50%;
  animation: recblink 1.1s steps(1, end) infinite;
}
@keyframes recblink { 50% { opacity: .25; } }

.camera-modes { margin: 12px 16px 0; }
.camera-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-error { margin: 0; padding: 12px 16px; color: #ffb4a8; font-size: 13px; background: #2a1a18; }
.camera-error[hidden] { display: none; }
.camera-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.camera-right { display: flex; align-items: center; gap: 8px; }
.camera-stage video { transition: none; }
.shutter {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--surface-2);
  box-shadow: 0 0 0 2px #fff;
  cursor: pointer;
}
.shutter:active { transform: scale(.94); }
.shutter:disabled { opacity: .45; cursor: not-allowed; }

/* 동영상 모드에서는 빨간 원, 녹화 중에는 정지 사각형 */
.shutter.video::after {
  content: '';
  position: absolute;
  inset: 6px;
  background: #e5484d;
  border-radius: 50%;
  transition: inset .15s, border-radius .15s;
}
.shutter.video.rec::after { inset: 15px; border-radius: 4px; }

.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 15, .78);
  font-size: 14px;
}
.busy[hidden] { display: none; }
.busy-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 28px;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
}
.progress { width: 100%; height: 6px; background: #333b45; border-radius: 999px; overflow: hidden; }
.progress[hidden] { display: none; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid #3a424d;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  z-index: 60;
  max-width: min(90vw, 460px);
  padding: 11px 18px;
  background: #21262e;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #7a3b34; background: #2c1c1a; }

/* -------------------------------------------------------------------- 모바일 */

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .panel-scroll { max-height: 46dvh; }
  .stage { padding: 10px; gap: 8px; }
  .stage-tip { display: none; }
  .brand-text small { display: none; }
  .topbar { gap: 10px; padding: 8px 12px; }
  .topbar-actions { gap: 6px; }
  .btn { padding: 7px 10px; font-size: 13px; }
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .brand-text strong { font-size: 13px; }
  .topbar-actions .btn span[aria-hidden] { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
