:root {
  --bg-dark: #08080d;
  --bg-card: #12121c;
  --bg-card-glass: rgba(22, 22, 34, 0.75);
  --border-gold: linear-gradient(135deg, #ffe259, #ffa751);
  --gold-primary: #ffd700;
  --gold-glow: rgba(255, 215, 0, 0.45);
  --cyan-primary: #00f2fe;
  --cyan-glow: rgba(0, 242, 254, 0.45);
  --purple-primary: #c471ed;
  --text-main: #f5f5f7;
  --text-muted: #8e8e9f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* App Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(8, 8, 13, 0.85);
  backdrop-filter: blur(15px);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #ffd700 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(255, 215, 0, 0.15);
  color: var(--gold-primary);
  border: 1px solid rgba(255, 215, 0, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 1px;
}

/* Screens System */
.screen {
  display: none;
  min-height: calc(100vh - 70px);
  padding: 16px 20px 30px;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* Hero / Home Screen */
.hero-card {
  background: linear-gradient(145deg, #181828, #10101b);
  border: 1px solid rgba(255, 215, 0, 0.25);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  margin-bottom: 24px;
}

.hero-card::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, var(--gold-glow), transparent 70%);
  pointer-events: none;
}

.hero-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
}

.hero-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 20px;
}

.btn-primary-glow {
  background: linear-gradient(135deg, #ffe259 0%, #ffa751 100%);
  color: #0b0b10;
  border: none;
  font-size: 16px;
  font-weight: 800;
  padding: 15px 28px;
  border-radius: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--gold-glow);
  transition: all 0.2s ease;
  width: 100%;
}

.btn-primary-glow:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px var(--gold-glow);
}

.section-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
}

.card-count {
  font-size: 13px;
  color: var(--text-muted);
}

/* Gallery Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 12px;
  opacity: 0.8;
}

/* Mini Card Item */
.mini-card {
  background: #141420;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.mini-card:active {
  transform: scale(0.96);
}

.mini-card-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: #0a0a10;
}

.mini-card-info {
  padding: 10px 12px;
  background: linear-gradient(to top, rgba(10, 10, 16, 0.95), rgba(18, 18, 28, 0.8));
}

.mini-card-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
}

.mini-card-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.mini-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid var(--gold-primary);
  color: var(--gold-primary);
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  text-transform: uppercase;
}

/* ========================================================================== */
/* CAMERA SCREEN */
/* ========================================================================== */
.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 65vh;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 20px;
}

#cameraVideo, #capturedCanvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-guide-overlay {
  position: absolute;
  inset: 16px;
  border: 2px dashed rgba(255, 215, 0, 0.4);
  border-radius: 16px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.camera-guide-text {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  color: #ffe259;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.camera-controls {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 10px 0;
}

.btn-icon-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon-circle:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.18);
}

.btn-shutter {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 215, 0, 0.9);
  box-shadow: 0 0 24px var(--gold-glow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.btn-shutter-inner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe259, #ffa751);
}

.btn-shutter:active {
  transform: scale(0.92);
}

/* ========================================================================== */
/* SIGNATURE SCREEN */
/* ========================================================================== */
.sig-instructions {
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.1), rgba(0, 242, 254, 0.1));
  border: 1px solid rgba(255, 215, 0, 0.3);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  text-align: center;
}

.sig-instructions h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold-primary);
  margin-bottom: 2px;
}

.sig-instructions p {
  font-size: 12px;
  color: var(--text-muted);
}

.sig-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  border: 2px solid rgba(255, 215, 0, 0.4);
  background: #000;
  touch-action: none;
}

.sig-bg-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
  filter: brightness(0.8) contrast(1.1);
  pointer-events: none;
}

#signatureCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  z-index: 10;
}

/* Color Selector Bar */
.color-selector-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.color-dot.active {
  transform: scale(1.2);
  border-color: #fff;
  box-shadow: 0 0 14px currentColor;
}

.color-gold { background: #ffd700; color: #ffd700; }
.color-cyan { background: #00f2fe; color: #00f2fe; }
.color-purple { background: #c471ed; color: #c471ed; }
.color-fire { background: #ff416c; color: #ff416c; }
.color-white { background: #ffffff; color: #ffffff; }

.sig-actions {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 14px 18px;
  border-radius: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.97);
}

/* ========================================================================== */
/* REVELATION & ANIMATION SCREEN (LIGHT BEAM) */
/* ========================================================================== */
.card-stage {
  perspective: 1200px;
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

/* The Collectible Trading Card */
.trading-card {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3 / 4.4;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  background: #0d0d15;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.8), 0 0 35px var(--gold-glow);
  transform-style: preserve-3d;
  transition: transform 0.1s ease-out;
}

/* Metallic Gold Border */
.trading-card.frame-gold {
  border: 6px solid #d4af37;
  border-image: linear-gradient(135deg, #ffe259, #b8860b, #ffd700, #ffe259) 1;
}

/* Holographic Shimmer */
.trading-card.frame-holo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 0%,
    rgba(255, 0, 150, 0.18) 25%,
    rgba(0, 255, 255, 0.22) 50%,
    rgba(255, 230, 0, 0.2) 75%,
    transparent 100%
  );
  mix-blend-mode: color-dodge;
  opacity: 0.7;
  pointer-events: none;
  z-index: 25;
}

/* Canvas layers inside the card */
.card-canvas-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cardPhotoCanvas {
  z-index: 5;
  object-fit: cover;
}

#cardAnimCanvas {
  z-index: 15;
  pointer-events: none;
}

/* Card Header & Footer Overlay */
.card-overlay-header {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
}

.card-brand-tag {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-edition-pill {
  font-size: 9px;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  color: var(--gold-primary);
  border: 1px solid var(--gold-primary);
  padding: 3px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-overlay-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 16px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.6) 70%, transparent 100%);
  z-index: 20;
}

.card-celeb-name {
  font-size: 20px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.card-meta-line {
  font-size: 12px;
  color: #cfcfe2;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-meta-line span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Form Controls for Card Details */
.card-edit-form {
  background: var(--bg-card-glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 20px;
  backdrop-filter: blur(10px);
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  border-color: var(--gold-primary);
}

.frame-options {
  display: flex;
  gap: 8px;
}

.frame-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.frame-btn.active {
  background: rgba(255, 215, 0, 0.15);
  border-color: var(--gold-primary);
  color: var(--gold-primary);
}

/* Export Actions Bar */
.action-buttons-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(20, 20, 32, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--gold-primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Modal for viewing saved card */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(15px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
