/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  /* Default Theme */
  --primary: #FF4757;
  --secondary: #2F3542;
  --text-dark: #2F3542;
  --text-light: #747d8c;
  --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  --card-bg: #FFFFFF;
  --border-color: #e1e1e1;
  --success: #2ed573;
  --danger: #ff6b81;
  --removed: #ff4757;
  --sold: #747d8c;
  --new: #FF4757;
  --character-img: none;
  --btn-bg: #2F3542;
  --btn-text: #ffffff;
}

/* XO Theme (Bad Badtz-Maru) */
[data-theme="xo"] {
  --primary: #FFD700;
  /* Yellow */
  --secondary: #2d3436;
  /* Dark Grey */
  --text-dark: #2d3436;
  --text-light: #636e72;
  --bg-gradient: linear-gradient(135deg, #b2bec3 0%, #636e72 100%);
  --card-bg: #ffffff;
  --border-color: #2d3436;
  --success: #00b894;
  --danger: #d63031;
  --character-img: url('images/xo.png');
  --btn-bg: #2d3436;
  --btn-text: #FFD700;
}

/* Pochacco Theme */
[data-theme="pochacco"] {
  --primary: #48C9B0;
  /* Mint Teal */
  --secondary: #1A2D2A;
  /* Dark Grey/Green */
  --text-dark: #1A2D2A;
  --text-light: #5F7D7A;
  --bg-gradient: linear-gradient(135deg, #E0F7FA 0%, #B2DFDB 100%);
  /* Light Mint Gradient */
  --card-bg: #F0FBF9;
  --border-color: #48C9B0;
  --success: #26A69A;
  --danger: #EF5350;
  --character-img: url('images/pochacco.png');
  --btn-bg: #48C9B0;
  --btn-text: #FFFFFF;
}

/* Kuromi Theme */
[data-theme="kuromi"] {
  --primary: #e056fd;
  /* Neon Purple */
  --secondary: #130f40;
  /* Deep Purple/Black */
  --text-dark: #30336b;
  /* Dark Purple Text */
  --text-light: #535c68;
  --bg-gradient: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
  --card-bg: #ffffff;
  --border-color: #be2edd;
  --success: #6ab04c;
  --danger: #eb4d4b;
  --character-img: url('images/kuromi.png');
  --btn-bg: #130f40;
  --btn-text: #e056fd;
}

/* Hello Kitty Theme */
[data-theme="hello-kitty"] {
  --primary: #ff4757;
  /* Red */
  --secondary: #ff6b81;
  /* Pink */
  --text-dark: #2f3542;
  --text-light: #747d8c;
  --bg-gradient: linear-gradient(135deg, #ffdde1 0%, #ee9ca7 100%);
  --card-bg: #fff0f3;
  --border-color: #ffcccc;
  --success: #badc58;
  --danger: #eb4d4b;
  --character-img: url('images/hello-kitty.png');
  --btn-bg: #ff6b81;
  --btn-text: #ffffff;
}

/* Badminton Theme */
[data-theme="badminton"] {
  --primary: #4CAF50;
  /* Sporty Green */
  --secondary: #1B5E20;
  /* Deep Green */
  --text-dark: #1B5E20;
  --text-light: #558B2F;
  --bg-gradient: linear-gradient(135deg, #E8F5E9 0%, #A5D6A7 100%);
  --card-bg: #F1F8E9;
  --border-color: #66BB6A;
  --success: #2E7D32;
  --danger: #E53935;
  --character-img: url('images/badminton.png');
  --btn-bg: #2E7D32;
  --btn-text: #FFFFFF;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-dark);
  line-height: 1.5;
  transition: background 0.5s ease;
  position: relative;
  min-height: 100vh;
}

/* Character Overlay */
body::after {
  content: "";
  position: fixed;
  bottom: 0px;
  right: 20px;
  width: 350px;
  height: 350px;
  background-image: var(--character-img);
  background-repeat: no-repeat;
  background-position: bottom right;
  background-size: contain;
  opacity: 0.8;
  pointer-events: none;
  z-index: 0;
  transition: background-image 0.5s ease;
}

/* Adjust main content z-index */
.app-container {
  max-width: 1600px;
  /* Wider layout */
  margin: 0 auto;
  padding: 0 2rem;
  /* More side breathing room */
  position: relative;
  z-index: 1;
}

/* Header */
header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(15px);
  padding: 2rem 3rem;
  /* More air in header */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 2rem;
  z-index: 100;
  border-bottom: 2px solid rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Noto+Sans+TC:wght@400;500;700&display=swap');

/* ... (existing variables) ... */

#main-title {
  font-family: 'Noto Sans TC', sans-serif;
  /* Use new Chinese font */
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--secondary);
  letter-spacing: -0.5px;
}

.app-version {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-light);
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 8px;
  border-radius: 6px;
  vertical-align: middle;
  margin-left: 8px;
}

/* ... */

/* NEW: Red New Badge with date */
.status-badge.sold {
  background: #747d8c;
  /* Grey */
  left: auto;
  right: 1rem;
}

.status-badge.new {
  background: #e74c3c;
  left: 1rem;
  right: auto;
  top: 1rem;
  font-size: 0.65rem;
  padding: 0.3rem 0.7rem;
  white-space: nowrap;
}

.title-area {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.user-display {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 6px 16px;
  background: white;
  border-radius: 30px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  animation: slideInLeft 0.5s ease-out;
}

.user-icon-wrapper {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: #f1f2f6;
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-icon-small {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#user-name-tag {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--secondary);
}

/* Presence System Styles */
.presence-list-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.online-label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
}

.online-user {
  display: flex !important;
  align-items: center !important;
  gap: 0.4rem !important;
}

.online-name {
  font-weight: 800 !important;
  font-size: 0.95rem !important;
  display: inline-block !important;
  color: var(--secondary) !important;
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  /* more space between controls */
}

.theme-selector {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#theme-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.theme-dropdown {
  width: auto !important;
  min-width: 180px;
  max-width: 250px;
  padding: 10px 20px !important;
  font-size: 0.95rem !important;
  height: 48px;
  /* taller for better touch/click targets */
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.stats {
  display: flex;
  gap: 2rem;
  font-size: 1rem;
  color: var(--text-light);
  background: #f8f9fa;
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.stats strong {
  color: var(--primary);
  font-weight: 700;
}

.app-layout {
  display: flex;
  gap: 3rem;
  /* More space between leaderboard and cards */
  margin-top: 3rem;
  /* More space from header */
  align-items: flex-start;
  padding-bottom: 4rem;
}

.sidebar {
  flex: 0 0 340px;
  position: sticky;
  top: 120px;
  /* adjusted for taller header */
}

.main-content {
  flex: 1;
}


/* Sidebar Leaderboard */
.leaderboard-card {
  background: var(--card-bg);
  padding: 2rem;
  /* more space */
  border-radius: 24px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.leaderboard-card h3 {
  margin-bottom: 1.5rem;
  color: var(--primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 12px;
  margin-bottom: 0.8rem;
  transition: transform 0.2s;
}

.leaderboard-item:hover {
  transform: translateX(5px);
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.rank {
  font-weight: 700;
  color: var(--text-light);
  width: 24px;
}

.lb-car-info {
  flex: 1;
}

.lb-car-title {
  font-weight: 600;
  font-size: 0.9rem;
  display: block;
}

.lb-voters {
  display: flex;
  gap: -8px;
  /* overlapping effect */
  margin-top: 4px;
}

/* Voter Bubbles */
.voter-bubble {
  width: 32px;
  /* Slightly larger for images */
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  text-transform: uppercase;
  overflow: hidden;
  /* For images */
  position: relative;
}

.voter-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.voter-bubble.xo {
  background: #34495e;
}

.voter-bubble.pochacco {
  background: #2ecc71;
}

.voter-bubble.kuromi {
  background: #9b59b6;
}

.voter-bubble.hello-kitty {
  background: #ff4757;
}

/* Voting UI on Cards */
.card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #f1f2f6;
}

.btn-vote {
  background: none;
  border: 2px solid #eee;
  padding: 0.6rem 1rem;
  border-radius: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.2s;
}

.btn-vote:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-vote.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-remove {
  background: none;
  border: 2px solid #eee;
  padding: 0.4rem 0.9rem;
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.2s;
}

.btn-remove:hover {
  border-color: var(--removed);
  color: var(--removed);
}

.btn-remove.active {
  background: var(--removed);
  border-color: var(--removed);
  color: #fff;
}

.card-voters {
  display: flex;
  gap: 4px;
}

@media (max-width: 1100px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
    /* In the stacked layout the 340px flex-basis would become height */
    flex: 0 0 auto;
  }
}

/* Filter Bar */
.filter-bar {
  background: white;
  padding: 2.5rem;
  /* much more padding */
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: flex-end;
  border: 1px solid var(--border-color);
  margin-bottom: 3rem;
  /* space before grid */
}

/* Phone-only filter toggle; on wider screens the panel's children lay out directly in .filter-bar */
.filter-toggle,
.theme-icon {
  display: none;
}

.filter-panel {
  display: contents;
}

.range-filters-container {
  display: flex;
  gap: 2.5rem;
  flex: 2 1 500px;
  /* Group takes more space */
}

@media (max-width: 900px) {
  .range-filters-container {
    flex-direction: column;
    gap: 1.5rem;
  }
}

.filter-group {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.range-filters-container .range-group {
  flex: 1;
}

.filter-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--secondary);
}

/* Checkbox Styling */
.checkbox-group {
  justify-content: flex-end;
  padding-bottom: 0.5rem;
}

.checkbox-container {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  cursor: pointer;
  user-select: none;
  font-weight: 700 !important;
  color: var(--secondary);
  transition: all 0.2s;
}

.checkbox-container input {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
}

.checkbox-container:hover {
  color: var(--primary);
}

.checkbox-label {
  font-size: 0.95rem;
}

/* Features Dropdown */
.features-dropdown {
  position: relative;
}

.features-dropdown-toggle {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: #f8f9fa;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--secondary);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.features-dropdown-toggle:hover {
  border-color: var(--primary);
}

.dropdown-arrow {
  font-size: 0.7rem;
  margin-left: 0.5rem;
  transition: transform 0.2s;
}

.features-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.features-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
  padding: 0.5rem 0;
}

.features-dropdown.open .features-dropdown-menu {
  display: block;
}

.features-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dark);
  transition: background 0.15s;
}

.features-option:hover {
  background: #f0f2f5;
}

.features-option input {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Select Styling */
.select-wrapper {
  position: relative;
}

select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: #f8f9fa;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--secondary);
  cursor: pointer;
  appearance: none;
  transition: all 0.2s;
}

select:hover {
  border-color: var(--primary);
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(100, 100, 100, 0.1);
}

.select-wrapper::after {
  content: "▼";
  font-size: 0.7rem;
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

/* Range Sliders */
.range-group {
  flex: 1 1 250px;
}

.range-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.range-header span {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
}

input[type=range] {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
  background: #e1e1e1;
  border-radius: 3px;
  cursor: pointer;
}

/* Listings Grid */
.listings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.25rem;
  /* compact grid: more cars per screen */
  align-items: stretch;
}

/* Card Styles */
.card {
  background: var(--card-bg);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  height: 100%;
  /* Force height to match grid row */
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.1);
  border-color: var(--primary);
}

/* Leaderboard → Card Highlight Effect */
.card.car-highlight {
  animation: carHighlightPulse 3s ease-out forwards;
  z-index: 10;
  position: relative;
}

@keyframes carHighlightPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 var(--primary);
    border-color: transparent;
  }

  8% {
    transform: scale(1.03);
    box-shadow:
      0 0 20px rgba(255, 71, 87, 0.4),
      0 0 60px rgba(255, 71, 87, 0.15),
      inset 0 0 15px rgba(255, 71, 87, 0.05);
    border-color: var(--primary);
  }

  /* Hold the glow */
  60% {
    transform: scale(1.03);
    box-shadow:
      0 0 20px rgba(255, 71, 87, 0.4),
      0 0 60px rgba(255, 71, 87, 0.15),
      inset 0 0 15px rgba(255, 71, 87, 0.05);
    border-color: var(--primary);
  }

  /* Fade out */
  100% {
    transform: scale(1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border-color: transparent;
  }
}

/* Sold & Removed States */
.card.is-sold,
.card.is-removed {
  background: #f1f2f6;
  border-color: #d1d8e0;
  opacity: 0.95;
}

.card.is-sold:hover,
.card.is-removed:hover {
  transform: translateY(-4px);
  border-color: #747d8c;
}

.card.is-sold .card-image,
.card.is-removed .card-image {
  filter: grayscale(1);
  opacity: 0.7;
}

.card.is-sold .btn-vote,
.card.is-removed .btn-vote {
  background: #dfe4ea;
  border-color: #ced6e0;
  color: #a4b0be;
  cursor: not-allowed;
  pointer-events: none;
}

.card.is-sold .btn-view,
.card.is-removed .btn-view {
  background: #ced6e0 !important;
  pointer-events: none;
}

.card.is-sold .card-price {
  color: #747d8c;
  /* De-emphasize price */
}

.card-image-wrapper {
  height: 150px;
  overflow: hidden;
  position: relative;
  background: #f1f2f6;
  flex-shrink: 0;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.card:hover .card-image {
  transform: scale(1.05);
}

/* Placeholder blends into the wrapper background instead of being cropped */
.card-image[src$="no-photo.svg"] {
  object-fit: contain;
}

.status-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.4rem 1rem;
  border-radius: 30px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: white;
  z-index: 2;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  background: var(--success);
}

.status-badge.sold {
  background: var(--sold) !important;
}

.status-badge.removed {
  background: var(--removed) !important;
}

.status-badge.new {
  left: 1rem;
  right: auto;
  background: var(--new) !important;
}

/* Presence Card */
.presence-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: 24px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.presence-card h3 {
  margin-bottom: 1.5rem;
  color: var(--success);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.presence-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.online-user {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
  background: #f8f9fa;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-content {
  padding: 0.9rem 1rem 1rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
  color: var(--text-dark);
  line-height: 1.3;
}

.card-description {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.4rem;
  line-height: 1.35;
  /* keep long titles to two lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-price {
  font-size: 1.2rem;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.specs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem 0.6rem;
  margin-bottom: 0.6rem;
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-dark);
  font-weight: 500;
  padding: 2px 0;
}

/* Horsepower Spec */
.spec-hp {
  position: relative;
  color: var(--primary);
  font-weight: 600;
}

.hp-tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border-color);
  color: var(--text-light);
  font-size: 0.65rem;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
  transition: all 0.2s;
}

.hp-tooltip-icon:hover {
  background: var(--primary);
  color: white;
}

.spec-hp::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--secondary);
  color: white;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  width: 200px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.spec-hp::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--secondary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}

.spec-hp:hover::after,
.spec-hp:hover::before {
  opacity: 1;
}

/* Features Section on Cards */
.features-section {
  margin-bottom: 0.6rem;
}

.features-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-color), transparent);
  margin-bottom: 0.5rem;
}

.features-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.feature-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  color: #2e7d32;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.btn-view {
  margin-top: auto;
  /* Ensure it stays at the bottom */
  display: block;
  text-align: center;
  background: var(--btn-bg);
  color: var(--btn-text);
  padding: 0.6rem;
  font-size: 0.9rem;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.1s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: 100%;
  /* Ensure full width button */
}

.btn-view:hover {
  background: var(--primary);
  color: #fff;
  transform: scale(1.02);
}

/* Vote Button */
.card-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: auto;
  /* Push actions + button to bottom so rows line up */
  padding-top: 0.6rem;
}

.btn-vote {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border: 2px solid #e1e1e1;
  border-radius: 30px;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.3s ease;
}

.btn-vote:hover {
  border-color: #ff4757;
  color: #ff4757;
}

.btn-vote .vote-icon {
  font-style: normal;
  font-size: 0.9rem;
  line-height: 1;
  transition: all 0.3s ease;
}

.btn-vote.active {
  border-color: #ff4757;
  background: #fff0f1;
  color: #ff4757;
}

.btn-vote.active .vote-icon {
  color: #ff4757;
}

/* Voter Bubbles */
.card-voters {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* Voter Overlay on Card Image */
.card-voters-overlay {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 60%;
  opacity: 0.8;
  z-index: 2;
}

/* Duplicate removed - see line ~180 */

/* NEW: Compact Header Presence */
.presence-list-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 1rem;
}

.online-label {
  color: #27ae60;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.presence-list-header .online-user {
  padding: 0;
  background: none;
  border: none;
  animation: fadeIn 0.5s ease-out;
}

.presence-list-header .online-user span {
  display: none;
  /* Hide names in header for compactness */
}

/* Ensure smooth scrolling */
html {
  scroll-behavior: smooth;
}

.voter-bubble {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f1f2f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid #e1e1e1;
  overflow: hidden;
}

.voter-bubble .voter-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Responsive */
@media (max-width: 768px) {

  /* Make container full width on mobile */
  .app-container {
    padding: 0 0.8rem;
  }

  .app-layout {
    gap: 0.8rem;
    margin-top: 1.2rem;
  }

  /* Fix header layout on mobile */
  header {
    padding: 1rem 1.2rem;
    gap: 0.8rem;
    border-radius: 0;
  }

  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .header-controls {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    width: 100%;
    flex-wrap: wrap;
    /* Allow wrapping */
  }

  .title-area {
    flex-direction: row;
    align-items: center;
    gap: 0.8rem;
  }

  #main-title {
    font-size: 1.3rem;
    writing-mode: horizontal-tb;
    white-space: normal;
    word-break: keep-all;
  }

  .theme-selector {
    flex: 1;
    justify-content: flex-end;
  }

  #theme-label {
    font-size: 0.75rem;
  }

  .theme-dropdown {
    min-width: 120px;
    max-width: 160px;
    font-size: 0.85rem;
    padding: 8px 12px;
  }

  /* Stats bar responsive */
  .stats {
    flex-direction: row;
    gap: 1.5rem;
    align-items: center;
    padding: 0.8rem 1rem;
    flex-wrap: wrap;
  }

  .stats span {
    font-size: 0.85rem;
  }

  /* Show sidebar on mobile - above filters */
  .sidebar {
    display: block;
    width: 100%;
    position: static;
    order: -1;
    /* Move before main content */
  }

  .app-layout {
    flex-direction: column;
  }

  .main-content {
    order: 1;
  }

  .leaderboard-card,
  .presence-card {
    margin-bottom: 1rem;
  }

  /* Filter bar responsive - more compact */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
    padding: 1rem 1.2rem;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 1rem;
  }

  .filter-group {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
  }

  .filter-group label {
    font-size: 0.8rem;
    margin-bottom: 0.3rem;
  }

  .filter-group select,
  .filter-group input {
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .range-filters-container {
    flex-direction: row;
    gap: 0.8rem;
    width: 100%;
    flex: 1 1 auto !important;
    /* Override flex: 2 1 500px */
  }

  .range-group {
    flex: 1 1 auto !important;
    /* Remove fixed 250px height */
    min-height: auto;
  }

  .range-filter {
    padding: 0.8rem;
    flex: 1;
    margin-bottom: 0;
    /* Remove bottom gap */
  }

  .range-filter label {
    font-size: 0.8rem;
  }

  .range-value {
    font-size: 0.9rem;
  }

  /* Card grid responsive - 1 column on very small screens */
  .car-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
    padding: 0 1rem;
  }

  .listings-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  /* Make cards more compact on mobile */
  .car-card {
    padding: 0.8rem;
  }

  .car-card h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }

  .car-card .price {
    font-size: 1.1rem;
  }

  .car-card .detail {
    font-size: 0.75rem;
    padding: 0.3rem 0;
  }

  .car-card img {
    height: 140px;
  }

  /* User display responsive */
  .user-display {
    padding: 4px 10px;
  }

  .user-icon-wrapper {
    width: 26px;
    height: 26px;
  }

  #user-name-tag {
    font-size: 0.8rem;
  }

  /* Character background fade */
  body::after {
    opacity: 0.2;
    width: 200px;
    height: 200px;
  }
}

/* Login Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.login-box {
  background: var(--card-bg);
  padding: 2rem 2.5rem;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 450px;
  width: 90%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: translateY(20px);
  transition: transform 0.4s ease;
}

.modal-overlay.active .login-box {
  transform: translateY(0);
}

.login-box h2 {
  margin-bottom: 0.5rem;
  color: var(--primary);
  font-size: 1.8rem;
}

.login-box p {
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.login-box select,
.login-box input {
  width: 100%;
  padding: 14px;
  margin: 12px 0;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.3s;
}

.login-box select:focus,
.login-box input:focus {
  border-color: var(--primary);
}

.login-box button {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  font-size: 1.1rem;
}

.error-message {
  color: #ff4757;
  font-size: 0.95rem;
  margin-top: 15px;
  font-weight: 500;
}

/* Login Mode Tabs */

.login-mode-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.25rem;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--primary);
}

.tab-icon {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  vertical-align: middle;
}

.login-tab {
  flex: 1;
  padding: 0.9rem 1rem;
  border: none;
  margin: 0 !important;
  background: white;
  /* Default inactive background */
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--primary);
}

.login-tab.active {
  background: var(--primary);
  color: white;
}

.login-tab:hover:not(.active) {
  background: #f1f2f6;
}

/* Login Panels */
.login-panel {
  display: none;
}

.login-panel.active {
  display: block;
}

.login-panel input:first-child,
.login-panel select:first-child {
  margin-top: 0 !important;
}

/* Guest Sport Selection */
.guest-sport-label {
  font-weight: 600 !important;
  color: var(--text-dark) !important;
  margin-top: 1rem !important;
  margin-bottom: 0.25rem !important;
}

.guest-hint {
  font-size: 0.85rem !important;
  color: var(--primary) !important;
  font-style: italic;
  margin-bottom: 0.75rem !important;
  opacity: 0.85;
}

.sport-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.sport-option {
  cursor: pointer;
}

.sport-option input[type="radio"] {
  display: none;
}

.sport-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem 0.5rem;
  border-radius: 12px;
  border: 2px solid var(--border-color);
  background: rgba(255, 255, 255, 0.6);
  transition: all 0.2s;
}

.sport-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sport-option input[type="radio"]:checked+.sport-card {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(76, 175, 80, 0.1), rgba(76, 175, 80, 0.05));
  box-shadow: 0 0 0 2px var(--primary);
}

.sport-emoji {
  font-size: 2rem;
}

.sport-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dark);
}

/* Medium mobile screens - 2 columns */
@media (min-width: 480px) and (max-width: 768px) {
  .car-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .listings-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Tablet screens - 3+ columns */
@media (min-width: 769px) and (max-width: 1100px) {
  .car-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .listings-grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)) !important;
  }
}

/* Confirmation Modal */
.confirm-box {
  max-width: 400px;
  text-align: center;
  padding: 2.5rem;
  border-radius: 24px;
  background: white;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.confirm-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.confirm-box h2 {
  color: var(--secondary);
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.confirm-box p {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 2rem;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn-cancel,
.btn-proceed {
  padding: 0.8rem 2rem;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 0.9rem;
}

.btn-cancel {
  background: #f1f2f6;
  color: var(--text-light);
}

.btn-cancel:hover {
  background: #dfe4ea;
  color: var(--secondary);
}

.btn-proceed {
  background: var(--primary);
  color: white;
}

.btn-proceed:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(255, 71, 87, 0.3);
}

/* Theme adjustments for confirm box */
[data-theme="xo"] .confirm-box {
  border-color: var(--primary);
}

[data-theme="pochacco"] .confirm-box {
  border-color: var(--primary);
}

[data-theme="kuromi"] .confirm-box {
  border-color: var(--primary);
}

[data-theme="hello-kitty"] .confirm-box {
  border-color: var(--primary);
}
/* ===== Phone layout (normal + wide phones) =====
   Compact two-row header with an icon theme picker, and a collapsible
   filter bar that also shows the result count, so cars appear sooner. */
@media (max-width: 768px) {

  /* Header: row 1 = title + theme button, row 2 = user + online */
  header {
    padding: 0.75rem 1rem;
  }

  .header-content {
    gap: 0;
  }

  .header-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.5rem;
  }

  .title-area {
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    min-width: 0;
  }

  #main-title {
    flex-basis: 100%;
    font-size: 1.2rem;
    line-height: 1.3;
    white-space: nowrap;
  }

  .app-version {
    font-size: 0.7rem;
    padding: 1px 6px;
    margin-left: 4px;
  }

  .online-label {
    font-size: 0.72rem;
  }

  .online-name {
    font-size: 0.85rem !important;
  }

  /* Theme: round 🎨 button; the transparent native select on top opens the phone's picker */
  .theme-selector {
    flex: none;
    position: relative;
    width: 40px;
    height: 40px;
    justify-content: center;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  }

  #theme-label {
    display: none;
  }

  .theme-icon {
    display: block;
    font-size: 1.2rem;
    line-height: 1;
    pointer-events: none;
  }

  .theme-dropdown {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100%;
    min-width: 0;
    max-width: none;
    padding: 0 !important;
    opacity: 0;
    cursor: pointer;
  }

  /* Count + average move into the filter bar */
  .stats {
    display: none;
  }

  /* Leaderboard: tighter card */
  .leaderboard-card {
    padding: 0.9rem 1rem;
    border-radius: 16px;
    margin-bottom: 0;
  }

  .leaderboard-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }

  /* Filter bar: collapsed to one row until tapped */
  .filter-bar {
    display: block;
    padding: 0;
    border-radius: 14px;
    margin-bottom: 0.8rem;
  }

  .filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: 0;
    font-family: inherit;
    color: var(--secondary);
    cursor: pointer;
    text-align: left;
  }

  .filter-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--btn-bg);
    color: var(--btn-text);
    font-size: 0.72rem;
  }

  .filter-count[hidden] {
    display: none;
  }

  .results-summary {
    margin-left: auto;
    min-width: 0;
    font-size: 0.8rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .filter-toggle .dropdown-arrow {
    margin-left: 0;
    color: var(--text-light);
  }

  .filter-bar.open .filter-toggle .dropdown-arrow {
    transform: rotate(180deg);
  }

  .filter-panel {
    display: none;
  }

  .filter-bar.open .filter-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem 0.75rem;
    padding: 0.8rem 1rem 1rem;
    border-top: 1px solid var(--border-color);
  }

  .filter-panel .filter-group label {
    margin-bottom: 0;
  }

  .filter-panel select,
  .filter-panel .features-dropdown-toggle {
    padding: 8px 26px 8px 10px;
    font-size: 0.85rem;
  }

  .filter-panel .select-wrapper::after {
    right: 0.6rem;
  }

  /* Features menu sits in the right column: grow leftwards so options stay on one line */
  .filter-panel .features-dropdown-menu {
    left: auto;
    min-width: 190px;
  }

  .filter-panel .features-option {
    white-space: nowrap;
  }

  .filter-panel .checkbox-group {
    justify-content: center;
    padding-bottom: 0;
  }

  .filter-panel .checkbox-container {
    gap: 0.45rem;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .filter-panel .checkbox-container input {
    width: 18px;
    height: 18px;
  }

  /* Sliders: full width each on normal phones (easier to drag) */
  .filter-panel .range-filters-container {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .filter-panel .range-header {
    font-size: 0.8rem;
    white-space: nowrap;
  }
}

/* Wide phones: sliders side by side */
@media (min-width: 420px) and (max-width: 768px) {
  .filter-panel .range-filters-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }
}
