:root {
  --cc-red: #d33;
  --cc-amber: #e0a526;
  --cc-green: #2a9d3f;
  --cc-coffee: #6f4e37;
  --cc-cream: #f5ead3;
  --cc-gold: #d4af37;
  --cc-silver: #a8b0b8;
  --cc-bronze: #b87333;
}

header.container { padding-top: 2rem; }
.header-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
header.container hgroup h1 {
  background: linear-gradient(135deg, var(--cc-coffee), var(--cc-amber));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.auth-area { display: flex; align-items: center; gap: .6rem; }
.auth-area button { margin: 0; padding: .35rem .9rem; font-size: .85rem; }
.auth-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  padding: .25rem .35rem .25rem .75rem;
  border-radius: 999px;
  font-size: .85rem;
}
.auth-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cc-amber), var(--cc-coffee));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .7rem;
}
.auth-chip button { padding: .2rem .55rem; font-size: .75rem; margin: 0; }

/* My teams list */
.my-teams-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.my-teams-actions button { margin: 0; padding: .3rem .8rem; font-size: .8rem; }
.my-teams-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .6rem; margin-bottom: 1.5rem;
}
.team-card {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 12px;
  padding: .65rem .85rem;
  background: var(--pico-card-background-color);
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
}
.team-card-name { font-weight: 600; }
.team-card-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--pico-secondary-background);
  padding: 1px 7px; border-radius: 6px;
  font-size: .78rem; cursor: copy;
  border: 1px dashed var(--pico-muted-border-color);
}
.team-card-code:hover { background: var(--cc-cream); }
.team-leave {
  all: unset; cursor: pointer; font-size: .75rem;
  color: var(--pico-muted-color); padding: .2rem .4rem; border-radius: 6px;
}
.team-leave:hover { color: var(--cc-red); background: rgba(221,51,51,0.08); }

.hint-row { display: block; margin-top: .25rem; font-size: .75rem; }

dialog#auth-dialog article,
dialog#team-dialog article { max-width: 420px; }

.muted { color: var(--pico-muted-color); }

/* ===== Team filter pills ===== */
.team-filter {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.team-filter-label {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--pico-muted-color); font-weight: 600;
}
.team-pills { display: flex; gap: .4rem; flex-wrap: wrap; }
.team-pill {
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  color: var(--pico-color);
  padding: .25rem .8rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  transition: all .15s ease;
  display: inline-flex; align-items: center; gap: .35rem;
}
.team-pill:hover { border-color: var(--cc-coffee); transform: translateY(-1px); }
.team-pill.active {
  background: linear-gradient(135deg, var(--cc-coffee), var(--cc-amber));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 10px rgba(111, 78, 55, 0.3);
}
.team-pill .count {
  background: rgba(0,0,0,0.1);
  font-size: .7rem;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
}
.team-pill.active .count { background: rgba(255,255,255,0.25); }

/* ===== Sub-ratings (taste/price/vibes/service) ===== */
.sub-ratings {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 10px;
  padding: .5rem .75rem;
  margin-bottom: 1rem;
}
.sub-ratings summary {
  cursor: pointer;
  font-size: .9rem;
  color: var(--pico-muted-color);
  font-weight: 500;
}
.sub-ratings[open] summary { margin-bottom: .5rem; }
.sub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .8rem; }
@media (max-width: 540px) { .sub-grid { grid-template-columns: 1fr; } }
.sub-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
  font-size: .85rem;
}
.sub-label { color: var(--pico-muted-color); font-weight: 500; }
.stars { display: inline-flex; gap: 2px; user-select: none; }
.stars button {
  all: unset;
  cursor: pointer;
  font-size: 1.05rem;
  color: var(--pico-muted-border-color);
  transition: transform .1s ease;
  line-height: 1;
}
.stars button:hover { transform: scale(1.15); }
.stars button.on { color: var(--cc-amber); }
.stars .clear {
  font-size: .7rem;
  color: var(--pico-muted-color);
  margin-left: .35rem;
}

/* Mini bar on recent cards / popups */
.sub-bars { display: grid; grid-template-columns: 1fr 1fr; gap: .15rem .6rem; margin-top: .4rem; font-size: .72rem; }
.sub-bar { display: flex; align-items: center; gap: .35rem; color: var(--pico-muted-color); }
.sub-bar .track {
  flex: 1; height: 4px; border-radius: 999px;
  background: var(--pico-muted-border-color); overflow: hidden;
}
.sub-bar .fill { height: 100%; background: linear-gradient(90deg, var(--cc-amber), var(--cc-coffee)); }

/* ===== Hero stats ===== */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 900px) { .hero-stats { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: linear-gradient(140deg, var(--cc-cream), #fff);
  border: 1px solid rgba(111, 78, 55, 0.15);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: 0 4px 14px rgba(111, 78, 55, 0.08);
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(111, 78, 55, 0.15); }
.stat-icon { font-size: 1.6rem; margin-bottom: .25rem; }
.stat-value {
  font-size: 2.1rem; font-weight: 800; line-height: 1.1;
  color: var(--cc-coffee);
  font-variant-numeric: tabular-nums;
}
.stat-value.stat-text { font-size: 1.15rem; line-height: 1.25; word-break: break-word; }
.stat-label { font-size: .8rem; color: var(--pico-muted-color); text-transform: uppercase; letter-spacing: .04em; margin-top: .15rem; }

@media (prefers-color-scheme: dark) {
  .stat-card { background: linear-gradient(140deg, #2a221b, #1d1916); border-color: rgba(255,255,255,0.08); }
  .stat-value { color: var(--cc-cream); }
}

/* ===== Podium ===== */
.podium {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: end;
  gap: 1rem;
  margin: 1rem 0 2rem;
}
@media (max-width: 700px) {
  .podium { grid-template-columns: 1fr; }
  .podium-slot { min-height: 0 !important; }
}
.podium-slot {
  border-radius: 14px;
  padding: 1.1rem .9rem;
  text-align: center;
  color: #fff;
  position: relative;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  transition: transform .15s ease;
}
.podium-slot:hover { transform: translateY(-3px); }
.podium-slot.gold {
  background: linear-gradient(160deg, #f6d365, var(--cc-gold) 60%, #8a6d1a);
  min-height: 200px;
  order: 2;
}
.podium-slot.silver {
  background: linear-gradient(160deg, #e8ecf0, var(--cc-silver) 60%, #6b7480);
  min-height: 170px;
  order: 1;
}
.podium-slot.bronze {
  background: linear-gradient(160deg, #e8b78c, var(--cc-bronze) 60%, #774a22);
  min-height: 150px;
  order: 3;
}
.medal { font-size: 2rem; line-height: 1; }
.podium-name { font-weight: 700; font-size: 1.1rem; margin: .4rem 0 .2rem; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.podium-score { font-size: 2.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.podium-count { font-size: .8rem; opacity: .9; margin-top: .25rem; }

/* ===== Recent feed ===== */
.recent-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: .75rem;
  margin-bottom: 2rem;
}
.recent-card {
  border: 1px solid var(--pico-muted-border-color);
  border-left: 4px solid var(--cc-amber);
  border-radius: 10px;
  padding: .75rem .9rem;
  background: var(--pico-card-background-color);
  transition: transform .12s ease, box-shadow .12s ease;
  cursor: pointer;
}
.recent-card:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,0.08); }
.recent-card.is-red    { border-left-color: var(--cc-red); }
.recent-card.is-amber  { border-left-color: var(--cc-amber); }
.recent-card.is-green  { border-left-color: var(--cc-green); }
.recent-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.recent-cafe { font-weight: 700; }
.recent-rating { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.recent-meta { font-size: .8rem; color: var(--pico-muted-color); margin-top: .15rem; }
.recent-comment { font-size: .85rem; margin-top: .35rem; font-style: italic; }

/* ===== Layout ===== */
.layout { grid-template-columns: 1fr 1.4fr; gap: 1.25rem; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  #form-panel { order: 1; }
  #map-panel  { order: 0; }
}

#map {
  width: 100%;
  height: 480px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(111, 78, 55, 0.12);
  overflow: hidden;
}
.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.75) !important;
  font-size: .7rem !important;
  border-radius: 6px 0 0 0;
}
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.leaflet-popup-content { margin: .8rem 1rem; }

/* Animated drop pin */
.cc-pin {
  width: 36px; height: 36px;
  position: relative;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.3));
  animation: cc-pin-drop .4s ease-out;
}
.cc-pin svg { width: 100%; height: 100%; display: block; }
.cc-pin::after {
  content: "";
  position: absolute;
  inset: 6px 6px auto 6px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(224,165,38,0.45), transparent 60%);
  animation: cc-pin-pulse 1.8s ease-out infinite;
  z-index: -1;
}
@keyframes cc-pin-drop {
  0% { transform: translateY(-30px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes cc-pin-pulse {
  0%   { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

.search-row { display: flex; gap: .5rem; }
.search-row input { flex: 1; }

.search-results {
  list-style: none;
  padding: 0;
  margin: -.5rem 0 .75rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 10px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--pico-card-background-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.search-results li {
  padding: .55rem .8rem;
  cursor: pointer;
  border-bottom: 1px solid var(--pico-muted-border-color);
  font-size: .9rem;
  display: flex; align-items: baseline; gap: .5rem;
  justify-content: space-between;
}
.search-results li small { white-space: nowrap; flex-shrink: 0; }
.search-results li.no-results {
  flex-direction: column; align-items: flex-start; gap: .15rem; cursor: default;
}
.search-results li.no-results small { white-space: normal; }
.search-results li.no-results:hover { background: transparent; }
.search-results li:last-child { border-bottom: none; }
.search-results li:hover,
.search-results li[aria-selected="true"] { background: var(--pico-secondary-background); }
.search-results .hint { color: var(--pico-muted-color); font-size: .78rem; margin-left: auto; }
.search-results.suggestions li::before { content: "🏷️"; }
.search-results .badge {
  background: var(--cc-amber); color: #fff;
  font-size: .68rem; padding: 1px 6px; border-radius: 999px;
  font-weight: 600;
}

.searching {
  font-size: .8rem; color: var(--pico-muted-color);
  padding: .3rem 0; display: none;
}
.searching.is-on { display: block; }

.status { margin-top: .5rem; }
.status.ok   { color: var(--cc-green); }
.status.err  { color: var(--cc-red); }

.row-between {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
label.inline input { margin: 0; }

.table-wrap { overflow-x: auto; }
#leaderboard th { cursor: pointer; user-select: none; white-space: nowrap; }
#leaderboard th[data-sort-active]::after {
  content: attr(data-sort-dir);
  margin-left: .25rem;
  opacity: .6;
}
#leaderboard tbody tr:first-child td:first-child::before { content: "🥇 "; }
#leaderboard tbody tr:nth-child(2) td:first-child::before { content: "🥈 "; }
#leaderboard tbody tr:nth-child(3) td:first-child::before { content: "🥉 "; }

.charts { grid-template-columns: 1fr 1fr; gap: 1rem; }
.charts article {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 380px;
}
.charts article header {
  display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap;
  flex: 0 0 auto;
}
.charts article header small { font-weight: 400; }
/* Chart.js needs a constrained parent for `maintainAspectRatio: false`.
   We make the article a fixed height and let the canvas fill the remainder
   via flex. min-height: 0 lets the flex child shrink below its content. */
.charts .chart-box {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}
.charts canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
.chart-wide { grid-column: 1 / -1; height: 340px; }
@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
}

/* Leaderboard avg cell with mini-bar */
.lb-avg {
  display: inline-flex; align-items: center; gap: .5rem; min-width: 130px;
}
.lb-avg-num { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 28px; }
.lb-avg-track {
  flex: 1; height: 6px; border-radius: 999px;
  background: var(--pico-secondary-background); overflow: hidden;
}
.lb-avg-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.lb-avg-fill.is-red    { background: linear-gradient(90deg, #f3a4a4, var(--cc-red)); }
.lb-avg-fill.is-amber  { background: linear-gradient(90deg, #f3d390, var(--cc-amber)); }
.lb-avg-fill.is-green  { background: linear-gradient(90deg, #a4dab0, var(--cc-green)); }

.popup-cafe h4 { margin: 0 0 .25rem; }
.popup-cafe .avg { font-size: 1.4rem; font-weight: 700; }
.popup-cafe .comments {
  margin: .5rem 0 .5rem;
  padding-left: 1rem;
  font-size: .85rem;
  max-height: 100px;
  overflow-y: auto;
}
.popup-cafe button { width: 100%; margin-top: .25rem; }
