:root {
  --bg: #14110e;
  --bg-elev: #1e1a16;
  --bg-elev-2: #292320;
  --line: #3a322c;
  --text: #f5efe6;
  --muted: #a1948a;
  --amber: #f0a830;
  --amber-dark: #c97f17;
  --green: #5fb87a;
  --red: #e2685c;
  --radius: 14px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ------------------------------------------------------------------ shell */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
.topbar h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.02em; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(30, 26, 22, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 0.68rem; color: var(--muted); text-decoration: none;
}
.tabbar-item.active { color: var(--amber); }
.tabbar-icon { font-size: 1.32rem; line-height: 1; }

/* ---------------------------------------------------------------- widgets */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.tight { padding: 12px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-elev-2);
  color: var(--text); font-size: 0.95rem; font-weight: 600;
  padding: 12px 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #201703; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(226, 104, 92, 0.4); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn:disabled { opacity: 0.5; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 12px; font-size: 1rem; font-family: inherit;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--text);
}
input:focus, select, textarea:focus { outline: 2px solid var(--amber-dark); outline-offset: -1px; }
textarea { min-height: 84px; resize: vertical; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; font-size: 0.78rem;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--amber); border-color: var(--amber); color: #201703; font-weight: 600; }

.chip-scroller { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chip-scroller::-webkit-scrollbar { display: none; }

.segmented { display: flex; background: var(--bg-elev-2); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 9px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.segmented button.active { background: var(--amber); color: #201703; }

.form-error { color: var(--red); font-size: 0.85rem; min-height: 1.2em; margin: 4px 0; }
.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty .big { font-size: 2.6rem; display: block; margin-bottom: 10px; }

/* ------------------------------------------------------------------- auth */
.auth-screen {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { font-size: 3.4rem; text-align: center; }
.auth-card h1 { text-align: center; margin: 4px 0; }
.auth-card > .muted { text-align: center; margin-bottom: 24px; }
.tabs { display: flex; gap: 4px; background: var(--bg-elev-2); border-radius: 12px; padding: 3px; margin-bottom: 20px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 9px; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--amber); color: #201703; }

/* --------------------------------------------------------------- scanner */
.scanner {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  background: #000; border-radius: var(--radius); overflow: hidden; margin-bottom: 12px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute; inset: 22% 10%;
  border: 2px solid rgba(240, 168, 48, 0.9); border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}
.scanner-hint {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  font-size: 0.8rem; color: #fff; text-shadow: 0 1px 4px #000;
}

/* ------------------------------------------------------------ beer / list */
.beer-head { display: flex; gap: 14px; }
.beer-thumb {
  width: 76px; height: 96px; border-radius: 10px; object-fit: cover;
  background: var(--bg-elev-2); flex: 0 0 auto;
}
.beer-thumb.placeholder { display: grid; place-items: center; font-size: 2rem; }
.beer-title { font-size: 1.1rem; font-weight: 700; margin: 0 0 2px; line-height: 1.25; }
.beer-meta { font-size: 0.82rem; color: var(--muted); margin: 0 0 6px; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 7px; font-size: 0.72rem;
  background: var(--bg-elev-2); color: var(--muted); margin: 0 4px 4px 0;
}
.badge.score { background: var(--amber); color: #201703; font-weight: 700; }

.stars { display: flex; gap: 4px; font-size: 2rem; line-height: 1; justify-content: space-between; }
.stars button { background: none; border: 0; padding: 0; cursor: pointer; filter: grayscale(1) opacity(0.35); }
.stars button.on { filter: none; }

.slider-row { margin-bottom: 14px; }
.slider-row label { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
input[type="range"] { accent-color: var(--amber); padding: 0; background: none; border: 0; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow strong { display: block; font-size: 0.95rem; }
.list-item .grow small { color: var(--muted); font-size: 0.78rem; }
.score-pill {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 700;
  background: var(--bg-elev-2); color: var(--amber);
}

#map { height: calc(100vh - var(--tabbar-h) - var(--safe-b) - 170px); min-height: 320px; border-radius: var(--radius); overflow: hidden; }
.leaflet-container { background: #1a1714; font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-elev); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 60;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 12px; font-size: 0.9rem;
  max-width: 88vw; text-align: center; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}
.toast.error { border-color: var(--red); color: var(--red); }

.spinner {
  width: 22px; height: 22px; border: 2px solid var(--line);
  border-top-color: var(--amber); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
