:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-muted: #f8f7f4;
  --border: rgba(28, 40, 35, 0.08);
  --border-strong: rgba(28, 40, 35, 0.14);
  --text: #1c2823;
  --text-secondary: #5c6b64;
  --text-tertiary: #8a9690;
  --accent: #1f6b58;
  --accent-dark: #185747;
  --accent-soft: rgba(31, 107, 88, 0.1);
  --accent-muted: rgba(31, 107, 88, 0.06);
  --danger: #b42318;
  --success: #18794e;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow-sm: 0 1px 2px rgba(28, 40, 35, 0.04);
  --shadow-md: 0 4px 20px rgba(28, 40, 35, 0.06);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --touch-min: 44px;
  --page-pad-x: max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --page-pad-bottom: max(0.875rem, env(safe-area-inset-bottom, 0px));
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.filter-open {
  overflow: hidden;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* —— Header —— */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.875rem var(--page-pad-x);
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.logo {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.logo-sub {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* —— Mobile filter bar —— */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem var(--page-pad-x);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  min-height: 2.375rem;
  padding: 0 0.875rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
}

.active-filters-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.active-filters-scroll::-webkit-scrollbar {
  display: none;
}

.active-filters {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding-right: 0.5rem;
  white-space: nowrap;
}

.active-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2rem;
  padding: 0.2rem 0.625rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.active-filter--teal {
  background: var(--accent-soft);
  border-color: rgba(31, 107, 88, 0.18);
  color: var(--accent-dark);
}

.active-filter--muted {
  color: var(--text-tertiary);
  border-style: dashed;
  background: transparent;
}

.active-filter-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-right: -0.125rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(28, 40, 35, 0.08);
  color: var(--text-secondary);
  font-size: 0.6875rem;
  line-height: 1;
  cursor: pointer;
}

/* —— Layout —— */
.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  min-height: 0;
}

/* —— Filter panel —— */
.filter-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  visibility: hidden;
}

.filter-panel.open {
  pointer-events: auto;
  visibility: visible;
}

.filter-panel-overlay {
  position: absolute;
  inset: 0;
  background: rgba(28, 40, 35, 0.4);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.filter-panel.open .filter-panel-overlay {
  opacity: 1;
}

.filter-panel-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88dvh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(28, 40, 35, 0.14);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.filter-panel.open .filter-panel-body {
  transform: translateY(0);
}

.filter-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.125rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-panel-header h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.filter-panel-body .filter-section {
  padding: 1rem 1.125rem;
  flex-shrink: 0;
}

.filter-panel-body .filter-section:nth-child(3) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-section + .filter-section {
  border-top: 1px solid var(--border);
}

.filter-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.filter-section-head h3 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.map {
  height: 152px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-muted);
  touch-action: manipulation;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.interest-search {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.625rem 0.875rem;
  margin-bottom: 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

.interest-search:focus {
  outline: none;
  border-color: rgba(31, 107, 88, 0.35);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.interest-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-content: flex-start;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.interest-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.125rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.interest-chip.hidden-by-search {
  display: none;
}

.interest-chip .chip-emoji {
  font-size: 0.875rem;
  line-height: 1;
}

.interest-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.field-row output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.field input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  height: 4px;
  min-height: var(--touch-min);
  margin: 0;
  cursor: pointer;
}

.btn-link,
.btn-done {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0 0.375rem;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-link {
  color: var(--accent);
  margin: -0.5rem -0.375rem -0.5rem 0;
}

.btn-done {
  color: var(--accent-dark);
  margin: -0.5rem -0.375rem -0.5rem 0;
}

/* —— Content —— */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 0 var(--page-pad-x) var(--page-pad-bottom);
}

.feed-header {
  flex-shrink: 0;
  padding: 0.75rem 0 0.625rem;
}

.feed-summary {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}

.results-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.25rem;
  text-align: center;
}

.state--compact {
  padding: 3.5rem 1.25rem;
}

.state h3 {
  margin: 0 0 0.375rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.state > p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  max-width: 28ch;
}

.state-error h3 {
  color: var(--danger);
}

.btn-cta {
  margin-top: 1.125rem;
  min-height: var(--touch-min);
  padding: 0 1.375rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.spinner {
  width: 24px;
  height: 24px;
  margin: 0 auto 0.75rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* —— Result cards —— */
.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  animation: fadeUp 0.28s ease both;
  overflow: hidden;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-card-inner {
  display: flex;
  align-items: stretch;
  min-height: 7.5rem;
}

.result-thumb {
  position: relative;
  flex: 0 0 7.5rem;
  width: 7.5rem;
  background: var(--surface-muted);
  overflow: hidden;
}

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

.result-thumb--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--accent-muted) 0%, var(--surface-muted) 100%);
}

.result-thumb--empty span {
  font-size: 1.75rem;
  opacity: 0.55;
}

.result-photo-credit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.25rem 0.375rem 0.3rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.5625rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.875rem 1rem;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.625rem;
}

.result-head h3 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.result-match {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.result-weather {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem 0.375rem;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.stat {
  display: inline-flex;
  align-items: center;
}

.stat-dot {
  opacity: 0.35;
  user-select: none;
}

.stat--rating::after {
  content: ' ★';
  color: #c99700;
  font-size: 0.6875rem;
}

.stat--open {
  color: var(--success);
  font-weight: 600;
}

.stat--closed {
  color: var(--danger);
  font-weight: 600;
}

.result-reason {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.35;
}

.hidden {
  display: none !important;
}

@media (max-width: 359px) {
  .result-thumb {
    flex: 0 0 6.25rem;
    width: 6.25rem;
  }

  .result-card-inner {
    min-height: 6.25rem;
  }

  .result-content {
    padding: 0.75rem 0.875rem;
  }
}

@media (hover: hover) and (pointer: fine) {
  .filter-toggle:hover {
    border-color: rgba(31, 107, 88, 0.25);
  }

  .btn-cta:hover {
    background: var(--accent-dark);
  }

  .btn-link:hover {
    color: var(--accent-dark);
  }

  .interest-chip:hover:not(.selected) {
    border-color: rgba(31, 107, 88, 0.22);
    background: var(--accent-muted);
  }

  .result-card {
    transition: box-shadow 0.15s ease, transform 0.15s ease;
  }

  .result-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }
}

@media (min-width: 768px) {
  html,
  body {
    font-size: 16px;
  }

  .topbar-inner {
    flex-direction: row;
    align-items: baseline;
    gap: 0.75rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  .logo {
    font-size: 1.1875rem;
  }

  .logo-sub {
    font-size: 0.875rem;
  }

  .filter-bar {
    display: none;
  }

  .layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    padding: 1.25rem var(--page-pad-x) 2rem;
    align-items: start;
  }

  .filter-panel {
    position: static;
    visibility: visible;
    pointer-events: auto;
    z-index: auto;
  }

  .filter-panel-overlay,
  .filter-panel-header {
    display: none;
  }

  .filter-panel-body {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 4.75rem);
    transform: none;
    transition: none;
    max-height: none;
    overflow: visible;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding-bottom: 0;
  }

  .filter-panel-body .filter-section:nth-child(2),
  .filter-panel-body .filter-section:nth-child(3) {
    flex: none;
  }

  .filter-panel-body .filter-section:nth-child(3) {
    max-height: 320px;
  }

  .map {
    height: 168px;
  }

  .filter-section-head h3 {
    font-size: 0.75rem;
  }

  .interest-search {
    min-height: 3rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 1rem;
  }

  .interest-grid {
    gap: 0.5rem;
  }

  .interest-chip {
    min-height: 2.625rem;
    padding: 0.5rem 1rem;
    gap: 0.375rem;
    font-size: 0.9375rem;
  }

  .interest-chip .chip-emoji {
    font-size: 1.0625rem;
  }

  .field-row {
    font-size: 0.875rem;
  }

  .hint {
    font-size: 0.8125rem;
  }

  .btn-link {
    font-size: 0.875rem;
  }

  .content {
    padding: 0;
  }

  .feed-header {
    padding-top: 0;
    padding-bottom: 0.875rem;
  }

  .feed-summary {
    font-size: 0.9375rem;
  }

  .results-panel {
    overflow: visible;
  }

  .results {
    gap: 0.75rem;
  }

  .result-card-inner {
    min-height: 10.5rem;
  }

  .result-thumb {
    flex: 0 0 12.5rem;
    width: 12.5rem;
  }

  .result-content {
    padding: 1rem 1.25rem;
    gap: 0.4375rem;
  }

  .result-head h3 {
    font-size: 1.125rem;
    line-height: 1.25;
  }

  .result-match {
    font-size: 0.9375rem;
  }

  .result-weather {
    font-size: 0.9375rem;
  }

  .result-stats {
    font-size: 0.8125rem;
  }

  .result-reason {
    font-size: 0.8125rem;
  }

  .stat--rating::after {
    font-size: 0.75rem;
  }

  .state {
    min-height: 260px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
  }

  .btn-cta {
    display: none;
  }
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 360px 1fr;
    gap: 2rem;
  }

  .filter-panel-body .filter-section:nth-child(3) {
    max-height: 360px;
  }

  .interest-chip {
    min-height: 2.75rem;
    padding: 0.5625rem 1.125rem;
    font-size: 1rem;
  }

  .interest-chip .chip-emoji {
    font-size: 1.125rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .feed-summary {
    font-size: 1rem;
  }

  .result-card-inner {
    min-height: 12.5rem;
  }

  .result-thumb {
    flex: 0 0 18rem;
    width: 18rem;
  }

  .result-content {
    padding: 1.25rem 1.625rem;
    gap: 0.5rem;
  }

  .result-head h3 {
    font-size: 1.25rem;
  }

  .result-match {
    font-size: 1rem;
  }

  .result-weather {
    font-size: 1rem;
  }

  .result-stats {
    font-size: 0.875rem;
  }

  .result-reason {
    font-size: 0.875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
