/* 내 캐러셀 공장 — 화면 공통 모양 */

@font-face { font-family: "Pretendard"; font-weight: 400; font-style: normal; font-display: swap; src: url("/fonts/Pretendard-Regular.woff2") format("woff2"); }
@font-face { font-family: "Pretendard"; font-weight: 500; font-style: normal; font-display: swap; src: url("/fonts/Pretendard-Medium.woff2") format("woff2"); }
@font-face { font-family: "Pretendard"; font-weight: 600; font-style: normal; font-display: swap; src: url("/fonts/Pretendard-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "Pretendard"; font-weight: 700; font-style: normal; font-display: swap; src: url("/fonts/Pretendard-Bold.woff2") format("woff2"); }
@font-face { font-family: "Pretendard"; font-weight: 800; font-style: normal; font-display: swap; src: url("/fonts/Pretendard-ExtraBold.woff2") format("woff2"); }

:root {
  --bg: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --surface: #f9fafb;
  --danger: #ef4444;
  --insta: linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5);
  --radius: 12px;
  --pad: 24px;
  --gap: 32px;
  --status-h: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; } /* 숨김은 언제나 이긴다(버튼 등 display 를 정한 부품도) */

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: calc(var(--status-h) + 16px);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1, h2, p { margin: 0; }

/* ── 머리 부분 ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
  background: var(--insta);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ── 탭 줄 ── */
.tabs {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  position: relative;
  flex: 0 0 auto;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 700; }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 4px;
  border-radius: 4px 4px 0 0;
  background: var(--insta);
}
.tab:focus-visible, .btn:focus-visible { outline: 3px solid #962fbf; outline-offset: 2px; }

/* ── 본문 ── */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--gap) 24px;
}
.panel { display: flex; flex-direction: column; gap: var(--gap); }
.panel[hidden] { display: none; }
.panel-lead { font-size: 20px; font-weight: 700; }

/* ── 공통 부품 ── */
.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: var(--pad);
}
.empty {
  text-align: center;
  padding: 64px var(--pad);
  background: var(--surface);
  border-style: dashed;
}
.empty p { max-width: 32em; margin: 0 auto; }
.empty-note { margin-top: 12px !important; font-size: 14px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { border: 0; background: var(--insta); color: #fff; }
.btn-primary:hover { background: var(--insta); filter: brightness(1.05); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--bg); }
.btn-ghost { border-color: transparent; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-weight: 700; background: var(--surface); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  vertical-align: middle;
}
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
}

/* ── 설정 판 ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px calc(var(--status-h) + 16px);
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 24px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sheet-head h2 { font-size: 22px; font-weight: 800; }

#settings-form { display: flex; flex-direction: column; gap: 24px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label, .field .label { font-weight: 700; }
.field input {
  width: 220px;
  max-width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
}
.field input[aria-invalid="true"] { border-color: var(--danger); }
.hint { font-size: 14px; color: var(--muted); }
.readonly { font-weight: 600; }
.form-error { color: var(--danger); font-weight: 600; }
.form-error[hidden] { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

.ai-box {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.ai-box h3 { margin: 0; font-size: 18px; font-weight: 800; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.kv dt { font-weight: 700; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.badge.is-ok { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
.badge.is-bad { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.ai-result { font-weight: 600; }
.ai-result:empty { display: none; }
.ai-result.is-ok { color: #047857; }
.ai-result.is-bad { color: var(--danger); }
.hint:empty { display: none; }

.log-view {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  font-family: Consolas, "D2Coding", monospace;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.log-view[hidden] { display: none; }

/* ── ① 수집 ── */
.stack { display: flex; flex-direction: column; gap: 16px; }
.card h3, .stack > h3 { margin: 0; font-size: 19px; font-weight: 800; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sub-title { margin: 8px 0 0; font-size: 17px; font-weight: 800; }
.req { font-size: 13px; font-weight: 700; color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }

.field textarea, .field input[type="text"], .field input[type="url"], .field input[type="datetime-local"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  resize: vertical;
}
.field input[type="file"] { font: inherit; font-size: 15px; max-width: 100%; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .grow { flex: 1 1 260px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }
.field-grid input { width: 100% !important; }
.track-fields summary { cursor: pointer; font-weight: 700; min-height: 32px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap .table { min-width: 680px; font-size: 15px; }
.table-wrap:has(tbody:empty) { display: none; }
.table td .hint, .table th .hint { font-weight: 400; }
.up { color: #047857; font-weight: 700; }

.badge.hot { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.badge.steady { color: #92400e; border-color: #fde68a; background: #fffbeb; }
.badge.rising { color: #6d28d9; border-color: #ddd6fe; background: #f5f3ff; }
.badge.evergreen { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }

.snap-form { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: var(--radius); background: var(--surface); }
.snap-form[hidden] { display: none; }
.snap-rows { display: flex; flex-direction: column; gap: 8px; }
.snap-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.snap-row span { flex: 1 1 200px; }
.snap-row input { width: 160px; min-height: 44px; padding: 0 12px; border: 1px solid #d1d5db; border-radius: var(--radius); font: inherit; }

.style-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.style-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.style-card.is-active { border: 2px solid #962fbf; }
.style-card h5 { margin: 0; font-size: 16px; font-weight: 800; }
.style-thumb { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); max-height: 180px; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch { display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; column-gap: 6px; align-items: center; font-size: 12px; line-height: 1.3; color: var(--muted); white-space: nowrap; }
.swatch i { grid-row: 1 / 3; display: block; width: 28px; height: 28px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.12); }
.swatch span:last-child { font-family: Consolas, monospace; font-size: 11px; }
.formula { margin: 0; padding-left: 18px; font-size: 14px; color: var(--ink); }
.formula li { margin: 2px 0; }

.ref-list { display: flex; flex-direction: column; gap: 16px; }
.ref-card { display: grid; grid-template-columns: 96px 1fr; gap: 16px; cursor: pointer; }
.ref-thumb { width: 96px; height: 120px; object-fit: cover; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.ref-thumb.none { display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); }
.ref-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ref-caption { font-weight: 600; }
.ref-meta { font-size: 14px; color: var(--muted); }
.ref-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ref-actions .btn { min-height: 44px; }
.ref-full { display: none; grid-column: 1 / -1; flex-direction: column; gap: 12px; cursor: auto; }
.ref-card.is-open .ref-full { display: flex; }
.ref-full pre { margin: 0; white-space: pre-wrap; font: inherit; line-height: 1.6; padding: 16px; background: var(--surface); border-radius: var(--radius); }
.ref-images { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.ref-images img { height: 280px; width: auto; border-radius: 8px; border: 1px solid var(--line); flex: 0 0 auto; }
.warn { color: #b45309; font-weight: 700; }

/* ── ② 분석 ── */
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 3px; flex: 0 0 auto; }
.pattern-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.pattern { padding: var(--pad); border-radius: 16px; border: 1px solid var(--line); background: var(--bg); position: relative; overflow: hidden; }
.pattern::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--insta); }
.pattern h4 { margin: 0 0 8px; font-size: 18px; font-weight: 800; }
.pattern p { margin: 0; }
.rec { font-weight: 600; }
.dna-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.dna-box { padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.dna-box h4 { margin: 0 0 6px; font-size: 15px; font-weight: 800; }
.dna-box p { margin: 0; font-size: 15px; }
#an-dna-swatches .swatches { grid-template-columns: repeat(6, 1fr); }
.an-table { min-width: 1100px !important; }
.an-table th:nth-child(1), .an-table td:nth-child(1) { min-width: 150px; }
.an-table td:nth-child(3) { min-width: 160px; }
.an-table th:nth-child(4), .an-table td:nth-child(4) { white-space: nowrap; }
.an-table td:nth-child(5) { min-width: 240px; }
.an-table td:nth-child(n+6) { min-width: 170px; }
.an-table { min-width: 1500px !important; }
.an-table tbody tr { cursor: pointer; }
.an-table tbody tr:hover { background: var(--surface); }
.an-table tr.is-gone { cursor: default; color: var(--muted); }
.an-thumb { width: 48px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.an-table .badge { margin-top: 4px; white-space: nowrap; }

/* ── ③ 내 계정 ── */
.field input.is-invalid, .field textarea.is-invalid { border-color: var(--danger); border-width: 2px; }
.color-row { display: flex; gap: 24px; flex-wrap: wrap; }
.color-input { display: flex; align-items: center; gap: 10px; }
.color-input input[type="color"] { width: 52px; height: 48px; padding: 2px; border: 1px solid #d1d5db; border-radius: var(--radius); background: var(--bg); cursor: pointer; }
.color-input input[type="text"] { width: 130px !important; font-family: Consolas, monospace; }
.color-chip { width: 36px; min-height: 36px; padding: 0; border-radius: 50%; }
.cover-preview {
  width: 216px; height: 270px; border-radius: 12px; padding: 18px;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  color: #ffffff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); position: relative; overflow: hidden;
}
.cover-preview.is-light { color: #1f2937; }
.cp-label { position: absolute; top: 16px; left: 18px; font-size: 12px; font-weight: 700; opacity: 0.9; }
.cp-name { font-size: 22px; font-weight: 800; line-height: 1.25; word-break: keep-all; }
.cp-handle { font-size: 13px; font-weight: 600; opacity: 0.9; }
.warn a { color: inherit; }

/* ── 아래 상태 줄 ── */
.status {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  min-height: var(--status-h);
  padding: 12px 24px;
  background: #111827;
  color: #f9fafb;
  font-size: 15px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.is-idle { color: #9ca3af; }

/* ── 폰(폭 720 px 아래) ── */
@media (max-width: 720px) {
  .topbar-inner { padding: 12px 16px 4px; }
  .brand { font-size: 22px; }
  .tabs { padding: 0 8px; }
  .tab { padding: 0 12px; }
  .page { padding: 24px 16px; }
  .panel-lead { font-size: 18px; }
  .empty { padding: 40px 20px; }
  .field input { width: 100%; }
  .ref-card { grid-template-columns: 72px 1fr; gap: 12px; }
  .ref-thumb { width: 72px; height: 90px; }
  .ref-images img { height: 220px; }
  .style-list { grid-template-columns: 1fr; }
  #an-dna-swatches .swatches { grid-template-columns: repeat(3, 1fr); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .actions .btn { flex: 1 1 100%; }
  .status { padding: 12px 16px; font-size: 14px; }
}

/* ── ④ 만들기 ── */
.style-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.style-opt { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); text-align: left; font: inherit; color: var(--ink); cursor: pointer; min-height: 48px; }
.style-opt[aria-checked="true"] { border: 2px solid #962fbf; padding: 13px 15px; background: #faf5ff; }
.style-opt b { font-weight: 800; }
.style-opt small { font-size: 13px; color: var(--muted); line-height: 1.4; }
.dots { display: flex; gap: 4px; }
.dots i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.15); display: block; }
.photo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.strip { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x proximity; }
.slide-item { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; scroll-snap-align: start; border: 0; background: none; padding: 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.slide-item canvas { width: 216px; height: 270px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: block; }
.slide-item.is-active canvas { outline: 3px solid #962fbf; outline-offset: 2px; }
.slide-item .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.badge.over { color: #ffffff; background: var(--danger); border-color: var(--danger); }
.badge.banned { color: #92400e; border-color: #fde68a; background: #fffbeb; }
.field select { min-height: 48px; padding: 0 12px; border: 1px solid #d1d5db; border-radius: var(--radius); font: inherit; background: var(--bg); color: var(--ink); }
.chips .chip.tag { cursor: pointer; }
.chips .chip.tag:hover { border-color: var(--danger); color: var(--danger); text-decoration: line-through; }
@media (max-width: 720px) {
  .slide-item canvas { width: 168px; height: 210px; }
  .style-picker { grid-template-columns: 1fr 1fr; }
}

/* ── ⑤ 내보내기 ── */
.ex-list { display: flex; flex-direction: column; gap: 12px; }
.ex-item { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center; padding: 16px; }
.ex-item.is-active { border: 2px solid #962fbf; padding: 15px; }
.ex-item canvas { width: 96px; height: 120px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); display: block; }
.ex-item .ref-actions .btn { min-height: 44px; }
.badge.done { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
.ex-check { font-weight: 700; }
.ex-check.is-ok { color: #047857; }
.ex-check.is-bad { color: var(--danger); }
.ex-problems { margin: 0; padding-left: 20px; color: var(--danger); font-weight: 600; }
.ex-singles { display: flex; flex-wrap: wrap; gap: 8px; }
#ex-strip canvas { width: 168px; height: 210px; border-radius: 8px; border: 1px solid var(--line); flex: 0 0 auto; }
label.btn { cursor: pointer; }
@media (max-width: 720px) {
  .ex-item { grid-template-columns: 72px 1fr; }
  .ex-item canvas { width: 72px; height: 90px; }
  #ex-strip canvas { width: 132px; height: 165px; }
}
