/* =========================================================
   SSO'S HUB — 로그인 전 전체 비공개 잠금 게이트
   ─────────────────────────────────────────────────────────
   이 파일 하나로 9개 페이지가 모두 같은 잠금 화면을 쓴다.
   · 로그인 전: 본문(body 의 모든 자식)은 visibility:hidden —
     자리는 남겨 두어 캔버스·편집실이 크기를 0으로 재지 않게 한다.
   · 잠금 화면은 JS(auth-gate.js)가 <body> 끝에 붙인다.
     #pdhAuthGate 만 예외로 보이게 둔다.
   ========================================================= */

/* ① 잠금 상태 — 본문을 아예 보이지 않게 (게이트 말고 전부) */
html:not(.ag-authed) body > *:not(#pdhAuthGate) {
  visibility: hidden !important;
}

/* 잠금 화면 자체는 항상 보이게 (visibility 는 상속되므로 명시) */
.ag-gate {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 26px 18px calc(26px + env(safe-area-inset-bottom, 0px));
  overflow: auto;
  overscroll-behavior: contain;
  background: #07050a;
  color: var(--text, #f5edf2);
  font-family: var(--font-body, 'Pretendard Variable', Pretendard, -apple-system,
    BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif);
  -webkit-font-smoothing: antialiased;
  visibility: visible !important;
  isolation: isolate;
}

/* ② 바탕 — 다크 + 핑크 번짐 + 아주 옅은 모눈 */
.ag-gate::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(58vw 46vh at 8% -6%, rgba(255, 77, 141, .20), transparent 66%),
    radial-gradient(48vw 38vh at 102% 8%, rgba(150, 88, 255, .13), transparent 70%),
    radial-gradient(70vw 52vh at 50% 118%, rgba(255, 77, 141, .14), transparent 72%),
    linear-gradient(180deg, #0a0710 0%, #07050a 48%, #050408 100%);
}

.ag-gate::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .5;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .035) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-mask-image: radial-gradient(74% 62% at 50% 46%, #000 0%, rgba(0, 0, 0, .35) 62%, transparent 100%);
  mask-image: radial-gradient(74% 62% at 50% 46%, #000 0%, rgba(0, 0, 0, .35) 62%, transparent 100%);
}

/* 천천히 떠다니는 핑크 빛덩이 */
.ag-orb {
  position: fixed;
  z-index: -1;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(70px);
  opacity: .5;
}
.ag-orb--a {
  top: -22vmax;
  left: -16vmax;
  background: radial-gradient(circle, rgba(255, 77, 141, .34), transparent 66%);
  animation: ag-drift-a 18s ease-in-out infinite alternate;
}
.ag-orb--b {
  right: -18vmax;
  bottom: -24vmax;
  background: radial-gradient(circle, rgba(170, 110, 255, .22), transparent 68%);
  animation: ag-drift-b 22s ease-in-out infinite alternate;
}
@keyframes ag-drift-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(3vmax, 2vmax, 0) scale(1.08); }
}
@keyframes ag-drift-b {
  from { transform: translate3d(0, 0, 0) scale(1.04); }
  to   { transform: translate3d(-3vmax, -2vmax, 0) scale(1); }
}

/* ③ 가운데 카드 */
.ag-shell {
  position: relative;
  z-index: 1;
  width: min(432px, 100%);
  margin: auto;
  text-align: center;
}

.ag-card {
  position: relative;
  padding: 42px 30px 22px;
  border: 1px solid rgba(255, 105, 165, .26);
  border-radius: 28px;
  background:
    radial-gradient(120% 96% at 100% -8%, rgba(255, 77, 141, .17), transparent 62%),
    linear-gradient(168deg, #1d1626 0%, #141019 56%, #0d0a12 100%);
  box-shadow:
    0 50px 120px -56px #000,
    0 0 0 1px rgba(255, 255, 255, .03),
    inset 0 1px 0 rgba(255, 255, 255, .08);
  animation: ag-card-in .46s cubic-bezier(.22, 1, .36, 1) both;
}
/* 카드 위쪽 핑크 테이프 */
.ag-card::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 84px;
  height: 17px;
  transform: translateX(-50%) rotate(-1.5deg);
  border-radius: 3px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0) 0 6px, rgba(255, 255, 255, .13) 6px 12px),
    linear-gradient(180deg, rgba(255, 77, 141, .52), rgba(255, 77, 141, .3));
  opacity: .92;
}
/* 오른쪽 아래 은은한 핑크 번짐 */
.ag-card::after {
  content: "";
  position: absolute;
  right: -30px;
  bottom: -40px;
  width: 150px;
  height: 150px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 77, 141, .20), transparent 68%);
  pointer-events: none;
}
@keyframes ag-card-in {
  from { opacity: 0; transform: translateY(16px) scale(.975); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ag-kicker {
  margin: 0 0 16px;
  font-size: 10px;
  line-height: 1;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--pink-2, #ff75a8);
}

/* 자물쇠 배지 */
.ag-badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 77, 141, .24), rgba(255, 77, 141, .07));
  box-shadow:
    inset 0 0 0 1px rgba(255, 105, 165, .36),
    0 16px 30px -20px rgba(255, 77, 141, .7);
}
.ag-badge svg { width: 27px; height: 27px; color: var(--pink-2, #ff75a8); }
/* 아주 천천히 번지는 테두리 */
.ag-badge::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 25px;
  border: 1px solid rgba(255, 105, 165, .3);
  animation: ag-ring 3.4s ease-in-out infinite;
}
@keyframes ag-ring {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: .12; transform: scale(1.06); }
}

.ag-brand {
  margin: 0 0 14px;
  font-family: var(--font-title, 'Gowun Dodum', sans-serif);
  font-size: 12.5px;
  line-height: 1;
  letter-spacing: .2em;
  color: var(--text-3, #a99aa6);
  text-transform: uppercase;
}
.ag-brand em {
  font-style: normal;
  color: var(--pink, #ff4d8d);
}

.ag-title {
  margin: 0;
  font-family: var(--font-title, 'Gowun Dodum', sans-serif);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: -.01em;
  color: var(--text, #f5edf2);
  word-break: keep-all;
}
.ag-sub {
  margin: 8px 0 24px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-3, #a99aa6);
  word-break: keep-all;
}

/* ④ 입력 */
.ag-form { margin: 0; }

.ag-label {
  display: block;
  margin: 0 2px 7px;
  font-size: 10.5px;
  line-height: 1;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-4, #82737f);
  text-align: left;
}

.ag-field {
  position: relative;
  display: flex;
  align-items: center;
}

.ag-input {
  width: 100%;
  padding: 15px 52px 15px 16px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 14px;
  background: rgba(255, 255, 255, .045);
  color: var(--text, #f5edf2);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: .18em;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
.ag-input::placeholder {
  color: var(--text-4, #82737f);
  letter-spacing: -.01em;
}
.ag-input:hover { border-color: rgba(255, 105, 165, .32); }
.ag-input:focus {
  outline: none;
  border-color: rgba(255, 105, 165, .7);
  background: rgba(255, 255, 255, .06);
  box-shadow: 0 0 0 3px rgba(255, 77, 141, .15);
}

.ag-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-3, #a99aa6);
  cursor: pointer;
  transition: color .16s, background .16s;
}
.ag-eye:hover { color: var(--pink-2, #ff75a8); background: rgba(255, 77, 141, .1); }
.ag-eye svg { width: 18px; height: 18px; }
.ag-eye[aria-pressed="true"] { color: var(--pink-2, #ff75a8); }

.ag-error {
  min-height: 18px;
  margin: 8px 2px 0;
  font-size: 12px;
  line-height: 1.45;
  color: #ff8fa3;
  text-align: left;
}

.ag-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  margin-top: 6px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--pink-2, #ff75a8), var(--pink, #ff4d8d));
  color: #1a0711;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  cursor: pointer;
  box-shadow:
    0 16px 30px -18px rgba(255, 77, 141, .85),
    inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: transform .16s, box-shadow .16s, filter .16s;
}
.ag-submit:hover { filter: brightness(1.06); transform: translateY(-1px); }
.ag-submit:active { transform: translateY(0) scale(.99); }
.ag-submit[aria-busy="true"] { opacity: .72; cursor: progress; }

.ag-foot {
  margin: 18px 0 0;
  padding-top: 13px;
  border-top: 1px dashed rgba(255, 255, 255, .08);
  font-size: 10.5px;
  line-height: 1.5;
  letter-spacing: .01em;
  color: var(--text-4, #82737f);
}

/* 잘못된 암호 — 카드가 살짝 흔들린다 */
.ag-card.is-error { animation: ag-shake .32s ease-in-out; }
@keyframes ag-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-3px); }
}

.ag-watermark {
  margin: 18px 0 0;
  font-size: 9.5px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .18);
}

/* ⑤ 잠금 해제 뒤 — 오른쪽 위 도구 줄(자동 잠금 안내 · 동기화 · 잠금)
   index 는 상단 바 안에 흐름으로 들어가고, 나머지 페이지는 오른쪽 위에 고정된다. */
.ag-tools {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  z-index: 105;
  display: flex;
  align-items: center;
  gap: 8px;
  /* 빈 공간이 아래 화면(리더 상단 버튼 등)의 클릭을 막지 않게 */
  pointer-events: none;
}
.ag-tools > * { pointer-events: auto; }
.ag-tools--inline {
  position: static;
  top: auto;
  right: auto;
  z-index: auto;
  margin-left: auto;
  flex: 0 1 auto;
  min-width: 0;
}
.ag-tools > .ag-idle { order: 1; }
.ag-tools > .ag-sync { order: 2; }
.ag-tools > .ag-relock { order: 3; }
.ag-tools .ag-relock {
  position: static;
  top: auto;
  right: auto;
}

/* 30분 미사용 시 자동 잠금 안내 */
.ag-idle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 210px;
  padding: 8px 12px;
  border: 1px dashed rgba(255, 255, 255, .14);
  border-radius: 999px;
  background: rgba(20, 16, 26, .72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text-4, #82737f);
  font-family: inherit;
  font-size: 11px;
  line-height: 1;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color .16s, border-color .16s, background .16s;
  animation: ag-pill-in .4s .12s cubic-bezier(.22, 1, .36, 1) both;
}
.ag-idle:hover {
  color: var(--text-2, #cbbcc8);
  border-color: rgba(255, 105, 165, .38);
  background: rgba(28, 22, 36, .88);
}
.ag-idle-ico { font-size: 11px; line-height: 1; opacity: .85; }
.ag-idle-short { display: none; }
/* 5분 안으로 들어가면 핑크로 살짝 알려 준다 */
.ag-idle.is-soon {
  color: var(--pink-3, #ff9dba);
  border-color: rgba(255, 105, 165, .5);
  background: rgba(48, 18, 32, .8);
}
.ag-idle.is-soon .ag-idle-ico { opacity: 1; }

/* ⑥ 잠금 버튼 */
.ag-relock {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  z-index: 105;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px 9px 13px;
  border: 1px solid rgba(255, 105, 165, .32);
  border-radius: 999px;
  background: rgba(20, 16, 26, .84);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text-2, #cbbcc8);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.01em;
  cursor: pointer;
  box-shadow: 0 12px 26px -20px #000;
  transition: color .16s, border-color .16s, background .16s, transform .16s;
  animation: ag-pill-in .4s .18s cubic-bezier(.22, 1, .36, 1) both;
}
.ag-relock:hover {
  color: var(--text, #f5edf2);
  border-color: rgba(255, 105, 165, .6);
  background: rgba(28, 22, 36, .92);
  transform: translateY(-1px);
}
.ag-relock-ico { font-size: 12px; line-height: 1; }
@keyframes ag-pill-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 페이지 위에 모달·리더·라이트박스가 열리면 잠금 버튼은 비켜 준다 */
html:has(dialog[open]) .ag-relock,
html:has(dialog[open]) .ag-idle,
html:has(dialog[open]) .ag-sync,
html:has(.modal:not([hidden])) .ag-relock,
html:has(.modal:not([hidden])) .ag-idle,
html:has(.modal:not([hidden])) .ag-sync,
html:has(.lightbox:not([hidden])) .ag-relock,
html:has(.lightbox:not([hidden])) .ag-idle,
html:has(.lightbox:not([hidden])) .ag-sync,
html:has(.reader:not([hidden])) .ag-relock,
html:has(.reader:not([hidden])) .ag-idle,
html:has(.reader:not([hidden])) .ag-sync {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ⑦ 자동 잠금으로 돌아왔을 때 잠금 화면에 남기는 한 줄 */
.ag-notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 105, 165, .3);
  border-radius: 12px;
  background: rgba(255, 77, 141, .1);
  color: var(--pink-3, #ff9dba);
  font-size: 11.5px;
  line-height: 1.5;
  text-align: left;
  word-break: keep-all;
}

/* ⑧ 잠금이 풀렸다는 짧은 안내 */
.ag-flash {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  z-index: 410;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border: 1px solid rgba(255, 105, 165, .3);
  border-radius: 999px;
  background: rgba(22, 17, 28, .94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text, #f5edf2);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 22px 44px -26px #000;
  transform: translateX(-50%);
  visibility: visible !important;
  animation: ag-flash-in .3s cubic-bezier(.22, 1, .36, 1) both,
             ag-flash-out .3s 2s ease both;
  pointer-events: none;
}
@keyframes ag-flash-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes ag-flash-out {
  to { opacity: 0; transform: translate(-50%, 6px); }
}

/* ⑦ 작은 화면 · 움직임 줄이기 */
@media (max-width: 460px) {
  .ag-gate { padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0px)); }
  .ag-card { padding: 36px 20px 18px; border-radius: 24px; }
  .ag-title { font-size: 19px; }
  .ag-sub { font-size: 12px; margin-bottom: 20px; }
  .ag-submit { height: 48px; }
  .ag-relock { top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; padding: 8px 12px; font-size: 11.5px; }
  .ag-tools { top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; gap: 6px; }
  .ag-idle { padding: 8px 10px; }
  .ag-idle-long { display: none; }
  .ag-idle-short { display: inline; }
}

@media (max-width: 760px) and (min-width: 461px) {
  .ag-idle { max-width: 170px; }
}
@media (max-height: 640px) {
  .ag-badge { width: 52px; height: 52px; margin-bottom: 12px; }
  .ag-badge svg { width: 23px; height: 23px; }
  .ag-card { padding-top: 32px; }
  .ag-kicker { margin-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-card,
  .ag-relock,
  .ag-flash,
  .ag-orb,
  .ag-badge::after,
  .ag-card.is-error { animation: none !important; }
}
