/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────── */
:root {
  --font:       -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;

  /* Idle screen */
  --bg:         #F0F0F0;
  --surface:    #FFFFFF;
  --border:     #D8D8D8;
  --label:      #111111;
  --label-2:    #555555;
  --label-3:    #999999;
  --tint:       #1A1A1A;
  --tint-text:  #FFFFFF;
  --row-sep:    #EBEBEB;

  /* Scanner screen */
  --scan-green:       #39FF14;   /* bright green — tracker & UI */
  --scan-green-dim:   rgba(57, 255, 20, 0.18);
  --scan-topbar-bg:   rgba(0,0,0,0.55);
  --scan-bottom-bg:   rgba(0,0,0,0.72);
  --scan-result-bg:   rgba(0,0,0,0.82);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #111111;
    --surface: #1E1E1E;
    --border:  #2E2E2E;
    --label:   #F0F0F0;
    --label-2: #AAAAAA;
    --label-3: #555555;
    --tint:    #F0F0F0;
    --tint-text: #111111;
    --row-sep: #2A2A2A;
  }
}

/* ── Base ──────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;   /* no scroll on root; screens handle their own */
}

body {
  font-family: var(--font);
  font-size: 16px;
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ───────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Idle screen ───────────────────────────────────── */
.idle-inner {
  max-width: 420px;
  margin: 0 auto;
  padding: 56px 20px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.idle-logo {
  width: 44px;
  height: 44px;
  color: var(--label);
  margin-bottom: 10px;
}

.idle-logo svg { width: 100%; height: 100%; }

h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--label);
  margin-bottom: 28px;
}

/* ── Form fields ───────────────────────────────────── */
.idle-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--label-2);
  margin-top: 10px;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--label);
  font-family: var(--font);
  font-size: 16px;
  padding: 12px 40px 12px 14px;
  cursor: pointer;
  outline: none;
}

.select-wrap select:focus {
  border-color: var(--label-2);
}

.chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  color: var(--label-3);
  pointer-events: none;
}

/* ── Scan button ───────────────────────────────────── */
.btn-scan {
  width: 100%;
  padding: 15px;
  background: var(--tint);
  color: var(--tint-text);
  border: none;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  margin-bottom: 32px;
  transition: opacity 0.12s;
}

.btn-scan:active { opacity: 0.75; }
.btn-scan:disabled { opacity: 0.35; pointer-events: none; }

/* ── History section ───────────────────────────────── */
.result-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.result-section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--label-2);
}

.result-section-title span {
  font-weight: 400;
  margin-left: 4px;
}

.link-btn {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--label-2);
  cursor: pointer;
  padding: 2px 0;
}

.link-btn:active { opacity: 0.5; }
.link-btn.light { color: rgba(255,255,255,0.6); }
.link-btn.light:active { opacity: 0.4; }

.empty-msg {
  font-size: 14px;
  color: var(--label-3);
  padding: 8px 0;
}

/* Result row */
.result-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--row-sep);
  animation: row-in 0.18s ease;
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

.row-fmt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--label-3);
  white-space: nowrap;
  margin-top: 2px;
  min-width: 64px;
}

.row-body { flex: 1; min-width: 0; }

.row-text {
  font-size: 14px;
  color: var(--label);
  word-break: break-all;
  line-height: 1.4;
}

.row-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.row-time { font-size: 12px; color: var(--label-3); margin-top: 2px; }

.row-copy {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 13px;
  color: var(--label-3);
  cursor: pointer;
  padding: 2px 0 2px 8px;
  align-self: flex-start;
  white-space: nowrap;
}

.row-copy:active { opacity: 0.4; }

/* ── Scanner screen ────────────────────────────────── */
#screen-scanner {
  background: #000;
  overflow: hidden;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#tracker-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ── Top bar ───────────────────────────────────────── */
.scanner-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 14px;
  background: var(--scan-topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: #fff;
  transition: background 0.15s;
}

.icon-btn:active { background: rgba(255,255,255,0.22); }
.icon-btn svg { width: 18px; height: 18px; }

.scanner-mode-label {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scanner-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--scan-green);
  flex-shrink: 0;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--scan-green);
  animation: pulse 1.3s ease-in-out infinite;
}

.status-dot.paused {
  background: rgba(255,255,255,0.5);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Aim box ───────────────────────────────────────── */
/* Purely decorative aim corners — no box drawn here.
   The actual barcode highlight is drawn by the canvas. */
.vf-aim {
  position: absolute;
  top: 50%; left: 50%;
  width: min(65vw, 260px);
  aspect-ratio: 1;
  transform: translate(-50%, -58%); /* slightly above center */
  pointer-events: none;
  transition: opacity 0.3s;
}

.vf-aim.hidden { opacity: 0; }

/* Four corner brackets via pseudo-elements + a child span */
.vf-aim::before, .vf-aim::after,
.vf-aim .c3, .vf-aim .c4 {
  content: '';
  position: absolute;
  width: 26px; height: 26px;
  border-color: rgba(255,255,255,0.7);
  border-style: solid;
}

.vf-aim::before { top:0; left:0;  border-width: 2px 0 0 2px; }
.vf-aim::after  { top:0; right:0; border-width: 2px 2px 0 0; }
.vf-aim .c3     { bottom:0; left:0;  border-width: 0 0 2px 2px; }
.vf-aim .c4     { bottom:0; right:0; border-width: 0 2px 2px 0; }

/* ── Bottom panel ──────────────────────────────────── */
.scanner-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--scan-bottom-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
}

.bottom-hint {
  padding: 20px 20px;
  text-align: center;
  font-size: 15px;
  color: rgba(255,255,255,0.5);
  font-weight: 400;
}

.bottom-result {
  padding: 18px 20px 20px;
}

.bottom-result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.bottom-result-format {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--scan-green);
}

.bottom-result-text {
  font-size: 18px;
  font-weight: 500;
  color: #fff;
  word-break: break-all;
  line-height: 1.35;
  margin-bottom: 16px;
  /* clamp to 3 lines */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.btn-scan-next {
  width: 100%;
  padding: 14px;
  background: var(--scan-green);
  color: #000;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: opacity 0.12s;
}

.btn-scan-next:active { opacity: 0.8; }

/* ── Utility ───────────────────────────────────────── */
[hidden] { display: none !important; }
