: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;
}

@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;
  }
}

* { 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,
.field textarea,
.select-block {
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  width: 100%;
}

.field input[type="color"] {
  padding: 4px;
  height: 42px;
  cursor: pointer;
}

.field input[type="file"] {
  padding: 8px;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.select-block:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

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

.geolocation-row {
  margin-bottom: 14px;
}

.geolocation-row .field-hint {
  margin-top: 6px;
}

.type-fields {
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}

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

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 14px;
}

@media (max-width: 420px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
}

.logo-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.logo-row .field {
  flex: 1;
  min-width: 180px;
  margin-bottom: 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;
}

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

.qr-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
}

#qr-canvas {
  max-width: 100%;
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  border-radius: 8px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  padding: 0 20px;
}

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