:root {
  --maroon: #7a1f2b;
  --maroon-dark: #591722;
  --cream: #faf3e8;
  --cream-dark: #f0e4cf;
  --gold: #b8862f;
  --ink: #2c2420;
  --muted: #7a6f63;
  --tier3: #7a1f2b;
  --tier2: #b8862f;
  --tier1: #8a9a5b;
  --radius: 10px;
  font-family: 'Iowan Old Style', 'Palatino Linotype', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--maroon);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.nav {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.nav a, .nav button {
  color: var(--cream);
  text-decoration: none;
  font-size: 0.95rem;
  background: none;
  border: 1px solid rgba(250,243,232,0.4);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
}

.nav a:hover, .nav button:hover { background: rgba(250,243,232,0.15); }
.nav .active { background: var(--gold); border-color: var(--gold); color: var(--maroon-dark); font-weight: 600; }

.app {
  flex: 1;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 18px;
}

h1 { font-size: 1.8rem; margin: 0 0 6px; color: var(--maroon-dark); }
h2 { font-size: 1.3rem; color: var(--maroon-dark); }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.tier-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--cream-dark);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 22px;
  font-size: 0.88rem;
}
.tier-legend span.pies { margin-right: 6px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
}

select, input, textarea, button.btn {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #d8cbb4;
  background: #fff;
}

button.btn {
  background: var(--maroon);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
button.btn:hover { background: var(--maroon-dark); }
button.btn.secondary { background: transparent; color: var(--maroon); border: 1px solid var(--maroon); }
button.btn.secondary:hover { background: rgba(122,31,43,0.08); }
button.btn.danger { background: #a33; }
button.btn.secondary.danger-text { color: #a33; border-color: #a33; }
button.btn.secondary.danger-text:hover { background: rgba(170,51,51,0.08); }

.pie-list { display: flex; flex-direction: column; gap: 12px; }

.pie-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-left: 5px solid transparent;
}
.pie-card.t3 { border-left-color: var(--tier3); }
.pie-card.t2 { border-left-color: var(--tier2); }
.pie-card.t1 { border-left-color: var(--tier1); }
.pie-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.14); }

.pie-card .info h3 { margin: 0 0 4px; font-size: 1.1rem; }
.pie-card .info .meta { color: var(--muted); font-size: 0.87rem; }
.pie-card .score { text-align: right; white-space: nowrap; }
.pie-card .score .pies { font-size: 1.2rem; }
.pie-card .score .num { font-size: 0.85rem; color: var(--muted); }

.region-group { margin-bottom: 30px; }
.region-group h2 { border-bottom: 2px solid var(--gold); padding-bottom: 4px; margin-bottom: 12px; }

.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  max-width: 520px;
  margin: 0 auto;
}

.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 0.88rem; font-weight: 600; color: var(--maroon-dark); }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.error { color: #a33; background: #fbe6e6; padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; margin-bottom: 12px; }
.notice { color: #4a5a2a; background: #eef2e2; padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; margin-bottom: 12px; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.detail-badge { text-align: center; }
.detail-badge .pies { font-size: 2rem; display: block; }
.detail-badge .label { font-size: 0.85rem; color: var(--muted); }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 10px; margin: 16px 0; font-size: 0.92rem; }
.meta-grid div b { display: block; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }

.notes { background: var(--cream-dark); padding: 12px 14px; border-radius: 8px; margin: 16px 0; font-style: italic; }

.rate-box { background: var(--cream-dark); padding: 16px; border-radius: 10px; margin: 20px 0; }
.rate-box input[type=range] { width: 100%; }
.rate-value { font-weight: 700; font-size: 1.3rem; color: var(--maroon); }

.criteria-slider { margin-bottom: 14px; }
.criteria-slider .row { display: flex; justify-content: space-between; align-items: baseline; }
.criteria-slider label { font-weight: 600; color: var(--maroon-dark); font-size: 0.92rem; }
.criteria-slider .hint { color: var(--muted); font-size: 0.78rem; display: block; }
.criteria-slider .val { font-weight: 700; color: var(--maroon); }
.criteria-slider.value-slider { border-top: 1px dashed #d8cbb4; padding-top: 12px; margin-top: 4px; }
.criteria-slider.value-slider label { color: #4a5a2a; }
.criteria-slider.value-slider .val { color: #4a5a2a; }

.overall-preview { background: #fff; border-radius: 8px; padding: 10px 14px; margin: 4px 0 16px; display: flex; justify-content: space-between; align-items: center; }
.overall-preview .big { font-size: 1.6rem; font-weight: 700; color: var(--maroon); }

.value-chip { display: inline-block; background: #eef2e2; color: #4a5a2a; font-size: 0.78rem; padding: 2px 8px; border-radius: 12px; margin-left: 6px; white-space: nowrap; }

.rating-list { list-style: none; padding: 0; margin: 10px 0; }
.rating-list li { padding: 10px 0; border-bottom: 1px solid var(--cream-dark); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.rating-list .who { font-weight: 600; display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.rating-list .who:hover { text-decoration: underline; }
.rating-list .cmt { color: var(--muted); font-size: 0.9rem; }
.rating-list .breakdown { color: var(--muted); font-size: 0.76rem; margin-top: 2px; }
.rating-list .sc { font-weight: 700; color: var(--maroon); white-space: nowrap; }
.rating-list .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; margin-top: 8px; cursor: pointer; display: block; }
.rating-list .mine-actions { margin-top: 6px; }
.rating-list .delete-review-btn { background: none; border: none; color: #a33; font-size: 0.78rem; cursor: pointer; padding: 0; text-decoration: underline; }

.photo-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.photo-btn { display: inline-flex; align-items: center; gap: 6px; }
.photo-preview-wrap { position: relative; display: inline-block; margin-top: 10px; }
.photo-preview { max-width: 160px; max-height: 160px; border-radius: 10px; display: block; box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
.photo-remove { position: absolute; top: -8px; right: -8px; background: var(--maroon); color: #fff; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 0.9rem; line-height: 1; }
.hidden-file-input { display: none; }

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

.map-container { width: 100%; height: 460px; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.1); margin-bottom: 16px; }
.map-container.small { height: 220px; }
.leaflet-popup-content { font-family: inherit; }
.map-popup h4 { margin: 0 0 4px; }
.map-popup a { color: var(--maroon); font-weight: 600; }

.distance-chip { display: inline-block; background: var(--cream-dark); color: var(--maroon-dark); font-size: 0.78rem; padding: 2px 8px; border-radius: 12px; margin-top: 4px; }

.directions-btn { display: inline-flex; align-items: center; gap: 6px; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 0.9rem; box-shadow: 0 2px 8px rgba(0,0,0,0.25); opacity: 0.95; }
.toast.error { background: #a33; }

.spinner-inline { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(0,0,0,0.15); border-top-color: var(--maroon); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.welcome-hero { text-align: center; padding: 30px 10px 10px; }
.welcome-hero .pies-big { font-size: 2.4rem; }

.tier-key-card { display: flex; align-items: center; gap: 10px; }
.tier-key-card .pies { font-size: 1.3rem; min-width: 60px; }

/* pie-shaped map markers */
.pie-pin {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

/* avatars */
.avatar-thumb { border-radius: 50%; object-fit: cover; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--cream-dark); vertical-align: middle; flex-shrink: 0;
}

.nav-profile {
  display: inline-flex !important; align-items: center; gap: 8px;
}

.profile-header { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.profile-avatar-wrap { flex-shrink: 0; }
.profile-avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); display: block; }
.profile-avatar-fallback {
  width: 84px; height: 84px; border-radius: 50%; background: var(--cream-dark);
  display: flex; align-items: center; justify-content: center; font-size: 2.4rem;
  border: 3px solid var(--gold);
}
.profile-header h1 { margin-bottom: 4px; }

/* want-to-try star */
.wish-star {
  background: none; border: none; cursor: pointer; font-size: 1.5rem; line-height: 1;
  color: #c9bda8; padding: 0 0 2px; font-family: inherit;
}
.wish-star:hover { color: var(--gold); }
.wish-star.on { color: var(--gold); }
.wish-star.big { font-size: 2rem; display: block; margin: 4px auto 0; }
.wish-star:disabled { opacity: 0.5; cursor: default; }

/* activity feed */
.feed { display: flex; flex-direction: column; gap: 12px; }
.feed-item { background: #fff; border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.feed-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.feed-who { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.feed-who:hover { text-decoration: underline; }
.feed-time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.feed-body { font-size: 0.95rem; }
.feed-body .cmt { color: var(--muted); font-style: italic; margin-top: 4px; }
.feed-body .thumb { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; margin-top: 8px; cursor: pointer; display: block; }

/* stats + badges */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--cream-dark); border-radius: 10px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; color: var(--maroon); }
.stat span { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 8px; }
.badge { background: #fff; border-radius: 10px; padding: 12px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.08); border-top: 3px solid var(--gold); }
.badge-emoji { font-size: 1.8rem; display: block; }
.badge-name { display: block; font-weight: 700; font-size: 0.9rem; margin-top: 4px; }
.badge-desc { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.taste-match { display: flex; align-items: center; gap: 16px; background: var(--cream-dark); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; }
.match-score { font-size: 2rem; font-weight: 700; color: var(--maroon); }

.rank { font-size: 1.3rem; min-width: 30px; text-align: center; font-weight: 700; color: var(--muted); }

.best-time { background: #fff6e0; border-left: 4px solid var(--gold); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.92rem; }

.saved-trip { cursor: pointer; }

/* trip planner */
.trip-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.trip-summary {
  background: var(--cream-dark); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px;
}
.auth-switch { text-align: center; margin: 16px 0 0; font-size: 0.92rem; color: var(--muted); }
.auth-switch a { color: var(--maroon); font-weight: 600; }

.admin-badge {
  display: inline-flex; align-items: center; background: var(--gold); color: var(--maroon-dark);
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 3px 8px; border-radius: 10px; align-self: center;
}
.gmaps-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.gmaps-bar .btn { text-decoration: none; display: inline-flex; align-items: center; }
.disabled-link { opacity: 0.5; cursor: not-allowed; }
.trip-pick { display: flex; align-items: center; margin-right: 4px; cursor: pointer; }
.trip-pick input { width: 20px; height: 20px; cursor: pointer; }
.trip-stop-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--maroon); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; flex-shrink: 0; margin-right: 12px;
}
@media (max-width: 600px) {
  .trip-fields { grid-template-columns: 1fr; }
}

/* pie chat */
.chat-wrap { display: flex; flex-direction: column; height: 65vh; background: #fff; border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,0.08); overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { display: flex; gap: 10px; align-items: flex-start; max-width: 80%; }
.chat-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble { background: var(--cream-dark); border-radius: 14px; padding: 8px 12px; }
.chat-msg.mine .chat-bubble { background: var(--maroon); color: #fff; }
.chat-msg.mine .chat-bubble .chat-who { color: rgba(255,255,255,0.8); }
.chat-who { font-weight: 700; font-size: 0.78rem; color: var(--maroon-dark); display: block; margin-bottom: 2px; }
.chat-who a { color: inherit; }
.chat-text { font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; }
.chat-time { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.chat-msg.mine .chat-time { text-align: right; }
.chat-del { background: none; border: none; color: var(--muted); font-size: 0.7rem; cursor: pointer; padding: 0; text-decoration: underline; }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--cream-dark); }
.chat-input-row textarea { flex: 1; resize: none; }

.photo-first { text-align: center; background: var(--cream-dark); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.photo-first .photo-row { justify-content: center; }
.photo-first-hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }

/* "how should pies be scored" poll */
.poll-card { margin-bottom: 22px; }
.poll-options { display: flex; flex-direction: column; gap: 10px; }
.poll-option {
  display: block; width: 100%; text-align: left; font-family: inherit;
  background: var(--cream-dark); border: 2px solid transparent; border-radius: 10px;
  padding: 12px 14px; cursor: pointer;
}
.poll-option:hover { border-color: var(--gold); }
.poll-option.mine { border-color: var(--maroon); background: #fff; }
.poll-option.winning { box-shadow: 0 0 0 2px var(--gold) inset; }
.poll-option:disabled { opacity: 0.6; cursor: default; }
.poll-option-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.poll-option-label { font-weight: 700; color: var(--maroon-dark); }
.poll-mine-tag { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--maroon); margin-left: 6px; }
.poll-option-count { font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.poll-bar-track { background: rgba(0,0,0,0.08); border-radius: 6px; height: 8px; margin: 8px 0; overflow: hidden; }
.poll-bar-fill { background: var(--gold); height: 100%; border-radius: 6px; }
.poll-option-blurb { font-size: 0.88rem; color: var(--ink); margin-bottom: 4px; }
.poll-option-weights { font-size: 0.76rem; color: var(--muted); }

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .pie-card { flex-direction: column; align-items: flex-start; }
  .pie-card .score { text-align: left; }
}
