:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181b;
  --muted: #5f6670;
  --border: #d9dde3;
  --accent: #d6342c;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --surface: #202326;
    --surface-2: #2a2e33;
    --text: #e9ebee;
    --muted: #9aa1ab;
    --border: #353a40;
    --accent: #e5483f;
    --ok: #4cc27f;
    --warn: #e0a040;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

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

h1, h2 { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

input[type="text"], input[type="url"], input[type="password"] {
  font: inherit;
  font-size: 16px; /* evita zoom automático no iOS */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:active { opacity: .8; }

.icon-btn {
  font-size: 20px;
  background: none;
  border: 0;
  color: var(--text);
  padding: 4px 8px;
  cursor: pointer;
}

/* Chips do tipo de busca */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.chips input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.chips input:focus-visible + span { outline: 2px solid var(--accent); }

/* Câmera */
.scanner {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-guide {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.scanner-stop {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  border-color: rgba(255, 255, 255, .5);
  background: rgba(0, 0, 0, .4);
}

/* OCR */
.ocr-box {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 38%;
  height: 24%;
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
}
.ocr-hint {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 13px;
  text-shadow: 0 1px 2px #000;
}
.scanner-actions {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.scanner-actions .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .5); background: rgba(0, 0, 0, .4); }
progress { width: 100%; accent-color: var(--accent); }
.cands { display: flex; flex-wrap: wrap; gap: 8px; }
.cand { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.cand small { display: block; font-family: inherit; font-size: 11px; font-weight: 400; color: var(--muted); }
#ocr-raw { white-space: pre-wrap; margin: 6px 0 0; color: var(--muted); }

/* Resultados */
#results { display: grid; gap: 10px; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; }
.source {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.source.ok { color: var(--ok); }
.source.err { color: var(--warn); }

.list, .history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
}
.cover {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
}
.item-body { min-width: 0; }
.item-title { font-weight: 600; }
.item-meta { font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 4px;
  color: #fff;
}
.badge.discogs { background: #333; }
.badge.musicbrainz { background: #ba478f; }
.badge.itunes { background: #fa2d48; }

.history li button {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  cursor: pointer;
}

/* Dialogs como "sheet" */
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .5); }
.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sheet-body {
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
}

.release-head { display: flex; gap: 12px; align-items: flex-start; }
.release-head img { width: 96px; height: 96px; border-radius: 8px; object-fit: cover; flex: none; }

.fields { display: grid; gap: 10px; }
.fields label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.fields label.check { display: flex; align-items: center; gap: 8px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; display: grid; gap: 6px; }
legend { font-size: 13px; color: var(--muted); }

.red-links { display: grid; gap: 8px; }
.red-links .btn { display: block; white-space: normal; }
.red-links .btn small { display: block; font-weight: 400; color: var(--muted); }
.red-links .btn-primary small { color: rgba(255, 255, 255, .8); }

.empty { text-align: center; color: var(--muted); padding: 16px; }
