:root[data-theme="dark"] {
  --bg: #0d0f1a;
  --surface: #161a2b;
  --surface-2: #1d2238;
  --border: #2a3050;
  --text: #eef0f8;
  --muted: #aab0c8;
  --accent: #3b82f6;
  --accent-2: #93c5fd;
  --ok: #4ade80;
  --err: #f87171;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f7fb;
  --surface-2: #eef0f5;
  --border: #d8dce6;
  --text: #111827;
  --muted: #5b6478;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #15803d;
  --err: #b91c1c;
}

/* Same tokens on elements without a data-theme attribute (plain <html> / edge cases) */
:root:not([data-theme]) {
  --bg: #0d0f1a;
  --surface: #161a2b;
  --surface-2: #1d2238;
  --border: #2a3050;
  --text: #eef0f8;
  --muted: #aab0c8;
  --accent: #3b82f6;
  --accent-2: #93c5fd;
  --ok: #4ade80;
  --err: #f87171;
}

/* Reuse the same tokens on body.theme-dark / body.theme-light (app.js class path) */
body.theme-dark {
  --bg: #0d0f1a;
  --surface: #161a2b;
  --surface-2: #1d2238;
  --border: #2a3050;
  --text: #eef0f8;
  --muted: #aab0c8;
  --accent: #3b82f6;
  --accent-2: #93c5fd;
  --ok: #4ade80;
  --err: #f87171;
}

body.theme-light {
  --bg: #ffffff;
  --surface: #f6f7fb;
  --surface-2: #eef0f5;
  --border: #d8dce6;
  --text: #111827;
  --muted: #5b6478;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #15803d;
  --err: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.15s ease, color 0.15s ease;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px clamp(14px, 4vw, 24px);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  transition: background 0.15s ease;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
}
.brand .amp { color: var(--accent-2); }
.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.language-toggle,
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  touch-action: manipulation;
  transition: border-color 0.15s ease;
}
.language-toggle:hover,
.theme-toggle:hover { border-color: var(--accent); }
.language-toggle {
  min-width: 44px;
}
.language-toggle__current {
  color: var(--accent-2);
  font-weight: 700;
}
.language-toggle__label {
  white-space: nowrap;
}
.theme-toggle svg { width: 14px; height: 14px; flex: none; }
.language-toggle:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html[dir="rtl"] body {
  text-align: right;
}
html[dir="rtl"] .site-header,
html[dir="rtl"] .header-actions,
html[dir="rtl"] .brand {
  direction: rtl;
}
html[dir="rtl"] .row,
html[dir="rtl"] .downlinks,
html[dir="rtl"] table {
  direction: rtl;
}
html[dir="rtl"] th,
html[dir="rtl"] td {
  text-align: right;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 clamp(14px, 4vw, 20px) 60px;
}

.hero { padding: 40px 0 8px; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.25; margin: 0 0 14px; }
.hero p { color: var(--muted); max-width: 68ch; }
.hero strong { color: var(--text); }
.hero a { color: var(--accent-2); }

/* App card */
.app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 0 var(--border);
  margin-top: 28px;
  overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.panel { padding: clamp(14px, 4vw, 24px); }
.hidden { display: none !important; }

/* minmax(0, 1fr) lets tracks shrink below their content's intrinsic width, so
   long <select> options or the canvas can't blow the grid past the card edge. */
.generate-grid, .scan-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
}
.generate-form, .preview-col, .scan-cam, .scan-file { min-width: 0; }
@media (max-width: 780px) {
  .generate-grid, .scan-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
}

label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
textarea#qr-text {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  transition: border-color 0.15s ease;
}
textarea#qr-text:focus { outline: none; border-color: var(--accent); }
/* auto-fit + minmax: two fields side by side when there is room, one when there isn't
   (e.g. each half of the desktop grid), so the <select> never gets crushed. */
.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 12px;
  margin-top: 14px;
}
.field { min-width: 0; }
input[type="color"] {
  width: 100%;
  height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
input[type="number"], select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
select { text-overflow: ellipsis; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 10px 0 0; }
.hint a { color: var(--accent-2); }

.preview-col { text-align: center; }
#qr-canvas {
  width: min(100%, 340px);
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 10px;
  image-rendering: pixelated;
}
.downlinks { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 420px) {
  .downlinks { flex-direction: column; align-items: stretch; }
  .downlinks .btn { width: 100%; }
}
.btn {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.status { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; margin-top: 10px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* Scan panel */
#video {
  width: 100%;
  max-width: 380px;
  border-radius: 10px;
  background: #000;
  display: none;
}
#video.on { display: block; }
.scan-file h2, .scan-cam h2 { font-size: 1.05rem; margin: 0 0 12px; }
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 20px;
}
.dropzone.drag { border-color: var(--accent); color: var(--accent-2); }
.result {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
  word-break: break-all;
}
.result p { margin: 0 0 6px; }
.result code { font-size: 0.9rem; }
.result img { width: 100%; max-width: 320px; border-radius: 8px; }

/* Content sections */
.why, .faq, .open-source { margin-top: 48px; }
h2 { font-size: 1.4rem; line-height: 1.3; }
table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--accent-2); font-weight: 600; }
tbody td:first-child { color: var(--text); font-weight: 600; white-space: nowrap; }
tbody td { color: var(--muted); }
@media (max-width: 640px) { tbody td:first-child { white-space: normal; } }

.faq h3 { font-size: 1.02rem; margin: 22px 0 6px; }
.faq p, .open-source p { color: var(--muted); margin: 0; max-width: 72ch; }
.faq a, .open-source a { color: var(--accent-2); }
.open-source code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.85rem;
  color: var(--accent-2);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px 40px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer a { color: var(--accent-2); }
