:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #15202b;
  --sub: #66758a;
  --line: #dde3ea;
  --pri: #0b63ce;
  --pri-ink: #ffffff;
  --pri-soft: #e6f0fc;
  --ok: #15924f;
  --warn: #c2620a;
  --danger: #d92d20;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #1a222c;
    --ink: #e8eef5;
    --sub: #93a1b3;
    --line: #2b3643;
    --pri: #4c9aff;
    --pri-ink: #06121f;
    --pri-soft: #16283d;
    --ok: #3ecf8e;
    --warn: #f0a04b;
    --danger: #ff6b5e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  overscroll-behavior-y: none;
  touch-action: manipulation; /* 두 번 탭 확대 방지 */
}
body.lock { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
[data-act] { cursor: pointer; } /* 아이폰은 이게 있어야 div 탭이 클릭으로 전달된다 */
[hidden] { display: none !important; }
svg { flex: none; }
.offscreen { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(110px + var(--sab)); }

/* ── 상단 ── */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(10px + var(--sat)) 16px 10px;
  background: var(--bg);
}
.top h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.top.sub { padding-left: 6px; padding-right: 6px; background: var(--card); border-bottom: 1px solid var(--line); }
.top.sub h1 { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .ttl { flex: 1; min-width: 0; padding: 0 4px; }
.top .ttl.c { text-align: center; }
.top .ttl p { margin: 1px 0 0; font-size: 13px; color: var(--sub); }
.ic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--ink); flex: none; }
.ic:active { background: var(--line); }
.txt { min-width: 56px; height: 44px; padding: 0 10px; font-size: 16px; color: var(--sub); }
.txt.pri { color: var(--pri); font-weight: 700; }

/* ── 홈 ── */
.tabs { display: flex; gap: 6px; margin: 4px 16px 14px; padding: 4px; background: var(--line); border-radius: 12px; }
.tabs button { flex: 1; min-width: 0; height: 40px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--sub); white-space: nowrap; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.tabs b { font-weight: 600; opacity: 0.6; margin-left: 2px; }

.list { display: grid; gap: 10px; padding: 0 16px; }
.card {
  display: block; padding: 14px 16px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.card:active { border-color: var(--pri); }
.card .row { display: flex; align-items: flex-start; gap: 10px; }
.card strong { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; word-break: keep-all; overflow-wrap: anywhere; }
.card .cnt { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--sub); white-space: nowrap; }
.card.full .cnt { color: var(--ok); }
.card .cnt svg { width: 18px; height: 18px; }
.card .meta { margin-top: 2px; font-size: 14px; color: var(--sub); }
.card .prog { margin-top: 10px; }
.card.tpl .btn { margin-top: 12px; }

.prog { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.prog i { display: block; height: 100%; border-radius: 3px; background: var(--pri); transition: width 0.25s; }
.card.full .prog i { background: var(--ok); }

.nothing { padding: 48px 20px; text-align: center; color: var(--sub); }
.nothing p { margin: 0 0 18px; }
.nothing b { color: var(--ink); }
.hint-box { margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px; background: var(--pri-soft); font-size: 14px; }
.foot { margin: 22px 16px 0; text-align: center; font-size: 12px; color: var(--sub); }


.fab {
  position: fixed; right: max(16px, calc(50vw - 304px)); bottom: calc(20px + var(--sab)); z-index: 6;
  display: inline-flex; align-items: center; gap: 6px;
  height: 54px; padding: 0 22px 0 16px; border-radius: 27px;
  background: var(--pri); color: var(--pri-ink); font-weight: 700; font-size: 17px;
  box-shadow: 0 6px 18px rgba(11, 99, 206, 0.35);
}
.fab:active { transform: scale(0.97); }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line); font-weight: 600;
}
.btn.pri { background: var(--pri); border-color: var(--pri); color: var(--pri-ink); }
.btn.big { width: 100%; min-height: 54px; font-size: 17px; }
.btn.sm { min-height: 40px; font-size: 15px; color: var(--pri); border-color: var(--pri); background: transparent; }
.btn.dashed { width: 100%; border-style: dashed; color: var(--pri); background: transparent; }
.btn.ghost { width: 100%; margin-top: 28px; border-color: transparent; background: transparent; }
.btn.danger, .danger { color: var(--danger); }
.btn:disabled { opacity: 0.6; }
.btn:active:not(:disabled) { filter: brightness(0.94); }

/* ── 작업 화면 ── */
.items { display: grid; gap: 12px; padding: 14px 16px 0; }
.item { padding: 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.item h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 16px; font-weight: 700; word-break: keep-all; overflow-wrap: anywhere; }
.no { flex: none; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--pri-soft); color: var(--pri); font-size: 13px; font-weight: 700; line-height: 22px; text-align: center; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.slot { position: relative; display: flex; flex-direction: column; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; width: 100%; }
.slot .lab {
  position: absolute; left: 6px; top: 6px; z-index: 1;
  padding: 1px 8px; border-radius: 6px; font-size: 13px; font-weight: 700;
  background: var(--card); color: var(--sub); border: 1px solid var(--line);
}
.slot .lab { max-width: calc(100% - 12px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* 칸 이름이 길면 줄인다 */
.slot.empty { border: 2px dashed var(--line); background: var(--bg); }
/* 빈칸에서는 칸 이름을 맨 위 한 줄로 두고 그 아래에 촬영 버튼을 둔다 (긴 칸 이름이 버튼을 가리지 않게) */
.slot.empty .lab { position: static; align-self: flex-start; margin: 6px 6px 0; }
.slot .shoot { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--pri); font-weight: 700; }
.slot .shoot svg { width: 26px; height: 26px; }
.slot .shoot:active { background: var(--pri-soft); }
.slot .pick { height: 34px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--sub); }
.slot .pick:active { background: var(--line); }
.slot.filled { background: #000; }
.slot.filled img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot.filled .lab { background: rgba(0, 0, 0, 0.6); color: #fff; border-color: transparent; }
.slot .time { position: absolute; right: 6px; bottom: 6px; padding: 1px 7px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.slot.busy { align-items: center; justify-content: center; gap: 8px; border: 2px dashed var(--line); background: var(--bg); color: var(--sub); }
.slot.busy em { font-style: normal; font-size: 13px; }

.spin { display: inline-block; width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--pri); border-radius: 50%; animation: spin 0.8s linear infinite; }
.spin.sm { width: 16px; height: 16px; border-width: 2px; margin-right: 8px; vertical-align: -2px; }
.btn.pri .spin { border-color: rgba(255, 255, 255, 0.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 16px calc(10px + var(--sab));
  background: var(--card); border-top: 1px solid var(--line);
}
.bar .btn { flex: 1; max-width: 300px; min-height: 52px; }
.bar .btn.pri { flex: 1.4; }

/* ── 편집 ── */
.form { padding: 16px; }
.fld { display: block; margin-bottom: 14px; }
.fld > span { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--sub); }
.fld small, h3 small { font-weight: 400; color: var(--sub); margin-left: 4px; font-size: 13px; }
input:not([type="checkbox"]) {
  width: 100%; height: 48px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-size: 16px; /* 16px 미만이면 아이폰이 화면을 확대한다 */
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { outline: 2px solid var(--pri); outline-offset: -1px; }
textarea {
  display: block; width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-size: 16px; line-height: 1.5;
  resize: vertical; -webkit-appearance: none; appearance: none;
}
input[type="date"] { min-width: 0; text-align: left; }
.form h3 { margin: 22px 0 10px; font-size: 16px; }

.ed-items { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.ed-items li { padding: 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.ed-items .r1 { display: flex; align-items: center; gap: 8px; }
.ed-items .r1 input { flex: 1; min-width: 0; height: 44px; }
.ed-items .r2 { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-left: 30px; }
.ed-items .has { font-size: 12px; color: var(--warn); font-weight: 600; white-space: nowrap; }
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line); }
.seg button { height: 32px; padding: 0 12px; border-radius: 6px; font-size: 14px; font-weight: 600; color: var(--sub); }
.seg button.on { background: var(--pri); color: var(--pri-ink); }
.mv { margin-left: auto; display: flex; }
.mv button { display: grid; place-items: center; width: 40px; height: 38px; border-radius: 8px; color: var(--sub); }
.mv button:active { background: var(--line); }
/* 하위 시트 목록: 행마다 이름 + 그 시트의 사진 항목 설정으로 들어가는 버튼 */
.ed-sheets .mv button { width: 34px; }
.lnk {
  display: inline-flex; align-items: center; gap: 2px; min-width: 0;
  height: 34px; padding: 0 4px 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 13px; font-weight: 600; color: var(--sub); white-space: nowrap;
}
.lnk svg { width: 16px; height: 16px; }
.lnk.own { border-color: var(--pri); background: var(--pri-soft); color: var(--pri); }
.lnk:active { filter: brightness(0.94); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); font-size: 15px; font-weight: 600; color: var(--sub); text-align: left; }
.chip.on { border-color: var(--pri); background: var(--pri-soft); color: var(--pri); }

/* ── 아래에서 올라오는 창 ── */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.sheet-body {
  position: relative; width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  padding: 20px 16px calc(18px + var(--sab));
  border-radius: 20px 20px 0 0; background: var(--bg);
  animation: up 0.2s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-body h2 { margin: 0 0 12px; font-size: 19px; word-break: keep-all; }
.desc { margin: 0 0 16px; color: var(--sub); font-size: 15px; }
.desc b { color: var(--ink); }
.desc b.warn { color: var(--warn); }
.hint { margin: 12px 0 0; font-size: 13px; color: var(--sub); }
.sheet-body .prog { margin-bottom: 14px; }
.chk { display: flex; align-items: center; gap: 10px; min-height: 48px; margin-bottom: 14px; padding: 0 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.chk input { width: 22px; height: 22px; accent-color: var(--pri); }
.menu { display: grid; border-radius: 14px; overflow: hidden; background: var(--card); border: 1px solid var(--line); }
.menu button { min-height: 54px; padding: 0 16px; text-align: left; font-weight: 600; }
.menu button + button { border-top: 1px solid var(--line); }
.menu button:active { background: var(--bg); }

/* ── 사진 크게 보기 ── */
.viewer { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: #000; color: #fff; }
.viewer header { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--sat)) 8px 6px; }
.viewer header .ic { color: #fff; }
.viewer header div { min-width: 0; }
.viewer header strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer header span { font-size: 13px; opacity: 0.7; }
.viewer .stage { flex: 1; min-height: 0; display: flex; }
.viewer .stage img { width: 100%; height: 100%; object-fit: contain; }
.viewer footer { display: flex; padding: 8px 4px calc(8px + var(--sab)); }
.viewer footer button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 58px; padding: 6px 2px; border-radius: 10px; color: #fff; font-size: 12px; }
.viewer footer button:active { background: rgba(255, 255, 255, 0.15); }
.viewer footer button:disabled { opacity: 0.4; }
.viewer footer button.danger { color: #ff7a6e; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--sab)); z-index: 40; transform: translateX(-50%);
  max-width: 86vw; padding: 10px 16px; border-radius: 22px;
  background: rgba(20, 28, 38, 0.92); color: #fff; font-size: 15px; text-align: center;
}

/* ── 시트 탭 (사진대장 화면 상단에 고정) ── */
.stick { position: sticky; top: 0; z-index: 5; background: var(--card); }
.stick .top { position: static; }
.sheets { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid var(--line); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.sheets::-webkit-scrollbar { display: none; }
.sh {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 12px; border-radius: 19px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 14px; font-weight: 600; color: var(--sub); white-space: nowrap;
}
.sh b { font-size: 12px; font-weight: 700; opacity: 0.75; font-variant-numeric: tabular-nums; }
.sh.full:not(.on) { color: var(--ok); border-color: var(--ok); }
.sh.on { background: var(--pri); border-color: var(--pri); color: var(--pri-ink); }
.sh.add { gap: 2px; padding-left: 8px; border-style: dashed; background: transparent; color: var(--pri); }
.sh.add svg { width: 18px; height: 18px; }

.item h2 .t { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; text-align: left; font-weight: 700; word-break: keep-all; overflow-wrap: anywhere; }
.item h2 .t svg { width: 15px; height: 15px; color: var(--sub); opacity: 0.7; }
.items .nothing { margin: 0; padding: 28px 12px; }
.when { margin: 0 2px -4px; font-size: 13px; color: var(--sub); }
.items .btn.dashed { min-height: 56px; }
.btn.allset { min-height: 56px; border-color: var(--ok); color: var(--ok); background: transparent; }
.card.done { opacity: 0.85; }

/* ── 만들기 ①② / 시트 추가 / 항목 추가 ── */
.step { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-weight: 700; }
.step b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 12px; background: var(--pri); color: var(--pri-ink); font-size: 14px; }
.step small { font-weight: 400; font-size: 13px; color: var(--sub); }
h2.withback { display: flex; align-items: center; gap: 2px; margin-left: -10px; }
.menu.pickmain button { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 64px; padding: 10px 10px 10px 16px; }
.pickmain span { display: block; min-width: 0; }
.pickmain b { display: block; font-size: 17px; }
.pickmain small { display: block; font-size: 13px; font-weight: 400; color: var(--sub); }
.pickmain svg { color: var(--sub); }
/* 음성 메모 녹음 */
.recbtn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--pri); font-weight: 600; }
.recbtn b { font-variant-numeric: tabular-nums; }
.recbtn.on { border-color: var(--danger); background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.recdone { padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.recdone audio { display: block; width: 100%; height: 40px; }
.recdone .hint { margin: 0; }
.recacts { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--sub); }
.recacts span { margin-right: auto; font-variant-numeric: tabular-nums; }
.recacts button { height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.item h2 .t.untitled { color: var(--warn); }
.item h2 .memo { flex: none; display: inline-flex; align-items: center; gap: 3px; height: 30px; padding: 0 10px 0 7px; border-radius: 15px; background: var(--pri-soft); color: var(--pri); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.item h2 .memo svg { width: 15px; height: 15px; }
.addrow { display: flex; gap: 8px; margin: 12px 0 18px; }
.addrow input { flex: 1; min-width: 0; }
.addrow .btn { flex: none; }
.seg.wide { display: flex; margin-bottom: 14px; }
.two { display: flex; gap: 8px; }
.two input { flex: 1; min-width: 0; }
.seg.wide button { flex: 1; height: 40px; }
.btn.gap { margin-top: 10px; }
.sheet-body .btn.ghost { margin-top: 8px; }
.hint.top0 { margin: -4px 0 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tags span { padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; color: var(--sub); }
.card.tpl .cnt svg { width: 18px; height: 18px; }
.xl-sheets { list-style: none; margin: 0 0 14px; padding: 0; max-height: 34vh; overflow-y: auto; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.xl-sheets li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; font-size: 15px; }
.xl-sheets li + li { border-top: 1px solid var(--line); }
.xl-sheets span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xl-sheets b { flex: none; font-weight: 600; color: var(--sub); font-variant-numeric: tabular-nums; }
