/* Zero Church 페이지 레이아웃. 색·곡률·모션은 JDS 토큰만 참조한다 */
/* 스크롤바 트랙도 배경색으로 맞춘다. 서랍·대화상자가 열려 스크롤바가 사라지면 menubar.js가 잰 폭만큼 오른쪽을 채운다 */
html { background: var(--bg); scrollbar-color: var(--bd-2) var(--bg); transition: background-color var(--ms-3) var(--ease); }
html:has(dialog.jds-ov[open]) { padding-inline-end: var(--sbw, 0px); }
.wrap { --max-w: 760px; padding-block: var(--s8) var(--s20); }
.wrap--wide { --max-w: 1180px; }
.page { display: grid; gap: var(--s8); }
.page > * { min-width: 0; margin-block-start: 0; }
.intro { display: grid; gap: var(--s2); }
.intro > * { margin-block-start: 0; }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); }
.bar > * { margin: 0; }
.input-row { display: flex; gap: var(--s2); }
.input-row > input { flex: 1; min-width: 0; }
.input-row > * { margin: 0; }
@media (max-width: 639.98px) {
    /* 끝 버튼이 글 없는 아이콘이면 입력칸 옆에 한 줄로 둔다 */
    .input-row:not(:has(> .btn--icon:last-child)) { flex-direction: column; }
}

/* 본문으로 건너뛰기: 평소엔 화면 밖, 키보드 포커스를 받으면 보인다 */
.skip-link {
    position: fixed; left: var(--s4); top: var(--s2); z-index: 100;
    padding: var(--s2) var(--s4); border-radius: var(--r-sm);
    background: var(--sf); color: var(--tx); border: 1px solid var(--bd-2);
    transform: translateY(-200%); transition: transform var(--fx) var(--ease-fx);
}
.skip-link:focus { transform: none; }
main[tabindex="-1"]:focus { outline: none; }

/* 도움말 버튼은 넓은 화면의 앱 바에만 (좁은 화면은 서랍 메뉴에 있다) */
.appbar-help { display: none; }
@media (min-width: 1024px) { .appbar-help { display: inline-flex; } }
/* 앱 바 제목은 글자 폭만큼만 누른다 (JDS는 빈 칸까지 채워 빈 바 전체가 홈 링크가 된다) */
.appbar-title { flex: 0 1 auto; margin-inline-end: auto; }

/* 밑줄 막대: 경계 없는 클릭 요소의 호버·현재 표시. 막대는 ::before를 쓴다(::after는 툴팁과 로딩 링이 쓴다) */
:is(.btn--ghost, .menu-item, .drawer-nav .mi-t, .lp-links a, .lib-name) { position: relative; }
:is(.btn--ghost, .menu-item, .drawer-nav .mi-t, .lp-links a, .lib-name)::before {
    content: ""; position: absolute; left: var(--ul-x, 0); right: var(--ul-x, 0); bottom: var(--ul-b, 5px);
    height: 2px; border-radius: 1px; background: var(--sky);
    transform: scaleX(0); transform-origin: right center; pointer-events: none;
    transition: transform .2s ease;
}
.btn--ghost:not(.btn--icon) { --ul-x: 14px; }
.btn--ghost.btn--sm:not(.btn--icon) { --ul-x: 10px; --ul-b: 3px; }
.btn--ghost.btn--icon { --ul-b: 6px; }
/* 아이콘 버튼은 아이콘 아래 가운데에 짧게 */
.btn--ghost.btn--icon::before { left: 50%; right: auto; width: 16px; translate: -50% 0; transform-origin: center; }
.menu-item { --ul-x: 10px; --ul-b: 7px; width: fit-content; }
/* 드로어 항목: 아이콘과 글(.mi-t)을 .mi로 묶고, 막대는 글 span에만 그어 아이콘 아래로 뻗지 않게 한다 */
.drawer-nav .mi { display: inline-flex; align-items: center; gap: var(--s3); min-width: 0; }
.drawer-nav .mi-t { --ul-x: 0; --ul-b: -4px; min-width: 0; }
.drawer-nav .mi-t::before { transition: transform var(--fx) var(--ease-fx); }
.lp-links a, .lib-name { --ul-x: 0; --ul-b: -4px; }

@media (hover: hover) {
    :is(.btn--ghost:not(.btn--icon), .menu-item, .lp-links a, .lib-name):hover::before { transform: scaleX(1); transform-origin: left center; }
    .btn--ghost.btn--icon:hover::before { transform: scaleX(1); }
    .drawer-nav :is(a, button):hover .mi-t::before { transform: scaleX(1); transform-origin: left center; }
}
.menu-item[aria-current="page"]::before, .menu-item[aria-selected="true"]::before,
.drawer-nav [aria-current="page"] .mi-t::before { transform: scaleX(1); transform-origin: left center; }
@media (prefers-reduced-motion: reduce) {
    :is(.btn--ghost, .menu-item, .drawer-nav .mi-t, .lp-links a, .lib-name)::before { transition: none; }
}

/* 배경 호버·강조 없음: 위 막대가 대신한다. 테두리 있는 버튼(.btn, .btn--pri)은 그대로 둔다.
   서랍 호버는 JDS 규칙과 같은 선택자로 덮는다(뒤에 오므로 이긴다) */
@media (hover: hover) and (pointer: fine) {
    .btn--ghost:hover:not(:disabled):not([aria-busy="true"]) { background: transparent; }
    .menu-item:hover, .menu-item[aria-selected="true"]:hover, .menu-item[aria-current="page"]:hover { background: transparent; }
    .drawer-nav :is(a, button):hover:not([aria-current="page"]) { background: transparent; color: var(--tx); }
}
.btn--ghost:active:not(:disabled):not([aria-busy="true"]), .menu-item:active, .drawer-nav :is(a, button):active { background: transparent; }
.drawer-nav [aria-current="page"] { background: transparent; font-weight: 600; color: var(--tx); }
.drawer-nav [aria-current="page"] :is(.ic, .jds-ic) { color: var(--sky-a); }

/* 입력 줄 */
.field-line > :is(input, .jds-trigger, .jds-box) { width: 160px; flex: 0 0 auto; }
.field-line > input.grow { width: auto; flex: 1; }

/* 툴팁: .opt 안의 .hint는 호버나 입력칸 포커스 때 보인다 */
.opt { position: relative; }
.opt:has(.hint) { text-decoration: underline dotted var(--bd-2); text-underline-offset: 3px; }
.hint {
    position: absolute; left: 0; top: calc(100% + var(--s2)); z-index: 10;
    width: max-content; max-width: 240px; padding: 5px 8px; border-radius: 7px;
    background: var(--tx); color: var(--bg); font-size: 12px; line-height: 1.4;
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity var(--fx) var(--ease-fx);
}
.opt:hover .hint, .field-line:focus-within .hint { opacity: 1; visibility: visible; }

/* data-tip 이름표는 JDS(bundle.js)가 그린다. 여기서는 기준 자리만 잡는다 (이름표 CSS를 두면 두 번 뜬다) */
[data-tip] { position: relative; }

/* 단계 스테퍼: 번호 원 + 이름, 단계 사이는 가는 선. 640px 미만은 현재 단계 이름만 보인다 */
.stepper { display: flex; align-items: center; margin: 0; padding: 0; list-style: none; min-width: 0; }
.stepper * { margin: 0; }
.stepper > li { position: relative; display: flex; align-items: center; gap: var(--s2); min-width: 0; flex: 0 0 auto; }
.stepper > li:not(:last-child) { flex: 1 1 auto; }
.stepper > li:not(:last-child)::after { content: ""; flex: 1 1 auto; min-width: var(--s4); height: 1px; margin-inline: var(--s1); background: var(--bd); }
.stepper button { display: inline-flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0; border: 0; background: none; color: var(--tx-2); font: inherit; cursor: pointer; }
.stepper button:hover .stepper-name { color: var(--tx); }
.stepper-dot { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--bd-2); font-size: 13px; font-weight: 600; color: var(--tx-2); }
.stepper-name { font-size: 14px; font-weight: 550; white-space: nowrap; color: var(--tx-2); }
.stepper li.is-ahead .stepper-dot, .stepper li.is-ahead .stepper-name { color: var(--tx-3); }
.stepper li[aria-current="step"] .stepper-dot { background: var(--sky-a); border-color: var(--sky-a); color: var(--bg); }
.stepper li[aria-current="step"] .stepper-name { color: var(--tx); }
.stepper li.is-done .stepper-dot { background: var(--sky-soft); border-color: var(--sky-a); color: var(--tx); }
@media (max-width: 639.98px) {
    .stepper li:not([aria-current]) .stepper-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .stepper li:not(:last-child) { flex: 1 1 auto; }
}

/* 토스트: 단계 이동 줄이 있는 화면에서는 그 위에 띄운다 */
body:has(.wz-nav) .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 72px); }
/* 편집 화면과 넓은 화면에서는 아래 가운데. 가운데 맞춤은 translate로 해 JDS의 transform과 겹치지 않게 한다 */
body:has(.sl) .toast { left: 50%; right: auto; translate: -50% 0; max-width: min(360px, calc(100vw - 32px)); }
@media (min-width: 1024px) { .toast { left: 50%; right: auto; translate: -50% 0; max-width: min(360px, calc(100vw - 32px)); } }

/* 메이커 단계 머리: 단계 이름 + n / 3 + 진행 막대(JDS .prog) */
.wz-head { display: grid; gap: var(--s3); }
.wz-head > * { margin: 0; }
.wizard-step > * { min-width: 0; margin-block-start: 0; }
/* 단계 이동 줄: 긴 편집기 아래로 묻히지 않게 화면 아래에 붙인다 */
.wz-nav {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; align-items: center; gap: var(--s2);
    padding-block: var(--s3) max(var(--s3), env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--bd);
}
.wz-nav > * { margin: 0; }
.wz-nav .grow { flex: 1; }
/* 아래 막대의 다운로드는 좁은 화면 전용 (넓은 화면은 작업 막대에 있다) */
@media (min-width: 1024px) { .wz-nav > #mk_dl { display: none; } }
/* 단계 본문과 아래 고정 막대를 한 묶음으로 둔다 */
.wz-body { display: grid; gap: var(--s6); min-width: 0; }
.wz-body > * { min-width: 0; margin-block-start: 0; }
/* 가사 수정 편집기 (2단계). 화면을 채우도록 높이를 잡는다 */
.ed-big { display: block; width: 100%; min-height: calc(100dvh - 320px); font-size: 16px; line-height: 1.7; }
/* 가사 PPT 머리: 넓으면 저장 상태가 제목 줄 오른쪽, 좁으면 부제 아래 */
.mk-head { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: var(--s4); }
#mk_saved { grid-column: 2; grid-row: 1; justify-self: end; }
#mk_saved[data-tone="err"] { color: var(--err); }
@media (max-width: 639.98px) {
    .mk-head { grid-template-columns: minmax(0, 1fr); }
    #mk_saved { grid-column: auto; grid-row: auto; justify-self: start; }
}
/* 편집기로 들어가면 편집기 위가 앱 머리 바로 아래에 오게 한다 */
#slides_root .sl { scroll-margin-top: calc(var(--head-h, 56px) + 8px); }

/* 콘티 불러오기 탭의 목록 */
.ly-conti-list { display: grid; gap: var(--s2); }
/* 콘티 불러오기 탭: 목록과 불러오기 줄 사이를 띄운다 ([hidden]은 그대로 숨긴다) */
#ly_panel_conti { display: grid; gap: var(--s3); }
#ly_panel_conti[hidden] { display: none; }
.ly-conti-row { display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer; }
/* 글 묶음의 위 여백(16px)을 없애 카드 위·아래 여백을 맞추고, 라디오를 제목 줄(t-card 22.4px)의 가운데에 맞춘다 */
.ly-conti-row > .stack { min-width: 0; margin: 0; }
.ly-conti-row > input[type="radio"] { margin: 2px 0 0; }

/* 계정 입력 오류 한 줄 (aria-describedby로 입력칸과 이어진다) */
.field-err { font-size: 13px; line-height: 1.45; color: var(--err); }
/* 계정 폼은 읽기 편한 너비로, 버튼은 폼 폭 전체 */
#acct_forms, #acct_signed { width: 100%; }

/* PPT 파인더 미리보기 */
#previewFrame { width: 100%; height: 100px; background: var(--sf); }
/* .btn이 display를 덮으므로 숨김 상태를 따로 준다 */
#downloadBtn[hidden] { display: none; }

/* 글 선택·끌기 금지. 입력칸과 편집 영역만 글을 고르고 I자 커서를 쓴다. select는 손가락 커서를 그대로 둔다 */
body { -webkit-user-select: none; user-select: none; cursor: default; }
input, textarea, select, [contenteditable="true"], [contenteditable="true"] * { -webkit-user-select: text; user-select: text; }
input, textarea, [contenteditable="true"], [contenteditable="true"] * { cursor: auto; }
/* 이미지·아이콘·버튼·링크·슬라이드 그림은 끌 수 없다. draggable="true"로 일부러 끄는 항목(슬라이드·예배·콘티 정렬)은 제외 */
:is(img, svg, i, button, a, .btn, [role="button"], .sl-slide):not([draggable="true"]) { -webkit-user-drag: none; }

/* 목록·격자 자체에는 포커스 링을 두지 않는다. 항목(썸네일, 카드)의 포커스 링은 그대로 */
[role="listbox"]:is(:focus, :focus-visible), [role="grid"]:is(:focus, :focus-visible),
.lib-grid:is(:focus, :focus-visible), .bb-text:is(:focus, :focus-visible), .ly-conti-list:is(:focus, :focus-visible) {
    outline: none; box-shadow: none;
}

/* 넓은 화면(1024px 이상, 높이 700px 이상): 단계 화면이 뷰포트에 맞는다.
   페이지는 스크롤하지 않고, 단계 안에서 넘치는 내용만 그 칸이 스크롤한다. 작은 화면은 위 규칙 그대로 */
@media (min-width: 1024px) and (min-height: 700px) {
    main.page:is(:has(> .wz-body), :has(> #slides_root)) {
        height: calc(100dvh - var(--head-h, 56px));
        grid-template-rows: auto auto minmax(0, 1fr);
        gap: var(--s6); padding-block: var(--s4) 0;
    }
    .wz-body { grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
    /* position: relative로 칸을 스크롤 영역 안에 묶는다 (안쪽 절대 위치 입력칸이 페이지를 넓히지 않게) */
    .wz-body > .wizard-step:not([hidden]) {
        position: relative; display: flex; flex-direction: column; min-height: 0;
        overflow: auto; padding-inline: 4px; margin-inline: -4px;
    }
    /* 남는 높이를 받는 칸: 가사 입력(1단계), 콘티 가사(2단계) */
    .wz-body > .wizard-step:not([hidden]) :is(#lyrics_root, #lyrics_root > .ly, #lyrics_root .field-wrap, .ct-lyr-step, .ct-lyr-panel) {
        display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0;
    }
    .wz-body > .wizard-step:not([hidden]) :is(#ly_text, .ct-lyr-panel > textarea, .ed-big) { flex: 1 1 0; min-height: 240px; }
    /* 디자인(2단계): 미리보기는 칸 맨 위에 붙어 있고 옵션만 스크롤된다 */
    .wz-body > .wizard-step:not([hidden]) .dz-grid > :first-child { top: 0; }
    /* 편집기(3단계): 작업 막대와 항목 목록이 칸 맨 위에 붙는다 */
    .wz-body > .wizard-step:not([hidden]) :is(.sl:has(.ws-editor) > .sl-top, .sl-body.ws-editor > .ws-list) { top: 0; }
    /* /slides/: 편집 영역(#slides_root)이 남는 높이를 받아 스스로 스크롤한다 */
    #slides_root { position: relative; min-height: 0; overflow: auto; padding-inline: 4px; margin-inline: -4px; }
    #slides_root .sl-view { top: var(--s4); }
}
