:root {
  --bg: #f4f6fb;
  --bg-card: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-soft: #dbeafe;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-card: #111827;
    --fg: #e2e8f0;
    --muted: #94a3b8;
    --border: #1f2937;
    --accent: #60a5fa;
    --accent-fg: #0b1220;
    --accent-soft: #1e293b;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 100%);
  color: var(--fg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: 0.2px; }
.brand .logo { font-size: 22px; }
.brand .tagline { color: var(--muted); font-size: 13px; }

.lang-toggle {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  box-shadow: var(--shadow);
}
.lang-btn {
  border: 0; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 13px; padding: 6px 10px; border-radius: 999px;
  cursor: pointer;
}
.lang-btn[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-fg);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.dropzone {
  margin-top: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 220px;
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone img {
  display: none;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
}
.dropzone.has-image img { display: block; }
.dropzone.has-image .placeholder { display: none; }

.placeholder { text-align: center; padding: 24px; }
.placeholder .big { font-size: 42px; }

.buttons {
  display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap;
}
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--fg); font-weight: 600; font-size: 14px;
  text-decoration: none; user-select: none;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); color: var(--accent-fg); border-color: var(--accent);
  margin-left: auto;
}
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--bg-card); }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  display: none; animation: spin 0.7s linear infinite;
}
.btn.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.results h2 { margin: 0 0 8px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .btn.primary { margin-left: 0; flex: 1; justify-content: center; }
  .buttons .btn { flex: 1; justify-content: center; }
}

.method header { margin-bottom: 8px; }
.method h3 { margin: 0; font-size: 16px; }
.method.is-pending {
  position: relative;
}
.method.is-pending::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: var(--radius);
  background: linear-gradient(110deg,
    transparent 0%,
    color-mix(in srgb, var(--accent) 8%, transparent) 50%,
    transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  pointer-events: none;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.serial-block {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  text-align: center;
}
.serial-label {
  display: block; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px;
}
.serial {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 28px; font-weight: 700; letter-spacing: 0.08em;
  word-break: break-all;
}
.serial.is-empty { color: var(--muted); font-weight: 500; font-size: 18px; letter-spacing: normal; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }

.error {
  margin-top: 12px;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

footer {
  text-align: center; padding: 16px;
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.confidence-bar {
  display: inline-block; min-width: 80px;
  height: 8px; border-radius: 4px;
  background: var(--border); position: relative; overflow: hidden;
  vertical-align: middle; margin-right: 8px;
}
.confidence-bar > span {
  display: block; height: 100%;
  background: var(--good); transition: width 0.3s ease;
}
.confidence-bar.low > span { background: var(--bad); }
.confidence-bar.mid > span { background: var(--warn); }
