:root {
  /* Dark mode — default */
  --bg: #0e1117;
  --surface: #161b27;
  --surface-2: #1d2535;
  --border: #2a3448;
  --border-focus: #12a8e0;
  --text: #dde6f0;
  --text-muted: #6b82a0;
  --accent: #12a8e0;
  --accent-dark: #0f8fbf;
  --accent-light: #091a28;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 6px 20px rgba(0,0,0,0.25);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
  --transition: 0.15s ease;
}

html[data-theme="light"] {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f5f8fb;
  --border: #dce6ef;
  --border-focus: #0e9dd6;
  --text: #0f1f2e;
  --text-muted: #5a7185;
  --accent: #0e9dd6;
  --accent-dark: #0880b3;
  --accent-light: #e5f5fc;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.07);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 2rem;
}

.app-header {
  text-align: center;
  margin-bottom: 2.5rem;
  position: relative;
}

/* ── Theme toggle ── */

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  flex-shrink: 0;
}

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

/* Dark mode: show sun, hide moon */
.icon-moon { display: none; }
.icon-sun  { display: block; }

/* Light mode: show moon, hide sun */
html[data-theme="light"] .icon-sun  { display: none; }
html[data-theme="light"] .icon-moon { display: block; }

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.header-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

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

.header-tagline {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin-bottom: 0.625rem;
}

.header-credit {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0.75rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.header-credit strong {
  color: var(--accent);
}

.header-credit:hover {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.header-credit svg {
  opacity: 0.6;
  flex-shrink: 0;
}

.app-main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.25rem;
  align-items: start;
}

/* ── Panels ── */

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.section {
  margin-bottom: 1.75rem;
}

.section:last-of-type {
  margin-bottom: 1.25rem;
}

.section h3 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.875rem;
}

/* ── Tabs ── */

.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.tab:not(.active):hover {
  color: var(--text);
}

/* ── Forms ── */

.form label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  margin-top: 0.875rem;
}

.form label:first-child {
  margin-top: 0;
}

.form input[type="text"],
.form input[type="url"],
.form input[type="email"],
.form input[type="tel"],
.form input[type="password"],
.form select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

.form input:focus,
.form select:focus {
  border-color: var(--border-focus);
}

.form select {
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.875rem;
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}

.hidden {
  display: none !important;
}

/* ── Drop zone ── */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
  overflow: hidden;
}

.drop-content {
  padding: 2rem 1rem;
  text-align: center;
}

.drop-icon {
  color: var(--text-muted);
  margin-bottom: 0.625rem;
  display: flex;
  justify-content: center;
}

.drop-content p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.drop-hint {
  font-size: 0.75rem !important;
  margin-top: 0.2rem;
  opacity: 0.6;
}

.link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.drop-zone.has-image {
  border-style: solid;
  border-color: var(--border);
}

.drop-preview {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}

/* ── Palette ── */

.palette-area {
  margin-top: 0.75rem;
}

.palette-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 2px;
}

.palette-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.palette-chip {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform var(--transition), opacity var(--transition), border-color var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18), inset 0 0 0 1px rgba(255,255,255,0.1);
  flex-shrink: 0;
  position: relative;
}

.palette-chip[draggable="true"] {
  cursor: grab;
}

.palette-chip[draggable="true"]:active {
  cursor: grabbing;
}

.palette-chip.on {
  border-color: var(--text);
  transform: scale(1.12);
}

.palette-chip.off {
  opacity: 0.28;
  transform: scale(0.92);
}

.palette-chip.dragging {
  opacity: 0.35;
  transform: scale(1);
}

.palette-chip.drag-over {
  box-shadow: -4px 0 0 var(--accent), 0 0 0 2px var(--accent-light);
}

.weight-badge {
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--text-muted);
  color: var(--surface);
  font-size: 8px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, background var(--transition);
  line-height: 1;
  user-select: none;
}

.weight-badge:hover {
  transform: scale(1.25);
}

.weight-badge[data-w="2"] {
  background: var(--accent);
  width: 16px;
  height: 16px;
}

.weight-badge[data-w="3"] {
  background: var(--accent);
  width: 18px;
  height: 18px;
  font-size: 9px;
  bottom: -6px;
  right: -6px;
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* ── Options ── */

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

.option-full {
  grid-column: 1 / -1;
}

.option label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.option select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.option select:focus {
  border-color: var(--border-focus);
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.color-picker-row input[type="color"] {
  width: 42px;
  height: 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 3px;
  background: var(--surface);
  outline: none;
}

.color-picker-row span {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.option input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin-top: 0.25rem;
}

/* ── Generate button ── */

.btn-generate {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
}

.btn-generate:hover {
  background: var(--accent-dark);
  box-shadow: 0 4px 14px rgba(14, 157, 214, 0.4);
  transform: translateY(-1px);
}

.btn-generate:active {
  transform: translateY(0);
  box-shadow: none;
}


/* ── Preview panel ── */

.panel-preview {
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.preview-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
}

.preview-container {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

#qrCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  color: var(--text-muted);
}

.empty-icon {
  opacity: 0.25;
}

.preview-empty p {
  font-size: 0.8125rem;
}

/* ── Readability badge ── */

.readability-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 100px;
  font-size: 0.8125rem;
  font-weight: 500;
}

/* Dark mode (default) */
.readability-badge.good {
  background: #0a2a18;
  color: #4ade80;
}

.readability-badge.warn {
  background: #2a1e00;
  color: #fbbf24;
}

/* Light mode overrides */
html[data-theme="light"] .readability-badge.good {
  background: #e7f9f0;
  color: #1a7a44;
}

html[data-theme="light"] .readability-badge.warn {
  background: #fff7e0;
  color: #7a5c00;
}

/* ── Download button ── */

.btn-download {
  padding: 0.7rem 1.5rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-download:hover {
  background: var(--surface);
  border-color: var(--text);
}

/* ── Footer ── */

.app-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.footer-link {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.footer-link:hover {
  color: var(--text);
  background: var(--surface);
}

.footer-link strong {
  color: var(--accent);
}

.footer-logo {
  width: 13px;
  height: 13px;
  object-fit: contain;
}

/* ── Responsive ── */

@media (max-width: 700px) {
  .app {
    padding: 1.5rem 1rem 3rem;
  }

  .app-main {
    grid-template-columns: 1fr;
  }

  .panel-preview {
    position: static;
  }

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