:root {
  --ink: #1b2433;
  --muted: #5d6879;
  --line: #d7dde6;
  --paper: #ffffff;
  --desk: #eef3f0;
  --brand: #1f9d55;        /* recycling green */
  --brand-soft: #dcf3e6;
  --alert: #a23b2a;
  --alert-soft: #f8e7e3;
  --warn: #8a6d00;
  --warn-soft: #fbf1d1;
  --radius: 10px;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--desk);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
img { max-width: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.topbar {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  background: var(--ink); color: #fff;
}
.topbar .logo { font-size: 1.6rem; }
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.topbar p { margin: 0.15rem 0 0; font-size: 0.9rem; color: #c3cad6; }

.layout {
  display: grid; gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  padding: 2rem clamp(1rem, 4vw, 3rem);
  max-width: 1100px; margin: 0 auto;
}
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem;
}
.panel h2 { margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; }

.intro {
  grid-column: 1 / -1;
  background: var(--brand-soft); border: 1px solid var(--brand);
  display: flex; align-items: center; gap: 1rem;
}
.intro .logo { font-size: 2rem; flex-shrink: 0; }
.intro p { margin: 0; line-height: 1.55; font-size: 1.02rem; }
.intro strong { color: var(--brand); }

.capture-buttons { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.capture-buttons button {
  font: inherit; font-weight: 600; font-size: 0.98rem; cursor: pointer;
  padding: 0.75rem 1.25rem; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--paper); color: var(--brand);
}
.capture-buttons button:hover { background: var(--brand-soft); }
.capture-buttons button:disabled { opacity: 0.6; cursor: wait; }

#cameraPanel { margin-top: 1rem; }
#cameraVideo {
  width: 100%; max-height: 320px; border-radius: 8px; background: #000;
  object-fit: cover;
}
.camera-actions { display: flex; gap: 0.75rem; margin-top: 0.75rem; }
.camera-actions button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 0.6rem 1.1rem; border-radius: 8px; border: none;
}
#captureBtn { background: var(--brand); color: #fff; }
#captureBtn:hover { background: #18824a; }
#cancelCameraBtn { background: var(--desk); color: var(--ink); border: 1px solid var(--line) !important; }

#previewWrap { margin-top: 1.25rem; }
#previewImg {
  display: block; width: 100%; max-height: 320px; object-fit: contain;
  border-radius: 8px; border: 1px solid var(--line); background: var(--desk);
}
.link-btn {
  margin-top: 0.6rem; font: inherit; font-size: 0.88rem; cursor: pointer;
  background: none; border: none; color: var(--brand); text-decoration: underline;
  padding: 0;
}

.camera-error, .model-note {
  margin-top: 0.75rem; font-size: 0.88rem;
}
.camera-error { color: var(--alert); }
.model-note { color: var(--muted); }

.empty { color: var(--muted); line-height: 1.6; }

.loading { text-align: center; padding: 1.5rem 0; color: var(--muted); }
.spinner {
  font-size: 2.5rem; display: inline-block;
  animation: spin 1.4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { margin: 0.75rem 0 0; font-weight: 600; }

.error {
  color: var(--alert); background: var(--alert-soft); border-radius: 8px;
  padding: 0.85rem 1rem; line-height: 1.5;
}

.result .material {
  margin: 0; font-size: 1rem; color: var(--muted);
}
.result .material strong {
  display: block; font-size: 1.7rem; color: var(--ink); text-transform: capitalize;
  margin-top: 0.15rem;
}

.bin-card {
  margin-top: 1rem; padding: 1rem 1.1rem; border-radius: 8px;
  border: 1px solid var(--line); border-left-width: 6px;
}
.bin-card .bin-name { margin: 0; font-size: 1.15rem; font-weight: 700; }
.bin-card .bin-catalan { margin: 0.15rem 0 0; font-size: 0.88rem; color: var(--muted); }
.bin-card .tip { margin: 0.65rem 0 0; font-size: 0.92rem; line-height: 1.5; }

.confidence-note {
  margin: 0.85rem 0 0; font-size: 0.82rem; color: var(--muted);
}

.unsure-card {
  margin-top: 1rem; padding: 1rem 1.1rem; border-radius: 8px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid #e3cf7a;
  font-size: 0.95rem; line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
