/* Photobooth gallery — 2 thẻ tải (chia sẻ file gốc) + 3 tab xem ảnh. Mobile-first,
   dùng token của tokens.css / brand.css (màu thương hiệu do brand-runtime.js áp). */

html,
body {
  overflow-x: clip;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

img,
video {
  max-width: 100%;
}

strong {
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

.gallery-shell {
  width: min(100%, 36rem);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

/* ── Header ─────────────────────────────────────────────────────────── */
.g-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-top: calc(var(--space-5) + env(safe-area-inset-top));
  padding-bottom: var(--space-4);
}

.gallery-wordmark {
  flex: none;
  width: clamp(6.5rem, 30vw, 8.5rem);
}

.g-retention {
  min-width: 0;
  max-width: 55%;
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-align: right;
}

/* ── Khối ───────────────────────────────────────────────────────────── */
.g-block {
  padding-block: var(--space-4);
}

.g-label {
  margin: 0 0 var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

/* ── Thẻ tải ────────────────────────────────────────────────────────── */
.g-cards {
  display: grid;
  gap: var(--space-3);
}

.g-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  min-height: 4.5rem;
  padding: var(--space-4) var(--space-5);
  border: var(--rule-hairline) solid var(--color-rule);
  border-radius: 14px;
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  text-align: left;
  transition:
    transform var(--motion-fast) var(--ease-standard),
    opacity var(--motion-fast) var(--ease-standard),
    box-shadow var(--motion-fast) var(--ease-standard);
}

.g-card--dark {
  border-color: var(--color-ink);
  background: var(--color-ink);
  color: var(--color-paper);
}

.g-card:active {
  transform: scale(0.985);
}

.g-card[disabled] {
  cursor: wait;
  opacity: 0.6;
  transform: none;
}

/* Ảnh đã chuẩn bị xong, chờ khách bấm lại để mở bảng chia sẻ */
.g-card.is-ready,
.lm-btn.is-ready {
  box-shadow: 0 0 0 3px var(--color-success);
}

.g-card__text {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 2px;
}

.g-card__title {
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.2;
}

.g-card__sub {
  overflow: hidden;
  font-size: var(--text-xs);
  line-height: 1.4;
  opacity: 0.72;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.g-card__icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
}

.action-status {
  margin: var(--space-3) 0 0;
  padding-left: var(--space-3);
  border-left: 2px solid var(--color-rule-strong);
  color: var(--color-ink-2);
  font-size: var(--text-sm);
}

.action-status.is-success {
  border-color: var(--color-success);
  color: var(--color-success);
}

.action-status.is-error {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* ── Tab (segmented) ────────────────────────────────────────────────── */
.g-tabs {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 4px;
  margin-bottom: var(--space-4);
  padding: 4px;
  border-radius: 12px;
  background: var(--color-paper-3);
}

.g-tab {
  min-width: 0;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-2);
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--color-ink-2);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  transition: background var(--motion-fast) var(--ease-standard);
}

.g-tab[aria-selected="true"] {
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow-card);
}

.g-tab[hidden] {
  display: none;
}

/* ── Lưới ảnh 3 cột ─────────────────────────────────────────────────── */
.g-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.tile {
  position: relative;
  display: block;
  min-width: 0;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--color-paper-3);
  cursor: pointer;
}

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

.tile__n {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  padding: 1px 6px;
  border-radius: 6px;
  background: color-mix(in oklab, var(--color-surface) 82%, transparent);
  color: var(--color-ink-2);
  font-family: var(--font-label);
  font-size: 0.6875rem;
  line-height: 1.5;
}

.tile:active {
  opacity: 0.85;
}

.g-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: var(--space-6);
  border: var(--rule-hairline) dashed var(--color-rule-strong);
  border-radius: 10px;
  color: var(--color-muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* ── Tab ảnh ghép & video ───────────────────────────────────────────── */
.g-collage {
  display: block;
  width: 100%;
  overflow: hidden;
  padding: 0;
  border: var(--rule-fine);
  border-radius: 14px;
  background: var(--color-paper-3);
  cursor: pointer;
}

.g-collage img {
  display: block;
  width: 100%;
  height: auto;
}

.g-video {
  margin-top: var(--space-3);
  overflow: hidden;
  border-radius: 14px;
  background: var(--color-ink);
}

.g-video video {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Hướng dẫn ──────────────────────────────────────────────────────── */
.g-guide {
  padding-bottom: calc(var(--space-12) + env(safe-area-inset-bottom));
}

.g-note {
  margin: 0 0 var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.55;
}

/* ── Nút chung / thông báo lỗi / khung chờ ─────────────────────────── */
.lm-btn {
  display: inline-flex;
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  border: var(--rule-hairline) solid var(--color-ink);
  border-radius: var(--radius-control);
  background: var(--color-ink);
  color: var(--color-paper);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.lm-btn[disabled] {
  cursor: wait;
  opacity: 0.52;
}

.lm-btn--ghost {
  border-color: var(--color-rule-strong);
  background: transparent;
  color: var(--color-ink);
}

.lm-btn--small {
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
}

.g-card:focus-visible,
.g-tab:focus-visible,
.tile:focus-visible,
.g-collage:focus-visible,
.lm-btn:focus-visible,
.lightbox-close:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.notice {
  padding: var(--space-6);
  border: var(--rule-fine);
  border-radius: 14px;
  background: var(--color-surface);
  text-align: center;
}

.notice-title {
  margin: 0 0 var(--space-2);
  font-weight: 700;
}

.notice-body {
  margin: 0 0 var(--space-4);
  color: var(--color-ink-2);
}

.skeleton {
  border-radius: 14px;
  background: var(--color-skeleton);
  animation: lm-pulse 1.2s var(--ease-in-out) infinite alternate;
}

.skeleton--card {
  height: 4.5rem;
  margin-bottom: var(--space-3);
}

.skeleton--tabs {
  height: 3.25rem;
  margin: var(--space-6) 0 var(--space-4);
}

.skeleton--tile {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
}

@keyframes lm-pulse {
  to {
    opacity: 0.5;
  }
}

/* ── Xem ảnh lớn ────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-overlay);
}

.lightbox-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 4.5rem;
  padding: var(--space-3) 4.5rem var(--space-3) var(--space-4);
  background: var(--color-ink);
}

.lightbox-label {
  min-width: 0;
  overflow: hidden;
  color: var(--color-paper);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.lightbox-stage {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-card-sm);
}

.lightbox-close {
  position: absolute;
  top: max(var(--space-3), env(safe-area-inset-top));
  right: var(--space-3);
  z-index: var(--z-dropdown);
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: var(--rule-hairline) solid var(--color-rule-strong);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-ink);
  cursor: pointer;
  font-size: var(--text-lg);
  line-height: 1;
}

@media (max-width: 22rem) {
  .g-tab {
    font-size: var(--text-xs);
  }

  .g-card__title {
    font-size: var(--text-base);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: var(--dur-micro) !important;
    animation-iteration-count: 1 !important;
    transition-duration: var(--dur-micro) !important;
  }
}

/* Thanh tiến trình khi ảnh còn đang được máy chụp tải lên */
.upload-progress { margin-top: 12px; height: 6px; border-radius: 999px; background: color-mix(in oklch, currentColor 12%, transparent); overflow: hidden; }
.upload-progress span { display: block; height: 100%; width: 4%; border-radius: inherit; background: currentColor; transition: width .4s ease; }
