:root {
  --bg: #0b0b12;
  --card: #15151f;
  --card-2: #1d1d2a;
  --line: #2a2a3a;
  --text: #f1f1f6;
  --muted: #9a9ab0;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --ok: #4ade80;
  --err: #f87171;
  --run: #fbbf24;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 640px; margin: 0 auto;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15px; margin: 18px 0 4px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; white-space: pre-line; }
.err { color: var(--err); font-size: 14px; white-space: pre-line; margin: 10px 0 0; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 20px 0; }

/* 버튼·입력 */
button { font: inherit; color: inherit; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700; }
.ghost { background: var(--card-2); border: 1px solid var(--line); }
.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.big { width: 100%; padding: 16px; font-size: 17px; margin-top: 12px; }
input[type=password], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 16px; /* 16px 미만이면 아이폰이 확대함 */
}
textarea { resize: vertical; }

/* 잠금 화면 */
#view-login { min-height: 90vh; display: grid; place-items: center; }
.login-box { width: 100%; max-width: 320px; text-align: center; }
.login-icon { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 12px; }
.login-box h1 { margin-bottom: 24px; }
.login-box form { display: grid; gap: 12px; }

/* 메인 */
.top { display: flex; justify-content: space-between; align-items: center; padding: 16px 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; font-size: 13px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #fff;
}

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button { background: var(--card-2); border: 1px solid var(--line); padding: 10px 6px; display: grid; gap: 2px; }
.seg button b { font-size: 14px; }
.seg button small { color: var(--muted); font-size: 11px; }
.seg button.on { border-color: var(--accent); background: #261f3d; }

.pick {
  display: grid; place-items: center; min-height: 150px; border: 1.5px dashed var(--line); border-radius: 14px;
  background: var(--card-2); overflow: hidden; position: relative; cursor: pointer;
}
.pick input, .add-ref input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.pick.filled { border-style: solid; }
.pick.filled .pick-empty { display: none; }
.pick-empty { color: var(--muted); font-size: 14px; padding: 20px; text-align: center; }
.pick img, .pick video { width: 100%; max-height: 360px; object-fit: contain; display: block; background: #000; }

.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin-top: 10px; }
.ref { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--card-2); }
.ref img { width: 100%; height: 100%; object-fit: cover; }
.ref.unused { opacity: .3; }
.ref button {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .7); font-size: 12px;
}
.add-ref {
  display: block; position: relative; margin-top: 10px; text-align: center; padding: 12px; border-radius: 12px;
  background: var(--card-2); border: 1px dashed var(--line); color: var(--muted); font-size: 14px; cursor: pointer;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; font-size: 14px; }
.field.check { display: flex; align-items: center; gap: 10px; }
.field.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.cost-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cost-row b { font-size: 18px; text-align: right; }
.bar { height: 6px; background: var(--card-2); border-radius: 3px; overflow: hidden; margin-top: 14px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }

/* 작업 기록 */
.job { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.job:first-child { border-top: 0; }
.job-main { display: grid; gap: 3px; min-width: 0; }
.job-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; margin-left: 4px; }
.badge.ok { background: #14361f; color: var(--ok); }
.badge.err { background: #3a1717; color: var(--err); }
.badge.run { background: #3a2f10; color: var(--run); }

/* 결과 보기 */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .85); display: grid; place-items: center; z-index: 10;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.modal-box { width: 100%; max-width: 520px; }
.modal-box video { width: 100%; max-height: 70vh; border-radius: 14px; background: #000; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row button { flex: 1; }
