/* 작업실 — mobile first (360–430 px), one centred column on desktop. */
:root {
  --bg: #f6f5f8;
  --surface: #ffffff;
  --surface-2: #efedf3;
  --text: #1c1a22;
  --muted: #6d6878;
  --line: #dcd8e3;
  --accent: #7a4dff;
  --accent-text: #ffffff;
  --accent-soft: #ece5ff;
  --danger: #c92a3c;
  --danger-soft: #fde8eb;
  --ok: #1f8a4c;
  --base: #17808c; /* a one-picture block's default tag (sd.yaml's line) */
  --base-soft: #e2f3f5;
  --shadow: 0 1px 3px rgba(20, 10, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131217;
    --surface: #1d1b23;
    --surface-2: #27242f;
    --text: #efedf4;
    --muted: #9e98ab;
    --line: #34303d;
    --accent: #9b7bff;
    --accent-text: #ffffff;
    --accent-soft: #2e2645;
    --danger: #ff6b7b;
    --danger-soft: #3a1d23;
    --ok: #4fcf86;
    --base: #62c9d6;
    --base-soft: #15313a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
img { display: block; }

.boot { padding: 48px 16px; text-align: center; color: var(--muted); }

.page {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px 120px;
}

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  margin: 0 -16px; padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .who { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status.err { color: var(--danger); }
.status button { color: var(--danger); text-decoration: underline; background: none; border: 0; padding: 10px 4px; min-height: 44px; }

.steps { display: flex; gap: 6px; margin: 12px 0 4px; font-size: 14px; color: var(--muted); }
.steps span { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); }
.steps span.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 16px; font-weight: 600;
  cursor: pointer; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 15px; }
.btn.block { width: 100%; }
.iconbtn {
  min-width: 44px; min-height: 44px; padding: 0 8px;
  border: 0; background: transparent; border-radius: 10px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.iconbtn:active { background: var(--surface-2); }

/* ---------- login / denied ---------- */
.center { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 72px 8px; text-align: center; }
.center h2 { margin: 0; font-size: 24px; }
.center p { margin: 0; color: var(--muted); }
.gbtn { min-height: 48px; display: flex; justify-content: center; }
.email { font-weight: 700; color: var(--text) !important; word-break: break-all; }

/* ---------- list ---------- */
.list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.newbtn { margin-top: 16px; }
.card {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
  text-align: left; padding: 0; cursor: pointer;
}
.card:active { transform: scale(.985); }
.card .cover { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--surface-2); }
.card .nocover { width: 100%; aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--muted); font-size: 14px; }
.card .meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .title.none { color: var(--muted); font-weight: 600; }
.card .when { font-size: 13px; color: var(--muted); }
.mark { align-self: flex-start; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.empty { padding: 40px 8px; text-align: center; color: var(--muted); }

/* ---------- sections ---------- */
.section { margin-top: 20px; }
.section > h3 { margin: 0 0 8px; font-size: 17px; }
.hint { font-size: 14px; color: var(--muted); margin: 4px 0 0; }

/* reference picture */
.ref {
  position: relative; width: 100%;
  border: 2px dashed var(--line); border-radius: 16px;
  background: var(--surface); overflow: hidden;
}
.ref.pick { min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; cursor: pointer; color: var(--muted); padding: 24px; text-align: center; }
.ref.pick .big { font-size: 18px; font-weight: 700; color: var(--accent); }
.ref.has { border-style: solid; }
.ref.has img { width: 100%; max-height: 360px; object-fit: contain; background: var(--surface-2); }
.ref .bar { display: flex; gap: 8px; padding: 8px; }
.ref .bar .btn { flex: 1; }
.overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  font-weight: 700; text-align: center; padding: 16px;
}
.confirm {
  margin-top: 10px; padding: 14px; border-radius: 14px;
  background: var(--danger-soft); border: 1px solid var(--danger);
}
.confirm p { margin: 0 0 10px; font-weight: 600; }
.confirm .row { display: flex; gap: 8px; }
.confirm .row .btn { flex: 1; }

/* gender */
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { flex: 1; min-height: 48px; border: 0; background: transparent; font-size: 16px; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-text); }

/* fields & chips */
.field { margin-top: 14px; padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-head h4 { margin: 0; font-size: 16px; }
.field-head .count { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.field .reach { font-size: 12.5px; color: var(--muted); line-height: 1.35; margin-top: -2px; }
.field.drop-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.head-btns { display: flex; align-items: center; gap: 2px; }
.textbtn { min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; }
.textbtn:disabled { color: var(--muted); opacity: .5; cursor: default; }
.subhead { margin: 22px 0 0; font-size: 15px; }
.legend { margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips.none { font-size: 14px; color: var(--muted); }
.chip {
  display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 48px; max-width: 100%;
  padding: 5px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2);
  text-align: left; cursor: pointer; user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none;
  position: relative;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.chip:active { transform: scale(.97); }
.chip.base { border: 1px dashed var(--base); background: var(--base-soft); padding-right: 30px; }
.chip.base .badge { position: absolute; top: 3px; right: 6px; font-size: 10px; font-weight: 700; color: var(--base); line-height: 1; }
.chip.join-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); transform: scale(1.06); }
.chip.lifted { transform: scale(1.06); box-shadow: 0 6px 16px rgba(0, 0, 0, .25); opacity: .55; }
.chip .ko { font-size: 15px; font-weight: 600; line-height: 1.25; }
.chip .en { font-size: 11px; color: var(--muted); line-height: 1.2; word-break: break-all; }
.chip.out { background: transparent; border-style: dashed; opacity: .8; }
.chip.out .ko { text-decoration: line-through; }
.chip.sug { border-color: var(--accent); background: var(--accent-soft); }
.chip.sug .where { font-size: 11px; color: var(--accent); }
.chip:disabled { opacity: .4; cursor: default; transform: none; }
.tray-toggle { margin-top: 8px; min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--muted); font-size: 14px; cursor: pointer; }
.tray { padding-top: 2px; }
.add { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.add .row { display: flex; gap: 8px; }
.add input { flex: 1; min-width: 0; }
.note { font-size: 13px; color: var(--ok); }
.err-inline { font-size: 14px; color: var(--danger); }

input[type=text], textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 16px; /* 16px: iOS does not zoom */
  outline: none;
}
input[type=text]:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 260px; resize: vertical; line-height: 1.6; }

/* drawing */
.draw-row { display: flex; gap: 8px; }
.draw-row .btn { flex: 1; }
.btn.both { margin-top: 8px; }
.photo-form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 4px; }
.job { margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.job.failed { background: var(--danger-soft); border-color: var(--danger); }
.job .label { font-weight: 600; margin-bottom: 8px; }
.job .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s ease; }

.strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.shot-item { flex: 0 0 auto; scroll-snap-align: start; display: flex; flex-direction: column; gap: 4px; }
.shot-item.thumbnail { width: 136px; }
.shot-item.background, .shot-item.photo_card { width: 120px; }
.shot {
  position: relative; width: 100%;
  border: 3px solid transparent; border-radius: 14px; overflow: hidden;
  padding: 0; background: var(--surface-2); cursor: pointer;
  -webkit-touch-callout: none; user-select: none;
}
.shot img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; -webkit-user-drag: none; }
.shot.thumbnail { aspect-ratio: 3 / 4; }
.shot.background, .shot.photo_card { aspect-ratio: 9 / 16; } /* sd.yaml: 576 x 1024 */
.shot.on { border-color: var(--accent); }
.shot .picked { position: absolute; left: 6px; top: 6px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; }
.shot .zoom {
  position: absolute; right: 0; bottom: 0;
  min-width: 44px; min-height: 44px; padding: 0 8px;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff;
  border-top-left-radius: 10px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.shot-meta { display: flex; gap: 6px; align-items: baseline; min-width: 0; font-size: 12px; color: var(--muted); }
.shot-meta .no { font-weight: 700; color: var(--text); }
.shot-meta .scene { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot-actions { display: flex; flex-direction: column; gap: 4px; }
.btn.tiny { min-height: 40px; width: 100%; padding: 0 6px; border-radius: 10px; font-size: 12.5px; line-height: 1.2; }
.nothing { font-size: 14px; color: var(--muted); padding: 8px 0; }

/* story */
.chosen { display: flex; gap: 10px; margin-top: 12px; }
.chosen figure { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.chosen figcaption { font-size: 12px; color: var(--muted); }
.chosen .img { border-radius: 12px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; text-align: center; cursor: pointer; padding: 0; border: 0; }
.chosen .img img { width: 100%; height: 100%; object-fit: cover; }
.chosen .thumbnail { width: 96px; aspect-ratio: 3 / 4; }
.chosen .background { width: 72px; aspect-ratio: 9 / 16; }
.label-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.label-row label { font-weight: 700; }
.ai { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

/* sticky bottom bar */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.bottom .inner { max-width: 528px; margin: 0 auto; display: flex; gap: 8px; }
.bottom .btn { flex: 1; }
.bottom .btn.wide { flex: 2; }

/* full-screen viewer */
.viewer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .92);
  display: flex; flex-direction: column;
}
.viewer .img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; will-change: transform; -webkit-user-drag: none; }
.viewer .vinfo .pos { color: rgba(255, 255, 255, .6); }
.viewer .bar { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }
.viewer .bar .btn { flex: 1; }
.viewer .vinfo { color: #fff; font-size: 14px; text-align: center; padding: 2px 16px; display: flex; gap: 8px; justify-content: center; }
.viewer .vinfo .no { font-weight: 700; }
.viewer .vactions { max-width: 560px; width: 100%; margin: 0 auto; padding: 6px 16px 0; }
.viewer .vactions .shot-actions { flex-direction: row; }
.viewer .vactions .btn.tiny { flex: 1; min-height: 44px; background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .28); color: #fff; }

/* a chip's menu, right next to it (TagMenu) */
.menu-back { position: fixed; inset: 0; z-index: 120; }
.tag-menu {
  position: fixed; overflow-y: auto; padding: 10px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
}
.menu-title { font-size: 12px; font-weight: 700; color: var(--muted); margin: 2px 0 6px; }
.aspect-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.aspect { min-height: 30px; padding: 0 10px; border-radius: 15px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.aspect.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tag-menu .hint, .tag-menu .err-inline { font-size: 12px; margin-bottom: 6px; }
.chips.variants { gap: 4px; margin-bottom: 8px; }
.chip.mini { padding: 5px 9px; border-radius: 9px; }
.chip.mini .ko { font-size: 13px; }
.chip.mini .en { font-size: 10px; }
.menu-moves { display: flex; flex-wrap: wrap; gap: 4px; }
.mbtn { min-height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 13px; cursor: pointer; }

/* the lifted chip under the finger */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 150; pointer-events: none;
  padding: 10px 14px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 15px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .3); white-space: nowrap;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 200;
  transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 528px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  display: flex; align-items: center; gap: 8px;
}
.toast.err { background: var(--danger); color: #fff; }
.toast span { flex: 1; }
.toast button { min-width: 44px; min-height: 44px; border: 0; background: none; color: inherit; font-size: 18px; cursor: pointer; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden-input { display: none; }

@media (min-width: 600px) {
  .list { grid-template-columns: 1fr 1fr 1fr; }
}

/* 스토리 추천 */
.pitches { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.pitch {
  display: flex; flex-direction: column; gap: 4px; width: 100%; min-height: 64px; padding: 14px;
  text-align: left; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.pitch strong { font-size: 16px; }
.pitch span { line-height: 1.45; }
.pitch.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pitch:disabled { cursor: default; }
.pitch:disabled:not(.on) { opacity: .6; }
.pitch-busy { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-weight: 600; color: var(--accent); }
.spinner.small { width: 16px; height: 16px; border-width: 2px; flex: none; }
textarea.grow { resize: none; overflow: hidden; }
.pitch .pitch-tags { display: flex; gap: 6px; margin-bottom: 2px; }
.pitch .genre { padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); }
.pitch .adult { padding: 1px 6px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; background: var(--danger); vertical-align: middle; }
