*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --brown-900: #3e2723;
  --brown-800: #4e342e;
  --brown-700: #5d4037;
  --brown-600: #6d4c41;
  --brown-500: #795548;
  --brown-400: #8d6e63;
  --brown-300: #a1887f;
  --brown-200: #bcaaa4;
  --brown-100: #d7ccc8;
  --brown-50: #efebe9;
  --cream: #faf7f4;
  --cream-dark: #f0ebe4;
  --white: #ffffff;
  --green: #2e7d32;
  --green-light: #e8f5e9;
  --red: #c62828;
  --red-light: #ffebee;
  --gold: #f9a825;
  --text: #2c1810;
  --text-muted: #78655b;
  --shadow-sm: 0 1px 2px rgba(62, 39, 35, 0.08);
  --shadow-md: 0 4px 12px rgba(62, 39, 35, 0.1);
  --shadow-lg: 0 8px 30px rgba(62, 39, 35, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */

header {
  background: var(--brown-900);
  color: var(--white);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.header-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.logo-icon {
  font-size: 1.8rem;
}

.logo h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1.1;
}

.tagline {
  font-size: 0.75rem;
  opacity: 0.7;
  font-weight: 400;
}

.user-greeting {
  font-size: 0.9rem;
  opacity: 0.9;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  text-decoration: none;
}

.btn-primary {
  background: var(--brown-600);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--brown-700);
}

.btn-secondary {
  background: transparent;
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-full {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
}

/* --- Main --- */

main {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
}

/* --- Category Tabs --- */

.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
}

.cat-tab {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  border-radius: 100px;
  border: 1.5px solid var(--brown-200);
  background: var(--white);
  color: var(--brown-600);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.cat-tab:hover {
  border-color: var(--brown-400);
  background: var(--brown-50);
}

.cat-tab.active {
  background: var(--brown-800);
  color: var(--white);
  border-color: var(--brown-800);
}

/* --- Search Bar --- */

.search-bar {
  position: relative;
  margin-bottom: 1rem;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 0.7rem 0.85rem 0.7rem 2.5rem;
  border: 1.5px solid var(--brown-100);
  border-radius: 100px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--brown-400);
  box-shadow: 0 0 0 3px rgba(141, 110, 99, 0.1);
}

.search-bar input::placeholder {
  color: var(--brown-300);
}

/* --- Action Bar --- */

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.action-bar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.results-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- View Toggle --- */

.view-toggle {
  display: flex;
  background: var(--brown-50);
  border-radius: 100px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  padding: 0.35rem 0.85rem;
  border: none;
  border-radius: 100px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.view-btn:hover {
  color: var(--brown-700);
}

.view-btn.active {
  background: var(--white);
  color: var(--brown-800);
  box-shadow: var(--shadow-sm);
}

/* --- Map --- */

#map-container {
  margin-bottom: 1rem;
}

.map-marker {
  width: 32px;
  height: 32px;
  background: var(--brown-800);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--white);
  box-shadow: var(--shadow-md);
}

.map-marker-rank {
  transform: rotate(45deg);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
}

.map-marker-icon {
  background: none !important;
  border: none !important;
}

.map-popup strong {
  font-size: 0.9rem;
  color: var(--brown-900);
}

/* --- Place Card --- */

.places-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.place-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(62, 39, 35, 0.06);
  display: flex;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}

.place-card:hover {
  box-shadow: var(--shadow-md);
}

.place-card.voted {
  box-shadow: 0 0 0 2px var(--green), var(--shadow-md);
  z-index: 1;
}

/* --- Vote Section --- */

.vote-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.75rem;
  min-width: 64px;
  gap: 0.15rem;
  background: var(--cream);
  border-right: 1px solid rgba(62, 39, 35, 0.06);
}

.vote-section.vote-readonly {
  gap: 0.3rem;
}

.vote-hint {
  font-size: 0.55rem;
  color: var(--brown-300);
  text-align: center;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.vote-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.2rem;
  border-radius: 6px;
  transition: all 0.15s ease;
  line-height: 1;
  opacity: 0.5;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vote-btn:hover {
  opacity: 1;
  background: var(--brown-50);
}

.vote-btn.upvote.active {
  opacity: 1;
  color: var(--green);
  background: var(--green-light);
}

.vote-btn.downvote.active {
  opacity: 1;
  color: var(--red);
  background: var(--red-light);
}

.vote-score {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--brown-700);
  min-width: 2ch;
  text-align: center;
}

.vote-score.positive {
  color: var(--green);
}

.vote-score.negative {
  color: var(--red);
}

/* --- Place Photo --- */

.place-photo {
  width: 100px;
  min-height: 100px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--brown-50);
  display: flex;
  align-items: center;
  justify-content: center;
}

.place-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.place-photo.no-photo {
  background: linear-gradient(135deg, var(--brown-100) 0%, var(--brown-50) 100%);
}

.place-photo.no-photo img {
  display: none;
}

.place-photo.no-photo::after {
  content: '☕';
  font-size: 2rem;
  opacity: 0.3;
}

/* --- Place Info --- */

.place-info {
  padding: 0.85rem 1.1rem;
  flex: 1;
  min-width: 0;
}

.place-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brown-100);
  color: var(--brown-700);
  font-size: 0.7rem;
  font-weight: 600;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.place-rank.top-1 {
  background: #ffd700;
  color: #5d4037;
}

.place-rank.top-2 {
  background: #c0c0c0;
  color: #424242;
}

.place-rank.top-3 {
  background: #cd7f32;
  color: white;
}

.place-header {
  display: flex;
  align-items: center;
  margin-bottom: 0.2rem;
}

.place-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--brown-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Google Stars --- */

.google-stars {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
}

.star {
  line-height: 1;
}

.star.full {
  color: var(--gold);
}

.star.half {
  color: var(--gold);
  opacity: 0.5;
}

.star.empty {
  color: var(--brown-200);
}

.rating-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 0.3rem;
}

.place-address {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.place-description {
  font-size: 0.82rem;
  color: var(--brown-600);
  line-height: 1.4;
}

.place-meta {
  font-size: 0.72rem;
  color: var(--brown-300);
  margin-top: 0.4rem;
}

.maps-link {
  color: var(--brown-500);
  text-decoration: none;
  font-weight: 500;
}

.maps-link:hover {
  color: var(--brown-700);
  text-decoration: underline;
}

.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0.4;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  margin-left: 0.3rem;
  transition: opacity 0.15s;
}

.delete-btn:hover {
  opacity: 1;
  background: var(--red-light);
}

/* --- Loading --- */

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* --- Empty State --- */

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
}

/* --- Place Detail --- */

.modal-wide {
  max-width: 560px;
}

.detail-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-photo {
  width: 140px;
  height: 140px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--brown-50);
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-photo.no-photo img { display: none; }
.detail-photo.no-photo::after { content: '☕'; font-size: 2.5rem; opacity: 0.3; }

.detail-info {
  flex: 1;
  min-width: 0;
}

.detail-info h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
}

.detail-info .place-description {
  margin-top: 0.4rem;
}

.detail-info .maps-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.82rem;
}

.detail-reviews h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-top: 1px solid var(--brown-100);
  padding-top: 1rem;
}

.review-form textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid var(--brown-100);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  background: var(--cream);
  color: var(--text);
  transition: border-color 0.15s;
}

.review-form textarea:focus {
  outline: none;
  border-color: var(--brown-400);
  background: var(--white);
}

.review-form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.char-count {
  font-size: 0.75rem;
  color: var(--brown-300);
}

.review-login-prompt {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.review-login-prompt a {
  color: var(--brown-600);
  font-weight: 600;
  text-decoration: none;
}

.reviews-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.review-card {
  padding: 0.75rem;
  background: var(--cream);
  border-radius: var(--radius-sm);
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.review-author {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--brown-800);
}

.review-date {
  font-size: 0.72rem;
  color: var(--brown-300);
}

.review-text {
  font-size: 0.88rem;
  color: var(--brown-700);
  line-height: 1.5;
}

.no-reviews {
  font-size: 0.88rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem;
}

.place-card {
  cursor: pointer;
}

.place-card-reported {
  border: 2px solid var(--red);
  box-shadow: 0 0 0 1px var(--red), var(--shadow-sm);
}

.report-badge {
  font-size: 0.7rem;
  background: var(--red-light);
  color: var(--red);
  padding: 0.1rem 0.4rem;
  border-radius: 100px;
  font-weight: 600;
  margin-left: 0.4rem;
  white-space: nowrap;
}

.report-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  opacity: 0.3;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  margin-left: 0.3rem;
  transition: opacity 0.15s;
}

.report-btn:hover {
  opacity: 1;
}

.dismiss-report-btn {
  background: var(--green-light);
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--green);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.3rem;
  font-weight: 600;
  transition: background 0.15s;
}

.dismiss-report-btn:hover {
  background: var(--green);
  color: var(--white);
}

/* --- Modals --- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44, 24, 16, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  position: relative;
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--brown-300);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-close:hover {
  background: var(--brown-50);
  color: var(--brown-600);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--brown-700);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid var(--brown-100);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
  background: var(--cream);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brown-400);
  background: var(--white);
}

.form-group textarea {
  resize: vertical;
}

.form-error {
  color: var(--red);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  min-height: 1.2em;
}

.modal-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal-footer a {
  color: var(--brown-600);
  font-weight: 600;
  text-decoration: none;
}

.modal-footer a:hover {
  text-decoration: underline;
}

/* --- Footer --- */

footer {
  text-align: center;
  padding: 2rem;
  color: var(--brown-300);
  font-size: 0.85rem;
}

/* --- Responsive --- */

@media (max-width: 600px) {
  .header-inner {
    height: 50px;
  }

  .logo {
    gap: 0.5rem;
  }

  .logo-icon {
    font-size: 1.4rem;
  }

  .logo h1 {
    font-size: 1.1rem;
  }

  .tagline {
    display: none;
  }

  nav {
    gap: 0.4rem;
  }

  .user-greeting {
    font-size: 0.8rem;
  }

  main {
    padding: 0.75rem;
  }

  .category-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
  }

  .category-bar::-webkit-scrollbar {
    display: none;
  }

  .cat-tab {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
  }

  .search-bar {
    margin-bottom: 0.75rem;
  }

  .search-bar input {
    padding: 0.55rem 0.75rem 0.55rem 2.2rem;
    font-size: 0.88rem;
  }

  .search-icon {
    font-size: 0.8rem;
    left: 0.75rem;
  }

  .action-bar {
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .action-bar-left {
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .results-info {
    font-size: 0.78rem;
  }

  .view-btn {
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
  }

  #map {
    height: 450px !important;
  }

  .place-card {
    flex-direction: column;
  }

  .vote-section {
    flex-direction: row;
    min-width: unset;
    padding: 0.4rem 0.75rem;
    border-right: none;
    border-bottom: none;
    gap: 0.5rem;
    order: 2;
    margin: 0.5rem 0.75rem 0.75rem;
    border: 1.5px solid var(--brown-300);
    border-radius: var(--radius-sm);
    background: var(--cream);
    justify-content: center;
  }

  .vote-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .vote-score {
    font-size: 1rem;
    min-width: 2ch;
  }

  .place-photo {
    width: 100%;
    height: 160px;
    min-height: unset;
    order: 0;
  }

  .place-info {
    padding: 0.65rem 0.75rem;
    order: 1;
  }

  .place-header {
    margin-bottom: 0.15rem;
  }

  .place-name {
    font-size: 0.95rem;
    white-space: normal;
  }

  .place-description {
    font-size: 0.8rem;
  }

  .place-meta {
    font-size: 0.7rem;
    margin-top: 0.3rem;
  }

  .places-list {
    gap: 0.65rem;
  }

  .modal {
    padding: 1.5rem;
  }

  .detail-header {
    flex-direction: column;
  }

  .detail-photo {
    width: 100%;
    height: 180px;
  }

  .detail-info h2 {
    font-size: 1.15rem;
  }

  .btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
  }

  .btn-primary#btn-add-place {
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
  }
}

/* --- Login prompt toast --- */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brown-800);
  color: var(--white);
  padding: 0.75rem 1.5rem;
  border-radius: 100px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.5s forwards;
  cursor: pointer;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(16px);
  }
}
