:root {
  --bg: #0f1115;
  --bg-elev: #1a1d24;
  --fg: #e8ecf2;
  --fg-muted: #8b93a3;
  --accent: #4da3ff;
  --accent-strong: #2b8aff;
  --success: #3ddc84;
  --wrong: #ff5a5a;
  --border: #262a33;
  --marker-found: rgba(61, 220, 132, 0.9);
  --marker-wrong: rgba(255, 90, 90, 0.9);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --pane-gap: 12px;
  --pane-pad: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-elev: #ffffff;
    --fg: #0f1115;
    --fg-muted: #5a6370;
    --border: #d9dde5;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.10);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", "Pretendard", "Apple SD Gothic Neo", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  /* CLS fix — wrap 제거. theme 텍스트 / pill 카운트 변경으로 wrap 발생 시 헤더 높이가
     1줄→2줄로 점프해 play-area 가 40px+ 밀려나던 문제 (CLS 0.463). 단일 행 강제 +
     theme 은 puzzle-meta min-width:0 로 ellipsis 흡수. */
  flex-wrap: nowrap;
  overflow: hidden;
  min-height: 54px;
}
.puzzle-meta {
  flex: 1 1 160px;
  min-width: 0;
}
.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.app-menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 18px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.app-menu:hover {
  filter: brightness(1.15);
  border-color: var(--accent);
}
.app-menu:active { transform: translateY(1px); }

.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--accent);
  text-decoration: none;
}
.app-title:hover {
  text-decoration: underline;
}

.puzzle-meta {
  min-width: 0;
  overflow: hidden;
}

.puzzle-theme {
  display: block;
  font-size: 13px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.counter {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 600;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  color: var(--success);
  transition: color 250ms ease, border-color 250ms ease;
  min-width: 52px;
  text-align: center;
}
.timer.warning { color: #ffb400; border-color: #ffb400; }
.timer.danger  { color: var(--wrong); border-color: var(--wrong); animation: spotdiff-flash 0.6s ease-in-out infinite; }

/* ---------- Progress bar (countdown visualization) ---------- */
.progress-bar {
  position: sticky;
  top: 0;
  height: 6px;
  width: 100%;
  background: var(--bg-elev);
  overflow: hidden;
  z-index: 9;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.progress-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--success);
  transform-origin: left;
  transition: background-color 280ms ease;
  will-change: width;
}
.progress-bar-fill.warning { background: #ffb400; }
.progress-bar-fill.danger  { background: var(--wrong); animation: spotdiff-flash 0.6s ease-in-out infinite; }

.progress-bar.penalty {
  animation: spotdiff-shake 380ms ease-out;
}
@keyframes spotdiff-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes spotdiff-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* Penalty indicator — floating "-5초" text */
.penalty-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: var(--wrong);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 30;
  animation: penalty-rise 900ms ease-out forwards;
}
@keyframes penalty-rise {
  0%   { opacity: 0; transform: translate(-50%, 12px); }
  15%  { opacity: 1; transform: translate(-50%, 0); }
  85%  { opacity: 1; transform: translate(-50%, -4px); }
  100% { opacity: 0; transform: translate(-50%, -16px); }
}

.token-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255, 194, 61, 0.16);
  color: #ffc23d;
  border: 1px solid rgba(255, 194, 61, 0.4);
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

/* ADR-059 — BGM mute toggle */
.bgm-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  padding: 0;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.bgm-toggle:hover {
  background: var(--bg-elev);
  color: var(--fg);
}
.bgm-toggle:active { transform: scale(0.94); }
.token-pill:hover {
  background: rgba(255, 194, 61, 0.24);
  filter: brightness(1.1);
}
.token-pill:active { transform: translateY(1px); }
.token-pill-icon { line-height: 1; }
.token-pill-plus {
  margin-left: 2px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255, 194, 61, 0.3);
  color: #ffd66b;
  font-size: 12px;
  font-weight: 900;
  line-height: 16px;
}

.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(77, 163, 255, 0.14);
  color: #4da3ff;
  border: 1px solid rgba(77, 163, 255, 0.36);
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-pill:hover {
  background: rgba(77, 163, 255, 0.22);
  filter: brightness(1.1);
}
.account-pill:active { transform: translateY(1px); }
.account-pill.logged-in {
  background: rgba(61, 220, 132, 0.14);
  color: #3ddc84;
  border-color: rgba(61, 220, 132, 0.36);
}

/* ADR-064 follow-up — trophy-pill (header, lifetime cleared count 항상 노출) */
.trophy-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255, 194, 61, 0.14);
  color: #ffc23d;
  border: 1px solid rgba(255, 194, 61, 0.36);
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.trophy-pill:hover {
  background: rgba(255, 194, 61, 0.22);
  filter: brightness(1.1);
}
.trophy-pill:active { transform: translateY(1px); }
.trophy-pill-icon { line-height: 1; }

/* Stats 모달 (purchase-card 재사용 + slim variant) */
.stats-card { max-width: 360px; }
.stats-hero {
  text-align: center;
  padding: 18px 0 12px;
}
.stats-hero-num {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  color: #ffc23d;
  font-variant-numeric: tabular-nums;
}
.stats-hero-label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim, #aaa);
}
.stats-rows {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 14px;
}
.stats-row-label { color: var(--text-dim, #aaa); }
.stats-row-val { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 결제 history + 환불 모달 */
.stats-payments {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.stats-payments-title {
  font-size: 13px;
  color: var(--text-dim, #aaa);
  margin: 0 0 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-payments-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.payment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 13px;
}
.payment-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.payment-row-main {
  color: var(--fg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.payment-row-sub {
  color: var(--text-dim, #888);
  font-size: 11px;
}
.payment-row-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.payment-row-status.done {
  background: rgba(80, 200, 120, 0.12);
  color: #8de0a8;
  border: 1px solid rgba(80, 200, 120, 0.3);
}
.payment-row-status.pending {
  background: rgba(255, 200, 80, 0.12);
  color: #ffd07a;
  border: 1px solid rgba(255, 200, 80, 0.3);
}
.payment-row-status.refunded {
  background: rgba(160, 160, 160, 0.12);
  color: #bbb;
  border: 1px solid rgba(160, 160, 160, 0.3);
}
.payment-row-refund-btn {
  background: transparent;
  border: 1px solid rgba(255, 138, 138, 0.4);
  color: #ff9a9a;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.payment-row-refund-btn:hover {
  background: rgba(255, 138, 138, 0.1);
}
.payment-row-refund-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.stats-payments-policy {
  font-size: 11px;
  color: var(--text-dim, #888);
  line-height: 1.5;
  margin: 12px 0 0;
}

/* Refund 모달 */
.refund-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  margin-bottom: 14px;
}
.refund-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.refund-summary-row.total {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 8px;
  margin-top: 4px;
  font-weight: 700;
  font-size: 15px;
}
.refund-summary-row .label { color: var(--text-dim, #aaa); }
.refund-summary-row .val { color: var(--fg); font-variant-numeric: tabular-nums; }
.refund-policy {
  font-size: 12px;
  margin: 0 0 12px;
}
.refund-reason-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim, #aaa);
  margin: 8px 0 4px;
}
.refund-reason {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
  font-size: 13px;
}
.refund-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.refund-actions > button { flex: 1; }
.refund-result {
  margin: 12px 0 0;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  background: rgba(80, 200, 120, 0.12);
  color: #8de0a8;
  border: 1px solid rgba(80, 200, 120, 0.3);
}
.refund-result.error {
  background: rgba(255, 80, 80, 0.12);
  color: #ff9a9a;
  border-color: rgba(255, 80, 80, 0.3);
}

/* ADR-064 — invite-pill (header, logged-in 시 노출) */
.invite-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255, 138, 220, 0.14);
  color: #ff8adc;
  border: 1px solid rgba(255, 138, 220, 0.36);
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.invite-pill:hover {
  background: rgba(255, 138, 220, 0.22);
  filter: brightness(1.1);
}
.invite-pill:active { transform: translateY(1px); }
.invite-pill[hidden] { display: none; }
@media (max-width: 480px) {
  /* 좁은 뷰포트에선 아이콘만 (label 숨김) */
  .invite-pill-label { display: none; }
}

.auth-email-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-email-input:focus {
  outline: 2px solid rgba(77, 163, 255, 0.5);
  border-color: rgba(77, 163, 255, 0.6);
}

/* ADR-064 — Referral (Invite friends) UI */
.referral-link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}
.referral-link-row .auth-email-input { flex: 1; }
.invite-rewards {
  margin: 14px 0 4px;
  padding: 10px 12px;
  background: rgba(255, 138, 220, 0.08);
  border: 1px solid rgba(255, 138, 220, 0.25);
  border-radius: 8px;
  font-size: 13px;
  color: var(--fg);
  line-height: 1.5;
}
.invite-stats {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}
.invite-limits {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: rgba(255, 162, 73, 0.08);
  border: 1px solid rgba(255, 162, 73, 0.25);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim, #cfd6dd);
  text-align: center;
}
.invite-limits b { color: #ffa249; }
.invite-limits i { color: var(--text-dim, #888); font-style: normal; opacity: 0.85; }
.invite-limits small { display: inline-block; margin-top: 4px; opacity: 0.7; font-size: 11px; }

/* ---------- Item bar (4 아이템) ----------
   ADR-061 — 원위치 (header 아래, play-area 위) + 가운데 정렬. */
.item-bar {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  justify-content: center;
  /* SEO 섹션 추가 후 body flex column 에서 squash 되어 13px 으로 줄어들던
     bug 방지. play-area 가 grow 차지해도 chrome 은 자기 height 유지. */
  flex-shrink: 0;
}
.item-bar::-webkit-scrollbar { display: none; }

.item-btn {
  appearance: none;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s ease, background-color 0.15s ease;
}
.item-btn:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.item-btn:active:not(:disabled) { transform: translateY(1px); }
.item-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* ADR-060 follow-up — 토큰 부족 시 시각만 disabled, 클릭은 받아 구매 modal 호출 */
.item-btn.is-insufficient {
  opacity: 0.55;
  cursor: pointer;
}
.item-btn.is-insufficient:hover {
  opacity: 0.85;
  background: rgba(255, 90, 90, 0.18);
  border-color: rgba(255, 90, 90, 0.45);
  color: #ff8a8a;
}
.item-btn.is-insufficient .item-cost {
  background: rgba(255, 90, 90, 0.22);
  color: #ff8a8a;
}
/* ADR-064 follow-up — 토큰 사용 후 쿨다운 (스팸 클릭 방지) */
.item-btn.is-cooldown {
  opacity: 0.45;
  cursor: not-allowed;
  position: relative;
  overflow: hidden;
}
.item-btn.is-cooldown::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent, #4da3ff);
  transform-origin: right center;
  animation: item-cooldown-bar 1500ms linear forwards;
}
@keyframes item-cooldown-bar {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.item-btn .item-icon { font-size: 14px; line-height: 1; }
.item-btn .item-label { }
.item-btn .item-cost {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  padding: 1px 5px;
  background: rgba(255, 194, 61, 0.22);
  color: #ffc23d;
  border-radius: 999px;
}
/* ADR-064 follow-up — 무료 hint pool 잔량 표시 (cost 자리에 🆓 N/3) */
.item-btn .item-cost.is-free {
  background: rgba(61, 220, 132, 0.22);
  color: #3ddc84;
}
.item-btn:hover:not(:disabled) .item-cost.is-free {
  background: rgba(61, 220, 132, 0.36);
  color: #fff;
}
.item-btn:hover:not(:disabled) .item-cost {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* 임베드 모드에서 아이템 바 간소화 */
body.embed .item-bar { padding: 4px 8px; }
body.embed .item-btn { font-size: 11px; padding: 4px 8px; }

/* 구버전 hint-btn 폴백 (삭제 예정) */
.hint-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.hint-btn:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.hint-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.hint-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.hint-icon { font-size: 14px; line-height: 1; }
.hint-label { }
.hint-count {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  padding: 1px 6px;
  background: rgba(255, 194, 61, 0.22);
  color: #ffc23d;
  border-radius: 999px;
  min-width: 14px;
  text-align: center;
}
.hint-btn:hover:not(:disabled) .hint-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.counter-sep {
  color: var(--fg-muted);
  margin: 0 2px;
}

/* ---------- Play area ---------- */
.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--pane-gap);
  padding: var(--pane-pad);
  /* SEO 섹션 추가 후 flex shrinking 으로 image 가 0px 되던 bug 방지.
     header (54) + item-bar (~46) = ~100px 차감. footer 는 viewport 밖이라
     차감 X — 사용자가 scroll 시 노출. */
  min-height: calc(100dvh - 100px);
}

.image-pane {
  position: relative;
  margin: 0;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: manipulation;
}

.puzzle-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  /* ADR-044 -- 이미지 로드 전에도 1:1 비율로 공간 예약 (CLS 방지). */
  aspect-ratio: 1 / 1;
  object-fit: contain;
  pointer-events: auto;
  -webkit-user-drag: none;
}

.marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Markers are absolutely positioned inside marker-layer, sized by JS using
   normalized coords relative to the rendered image box (not the pane). */
.marker {
  position: absolute;
  border-radius: 50%;
  border: 3px solid var(--marker-found);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 0 14px var(--marker-found);
  pointer-events: none;
  animation: marker-pop 240ms ease-out;
}

.marker.wrong {
  border-color: var(--marker-wrong);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 0 10px var(--marker-wrong);
  animation: marker-pop 200ms ease-out, marker-fade 700ms ease-out 200ms forwards;
}

.marker.hint {
  border-color: #ffc23d;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 0 24px #ffc23d, inset 0 0 12px rgba(255, 194, 61, 0.35);
  animation: marker-pop 240ms ease-out, hint-pulse 1s ease-in-out infinite 240ms;
}
@keyframes hint-pulse {
  0%, 100% { transform: scale(1);    opacity: 1;   }
  50%      { transform: scale(1.10); opacity: 0.65; }
}

@keyframes marker-pop {
  from { transform: scale(0.35); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes marker-fade {
  to { opacity: 0; transform: scale(1.3); }
}

/* ---------- Complete overlay ---------- */
.complete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  backdrop-filter: blur(4px);
}

.complete-overlay.hidden {
  display: none;
}

.complete-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 22px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
}

.complete-card h2 {
  margin: 0 0 6px;
  color: var(--success);
  font-size: 22px;
}
.complete-card.failure-card h2 {
  color: var(--wrong);
}

.failure-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  backdrop-filter: blur(4px);
}
.failure-overlay.hidden { display: none; }

.complete-card p {
  margin: 0 0 16px;
  color: var(--fg-muted);
  font-size: 14px;
}

.complete-card button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin: 4px;
  min-width: 120px;
}

.complete-card .complete-actions > button:first-of-type {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

.complete-card button:hover { filter: brightness(1.08); }
.complete-card button:active { transform: translateY(1px); }

/* ---------- Rating ---------- */
.rating-box {
  margin: 4px 0 14px;
  padding: 12px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.rating-prompt {
  margin: 0 0 6px !important;
  font-size: 13px;
  color: var(--fg-muted);
}
.rating-stars {
  display: inline-flex;
  gap: 2px;
  justify-content: center;
}
.complete-card .rating-star {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 6px;
  margin: 0;
  min-width: 0;
  font-size: 28px;
  line-height: 1;
  color: #555;
  cursor: pointer;
  transition: color 0.1s, transform 0.08s;
}
.complete-card .rating-star.filled {
  color: #f5c542;
  text-shadow: 0 0 6px rgba(245, 197, 66, 0.35);
}
.rating-stars:hover .rating-star.filled {
  color: #555;
  text-shadow: none;
}
.rating-stars:hover .rating-star:hover,
.rating-stars:hover .rating-star:has(~ .rating-star:hover) {
  color: #f5c542;
  text-shadow: 0 0 6px rgba(245, 197, 66, 0.35);
}
.complete-card .rating-star:hover:not(:disabled) {
  transform: scale(1.12);
}
.complete-card .rating-star:disabled {
  cursor: default;
}
.rating-thanks {
  margin: 6px 0 0 !important;
  font-size: 12px;
  color: var(--success, #6cc070);
}

.complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
}

/* ---------- Footer ---------- */
.app-footer {
  padding: 8px 14px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

/* ---------- Legal footer (Privacy / Terms / Contact) ---------- */
.legal-footer {
  padding: 14px 16px 22px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}
.legal-footer a {
  color: var(--fg-muted);
  text-decoration: none;
}
.legal-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.legal-sep {
  margin: 0 8px;
  opacity: 0.5;
}

/* ---------- Landscape / 태블릿 ---------- */
/* ADR-051 -- 모바일 가로 임계값 완화. 360px 높이도 가로 split 허용 (대부분 폰).
   min-width 도 768 로 내려 7-9" 태블릿/일부 폴더블 잡음. */
@media (min-width: 768px), (orientation: landscape) and (min-height: 360px) {
  .play-area {
    flex-direction: row;
    justify-content: center;
  }
  .image-pane {
    flex: 1 1 50%;
    /* ADR-054 -- 페인 너비를 viewport 높이로 캡. 1:1 이미지가 페인 거의 가득
       채우도록 (이전엔 좌우 여백이 컸음). */
    max-width: 100dvh;
  }
}

/* ---------- Compact mobile (좁은 viewport) ---------- */
/* 화면 budget 짤 때 chrome 줄여 image-pane 면적 최대화. */
@media (max-width: 600px) {
  :root {
    --pane-gap: 6px;
    --pane-pad: 4px;
  }
  .app-header {
    padding: 6px 10px;
    gap: 6px;
    /* ADR-054 -- 좁은 viewport 에선 sticky 해제. 스크롤 시 화면 면적 더 확보. */
    position: static;
  }
  .app-title { font-size: 16px; }
  .puzzle-theme { font-size: 12px; }
  .timer { font-size: 13px; }
  .header-tools { gap: 4px; }
  .item-bar {
    padding: 4px 8px;
    gap: 4px;
  }
  .item-btn {
    padding: 5px 8px;
    font-size: 12px;
  }
  .counter { font-size: 13px; }
}

/* 가로 모바일 -- 짧은 height (<= 480) 에선 chrome 더 압축 */
@media (orientation: landscape) and (max-height: 480px) {
  .app-header { padding: 4px 10px; }
  .item-bar { padding: 4px 8px; }
  .app-title { font-size: 15px; }
  .puzzle-theme { display: none; }  /* 짧은 가로엔 theme 숨김 */
  /* ADR-054 -- 짧은 가로에선 footer 도 숨김 (image 우선) */
  .legal-footer, .footer { display: none; }
  /* SEO 섹션 (메인 페이지 fold 아래) 도 가로 모드에선 숨김 — game UX 우선 */
  .seo-content { display: none; }
  /* play-area 의 min-height 차감 줄임 (chrome 더 작아짐: header ~38 + item-bar ~30 = 68) */
  .play-area {
    min-height: calc(100dvh - 70px);
    flex-direction: row;  /* image 좌우 배치 — 가로 viewport 활용 */
  }
  .image-pane { flex: 1 1 50%; }
}

/* ---------- Share overlay ---------- */
.share-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
  backdrop-filter: blur(4px);
}
.share-overlay.hidden { display: none; }

.share-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px 18px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}

.share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.share-header h2 { margin: 0; font-size: 18px; }
.share-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
.share-close:hover { color: var(--fg); background: var(--bg); }

.share-preview {
  margin: 2px 0 14px;
  color: var(--fg-muted);
  font-size: 13px;
}

.share-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-option {
  appearance: none;
  text-align: left;
  display: grid;
  grid-template-columns: 34px 1fr;
  column-gap: 12px;
  row-gap: 1px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.share-option:hover {
  border-color: var(--accent-strong);
  background: var(--bg-elev);
}
.share-option:active { transform: translateY(1px); }

.share-opt-icon {
  grid-row: 1 / 3;
  font-size: 22px;
  line-height: 1;
  text-align: center;
  color: var(--accent);
}
.share-opt-label { grid-column: 2; }
.share-opt-hint {
  grid-column: 2;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-muted);
}

/* ---------- Purchase overlay (sandbox token shop) ---------- */
.purchase-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
  backdrop-filter: blur(4px);
}
.purchase-overlay.hidden { display: none; }
.purchase-card {
  background: var(--bg-elev);
  border: 1px solid rgba(255, 194, 61, 0.45);
  border-radius: 14px;
  padding: 20px 22px 18px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(255, 194, 61, 0.12), var(--shadow);
}
.purchase-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.purchase-header h2 { margin: 0; font-size: 18px; color: #ffc23d; }
.purchase-note {
  margin: 6px 0 14px;
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.4;
}
.purchase-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.purchase-option {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: transform 0.1s, filter 0.1s;
}
.purchase-option:hover {
  filter: brightness(1.12);
  border-color: rgba(255, 194, 61, 0.6);
}
.purchase-option:active { transform: translateY(1px); }
.purchase-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.purchase-option:disabled:hover {
  filter: grayscale(0.5);
  border-color: var(--border);
}
.purchase-option.po-featured {
  border-color: rgba(255, 194, 61, 0.6);
  background: rgba(255, 194, 61, 0.08);
}
.po-amount {
  font-size: 18px;
  font-weight: 800;
  color: #ffd66b;
  font-variant-numeric: tabular-nums;
}
.po-price {
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 600;
}
.po-badge {
  position: absolute;
  top: -8px;
  right: 10px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: rgba(255, 194, 61, 0.85);
  color: #3a2500;
  border-radius: 999px;
}
.po-badge-best {
  background: rgba(77, 163, 255, 0.85);
  color: #052135;
}
/* ADR-060 — 할인율: 별도 배지 X. po-badge 와 통합 표시 ("POPULAR · -9%"). */
.po-discount { display: none; }
.po-rate {
  display: block;
  font-size: 11px;
  color: var(--fg-muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
/* ADR-060 — 추가 액션 (daily reward link 등) */
.purchase-extras {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.purchase-extras .purchase-daily-link[hidden] { display: none; }
.purchase-daily-link {
  display: inline-block;
  padding: 8px 14px;
  color: var(--accent);
  text-decoration: none;
  border: 1px dashed rgba(77, 163, 255, 0.5);
  border-radius: 8px;
  transition: background .15s;
}
.purchase-daily-link:hover {
  background: rgba(77, 163, 255, 0.08);
  text-decoration: none;
}
/* PAYMENT_DISABLED 시 invite CTA 강조 — 결제 옵션이 disabled 라 시각적 무게중심을 여기로 */
.purchase-daily-link.purchase-invite-cta-strong {
  display: block;
  width: 100%;
  padding: 14px 18px;
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, #ff7e3d 0%, #ffa249 100%);
  border: 1px solid #ffa249;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(255, 162, 73, 0.35);
  animation: ctaPulse 2.4s ease-in-out infinite;
}
.purchase-daily-link.purchase-invite-cta-strong:hover {
  background: linear-gradient(135deg, #ff6e25 0%, #ff9233 100%);
  box-shadow: 0 6px 20px rgba(255, 162, 73, 0.5);
  text-decoration: none;
}
@keyframes ctaPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.02); }
}
/* PAYMENT_DISABLED 시 결제 옵션 영역 시각적 무게 줄이기 (강제 X — 가격은 계속 보임) */
#purchase-overlay .purchase-options:has(.purchase-option[disabled]) {
  opacity: 0.55;
  filter: grayscale(0.4);
}
/* ADR-060 — token-pill balance=0 강조 (insufficient funds) */
.token-pill.is-empty {
  background: rgba(255, 90, 90, 0.18);
  border-color: rgba(255, 90, 90, 0.55);
  color: #ff8a8a;
  animation: tokenPulse 2.2s ease-in-out infinite;
}
.token-pill.is-empty .token-pill-plus {
  background: rgba(255, 90, 90, 0.4);
  color: #fff;
}
@keyframes tokenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 90, 90, 0.18); }
}
/* stages.html 의 token-badge 도 동일 강조 */
.token-badge.is-empty {
  background: rgba(255, 90, 90, 0.18);
  border-color: rgba(255, 90, 90, 0.55);
  color: #ff8a8a;
  animation: tokenPulse 2.2s ease-in-out infinite;
}
@media (min-width: 420px) {
  .purchase-options {
    grid-template-columns: repeat(3, 1fr);
  }
  .purchase-option {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 4px;
  }
}

/* ---------- Daily reward overlay ---------- */
.daily-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
  backdrop-filter: blur(4px);
}
.daily-overlay.hidden { display: none; }

.daily-card {
  background: var(--bg-elev);
  border: 1px solid rgba(255, 194, 61, 0.6);
  border-radius: 14px;
  padding: 28px 24px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(255, 194, 61, 0.22), var(--shadow);
}
.daily-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  color: #ffc23d;
}
.daily-streak {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--fg);
  font-weight: 600;
}
.daily-stats {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
}
.daily-bonus {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--fg-muted);
  font-style: italic;
}
.daily-card button {
  appearance: none;
  border: 0;
  background: linear-gradient(135deg, #ffc23d, #ff9a3d);
  color: #1a1d24;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 154, 61, 0.35);
}
.daily-card button:hover { filter: brightness(1.08); }
.daily-card button:active { transform: translateY(1px); }

/* ---------- Toast notifications (token/item feedback) ---------- */
.toast-host {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 25;
  align-items: center;
}
.toast {
  padding: 8px 14px;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  animation: toast-rise 1600ms ease-out forwards;
  white-space: nowrap;
}
.toast.success { background: var(--success); color: #062a14; }
.toast.warn    { background: #ffb400; color: #3b2a00; }
.toast.info    { background: var(--accent-strong); }
.toast.bonus   { background: linear-gradient(135deg, #ffc23d, #ff9a3d); color: #1a1d24; }

@keyframes toast-rise {
  0%   { opacity: 0; transform: translateY(12px); }
  15%  { opacity: 1; transform: translateY(0); }
  85%  { opacity: 1; transform: translateY(-2px); }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .marker, .marker.wrong {
    animation: none;
  }
}

/* ---------- Embed mode (?embed=1) ----------
   화이트라벨 임베드용 — 헤더/푸터 최소화, 단일 퍼즐 포커스.
   호스트 페이지에 <iframe src="...?embed=1"> 로 삽입되는 경우 적용. */
body.embed .app-header {
  padding: 6px 10px;
  gap: 8px;
}
body.embed .app-title {
  font-size: 14px;
}
body.embed .puzzle-theme {
  font-size: 11px;
}
body.embed .app-footer {
  display: none;
}
body.embed .play-area {
  padding: 4px;
  gap: 6px;
}
body.embed .counter {
  font-size: 14px;
  padding: 3px 8px;
}

/* 완전 최소 (?embed=1&minimal=1) — 헤더도 숨김, 카운터만 floating */
body.embed.minimal .app-header {
  display: none;
}
body.embed.minimal .counter-float {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 5;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow);
}
body:not(.embed) .counter-float,
body.embed:not(.minimal) .counter-float {
  display: none;
}

/* SEO content section (메인 페이지 fold 아래, AdSense / 검색엔진 인식용) */
.seo-content {
  margin-top: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex: 0 0 auto;
}
.seo-details {
  /* 기본 closed — 사용자 클릭 시 expand */
}
.seo-summary {
  list-style: none;
  cursor: pointer;
  text-align: center;
  padding: 8px 16px;
  font-size: 11px;
  color: var(--fg-muted, #888);
  user-select: none;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.seo-summary::-webkit-details-marker { display: none; }
.seo-summary::after {
  content: ' ▾';
  opacity: 0.5;
}
.seo-details[open] .seo-summary::after { content: ' ▴'; }
.seo-details[open] .seo-inner {
  padding: 28px 16px 48px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.seo-inner {
  max-width: 760px;
  margin: 0 auto;
  color: var(--text-dim, #aaa);
  font-size: 15px;
  line-height: 1.65;
}
.seo-inner h2 {
  color: var(--fg);
  font-size: 20px;
  font-weight: 700;
  margin: 28px 0 12px;
  letter-spacing: -0.01em;
}
.seo-inner h2:first-of-type { margin-top: 0; }
.seo-inner p { margin: 0 0 14px; }
.seo-inner a {
  color: var(--accent, #ffb84d);
  text-decoration: underline;
}
.seo-inner a:hover { filter: brightness(1.15); }
.seo-list {
  margin: 0 0 14px;
  padding-left: 22px;
}
.seo-list li {
  margin: 8px 0;
}
.seo-list strong { color: var(--fg); }
.seo-faq {
  margin: 0 0 18px;
}
.seo-faq dt {
  color: var(--fg);
  font-weight: 600;
  margin: 14px 0 4px;
}
.seo-faq dd {
  margin: 0 0 8px;
}
.seo-cta {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
  text-align: center;
}
.seo-cta a { margin: 0 6px; }

/* embed 모드에선 SEO 섹션 숨김 (iframe 임베드 용도) */
body.embed .seo-content { display: none; }
