/* ============================================
   Haolei QR Code Generator - Modern UI Design
   ============================================ */

/* CSS Variables - Light Theme (default) */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #10b981;
  --accent: #f59e0b;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-elevated: rgba(255, 255, 255, 0.95);
  --background: #0f172a;
  --background-alt: #1e293b;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-light: rgba(226, 232, 240, 0.8);
  --shadow: rgba(15, 23, 42, 0.08);
  --shadow-lg: rgba(15, 23, 42, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --card-border: rgba(255, 255, 255, 0.6);
  --topbar-bg: rgba(255, 255, 255, 0.95);
  --overlay-bg: rgba(15, 23, 42, 0.7);
}

/* Dark Theme */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-light: #a5b4fc;
  --secondary: #34d399;
  --accent: #fbbf24;
  --surface: #1e293b;
  --surface-alt: #0f172a;
  --surface-elevated: rgba(30, 41, 59, 0.95);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #334155;
  --border-light: rgba(51, 65, 85, 0.8);
  --shadow: rgba(0, 0, 0, 0.2);
  --shadow-lg: rgba(0, 0, 0, 0.3);
  --gradient-bg: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
  --card-bg: rgba(30, 41, 59, 0.9);
  --card-border: rgba(51, 65, 85, 0.6);
  --topbar-bg: rgba(15, 23, 42, 0.95);
  --overlay-bg: rgba(0, 0, 0, 0.8);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gradient-bg);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease;
}

/* Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Header / Topbar
   ============================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: var(--topbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 2.5rem;
}

.topbar-right {
  display: flex;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text);
}

.brand .logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
}

.brand-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.125rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary) 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav {
  display: flex;
  gap: 0.5rem;
}

.nav a {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.nav a:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.nav a.active {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.language-select {
  padding: 0.5rem 2rem 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: all var(--transition);
}

.language-select:hover {
  border-color: var(--primary-light);
}

.language-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ============================================
   Theme Toggle
   ============================================ */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: 0.75rem;
  padding: 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle:hover {
  border-color: var(--primary-light);
  background: var(--surface);
}

.theme-toggle:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: color var(--transition), transform 0.3s ease;
}

.theme-toggle:hover svg {
  color: var(--primary);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
}

/* Light mode: show moon icon (to switch to dark) */
.theme-toggle .icon-moon {
  display: block;
}

/* Dark mode: show sun icon (to switch to light), hide moon */
[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ============================================
   Main Shell Layout
   ============================================ */
.shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  max-width: 1100px;
  margin: 3rem auto;
  padding: 0 2rem 2rem;
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 
    0 4px 6px -1px var(--shadow),
    0 10px 15px -3px var(--shadow-lg);
  border: 1px solid var(--card-border);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.card .brand {
  margin-bottom: 0.5rem;
  justify-content: flex-start;
}

.card .brand .logo {
  width: 48px;
  height: 48px;
}

.card .title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.card .subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

/* ============================================
   Form Elements
   ============================================ */
.field {
  margin-bottom: 1.25rem;
}

.label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

input[type="text"]:hover,
select:hover {
  border-color: var(--primary-light);
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

input[type="text"]::placeholder {
  color: var(--text-light);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

input[type="color"] {
  width: 100%;
  height: 48px;
  padding: 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
  transition: all var(--transition);
}

input[type="color"]:hover {
  border-color: var(--primary-light);
}

input[type="color"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 6px;
}

/* Row Layouts */
.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.row.two {
  grid-template-columns: 1fr;
}

/* ============================================
   Buttons
   ============================================ */
.actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

button {
  flex: 1;
  padding: 0.875rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

button:not(.secondary) {
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

button:not(.secondary):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

button:not(.secondary):active {
  transform: translateY(0);
}

button.secondary {
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
}

button.secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.04);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ============================================
   Preview Card
   ============================================ */
.preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.preview-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.preview-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

#qr {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  min-height: 200px;
  padding: 1.5rem;
  background: var(--surface-alt);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
  transition: all var(--transition);
}

#qr:has(canvas),
#qr:has(img) {
  border: none;
  background: transparent;
  padding: 0;
}

#qr canvas,
#qr img {
  display: block;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* Status Indicator */
.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding: 0.625rem 1rem;
  background: var(--surface-alt);
  border-radius: 100px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--secondary);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================
   Cookie Consent Overlay
   ============================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
  visibility: visible;
  transition: all 0.3s ease;
}

.overlay[aria-hidden="true"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.consent-card {
  max-width: 440px;
  text-align: center;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.consent-card .title {
  font-size: 1.35rem;
  margin-bottom: 0.75rem;
}

.consent-card .subtitle {
  margin-bottom: 1.5rem;
}

.consent-list {
  list-style: none;
  margin-bottom: 1.5rem;
  text-align: left;
}

.consent-list li {
  position: relative;
  padding: 0.625rem 0 0.625rem 2rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.consent-list li:last-child {
  border-bottom: none;
}

.consent-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--secondary) 0%, #34d399 100%);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px;
}

.consent-card .actions {
  justify-content: center;
}

.consent-card button {
  flex: none;
  min-width: 180px;
}

/* ============================================
   Footer
   ============================================ */
.footer {
  padding: 2rem;
  text-align: center;
}

.footer-copy {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.75rem;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.footer-links span {
  color: rgba(255, 255, 255, 0.4);
}

.footer-links a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-links a:hover {
  color: #fff;
}

/* ============================================
   Content Pages (About, Privacy)
   ============================================ */
.content-page {
  max-width: 720px;
  margin: 3rem auto;
  padding: 0 2rem 2rem;
}

.content-page .card {
  padding: 2.5rem;
}

.content-page h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.content-page .lead {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.content-page h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.75rem 0 0.75rem;
}

.content-page h2:first-of-type {
  margin-top: 0;
}

.content-page p {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  line-height: 1.7;
}

.content-page ul {
  margin: 0.75rem 0 1rem 1.5rem;
  color: var(--text-muted);
}

.content-page li {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.content-page a.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all var(--transition);
}

.content-page a.back-link:hover {
  background: rgba(99, 102, 241, 0.15);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    max-width: 540px;
  }

  .topbar-left {
    gap: 1.5rem;
  }

  .brand-name {
    display: none;
  }

  .nav {
    gap: 0.25rem;
  }

  .nav a {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0.625rem 1rem;
  }

  .topbar-left {
    gap: 1rem;
  }

  .brand .logo {
    width: 32px;
    height: 32px;
  }

  .nav a {
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
  }

  .language-select {
    padding: 0.4rem 1.75rem 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .shell {
    margin: 1.5rem auto;
    padding: 0 1rem 1.5rem;
    gap: 1.5rem;
  }

  .card {
    padding: 1.5rem;
  }

  .card .title {
    font-size: 1.25rem;
  }

  .row {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .row .field:first-child {
    grid-column: 1 / -1;
  }

  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .content-page {
    margin: 1.5rem auto;
    padding: 0 1rem 1.5rem;
  }

  .content-page .card {
    padding: 1.5rem;
  }

  .content-page h1 {
    font-size: 1.35rem;
  }
}

/* ============================================
   Animations & Effects
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.card {
  animation: scaleIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.shell .card:nth-child(2) {
  animation-delay: 0.1s;
}

/* Focus Visible */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   Dark Theme Refinements
   ============================================ */
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .language-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .consent-list li::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23022c22' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] #qr canvas,
[data-theme="dark"] #qr img {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .content-page a:not(.back-link) {
  color: var(--primary-light);
}

[data-theme="dark"] .content-page a:not(.back-link):hover {
  color: var(--primary);
}
