:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e0d8;
  --primary: #2d2a4a;
  --primary-contrast: #ffffff;
  --accent: #6d5bd0;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 14px;
  --checker-a: #e5e0d8;
  --checker-b: #f4f1ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14121f;
    --surface: #1e1b2e;
    --text: #f1f2f4;
    --text-muted: #a7a2bd;
    --border: #33304a;
    --primary: #f1f2f4;
    --primary-contrast: #14121f;
    --accent: #a996ff;
    --danger: #f87171;
    --danger-bg: #3a1414;
    --checker-a: #2a2740;
    --checker-b: #322f4d;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.update-banner {
  background: var(--accent);
  color: #fff;
  text-align: center;
  font-size: 13px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.app-header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-refresh {
  width: 16px;
  height: 16px;
}

.icon-refresh.spinning {
  animation: spin 0.8s linear infinite;
}

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

.header-update-check {
  position: relative;
}

.update-check-status {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 20;
}

main#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.app-intro {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 15px;
  margin: 0 0 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field input[type="color"] {
  padding: 4px;
  height: 42px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 8px 0 0;
}

.form-error {
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
  margin: 10px 0 0;
}

.btn {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-small {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
}

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

/* Dropzone */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.dropzone-icon {
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  color: var(--accent);
}

.dropzone p {
  margin: 0 0 4px;
  font-size: 14px;
}

.dropzone strong {
  color: var(--text);
}

/* Progress */

.progress-status {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 10px;
  text-align: center;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.progress-fill.indeterminate {
  width: 100% !important;
  animation: pulse 1.2s ease-in-out infinite;
}

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

/* Preview */

.qr-preview-card {
  text-align: center;
}

.result-toolbar {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.preview-checker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  border-radius: 10px;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: var(--checker-b);
}

.preview-checker img,
.preview-checker canvas {
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  display: block;
}

.download-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* Background swatches */

.swatch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.swatch[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.swatch-transparent {
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-color: var(--checker-b);
}

.swatch-custom {
  margin: 0 0 0 4px;
  min-width: 140px;
}
