:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #dbeafe;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #0b0e14;
  --text-soft: #4b5563;
  --border: #d7dbe2;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --radius-sm: 10px;
  --focus: 0 0 0 3px rgba(37,99,235,.45);
}

[data-theme="dark"] {
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-soft: #1e293b;
  --bg: #0b0e14;
  --surface: #141821;
  --surface-2: #1b2030;
  --text: #f2f4f8;
  --text-soft: #9aa4b2;
  --border: #2a3142;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.5);
  --focus: 0 0 0 3px rgba(59,130,246,.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  z-index: 100;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--blue); display: inline-flex; }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }

.header-actions { display: flex; gap: 8px; }
.btn-icon {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon:active { transform: scale(.96); }
.btn-icon:focus-visible { outline: none; box-shadow: var(--focus); }

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline; }

/* Layout */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 860px) {
  .app-main { grid-template-columns: 1.1fr .9fr; align-items: start; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.tab:focus-visible { outline: none; box-shadow: var(--focus); }

/* Fields */
.fields { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--text-soft); }

input[type="text"], input[type="tel"], input[type="email"], input[type="url"],
textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--focus);
}

.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; color: var(--text-soft); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

.divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.options { display: flex; flex-direction: column; gap: 14px; }
output { font-weight: 700; color: var(--blue); }

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  accent-color: var(--blue);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: 2px solid var(--surface);
}
input[type="range"]:focus-visible { outline: none; box-shadow: var(--focus); }

.form-buttons, .result-buttons { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease, opacity .15s ease;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn { flex: 1 1 auto; min-width: 140px; }

/* Result */
.result-panel { display: flex; flex-direction: column; }
.result-stage { display: flex; flex-direction: column; align-items: center; gap: 12px; flex: 1; }
.canvas-wrap {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
}
#qrCanvas { width: 100%; height: auto; image-rendering: pixelated; display: block; }
.result-meta { font-size: .85rem; color: var(--text-soft); text-align: center; word-break: break-word; margin: 0; }

/* Footer */
.app-footer {
  padding: 16px;
  text-align: center;
  font-size: .8rem;
  color: var(--text-soft);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 90;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 100%;
  padding: 20px;
}
.modal-title { margin: 0 0 8px; font-size: 1.15rem; }
.modal-body { margin: 0 0 18px; color: var(--text-soft); word-break: break-word; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.hidden { display: none !important; }

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