/* ============================================================
   QR Code Generator — theme tokens
   ============================================================ */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: 160ms ease;
}

html[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-accent: radial-gradient(1200px 480px at 50% -10%, #e8ecf5 0%, transparent 70%);
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --stage: #eceef2;
  --text: #14181f;
  --muted: #6b7280;
  --border: #e2e5ea;
  --border-strong: #d3d7de;
  --accent: #3b6ef5;
  --accent-hover: #2f5ce0;
  --accent-contrast: #ffffff;
  --danger: #d14343;
  --shadow: 0 1px 2px rgba(16, 20, 28, 0.05),
            0 12px 32px -12px rgba(16, 20, 28, 0.16);
  --stage-shadow: inset 0 0 0 1px rgba(16, 20, 28, 0.08);
}

html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-accent: radial-gradient(1200px 480px at 50% -10%, #1b2030 0%, transparent 70%);
  --surface: #171a21;
  --surface-2: #1e222b;
  --stage: #10131a;
  --text: #e8eaee;
  --muted: #98a0ad;
  --border: #262b35;
  --border-strong: #333947;
  --accent: #f0a35e;
  --accent-hover: #f5b175;
  --accent-contrast: #1a1204;
  --danger: #f07a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4),
            0 18px 40px -18px rgba(0, 0, 0, 0.75);
  --stage-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

/* Author `display` rules below would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-accent);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

h1, h2, p { margin: 0; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}
a:hover { border-bottom-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   Header
   ============================================================ */

.site-header {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand-text p {
  font-size: 13.5px;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition);
}
.theme-toggle:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

/* Show only the icon for the theme you'd switch TO */
html[data-theme="light"] .icon-sun,
html[data-theme="dark"] .icon-moon { display: none; }

.icon {
  display: block;
  flex-shrink: 0;
}

/* ============================================================
   Layout
   ============================================================ */

.layout {
  max-width: 1080px;
  margin: 24px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: background var(--transition), border-color var(--transition);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.preview {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ============================================================
   Fields
   ============================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

label,
.field-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.counter,
output,
.range-legend {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  transition: border-color var(--transition), background var(--transition);
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.55;
}

textarea::placeholder { color: var(--muted); opacity: 0.75; }

textarea:hover,
select:hover { border-color: var(--border-strong); }

textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

select {
  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='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 36px;
  cursor: pointer;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.hint.is-warning { color: var(--danger); }

/* ============================================================
   Range slider
   ============================================================ */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition);
}

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

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.range-legend {
  display: flex;
  justify-content: space-between;
  margin-top: -2px;
}

/* ============================================================
   Colors
   ============================================================ */

.color-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.color-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px 6px 6px;
  transition: border-color var(--transition);
}

.color-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }

input[type="text"]#fgHex,
input[type="text"]#bgHex {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  padding: 0;
}
input[type="text"]#fgHex:focus,
input[type="text"]#bgHex:focus { outline: none; }

/* ============================================================
   Buttons
   ============================================================ */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition),
              opacity var(--transition);
}

.btn:not(:disabled):active { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:not(:disabled):hover {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn-text {
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  margin-left: auto;
}
.btn-text:hover { color: var(--text); }

/* ============================================================
   Preview
   ============================================================ */

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}

.badge {
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 340px;
  padding: 24px;
  border-radius: var(--radius-md);
  background: var(--stage);
  box-shadow: var(--stage-shadow);
  overflow: hidden;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  opacity: 0.6;
  padding: 24px 0;
}

.placeholder p { font-size: 13.5px; max-width: 220px; }

#qrCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 6px 24px -10px rgba(0, 0, 0, 0.45);
  animation: pop 220ms cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

.status {
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.status.is-error { color: var(--danger); font-weight: 500; }
.status.is-success { color: var(--accent); font-weight: 500; }

/* ============================================================
   Footer
   ============================================================ */

.site-footer {
  max-width: 1080px;
  margin: 28px auto 0;
  padding: 0 24px 40px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 10px;
  margin-top: 14px;
}

.footer-links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  transition: border-color var(--transition), color var(--transition);
}

.footer-links a:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; order: -1; }
  .site-header { padding-top: 28px; }
}

@media (max-width: 520px) {
  .brand-text p { display: none; }
  .panel { padding: 18px; }
  .stage { min-height: 280px; padding: 18px; }
  .btn-text { margin-left: 0; width: 100%; }
}

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