/* 모바일 셀카 여정(src/selfie-flow.js). 키오스크와 같은 크림·잉크 톤을 쓰고,
   휴대폰을 한 손으로 쥐고 엄지로 누르기 좋게 주요 버튼을 화면 아래에 둔다. */

body.selfie-mobile-flow-active {
  background: #f4f1ea;
}

/* 셀카 QR로 들어오면(index.html이 html.selfie-entry를 붙인다) 행사 정보를 읽는 동안에도
   셀카 화면과 같은 크림 바탕에 서비스 이름과 진행 표시를 보여 준다. */
html.selfie-entry,
html.selfie-entry body {
  background: #f4f1ea;
}

html.selfie-entry .entry-gate[data-state="booting"] {
  background: #f4f1ea;
}

html.selfie-entry .entry-gate[data-state="booting"] .entry-gate-glow {
  display: none;
}

html.selfie-entry .entry-gate[data-state="booting"]::before,
html.selfie-entry .entry-gate[data-state="booting"]::after {
  position: absolute;
  top: 50%;
  left: 50%;
}

html.selfie-entry .entry-gate[data-state="booting"]::before {
  content: "포토지니 PHOTOGENIE";
  color: #121212;
  font-family: "Photogenie Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: 19px;
  letter-spacing: -0.045em;
  white-space: nowrap;
  transform: translate(-50%, calc(-50% - 14px));
}

html.selfie-entry .entry-gate[data-state="booting"]::after {
  content: "";
  width: 96px;
  height: 3px;
  margin: 12px 0 0 -48px;
  border-radius: 3px;
  background:
    linear-gradient(90deg, transparent, #121212, transparent) 0 0 / 50% 100% no-repeat,
    rgba(18, 18, 18, 0.12);
  animation: selfie-boot 1.1s ease-in-out infinite;
}

@keyframes selfie-boot {
  from { background-position: -100% 0, 0 0; }
  to { background-position: 200% 0, 0 0; }
}

body.selfie-mobile-flow-active .language-picker,
body.selfie-mobile-flow-active .relock-dialog {
  display: none !important;
}

.selfie-flow {
  --s-paper: #f4f1ea;
  --s-card: #fffdf8;
  --s-ink: #121212;
  --s-muted: #6f6a61;
  --s-line: rgba(18, 18, 18, 0.12);
  --s-soft: #e8e2d5;
  --s-acid: #d9ff53;
  --s-pad: 16px;
  --s-safe-bottom: env(safe-area-inset-bottom, 0px);
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--s-paper);
  color: var(--s-ink);
  color-scheme: light;
  font-family: "Photogenie Sans", var(--script-font), Inter, Pretendard, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.selfie-flow[hidden] {
  display: none;
}

.selfie-flow :focus-visible {
  outline: 3px solid var(--s-ink);
  outline-offset: 3px;
}

/* 입장 직후 첫 버튼에 초점을 옮기는데, 휴대폰에서는 그 테두리가 눌린 버튼처럼 보인다.
   터치 기기의 화면 낭독기는 자기 커서를 따로 그린다. */
@media (hover: none) and (pointer: coarse) {
  .selfie-flow :focus-visible {
    outline: none;
  }
}

/* 열을 minmax(0, 1fr)로 묶어야 한다. 첫 화면 사진 띠는 화면보다 훨씬 넓어서
   auto 열이면 그 폭만큼 화면 전체가 옆으로 밀린다. */
.selfie-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 520px);
  height: 100%;
  margin: 0 auto;
}

/* ---- 머리말 ---- */

.selfie-top {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 56px;
  padding: env(safe-area-inset-top, 0px) 12px 0;
}

.selfie-back {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--s-ink);
  cursor: pointer;
}

.selfie-back svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.selfie-flow[data-state="idle"] .selfie-back {
  display: none;
}

.selfie-brand {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.045em;
  white-space: nowrap;
}

.selfie-brand strong {
  font-weight: 950;
}

.selfie-flow[data-state="idle"] .selfie-brand {
  grid-column: 1 / -1;
  padding-left: 4px;
}

/* ---- 화면 공통 ---- */

.selfie-view {
  display: none;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 4px var(--s-pad) calc(14px + var(--s-safe-bottom));
}

.selfie-flow[data-view="idle"] .selfie-idle,
.selfie-flow[data-view="camera"] .selfie-camera,
.selfie-flow[data-view="review"] .selfie-review,
.selfie-flow[data-view="theme"] .selfie-theme,
.selfie-flow[data-view="generating"] .selfie-generating,
.selfie-flow[data-view="result"] .selfie-result,
.selfie-flow[data-view="error"] .selfie-error {
  display: flex;
}

.selfie-view-title {
  margin: 6px 0 12px;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.03em;
}

.selfie-view-lead {
  margin: 4px 0 0;
  color: var(--s-muted);
  font-size: 14.5px;
  line-height: 1.55;
}

.selfie-camera .selfie-view-title,
.selfie-review .selfie-view-title,
.selfie-result .selfie-view-title {
  text-align: center;
}

.selfie-primary,
.selfie-secondary,
.selfie-text {
  min-height: 56px;
  padding: 0 18px;
  border-radius: 14px;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.2s ease, opacity 0.2s ease;
}

.selfie-primary {
  border: 0;
  background: var(--s-ink);
  color: #fff;
}

.selfie-primary:disabled {
  background: #cfc9bd;
  color: #f7f5ef;
  cursor: default;
}

.selfie-secondary {
  min-height: 50px;
  border: 1.5px solid var(--s-ink);
  background: transparent;
  color: var(--s-ink);
  font-size: 15.5px;
}

.selfie-text {
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--s-muted);
  font-size: 15px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.selfie-primary:active:not(:disabled),
.selfie-secondary:active,
.selfie-shutter:active:not(:disabled) {
  transform: scale(0.98);
}

.selfie-dock {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
}

.selfie-dock-pair {
  grid-template-columns: 1fr 1.4fr;
}

.selfie-dock-pair .selfie-secondary {
  min-height: 56px;
}

.selfie-dock-row {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 8px;
}

.selfie-dock-row > [hidden] {
  display: none;
}

.selfie-fineprint {
  margin: 2px 0 0;
  color: var(--s-muted);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
}

.selfie-fineprint:empty,
.selfie-fineprint[hidden] {
  display: none;
}

/* 2:3 사진 판. 남은 높이와 폭 안에서 가장 크게 맞춘다. */
.selfie-stage,
.selfie-photo {
  position: relative;
  display: grid;
  flex: 1 1 0;
  place-items: center;
  min-height: 0;
  margin: 0;
  container-type: size;
}

.selfie-viewfinder,
.selfie-photo > img,
.selfie-photo > .selfie-scan {
  grid-area: 1 / 1;
  width: min(100cqw, 100cqh * 2 / 3);
  height: min(100cqh, 100cqw * 1.5);
  border-radius: 22px;
}

.selfie-photo > img {
  object-fit: cover;
  background: var(--s-soft);
  box-shadow: 0 18px 40px -24px rgba(18, 18, 18, 0.55);
}

/* ---- 첫 화면 ---- */

.selfie-idle {
  padding-top: 0;
}

.selfie-reel {
  display: grid;
  gap: 10px;
  margin: 6px calc(-1 * var(--s-pad)) 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
}

/* 같은 묶음을 두 번 이어 붙였으므로 절반만큼 흘리면 처음과 이어진다.
   끝 간격까지 절반에 들어가도록 오른쪽에 간격 하나를 더 둔다. */
.selfie-reel-row {
  display: flex;
  gap: 10px;
  width: max-content;
  padding-right: 10px;
  animation: selfie-reel calc(var(--reel-count, 8) * 5.5s) linear infinite;
}

.selfie-reel-row:nth-child(2) {
  animation-direction: reverse;
}

.selfie-reel-row img {
  flex: none;
  width: 150px;
  height: 100px;
  border-radius: 12px;
  background: var(--s-soft);
  object-fit: cover;
}

@keyframes selfie-reel {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.selfie-idle-copy {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  padding: 20px 4px 4px;
}

.selfie-eyebrow {
  margin: 0 0 10px;
  color: var(--s-muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.selfie-title {
  margin: 0;
  font-size: clamp(31px, 9.4vw, 42px);
  font-weight: 900;
  line-height: 1.14;
  letter-spacing: -0.045em;
  white-space: pre-line;
}

.selfie-lead {
  max-width: 34em;
  margin: 14px 0 0;
  color: var(--s-muted);
  font-size: 15.5px;
  line-height: 1.6;
}

.selfie-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13.5px;
  font-weight: 700;
}

.selfie-steps li {
  display: flex;
  align-items: center;
  gap: 7px;
}

.selfie-steps b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--s-ink);
  color: var(--s-acid);
  font-size: 12px;
}

/* ---- 카메라 ---- */

.selfie-viewfinder {
  position: relative;
  overflow: hidden;
  background: #1b1a18;
}

.selfie-viewfinder video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* 전면 카메라는 거울처럼 보여야 자연스럽다. 저장본도 같은 방향으로 남긴다. */
.selfie-viewfinder[data-facing="user"] video {
  transform: scaleX(-1);
}

.selfie-viewfinder[data-source="live"] video {
  opacity: 1;
}

.selfie-standby {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 28px;
  color: #f3efe6;
  font-size: 15px;
  line-height: 1.6;
  text-align: center;
}

.selfie-viewfinder[data-source="live"] .selfie-standby {
  display: none;
}

.selfie-corners {
  --corner: rgba(255, 255, 255, 0.86);
  position: absolute;
  inset: 14px;
  pointer-events: none;
  background:
    linear-gradient(var(--corner), var(--corner)) top left / 26px 3px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top left / 3px 26px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top right / 26px 3px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top right / 3px 26px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom left / 26px 3px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom left / 3px 26px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom right / 26px 3px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom right / 3px 26px no-repeat;
}

.selfie-countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 120px;
  font-weight: 900;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
}

.selfie-viewfinder.is-counting .selfie-countdown {
  opacity: 1;
}

.selfie-camera-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 8px 4px;
}

.selfie-round {
  position: relative;
  display: grid;
  justify-items: center;
  justify-self: center;
  gap: 5px;
  min-width: 64px;
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--s-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.selfie-round svg {
  width: 46px;
  height: 46px;
  padding: 11px;
  border-radius: 50%;
  background: var(--s-card);
  box-shadow: inset 0 0 0 1px var(--s-line);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.selfie-album {
  grid-column: 1;
}

.selfie-album input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.selfie-album:focus-within svg {
  outline: 3px solid var(--s-ink);
  outline-offset: 2px;
}

/* 카메라를 못 쓰면 앨범이 주 경로다. */
.selfie-camera:has(.selfie-viewfinder[data-source="denied"]) .selfie-album svg {
  background: var(--s-ink);
  color: #fff;
  box-shadow: none;
}

.selfie-flip {
  grid-column: 3;
}

.selfie-flip[hidden] {
  display: none;
}

.selfie-shutter {
  grid-column: 2;
  width: 78px;
  height: 78px;
  padding: 5px;
  border: 4px solid var(--s-ink);
  border-radius: 50%;
  background: var(--s-paper);
  cursor: pointer;
}

.selfie-shutter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--s-ink);
}

.selfie-shutter:disabled {
  opacity: 0.32;
  cursor: default;
}

/* ---- 테마 고르기 ---- */

.selfie-theme {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 0;
}

.selfie-theme-head {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 6px 0 14px;
}

.selfie-theme-head .selfie-view-title {
  margin: 0;
}

.selfie-theme-selfie {
  width: 54px;
  height: 81px;
  border-radius: 12px;
  background: var(--s-soft);
  object-fit: cover;
}

.selfie-people {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.selfie-people[hidden] {
  display: none;
}

.selfie-people-label {
  color: var(--s-muted);
  font-size: 12.5px;
  font-weight: 800;
}

.selfie-people-options {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--s-soft);
}

.selfie-people-option {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--s-muted);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.selfie-people-option[aria-checked="true"] {
  background: var(--s-card);
  color: var(--s-ink);
  box-shadow: 0 1px 2px rgba(18, 18, 18, 0.14), 0 4px 12px -6px rgba(18, 18, 18, 0.3);
}

.selfie-theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 6px;
}

.selfie-theme-card {
  position: relative;
  display: grid;
  align-content: start;
  gap: 5px;
  padding: 0 0 12px;
  overflow: hidden;
  border: 0;
  border-radius: 16px;
  background: var(--s-card);
  color: var(--s-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* 사진 위에 그려야 테두리가 사진에 가려지지 않는다. */
.selfie-theme-card::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px var(--s-line);
  pointer-events: none;
}

.selfie-theme-card[aria-checked="true"]::before {
  box-shadow: inset 0 0 0 3px var(--s-ink);
}

.selfie-theme-card[aria-checked="true"]::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--s-ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m3.5 8.4 3 3 6-6.4' fill='none' stroke='%23d9ff53' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
  box-shadow: 0 0 0 2px #fff;
}

.selfie-theme-image {
  position: relative;
  display: block;
  aspect-ratio: 1;
  margin-bottom: 4px;
  overflow: hidden;
  background: var(--s-soft);
}

.selfie-theme-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selfie-theme-made {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(18, 18, 18, 0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.selfie-theme-name {
  padding: 0 11px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.selfie-theme-desc {
  display: -webkit-box;
  padding: 0 11px;
  overflow: hidden;
  color: var(--s-muted);
  font-size: 12px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.selfie-dock-sticky {
  position: sticky;
  z-index: 3;
  bottom: 0;
  margin: 0 calc(-1 * var(--s-pad));
  padding: 24px var(--s-pad) calc(14px + var(--s-safe-bottom));
  background: linear-gradient(rgba(244, 241, 234, 0), var(--s-paper) 32%);
}

/* ---- 생성 중 ---- */

.selfie-generating {
  text-align: center;
}

.selfie-photo.is-working > img {
  filter: saturate(0.8) brightness(0.97);
}

.selfie-scan {
  overflow: hidden;
  background: linear-gradient(180deg,
    rgba(217, 255, 83, 0) 0%,
    rgba(217, 255, 83, 0) 42%,
    rgba(217, 255, 83, 0.62) 50%,
    rgba(217, 255, 83, 0) 58%,
    rgba(217, 255, 83, 0) 100%) 0 0 / 100% 260%;
  pointer-events: none;
  animation: selfie-scan 2.6s ease-in-out infinite alternate;
}

@keyframes selfie-scan {
  from { background-position: 0 100%; }
  to { background-position: 0 0; }
}

.selfie-chip {
  align-self: center;
  max-width: 100%;
  margin: 14px 0 0;
  padding: 6px 13px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--s-ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selfie-chip:empty {
  display: none;
}

.selfie-generating .selfie-view-title {
  margin: 12px 0 12px;
}

.selfie-progress {
  height: 8px;
  margin: 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--s-soft);
}

.selfie-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--s-ink);
  transition: width 0.35s linear;
}

.selfie-progress-copy {
  min-height: 1.5em;
  margin: 10px 0 0;
  font-size: 14.5px;
  font-weight: 700;
}

/* ---- 결과 ---- */

.selfie-result .selfie-view-title {
  margin-bottom: 10px;
}

.selfie-result .selfie-chip {
  margin-top: 12px;
}

.selfie-limit {
  color: var(--s-ink);
  font-weight: 700;
}

/* ---- 오류 ---- */

.selfie-error {
  justify-content: center;
  text-align: center;
}

.selfie-error-mark {
  display: grid;
  align-self: center;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: var(--s-ink);
  color: var(--s-acid);
  font-size: 34px;
  font-weight: 900;
}

.selfie-error .selfie-view-title {
  margin-bottom: 4px;
}

.selfie-error .selfie-view-lead {
  max-width: 30em;
  margin: 0 auto;
}

.selfie-error .selfie-dock {
  margin-top: 28px;
}

/* ---- 나가기 확인 ---- */

.selfie-confirm {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(18, 18, 18, 0.42);
}

.selfie-confirm[hidden] {
  display: none;
}

.selfie-confirm-card {
  width: min(100%, 480px);
  padding: 22px 20px calc(16px + var(--s-safe-bottom));
  border-radius: 22px;
  background: var(--s-card);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.45);
}

.selfie-confirm-card h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.selfie-confirm-card p {
  margin: 8px 0 18px;
  color: var(--s-muted);
  font-size: 14.5px;
  line-height: 1.55;
}

.selfie-confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.selfie-confirm-actions .selfie-secondary {
  min-height: 52px;
}

.selfie-confirm-actions .selfie-primary {
  min-height: 52px;
  font-size: 15.5px;
}

.selfie-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- 작은 화면·움직임 줄이기 ---- */

@media (max-height: 700px) {
  .selfie-reel-row img {
    width: 117px;
    height: 78px;
  }

  .selfie-title {
    font-size: 29px;
  }

  .selfie-idle-copy {
    padding-top: 12px;
  }

  .selfie-lead {
    margin-top: 10px;
    font-size: 14.5px;
  }

  .selfie-steps {
    margin-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .selfie-reel-row,
  .selfie-scan,
  html.selfie-entry .entry-gate[data-state="booting"]::after {
    animation: none;
  }
}
