:root {
  --bg: #F5F0FA;
  --bg-soft: #EFE6F7;
  --primary: #A78BC9;
  --primary-deep: #7B5EA7;
  --primary-darker: #5A4286;
  --text: #3D2D5C;
  --text-soft: #6B5A85;
  --success: #8FB89A;
  --error: #B85C7A;
  --border: #E1D4F0;
  --white: #ffffff;
  --shadow: 0 8px 24px rgba(123, 94, 167, 0.10);
  --shadow-soft: 0 2px 8px rgba(123, 94, 167, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(2rem + var(--safe-top)) 1.25rem calc(2rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  margin: 1.5rem 0 1.75rem;
}

.hero__names {
  font-family: 'Great Vibes', 'Brush Script MT', cursive;
  font-weight: 400;
  font-size: clamp(2.6rem, 11vw, 3.5rem);
  margin: 0;
  color: var(--primary-darker);
  line-height: 1;
  letter-spacing: 0.02em;
}

.hero__date {
  margin: 0.4rem 0 0;
  font-size: 1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 500;
}

/* ---------- Card ---------- */
.card {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card__title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
  color: var(--primary-darker);
  text-align: center;
}

.card__text {
  margin: 0 0 1.25rem;
  text-align: center;
  color: var(--text-soft);
  font-size: 1.05rem;
}

/* ---------- Form ---------- */
.field {
  display: block;
  margin-bottom: 1rem;
}

.field__label {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
  color: var(--text-soft);
  font-weight: 500;
  letter-spacing: 0.02em;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input[type="password"]:focus,
input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(167, 139, 201, 0.18);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 56px;
  padding: 0.85rem 1.25rem;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s, background 0.15s;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--primary-deep);
  color: var(--white);
  box-shadow: var(--shadow-soft);
}

.btn--primary:hover,
.btn--primary:focus-visible {
  background: var(--primary-darker);
}

.btn--secondary {
  background: transparent;
  color: var(--primary-deep);
  border: 1.5px solid var(--primary);
}

.btn--secondary:hover,
.btn--secondary:focus-visible {
  background: var(--bg-soft);
}

.btn--big {
  min-height: 64px;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}

#camera-btn {
  margin-top: 0.75rem;
}

.btn[disabled],
.btn.is-loading {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.btn__spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
  display: none;
}

.btn.is-loading .btn__spinner { display: inline-block; }
.btn.is-loading .btn__label    { opacity: 0.6; }

@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  margin: 0.75rem 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* ---------- File list ---------- */
.file-list {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.file-item {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.875rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 0.75rem;
  align-items: center;
  font-size: 0.92rem;
}

.file-item__name {
  grid-column: 1 / 2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-weight: 500;
}

.file-item__status {
  grid-column: 2 / 3;
  font-size: 0.85rem;
  color: var(--text-soft);
  text-align: right;
  white-space: nowrap;
}

.file-item__bar {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.file-item__bar-fill {
  position: absolute;
  inset: 0 100% 0 0;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-deep) 100%);
  transition: right 0.2s ease;
}

.file-item.is-done .file-item__status { color: var(--success); font-weight: 600; }
.file-item.is-done .file-item__bar-fill { background: var(--success); right: 0 !important; }
.file-item.is-error .file-item__status { color: var(--error); font-weight: 600; }
.file-item.is-error .file-item__bar-fill { background: var(--error); right: 0 !important; }

/* ---------- Summary ---------- */
.summary {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

#retry-failed {
  margin-bottom: 0.6rem;
}

.summary__icon {
  font-size: 2.5rem;
  color: var(--primary-deep);
  margin: 0 0 0.5rem;
  line-height: 1;
}

.summary__text {
  margin: 0 0 1.25rem;
  font-size: 1.15rem;
  color: var(--text);
  font-weight: 500;
}

/* ---------- Errors ---------- */
.error {
  margin: 0 0 1rem;
  padding: 0.65rem 0.9rem;
  background: rgba(184, 92, 122, 0.08);
  border-left: 3px solid var(--error);
  border-radius: 6px;
  color: var(--error);
  font-size: 0.95rem;
}

/* ---------- Helpers ---------- */
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition: none !important; }
}

/* ---------- Admin ---------- */
.admin-page {
  max-width: 980px;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
  justify-content: space-between;
}

.stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.stats__item {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  color: var(--text);
}

.stats__item strong {
  color: var(--primary-darker);
  font-weight: 600;
  margin-right: 0.3rem;
}

.toolbar-buttons {
  display: flex;
  gap: 0.5rem;
}

.toolbar-buttons .btn {
  width: auto;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
}

.qr-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  overflow: hidden;
}

.qr-panel__summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-deep);
  user-select: none;
}

.qr-panel__summary:hover {
  background: var(--bg-soft);
}

.qr-panel__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.qr-panel__img {
  width: 100%;
  max-width: 280px;
  height: auto;
  border-radius: var(--radius-sm);
  background: #F5F0FA;
}

.qr-panel__url {
  font-size: 0.85rem;
  color: var(--text);
  word-break: break-all;
  text-align: center;
  margin: 0;
}

.qr-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.qr-panel__actions .btn {
  width: auto;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
}

.card-info {
  width: 100%;
  max-width: 420px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}

.card-info__title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-deep);
}

.card-info__line {
  margin: 0.25rem 0;
  font-size: 0.95rem;
  color: var(--text);
}

.card-info__line span {
  display: inline-block;
  min-width: 5rem;
  color: var(--text-soft);
}

.card-info__line code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
  word-break: break-all;
}

.guest-pw {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.guest-pw .btn {
  width: auto;
  align-self: flex-start;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.625rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.gallery__item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.gallery__item:focus-visible {
  outline: none;
  border-color: var(--primary-deep);
  box-shadow: 0 0 0 3px rgba(123, 94, 167, 0.25);
}

.gallery__item.is-selected {
  border-color: var(--primary-deep);
  box-shadow: 0 0 0 3px rgba(123, 94, 167, 0.35);
  transform: scale(0.97);
}

.gallery__item.is-selected img {
  filter: brightness(0.85) saturate(0.9);
}

.gallery__check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  z-index: 2;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  pointer-events: none;
}

.gallery__check svg {
  width: 18px;
  height: 18px;
}

.gallery__item.is-selected .gallery__check {
  background: var(--primary-deep);
  color: var(--white);
  border-color: var(--primary-deep);
}

.gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--bg-soft);
}

.gallery__badge {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 2;
  background: rgba(123, 94, 167, 0.92);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  pointer-events: none;
}

.gallery__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.5rem;
  background: linear-gradient(to top, rgba(61, 45, 92, 0.7) 0%, rgba(61, 45, 92, 0) 60%);
  color: var(--white);
  font-size: 0.78rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.gallery__item:hover .gallery__overlay,
.gallery__item:focus-within .gallery__overlay { opacity: 1; }

.gallery__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.gallery__actions {
  display: flex;
  gap: 0.25rem;
}

.gallery__actions a,
.gallery__actions button {
  flex: 1;
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-darker);
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  font-size: 0.75rem;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-soft);
}

/* ---------- Media-Viewer (Lightbox) ---------- */
.viewer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(31, 22, 48, 0.92);
}

.viewer__content {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer__media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #000;
}

.viewer__note {
  max-width: 22rem;
  text-align: center;
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 1.5rem 1.25rem;
  line-height: 1.5;
}

.viewer__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 640px;
}

.viewer__name {
  flex: 1;
  color: var(--white);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer__bar .btn {
  width: auto;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.95);
  flex-shrink: 0;
}

.viewer__close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: var(--white);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.viewer__close:hover,
.viewer__close:focus-visible { background: rgba(255, 255, 255, 0.3); }

/* ---------- Danger / Ghost Buttons ---------- */
.btn--danger {
  background: var(--error);
  color: var(--white);
  box-shadow: var(--shadow-soft);
}
.btn--danger:hover,
.btn--danger:focus-visible { background: #9c4666; }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn--ghost:hover,
.btn--ghost:focus-visible {
  background: var(--bg-soft);
  border-color: var(--primary);
}
.btn--ghost[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Selection Bar ---------- */
.selection-bar {
  position: sticky;
  top: 0.5rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.875rem;
  background: var(--white);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: slideDown 0.18s ease;
}

@keyframes slideDown {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.selection-bar__info {
  font-size: 1rem;
  font-weight: 500;
  color: var(--primary-darker);
}

.selection-bar__info #selection-count {
  font-size: 1.15rem;
  font-weight: 600;
  margin-right: 0.15rem;
}

.selection-bar__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.selection-bar__actions .btn {
  width: auto;
  min-height: 40px;
  padding: 0.45rem 0.95rem;
  font-size: 0.95rem;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(61, 45, 92, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.25rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(61, 45, 92, 0.35);
  animation: scaleIn 0.18s cubic-bezier(0.2, 0.9, 0.4, 1.2);
}

@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal__title {
  margin: 0 0 0.5rem;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--primary-darker);
}

.modal__text {
  margin: 0 0 1.25rem;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1.5;
}

.modal__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.modal__actions .btn {
  width: auto;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  font-size: 0.98rem;
}

@media (max-width: 480px) {
  .modal__actions { flex-direction: column-reverse; }
  .modal__actions .btn { width: 100%; }
}
