/* 애플 느낌의 차분한 화면. 색은 아래 토큰만 바꾸면 전체가 바뀐다. */
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: rgba(0, 0, 0, .08);
  --line-strong: rgba(0, 0, 0, .14);
  --fill: rgba(118, 118, 128, .12);   /* 토글 바탕 */
  --fill-hover: rgba(118, 118, 128, .18);
  --knob: #ffffff;                     /* 토글에서 고른 칸 */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, .08);
  --good: #1a7f37;
  --bad: #d70015;
  --bad-soft: rgba(215, 0, 21, .06);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --knob-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .04);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --faint: #8e8e93;
    --line: rgba(255, 255, 255, .09);
    --line-strong: rgba(255, 255, 255, .16);
    --fill: rgba(118, 118, 128, .24);
    --fill-hover: rgba(118, 118, 128, .32);
    --knob: #636366;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, .14);
    --good: #30d158;
    --bad: #ff453a;
    --bad-soft: rgba(255, 69, 58, .1);
    --shadow: none;
    --knob-shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* 애플 기기: 애플 글꼴 / 윈도우 등: 프리텐다드(애플 글꼴과 닮은 무료 글꼴) */
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard Variable", Pretendard,
    "SF Pro Text", "Helvetica Neue", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header, main, footer { max-width: 840px; margin: 0 auto; padding: 0 20px; }

/* ---------- 머리 ---------- */
header { padding-top: 28px; padding-bottom: 4px; }
h1 {
  margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.03em;
  display: flex; align-items: center; gap: 10px;
}
.logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: linear-gradient(140deg, #2b2b2e, #000);
  box-shadow: inset 0 0 0 .5px rgba(255, 255, 255, .15);
}
.logo svg { width: 15px; height: 15px; fill: #fff; margin-left: 2px; }
.sub { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- 카드 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
h2 { margin: 0 0 14px; font-size: 16px; font-weight: 650; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.row-between h2 { margin-bottom: 0; }
.num {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--text); color: var(--card); font-size: 11px; font-weight: 700; letter-spacing: 0;
}
.count { color: var(--faint); font-size: 13px; font-weight: 500; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* ---------- 토글 (세그먼트) : 모델·탭·화질·속도 ---------- */
.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: 11px; background: var(--fill);
}
.seg-item, .seg > .tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 8px; border: 0; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 550; white-space: nowrap;
  cursor: pointer; transition: background .2s, color .2s, box-shadow .2s;
}
.seg-item:hover, .seg > .tab:hover:not(.active):not(:disabled) { color: var(--text); }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item:has(input:checked), .seg > .tab.active {
  background: var(--knob); color: var(--text); box-shadow: var(--knob-shadow);
}
.seg-item:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-item:has(input:disabled) { opacity: .4; cursor: not-allowed; }
.seg > .tab:disabled { opacity: .5; cursor: default; }
.seg-item .dot { width: 6px; height: 6px; border-radius: 50%; background: #ff9f0a; }
.tabs { padding: 3px; }
.tabs > .tab { padding: 6px 16px; }

/* ---------- 버튼 ---------- */
button, .button {
  font: inherit; font-size: 14px; font-weight: 550; border: 0; border-radius: 10px; padding: 8px 16px; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: background .15s, opacity .15s, border-color .15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.ghost, .button.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
button.ghost:hover:not(:disabled), .button.ghost:hover { background: var(--fill); }
button.soft { background: var(--accent-soft); color: var(--accent); }
button.soft:hover:not(:disabled) { background: var(--accent-soft); filter: brightness(.96); }
.icon-btn { font-size: 15px !important; line-height: 1; }
button.small, .button.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
button.big {
  width: 100%; font-size: 15px; font-weight: 600; padding: 13px; border-radius: 12px; margin-top: 14px;
}
button.link { background: none; color: var(--accent); padding: 4px 6px; font-size: 13px; font-weight: 550; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
#need-key { color: #c93400; }
button:focus-visible, .button:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.buttons.tight { gap: 6px; margin: 8px 0 4px; }
.icon-btn { background: none; color: var(--faint); padding: 4px 6px; font-size: 13px; border-radius: 6px; }
.icon-btn:hover:not(:disabled) { background: var(--fill); color: var(--text); }

/* ---------- 모델 줄 ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 14px 12px 18px; }
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0; }
.toolbar-label { font-weight: 600; font-size: 13px; color: var(--muted); min-width: 30px; }
.balance-mini {
  margin-left: auto; display: flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 500;
  color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.balance-mini.warn { color: var(--bad); }
.balance-detail { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.balance-detail summary { cursor: pointer; }
.balance-detail pre { white-space: pre-wrap; word-break: break-all; max-height: 200px; overflow: auto; }

/* ---------- 입력 ---------- */
textarea, select, input[type="password"], input[type="text"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea::placeholder, input::placeholder { color: var(--faint); }
textarea:focus, select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.5; }
select {
  width: auto; padding: 6px 30px 6px 10px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%2386868b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 12px;
}

/* ---------- 1. AI 영상 만들기 ---------- */
.gen { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 16px; align-items: start; }
.drop {
  display: grid; place-items: center; border: 1.5px dashed var(--line-strong); border-radius: 14px; padding: 12px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s; color: var(--muted); font-size: 13px;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop u { color: var(--accent); text-decoration: none; font-weight: 550; }
.drop-svg { width: 28px; height: 28px; fill: none; stroke: var(--faint); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.img-drop { min-height: 160px; }
#img-preview { max-width: 100%; max-height: 230px; border-radius: 10px; display: block; }
.small-row { margin-bottom: 6px; }
.small-row .hint { margin: 0; }
.opts { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; align-items: center; }
.opts label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
#cost { margin: 0; font-variant-numeric: tabular-nums; }
#cost.warn { color: var(--bad); font-weight: 600; }

/* ---------- 2. 영상 목록 ---------- */
.clip-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.clip {
  display: grid; grid-template-columns: 22px 200px minmax(0, 1fr); gap: 14px; align-items: start;
  border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.clip .join { display: grid; place-items: center; height: 100%; cursor: pointer; }
.clip .join input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.clip video { width: 200px; max-height: 200px; border-radius: 10px; background: #000; }
.clip-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.clip-head .tools { margin-left: auto; display: flex; gap: 4px; }
.clip-head .tools button, .merge-item .tools button { width: 28px; height: 28px; padding: 0; font-size: 11px; }
.clip-title { font-size: 15px; font-weight: 650; }
.tag { background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.meta { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.prompt-text {
  margin: 4px 0; font-size: 13px; color: var(--muted); overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word;
}
.last { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--fill); border-radius: 10px; padding: 6px 8px; margin-top: 4px; }
.last img { width: 64px; border-radius: 6px; }

/* ---------- 이어 붙이기 탭 ---------- */
.merge-drop { gap: 6px; padding: 26px 14px; }
.merge-drop .drop-main { font-weight: 550; color: var(--text); font-size: 14px; }
.merge-drop .hint { margin: 0; font-size: 12px; }
.merge-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.merge-list:empty { display: none; }
.merge-item {
  display: grid; grid-template-columns: 22px 88px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px;
}
.merge-item .order { font-weight: 650; text-align: center; color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }
.merge-item video { width: 88px; height: 50px; object-fit: cover; border-radius: 6px; background: #000; }
.merge-item .name { font-weight: 550; font-size: 13px; word-break: break-all; }
.merge-item .tools { display: flex; gap: 4px; }
#steps-desc, #merge-steps-desc { margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- 진행 / 결과 / 오류 ---------- */
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--fill); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 6px; background: var(--fill); border-radius: 99px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.progress-info { display: flex; justify-content: space-between; margin: 8px 0 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#percent { color: var(--text); font-weight: 600; }
#progress #cancel { margin-top: 10px; }
#result-video { width: 100%; border-radius: 12px; background: #000; max-height: 440px; }
#result-meta { font-variant-numeric: tabular-nums; }
#report h3 { font-size: 13px; font-weight: 650; margin: 16px 0 4px; color: var(--text); }
#report ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
#report li { margin: 3px 0; }
#report b { color: var(--text); font-weight: 600; }
.ok { color: var(--good); font-weight: 600; }
.no { color: var(--bad); font-weight: 600; }
.error { background: var(--bad-soft); border-color: rgba(215, 0, 21, .2); }
.error h2 { color: var(--bad); }
.error p { white-space: pre-wrap; font-size: 14px; }
.error summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.error pre { white-space: pre-wrap; word-break: break-all; font-size: 12px; max-height: 260px; overflow: auto; }

/* ---------- 설정 ---------- */
.provider { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.provider:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.provider h3 { margin: 0 0 2px; font-size: 15px; font-weight: 650; }
.key-block { margin-top: 16px; }
.key-block h4, .tips h4 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.key-block p { margin: 4px 0 8px; font-size: 13px; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; }
.guide { margin-top: 10px; }
.guide summary { cursor: pointer; font-weight: 550; font-size: 13px; color: var(--accent); }
.guide ol { padding-left: 20px; }
.guide li { margin: 4px 0; font-size: 13px; color: var(--muted); }
.tips { margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--fill); }
.tips ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

/* ---------- 알림 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: rgba(29, 29, 31, .92); color: #f5f5f7; padding: 11px 18px; border-radius: 14px;
  font-size: 14px; font-weight: 500; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.update-banner {
  max-width: 800px; margin: 0 auto 14px; padding: 10px 12px 10px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 550;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.update-banner button { background: var(--bg); color: var(--text); }
.update-banner button:hover:not(:disabled) { background: var(--bg); opacity: .9; }
@media (max-width: 840px) { .update-banner { margin-left: 20px; margin-right: 20px; } }
footer { color: var(--faint); font-size: 12px; padding: 8px 20px 32px; text-align: center; }

/* ---------- 좁은 화면 (휴대폰) ---------- */
@media (max-width: 600px) {
  header, main, footer { padding-left: 16px; padding-right: 16px; }
  header { padding-top: 20px; }
  h1 { font-size: 20px; }
  .card { padding: 16px; border-radius: 16px; }
  .tabs > .tab { padding: 6px 12px; }
  .gen { grid-template-columns: 1fr; }
  .img-drop { min-height: 120px; }
  .clip { grid-template-columns: 20px minmax(0, 1fr); gap: 10px; }
  .clip video { grid-column: 2; width: 100%; max-height: 240px; }
  .clip .clip-side { grid-column: 2; }
  .clip .join { grid-row: 1 / span 2; }
  .merge-item { grid-template-columns: 20px minmax(0, 1fr) auto; }
  .merge-item video { display: none; }
  .key-row { flex-direction: column; }
  .balance-mini { margin-left: 0; }
}
