:root {
  --bg-color: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.7);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-color: #a855f7;
  --accent-hover: #9333ea;
  --border-color: rgba(148, 163, 184, 0.1);
  --glass-border: 1px solid rgba(255, 255, 255, 0.1);
  --radius: 16px;
  --transition: all 0.3s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow: hidden;
  /* Prevent scroll on html */
  width: 100%;
  height: 100%;
  position: fixed;
  /* Lock position to prevent bounce/scroll */
  overscroll-behavior: none;
  /* Prevent rubber-banding */
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  width: 100%;
  height: 100%;
  position: fixed;
  /* Lock position to prevent bounce/scroll */
  overflow: hidden;
  /* Prevent scroll on body */
  overscroll-behavior: none;
  /* Prevent rubber-banding */
  touch-action: manipulation;
  /* Prevent accidental zoom */
  display: flex;
  justify-content: center;
  background-image:
    radial-gradient(circle at 0% 0%, rgba(94, 28, 196, 0.25) 0%, transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(196, 83, 243, 0.25) 0%, transparent 55%);
}

@media (max-width: 767px) and (min-height: 680px) {
  /* No specific overrides needed as base styles now enforce lock */
}

@media (min-width: 768px) {
  body {
    align-items: center;
  }
}

#app {
  width: 100%;
  max-width: 480px;
  padding: max(1.5rem, env(safe-area-inset-top)) 0 100px 0;
  /* Space for bottom navbar */
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: all 0.5s ease-in-out;

  /* Enable scrolling within app container */
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Smooth scrolling on iOS */
  touch-action: pan-y;
  /* Allow vertical scroll only */
  overscroll-behavior: none;
  /* Prevent chaining to body */
}

@media (min-width: 768px) {
  body {
    padding: 2rem;
  }

  #app {
    max-height: 90vh;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.05),
      0 30px 60px -12px rgba(0, 0, 0, 0.6),
      0 18px 36px -18px rgba(0, 0, 0, 0.5);
    padding: 20px;
    overflow-y: auto;
    transition: height 0.5s ease-in-out, max-height 0.5s ease-in-out;
  }
}

.app-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.50rem;
  margin-top: 0.50rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 768px) {
  .app-header {
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
  }
}

.app-logo {
  height: 32px;
  width: auto;
  display: block;
}

.subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  margin: 0;
  font-weight: 500;
}

/* Navbar */
.navbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  /* Auto width to fit content */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  background: transparent;
  /* Remove box style */
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  z-index: 1000;
}

@media (min-width: 768px) {
  .navbar {
    /* On desktop, position relative to the phone container */
    position: absolute;
    bottom: 30px;
  }
}

/* Removed .logo styles as it is deleted from HTML */

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  position: relative;
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(12px);
  padding: 4px;
  border-radius: 100px;
  border: var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  width: 240px;
  /* Fixed width for reliable animation */
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 0;
  /* Center text vertically */
  border-radius: 100px;
  cursor: pointer;
  font-weight: 600;
  transition: color 0.3s ease;
  font-size: 1rem;
  z-index: 2;
  /* Above glider */
  text-align: center;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  /* Fix blue flash on mobile */
}

.mode-btn:focus {
  outline: none;
}

.mode-btn.active {
  color: white;
  background: transparent;
  /* Glider provides background */
  box-shadow: none;
}

.glider {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  /* Half width minus padding */
  height: calc(100% - 8px);
  background: var(--accent-color);
  border-radius: 100px;
  transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 1;
}

/* Animation Logic based on active class on buttons */
/* If first button (generator/send) is active, glider stays at 0 */
#btn-generator.active~.glider {
  transform: translateX(0);
}

/* If second button (scanner/receive) is active, glider moves right */
#btn-scanner.active~.glider {
  transform: translateX(100%);
}

/* Main Content */
.container {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* Mask off-screen content */
  transition: all 0.5s ease-in-out;
}

.slider-wrapper {
  display: flex;
  width: 200%;
  /* Two sections side by side */
  transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.slider-wrapper.show-scanner {
  transform: translateX(-50%);
  /* Slide to show second half */
}

.mode-section {
  width: 50%;
  /* Each section takes half of the 200% width */
  padding: 0 20px;
  /* Horizontal padding for mobile */
}

@media (min-width: 768px) {
  .mode-section {
    padding: 0 4px;
  }
}

.card {
  background: transparent;
  backdrop-filter: none;
  border-radius: 0;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: none;
  transition: min-height 0.5s ease-in-out, height 0.5s ease-in-out;
}

/* Center generator input when QR is hidden */
#generator-section .card {
  min-height: 60vh;
  justify-content: center;
  display: flex;
  flex-direction: column;
  margin-top: 1.5rem;
}

#generator-section .card.has-qr {
  min-height: auto;
  justify-content: flex-start;
}

#generator-section .card.has-qr .input-group {
  animation: slideUp 0.8s cubic-bezier(0.4, 0.0, 0.2, 1);
}

@media (min-width: 768px) {
  #generator-section .card {
    min-height: 70vh;
    position: relative;
    margin-top: 2.5rem;
  }

  #generator-section .card.has-qr {
    min-height: 70vh;
    margin-top: 0.5rem;
  }
}

h2 {
  text-align: center;
  font-weight: 600;
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.section-description {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  line-height: 1.4;
}

/* Inputs */
.input-group {
  position: relative;
  width: 100%;
}

.input-group input {
  width: 100%;
  padding: 0.875rem;
  padding-right: 3rem;
  /* Space for toggle button */
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: var(--transition);
}

.input-group input::placeholder {
  color: rgba(255, 255, 255, 0.8);
}

.input-group input:focus {
  outline: none;
  border-color: rgba(148, 163, 184, 0.8);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-primary);
  box-shadow: none;
}

.input-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px;
  color: var(--text-secondary);
  z-index: 10;
}

.input-icon:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

/* QR Display */
.qr-display {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  padding: 0.75rem;
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.6s ease 0.3s both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  0% {
    transform: translateY(20vh);
  }

  100% {
    transform: translateY(0);
  }
}

.qr-instruction {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: .5rem 0;
  animation: fadeIn 0.6s ease 0.4s both;
}

@media (min-width: 768px) {
  .qr-instruction {
    padding-bottom: 4rem;
  }
}

.timer-highlight {
  display: block;
  color: var(--accent-color);
  font-weight: 600;
  margin-top: 0.25rem;
}

.scanner-instruction {
  text-align: center;
  color: var(--text-primary);
  font-size: 1.0rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
}

#qr-canvas {
  max-width: 100%;
  display: none;
  /* Hidden initially */
}

#qr-canvas.visible {
  display: block;
  animation: fadeIn 0.5s ease;
}

.placeholder {
  color: rgba(148, 163, 184, 0.6);
  text-align: center;
  font-size: 0.95rem;
}

/* Scanner */
.scanner-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

#btn-camera-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 20;
  padding: 0;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#btn-camera-toggle svg {
  width: 25px;
  height: auto;
}

#btn-camera-toggle.hidden {
  display: none;
}

.scanner-container {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: black;
  position: relative;
}

/* Ensure HTML5-QRCode elements fill the container */
#reader {
  width: 100% !important;
  height: 100% !important;
  border-radius: 12px;
  overflow: hidden;
}

#reader>div {
  width: 100% !important;
  height: 100% !important;
}

#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  border-radius: 12px;
}

/* Style the QR box overlay to align with corners */
#reader__scan_region {
  width: 100% !important;
  height: 100% !important;
  position: relative !important;
  z-index: 10 !important;
}

#reader__dashboard_section {
  display: none !important;
}

/* Ensure QR box border is visible */
#reader__scan_region img {
  opacity: 1 !important;
  z-index: 15 !important;
  position: relative !important;
}

/* Style the shaded region */
#reader__scan_region>div:first-child {
  border: 4px solid rgba(255, 255, 255, 0.9) !important;
  box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.4) !important;
  position: relative !important;
  z-index: 12 !important;
}

.scanner-placeholder {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.scanner-placeholder:hover {
  background: rgba(15, 23, 42, 0.5);
  border-color: rgba(148, 163, 184, 0.25);
}

.scanner-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1rem;
}

.scanner-icon svg {
  color: rgba(148, 163, 184, 0.6);
}

.scanner-placeholder-text {
  color: rgba(148, 163, 184, 0.6);
  font-size: 0.95rem;
  margin: 0;
}

.scanner-container video {
  object-fit: cover;
  border-radius: 12px;
}

/* Result Box */
.result-container {
  background: rgba(15, 23, 42, 0.5);
  padding: 2rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  /* Even brighter border */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  /* Added shadow for pop */
  animation: slideInUp 0.5s ease-in-out;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOutScale {
  from {
    opacity: 1;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

.flash-green {
  background-color: rgba(74, 222, 128, 0.4) !important;
  /* Brighter green */
  border-color: rgba(74, 222, 128, 0.8) !important;
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.3);
  transition: all 0.1s ease;
}

/* Fade out animation for camera tile */
.scanner-container.fade-out {
  animation: fadeOutScale 0.15s ease-in-out forwards;
}

.success-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.success-icon {
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.2s both;
  transition: color 0.3s ease;
  position: relative;
  width: 48px;
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.success-icon svg {
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Default state: Copy icon visible, Check hidden */
.success-icon .icon-copy {
  opacity: 1;
  transform: scale(1);
}

.success-icon .icon-check {
  opacity: 0;
  transform: scale(0.5);
}

/* Copied state: Copy icon hidden, Check visible */
.success-icon.copied {
  color: #4ade80;
}

.success-icon.copied .icon-copy {
  opacity: 0;
  transform: scale(0.5);
}

.success-icon.copied .icon-check {
  opacity: 1;
  transform: scale(1);
}

/* Error state */
.success-icon.error {
  color: #ef4444;
  /* Red */
}

.success-icon.error .icon-copy {
  opacity: 0.5;
  /* Dim copy icon to show disabled */
}


.success-message h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-primary);
  font-weight: 600;
}

.success-message p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

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

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.hidden {
  display: none !important;
}

.actions {
  animation: fadeIn 0.6s ease 0.5s both;
}

/* Buttons */
.action-btn {
  width: 100%;
  padding: 1rem;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.action-btn.small {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.action-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #475569;
}

.action-btn.secondary {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.2);
  /* Much dimmer border */
  color: var(--text-secondary);
}

.action-btn.secondary:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.1);
  transform: translateY(-1px);
}

/* Staggered animations for scan result buttons */
#btn-scan-again {
  animation: slideInUp 0.4s ease-in-out 0.2s both;
}

#btn-resend {
  animation: slideInUp 0.4s ease-in-out 0.4s both;
}


.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.permission-message {
  text-align: center;
  padding: 1rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 12px;
  color: #fca5a5;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Start Screen */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0f172a 0%, #2e1065 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  overflow: hidden;
  /* Prevent scroll within start screen */
}

.start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-content {
  text-align: center;
  max-width: 500px;
  padding: 2rem;
  animation: fadeIn 0.8s ease;
}

.start-logo {
  width: 160px;
  height: auto;
  margin-bottom: 1.5rem;
  display: block;
  margin-left: auto;
  margin-right: auto;
  filter: drop-shadow(0 20px 20px rgba(0, 0, 0, 0.6)) drop-shadow(0 10px 10px rgba(0, 0, 0, 0.25));
}

.start-tagline {
  font-size: 1.25rem;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 2rem 0;
  font-weight: 500;
}

.start-description {
  margin-bottom: 2.5rem;
}

.start-description p {
  color: var(--text-primary);
  font-size: 1.0rem;
  line-height: 1.6;
  margin: 0 0 1rem 0;
}

.start-examples {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-top: 1.5rem;
}

p.highlight-text {
  color: var(--accent-color);
  font-weight: 600;
}

#btn-get-started {
  font-size: 1.1rem;
  padding: 1rem 2.5rem;
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.3),
    0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

/* Flash Overlay */
.flash-overlay {
  position: fixed;
  top: -10vh;
  left: -10vw;
  width: 120vw;
  height: 120vh;
  background-color: white;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 9999;
  transition: opacity 1s ease-out, visibility 0s linear 1s;
}

.flash-overlay.active {
  opacity: 1;
  visibility: visible;
  transition: none;
}

.input-hint-container {
  margin-bottom: 2rem;
  text-align: center;
  padding: 0 1rem;
  opacity: 1;
  max-height: 500px;
  overflow: hidden;
  transition: opacity 0.4s ease-in-out, max-height 0.4s ease-in-out, margin 0.4s ease-in-out;
}

.input-hint-container.fade-out {
  opacity: 0;
  max-height: 0;
  margin-bottom: 0;
  pointer-events: none;
}

.input-hint-container h3 {
  font-size: 1.0rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.input-hint-container p {
  font-size: 1.0rem;
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
}

/* Generator card animation when input is focused */
#generator-section .card {
  transition: transform 0.4s ease-in-out;
}

#generator-section .card.input-focused {
  transform: translateY(-2rem);
}

@media (min-width: 768px) {
  #generator-section .card.input-focused {
    transform: translateY(-1rem);
  }
}