html.mc-theme-light {
  --bg: #eff3f8;
  --surface: #ffffff;
  --surface-alt: #f6f8fc;
  --border: #cfd8e6;
  --text: #152236;
  --muted: #5f6f84;
  --accent: #2f83dd;
  --accent-2: #1d6cbc;
  --danger: #c93d3d;
  --shadow: 0 18px 40px rgba(19, 32, 47, 0.13);
  --focus: rgba(47, 131, 221, 0.25);
  --radius: 14px;
}

html.mc-theme-dark {
  --bg: #101722;
  --surface: #1a2435;
  --surface-alt: #151f2f;
  --border: #2e3b54;
  --text: #e7edf5;
  --muted: #99aac0;
  --accent: #4da4ff;
  --accent-2: #2f84db;
  --danger: #ff7b7b;
  --shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
  --focus: rgba(77, 164, 255, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: clamp(8px, 1.6vh, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 70% 45% at 50% -15%, color-mix(in srgb, var(--accent) 25%, transparent), transparent),
    var(--bg);
}

.app-shell {
  width: 100%;
  max-width: 1160px;
  max-height: calc(100dvh - clamp(16px, 3.2vh, 48px));
  padding: clamp(12px, 2vh, 24px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}

.topbar .barcode-type-field {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin: 0;
  padding: 0;
  border-bottom: 0;
  text-align: left;
}

.topbar .barcode-type-field select {
  /* Match the scan button exactly so they share the same baseline + height. */
  width: auto;
  max-width: min(420px, 90vw);
  font-size: clamp(0.82rem, 0.55rem + 0.45vh, 0.95rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  /* Extra right-padding leaves room for the custom chevron icon. */
  padding: clamp(6px, 1vh, 10px) clamp(32px, 2.6vw, 42px) clamp(6px, 1vh, 10px) clamp(12px, 1.2vw, 18px);
  border-radius: 10px;
  text-align: left;
  text-align-last: left;
  color: var(--text);
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23808a99' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right clamp(10px, 1vw, 14px) center / 14px 14px,
    color-mix(in srgb, var(--accent) 8%, var(--surface));
  box-shadow: 0 4px 10px -8px color-mix(in srgb, var(--accent) 55%, transparent);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.2s ease, background-color 0.15s ease;
}

.topbar .barcode-type-field select:hover {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--border));
  box-shadow: 0 6px 14px -8px color-mix(in srgb, var(--accent) 60%, transparent);
}

.topbar .barcode-type-field select:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

/* The native list of <option>s falls back to the OS palette, so make sure
   it remains legible on both themes. */
.topbar .barcode-type-field select option {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.topbar-scan-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding: clamp(6px, 1vh, 10px) clamp(12px, 1.2vw, 18px);
  border-radius: 10px;
  font-size: clamp(0.82rem, 0.55rem + 0.45vh, 0.95rem);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  /* Transparent 1px border so the visual height equals the dropdown,
     which has a 1px accent-tinted border of its own. */
  border: 1px solid transparent;
}

.topbar-scan-icon {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
}

.chrome-stack {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.app-footer {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px -10px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  pointer-events: auto;
}

.app-footer-version {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 600;
  color: var(--text);
}

.app-footer-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.app-footer-link:hover,
.app-footer-link:focus-visible {
  text-decoration: underline;
}

.app-footer-sep {
  opacity: 0.55;
}

@media (max-width: 520px) {
  .app-footer {
    right: 50%;
    transform: translateX(50%);
    bottom: 6px;
    font-size: 0.66rem;
    padding: 4px 10px;
    gap: 6px;
  }
}

.theme-switcher {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.lang-switcher {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.theme-switcher .theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  margin: 0;
  padding: 4px;
  line-height: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.theme-switcher .theme-btn:hover:not(:disabled) {
  opacity: 0.92;
  transform: scale(1.06);
}

.theme-switcher .theme-btn.active {
  opacity: 1;
  border-color: var(--accent);
}

.theme-switcher .theme-btn svg {
  display: block;
  width: 22px;
  height: 22px;
}

.lang-switcher .lang-btn {
  margin: 0;
  padding: 2px 4px;
  line-height: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.lang-switcher .lang-flag {
  display: block;
  line-height: 0;
}

.lang-switcher .lang-flag svg {
  display: block;
  width: 30px;
  height: auto;
  vertical-align: middle;
  border-radius: 2px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 15%, transparent);
}

.lang-switcher .lang-btn:hover:not(:disabled) {
  opacity: 0.95;
  transform: scale(1.08);
}

.lang-switcher .lang-btn.active {
  opacity: 1;
  border-color: var(--accent);
}

html.mc-theme-dark .theme-switcher,
html.mc-theme-dark .lang-switcher {
  background: rgba(18, 18, 24, 0.98);
  border-color: rgba(255, 255, 255, 0.07);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

html.mc-theme-dark .theme-switcher .theme-btn {
  color: #a6a6b4;
}

html.mc-theme-dark .theme-switcher .theme-btn:hover:not(:disabled) {
  color: #c4c4d0;
}

html.mc-theme-dark .theme-switcher .theme-btn.active {
  color: #d8d8e4;
  border-color: #4580c4;
}

.topbar-label,
label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lead {
  color: var(--muted);
  font-size: clamp(0.82rem, 0.55rem + 0.45vh, 0.92rem);
  line-height: 1.45;
  margin: clamp(8px, 1.4vh, 14px) 0 clamp(8px, 1.4vh, 16px);
  flex: 0 0 auto;
}

.panel {
  padding: clamp(10px, 1.6vh, 16px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(8px, 1.4vh, 16px);
  flex: 1 1 auto;
  min-height: 0;
}

.barcode-type-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0 0 clamp(8px, 1.4vh, 14px);
  padding: 0 0 clamp(8px, 1.4vh, 14px);
  border-bottom: 1px dashed var(--border);
  text-align: center;
}

.barcode-type-field select {
  width: 100%;
  max-width: 280px;
  text-align: center;
  text-align-last: center;
}

.qr-only.is-hidden,
.barcode-only.is-hidden,
.generator-only.is-hidden,
.scanner-only.is-hidden,
.scanner-result.is-hidden {
  display: none !important;
}

.scanner-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.scanner-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.scanner-status[data-tone="error"] {
  color: var(--danger, #c0392b);
}

.scanner-stage {
  position: relative;
  background: #000;
  border: 1px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  max-height: 100%;
}

.scanner-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.scanner-overlay {
  position: absolute;
  inset: 12% 12%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.scanner-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.scanner-result-meta {
  display: flex;
  gap: 8px;
  align-items: center;
}

.scanner-result-format {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  color: #fff;
}

.scanner-result-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  white-space: pre-wrap;
  color: var(--text, inherit);
}

.scanner-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scanner-open-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.editor-column {
  min-width: 0;
}

.preview-column {
  min-width: 0;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: clamp(8px, 1.2vh, 12px);
}

.field-grid .field {
  margin-top: 0;
}

input[type="text"],
input[type="url"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  padding: clamp(8px, 1.2vh, 11px) 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: clamp(0.86rem, 0.55rem + 0.5vh, 0.95rem);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="file"] {
  padding: clamp(7px, 1vh, 9px) 10px;
  font-size: clamp(0.78rem, 0.55rem + 0.35vh, 0.86rem);
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

input:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.option-row {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: clamp(8px, 1.2vh, 12px);
}

.option-row input[type="checkbox"] {
  margin-top: 2px;
}

.option-row label {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 500;
}

.option-hint {
  margin: 4px 0 0 24px;
  color: var(--muted);
  font-size: clamp(0.72rem, 0.5rem + 0.35vh, 0.8rem);
  line-height: 1.4;
}

.logo-block {
  margin-top: clamp(6px, 1vh, 10px);
  margin-left: 24px;
}

.logo-size-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#logo-size {
  flex: 1;
}

#logo-size-value {
  color: var(--muted);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  min-width: 3rem;
  text-align: right;
}

.sub-label {
  margin: 8px 0 6px;
}

.actions {
  margin-top: clamp(10px, 1.4vh, 14px);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.qr-size-control {
  margin-top: clamp(10px, 1.4vh, 14px);
}

.qr-size-row {
  display: grid;
  grid-template-columns: minmax(4.8rem, auto) minmax(160px, 1fr) minmax(92px, 120px);
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.qr-size-value {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.qr-size-number {
  min-width: 0;
}

@media (max-width: 560px) {
  .qr-size-row {
    grid-template-columns: auto 1fr;
  }
  .qr-size-number {
    grid-column: 1 / -1;
  }
}

button:not(.theme-btn):not(.lang-btn) {
  border: 0;
  border-radius: 9px;
  padding: clamp(8px, 1.2vh, 11px) clamp(12px, 1.6vw, 18px);
  font: inherit;
  font-size: clamp(0.86rem, 0.55rem + 0.5vh, 0.95rem);
  font-weight: 600;
  cursor: pointer;
}

button:not(.theme-btn):not(.lang-btn):disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

.btn-secondary {
  color: var(--text);
  background: color-mix(in srgb, var(--border) 85%, transparent);
}

.error {
  min-height: 1.25em;
  margin-top: clamp(6px, 1vh, 11px);
  color: var(--danger);
  font-size: clamp(0.78rem, 0.55rem + 0.35vh, 0.86rem);
  flex: 0 0 auto;
}

.encoded {
  margin-top: 6px;
  color: var(--muted);
  font-size: clamp(0.74rem, 0.5rem + 0.4vh, 0.82rem);
  line-height: 1.4;
  word-break: break-word;
  flex: 0 0 auto;
  max-height: 4.2em;
  overflow-y: auto;
}

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

.encoded a {
  color: var(--accent);
}

.calibrate-row {
  margin: 0 0 clamp(6px, 1vh, 10px);
  padding: clamp(6px, 1vh, 10px) 0;
  flex: 0 0 auto;
}

.calibrate-track {
  position: relative;
  height: 22px;
  background: color-mix(in srgb, var(--border) 60%, transparent);
  border-radius: 5px;
  cursor: ew-resize;
  user-select: none;
  touch-action: none;
  /* The track is the slider thumb area too — its leftmost pixel is the
     ruler origin the user lines up with 0 cm. */
}

.calibrate-track:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.calibrate-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 189px;
  max-width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 5px 3px 3px 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  padding-left: 8px;
  pointer-events: none;
}

.calibrate-bar-label {
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.calibrate-handle {
  position: absolute;
  right: 0;
  top: -4px;
  bottom: -4px;
  width: 8px;
  background: var(--accent-2);
  border: 2px solid var(--surface);
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.calibrate-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(0.68rem, 0.5rem + 0.3vh, 0.78rem);
  line-height: 1.35;
}

.preview {
  margin-top: 0;
  padding: clamp(8px, 1.4vh, 16px);
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  /* Cap preview height so very large render sizes do not push the layout
     below the viewport. The canvas inside is downscaled via max-width/
     max-height while the underlying pixel buffer (used for PNG/PDF
     export) stays at full resolution. */
  max-height: calc(100dvh - clamp(160px, 28vh, 260px));
  overflow: hidden;
}

.preview.hidden {
  display: none;
}

.preview canvas {
  display: block;
  border-radius: 4px;
  background: #ffffff;
  /* No padding / object-fit on the canvas itself: padding on <canvas>
     interacts unpredictably with the bitmap-to-display-box mapping
     across browsers (the bitmap sometimes fills the padding-box rather
     than the content-box, which makes the on-screen size off by exactly
     the padding amount). The preview's own border + padding already
     provides the visual "card" framing. */
  max-width: 100%;
  max-height: 100%;
}

.hint {
  margin: clamp(8px, 1.4vh, 14px) 0 0;
  color: var(--muted);
  font-size: clamp(0.72rem, 0.5rem + 0.35vh, 0.8rem);
  line-height: 1.4;
  flex: 0 0 auto;
}

@media (min-width: 980px) {
  .workspace {
    grid-template-columns: minmax(420px, 1fr) minmax(300px, 0.8fr);
    align-items: stretch;
    gap: clamp(12px, 1.8vh, 20px);
  }
  .editor-column {
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
  }
  .preview-column {
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .preview-column .preview {
    flex: 1 1 auto;
    position: static;
  }
}
