:root {
  --font-display: "Outfit", sans-serif;
  --font-body: "Plus Jakarta Sans", sans-serif;

  --bg: #0d1117;
  --bg-accent: #161b22;
  --surface: #161b22;
  --surface-border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-subtle: #6e7681;
  --primary: #7c5cbf;
  --primary-hover: #6e56cf;
  --primary-muted: rgba(124, 92, 191, 0.15);
  --accent: #3b82f6;
  --accent-muted: rgba(59, 130, 246, 0.12);
  --button-bg: #21262d;
  --button-hover: #30363d;
  --input-bg: #0d1117;
  --focus-ring: rgba(124, 92, 191, 0.35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

html[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-accent: #ffffff;
  --surface: #ffffff;
  --surface-border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-subtle: #8b949e;
  --primary: #7c5cbf;
  --primary-hover: #6e56cf;
  --primary-muted: rgba(124, 92, 191, 0.1);
  --accent: #2563eb;
  --accent-muted: rgba(37, 99, 235, 0.1);
  --button-bg: #f3f4f6;
  --button-hover: #e5e7eb;
  --input-bg: #f6f8fa;
  --focus-ring: rgba(124, 92, 191, 0.25);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 1.5rem;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

.app-container {
  width: 100%;
  max-width: 1040px;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─── */

.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0.5rem 0;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  user-select: none;
}

.app-header h1 span {
  color: var(--primary);
}

.badge-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 100px;
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: border-color 0.2s, background 0.2s;
  white-space: nowrap;
}

.badge-link:hover {
  border-color: var(--primary);
}

.badge-link svg {
  width: 12px;
  height: 12px;
}

.header-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-subtle);
  font-weight: 500;
}

/* ─── Main Layout ─── */

.main-layout {
  display: grid;
  grid-template-columns: 324px 1fr;
  gap: 1.125rem;
  flex: 1;
  min-height: 0;
}

/* ─── Cards ─── */

.card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

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

.controls-panel {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 200px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-border) transparent;
}

.controls-panel::-webkit-scrollbar {
  width: 5px;
}

.controls-panel::-webkit-scrollbar-track {
  background: transparent;
}

.controls-panel::-webkit-scrollbar-thumb {
  background: var(--surface-border);
  border-radius: 4px;
}

/* Theme Toggle */

.theme-toggle {
  display: flex;
  background: var(--button-bg);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0;
}

.theme-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.theme-btn:hover {
  color: var(--text);
}

.theme-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ─── Form ─── */

.config-form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.input-group {
  margin-bottom: 1rem;
}

.input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.65rem 0.8rem;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

textarea::placeholder {
  color: var(--text-subtle);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
}

.setting.full-width {
  grid-column: span 2;
}

.setting label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.setting select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b949e' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.5rem;
}

.setting select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}

.value-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Color Picker */

.color-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.color-wrap input[type="color"] {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  cursor: pointer;
}

.color-wrap input[type="color"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.color-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: monospace;
  text-transform: uppercase;
}

/* Size Presets */

.size-presets {
  display: flex;
  gap: 0.35rem;
}

.size-preset {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  background: var(--button-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  letter-spacing: 0.03em;
}

.size-preset:hover {
  border-color: var(--primary);
  color: var(--text);
}

.size-preset.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Custom Range */

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-border);
  border-radius: 4px;
  outline: none;
  transition: background 0.15s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text);
  border: 2px solid var(--primary);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Toggle Row */

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toggle-row input[type="checkbox"] {
  width: 36px;
  height: 20px;
  appearance: none;
  background: var(--surface-border);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-row input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-row input[type="checkbox"]:checked {
  background: var(--primary);
}

.toggle-row input[type="checkbox"]:checked::before {
  transform: translateX(16px);
}

.toggle-row input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--focus-ring);
}

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

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.preview-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1rem;
  text-align: center;
}

.preview-card:hover {
  box-shadow: var(--shadow-md);
}

.qr-canvas-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.qr-canvas-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.25s ease;
}

/* Loading Spinner */

.qr-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--surface);
  border-radius: var(--radius);
  z-index: 10;
  transition: opacity 0.25s ease, background 0.3s ease;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.qr-loading span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Empty State */

.qr-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  pointer-events: none;
}

.qr-empty-state svg {
  width: 36px;
  height: 36px;
  opacity: 0.25;
}

.qr-empty-state span {
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-weight: 500;
  text-align: center;
  max-width: 180px;
  line-height: 1.4;
}

.qr-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-subtle);
}

.qr-placeholder svg {
  width: 40px;
  height: 40px;
  opacity: 0.4;
}

.qr-placeholder-text {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.5;
}

/* ─── Action Bar ─── */

.action-bar {
  display: flex;
  gap: 0.4rem;
  width: 100%;
}

.action-bar .btn-primary {
  flex: 2;
}

.action-bar .btn-secondary {
  flex: 1;
}

.format-select {
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0 0.6rem;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  background: var(--button-bg);
  color: var(--text-muted);
  cursor: pointer;
  appearance: none;
  min-width: 62px;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

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

.format-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ─── Buttons ─── */

button {
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 0.55rem 1.25rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-0.5px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn-secondary {
  background: var(--button-bg);
  color: var(--text);
  padding: 0.55rem 1.25rem;
  border: 1px solid var(--surface-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--button-hover);
  border-color: var(--text-subtle);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.55rem 0.75rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--button-bg);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Status ─── */

.status-message {
  text-align: center;
  font-size: 0.8rem;
  min-height: 1.2rem;
  color: var(--text-muted);
}

/* ─── Footer ─── */

.app-footer {
  margin-top: 1.25rem;
  padding: 0.9rem 0;
  text-align: center;
  color: var(--text-subtle);
  font-size: 0.75rem;
  border-top: 1px solid var(--surface-border);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.25rem;
}

.footer-links a,
.footer-links button {
  color: var(--text-muted);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s;
}

.footer-links a:hover,
.footer-links button:hover {
  color: var(--primary);
}

/* ─── Modal ─── */

#privacy-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#privacy-modal[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
}

.modal-glass {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  padding: 1.75rem;
  z-index: 1;
  transform: translateY(12px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s, border-color 0.2s;
}

#privacy-modal[aria-hidden="false"] .modal-content {
  transform: translateY(0);
}

.modal-content h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

.scroll-area {
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 1.5rem;
  padding-right: 0.75rem;
}

.scroll-area p {
  margin-bottom: 0.85rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.scroll-area p strong {
  color: var(--text);
}

.modal-content .btn-primary {
  width: 100%;
  padding: 0.6rem;
}

/* ─── Toasts ─── */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-weight: 500;
  font-size: 0.8rem;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.toast-out {
  animation: fadeOut 0.2s ease forwards;
}

/* ─── Animations ─── */

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

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(80px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(6px); }
}

/* ─── Scanner Modal ─── */

#scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#scanner-modal[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
}

#scanner-modal .modal-glass {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.scanner-modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  z-index: 1;
  transform: translateY(12px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s, border-color 0.2s;
}

#scanner-modal[aria-hidden="false"] .scanner-modal-content {
  transform: translateY(0);
}

#scannerVideo {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #000;
}

.scanner-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.scanner-hint {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ─── Utility ─── */

.hidden {
  display: none !important;
}

/* ─── Responsive ─── */

@media (max-width: 900px) {
  body {
    padding: 0.75rem;
  }

  .main-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }

  .tagline {
    display: none;
  }

  .controls-panel {
    max-height: none;
  }

}

@media (max-width: 500px) {
  body {
    padding: 0.5rem;
  }

  .app-header {
    flex-wrap: wrap;
  }

  .app-header h1 {
    font-size: 1.1rem;
  }

  .badge-link {
    font-size: 0.65rem;
  }

  .controls-panel {
    padding: 1rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .setting.full-width {
    grid-column: span 1;
  }

  .action-bar {
    flex-wrap: wrap;
  }

  .action-bar .btn-primary {
    flex: 1 1 100%;
    order: -1;
  }

  .action-bar .btn-secondary,
  .action-bar .btn-ghost,
  .format-select {
    flex: 1;
  }

  .preview-card {
    padding: 1rem;
  }

}
