:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-light: #e5ebf7;
  --text: #27364d;
  --text-muted: #5f6f89;
  --primary: #1d8ecf;
  --primary-hover: #1777ad;
  --secondary: #8d3ab8;
  --danger: #cf2f4f;
  --radius: 14px;
}

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

html {
  font-size: 16px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #f7f9fd 0%, #ecf0f8 100%);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ───── Container ───── */

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

/* ───── Start Page ───── */

.center-card {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.2rem;
  padding: 2rem 1.5rem;
}

.center-card h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.center-card p {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 280px;
  line-height: 1.5;
}

/* ───── Typography ───── */

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.brand-header {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 0.15rem 0 0.75rem;
}

.brand-logo {
  width: min(100%, 250px);
  max-height: 74px;
  object-fit: contain;
  display: block;
}

/* ───── Panel ───── */

.panel {
  background: var(--surface);
  border: 1px solid #dbe4f2;
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0.75rem 0;
  box-shadow: 0 6px 20px rgba(83, 104, 143, 0.08);
}

/* ───── Camera ───── */

.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #dbe6fb;
  border-radius: var(--radius);
  overflow: hidden;
}

.camera-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-wrapper canvas {
  display: none;
}

.camera-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem;
  background: linear-gradient(transparent, rgba(39, 54, 77, 0.55));
}

.btn-capture {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid #f8fbff;
  background: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.btn-capture:active {
  transform: scale(0.9);
}

.btn-flip {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(248, 252, 255, 0.28);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.btn-flip:active {
  background: rgba(248, 252, 255, 0.45);
}

/* ───── Template Chooser ───── */

.template-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0 1rem;
}

.template-scroll-wrapper::-webkit-scrollbar {
  height: 4px;
}

.template-scroll-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.template-scroll-wrapper::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 4px;
}

.template-card {
  scroll-snap-align: center;
  flex: 0 0 70vw;
  max-width: 280px;
  border: 2px solid #dbe4f2;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.template-card:active {
  transform: scale(0.97);
}

.template-card.selected {
  border-color: var(--primary);
}

.template-card img {
  width: 100%;
  aspect-ratio: 8 / 11;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.template-card .template-name {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
}

/* ───── Final Output ───── */

.final-panel {
  text-align: center;
}

.final-image {
  width: 100%;
  max-height: 70dvh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #ecf3ff;
}

.qr-panel {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.6rem;
  justify-items: center;
  text-align: center;
}

.qr-image {
  width: min(72vw, 220px);
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #ffffff;
  padding: 8px;
  border: 1px solid #d9e4f7;
}

.share-link {
  color: #2f8ccd;
  font-size: 0.85rem;
  text-decoration: underline;
  word-break: break-all;
}

.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 38, 69, 0.58);
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.qr-modal-card {
  width: min(92vw, 360px);
  margin: 0;
  position: relative;
}

.qr-close-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.45rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

/* ───── Buttons ───── */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.actions .btn {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
}

.btn {
  border: 1px solid #c5d3eb;
  color: var(--text);
  background: var(--surface-light);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn:active {
  filter: brightness(0.9);
}

.btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:active {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  border-color: var(--secondary);
  color: #ffffff;
}

/* ───── Status ───── */

.status-text {
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: #2f8ccd;
  margin-top: 0.5rem;
  text-align: center;
}

.status-text.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

/* ───── Loading overlay ───── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 38, 69, 0.58);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #d2def1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-overlay p {
  color: #ffffff;
  font-size: 0.95rem;
}
