:root {
    --bg: #ffffff;
    --bg-soft: #f7f7f7;
    --card: #ffffff;
    --text: #222222;
    --muted: #717171;
    --line: #ebebeb;
    --accent: #ff385c;
    --accent-soft: #fff0f3;
    --shadow: 0 2px 16px rgba(0,0,0,.12);
    --shadow-lg: 0 8px 28px rgba(0,0,0,.16);
    --radius: 16px;
    --radius-sm: 12px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --panel-w: min(400px, 100%);
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; margin: 0; }
  body {
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    color: var(--text); background: var(--bg); overflow: hidden;
  }
  .app {
    height: 100%; width: 100%;
    display: grid;
    grid-template-columns: var(--panel-w) 1fr;
    grid-template-rows: 1fr;
  }
  .panel {
    background: var(--bg);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    min-height: 0; z-index: 5;
  }
  .topbar {
    padding: 16px 16px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }
  .brand {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-bottom: 10px;
  }
  .brand h1 {
    margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em;
  }
  .budget-pill {
    font-size: 0.72rem; font-weight: 600;
    background: var(--accent-soft); color: var(--accent);
    padding: 5px 10px; border-radius: 999px; white-space: nowrap;
  }
  .sub {
    margin: 0 0 12px; font-size: 0.8rem; color: var(--muted); line-height: 1.35;
  }
  .search {
    width: 100%; border: 1px solid var(--line); border-radius: 999px;
    padding: 12px 14px 12px 40px; font-size: 0.9rem; outline: none;
    background: var(--bg-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23717171' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l3.5 3.5'/%3E%3C/svg%3E") 14px center no-repeat;
    transition: box-shadow .15s, border-color .15s;
  }
  .search:focus { background-color: #fff; border-color: #222; box-shadow: 0 0 0 2px rgba(0,0,0,.06); }
  .chips {
    display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex: 0 0 auto; border: 1px solid var(--line); background: #fff;
    border-radius: 999px; padding: 8px 14px; font-size: 0.78rem; font-weight: 500;
    color: var(--text); cursor: pointer; white-space: nowrap;
  }
  .chip.active { background: #222; color: #fff; border-color: #222; }
  .guide-btn {
    margin: 10px 16px 0; border: 1px solid var(--line); background: #fff;
    border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.8rem;
    text-align: left; cursor: pointer; color: var(--text); font-weight: 500;
  }
  .guide-btn:active { background: var(--bg-soft); }
  .list {
    flex: 1; overflow-y: auto; padding: 8px 12px 24px;
    -webkit-overflow-scrolling: touch;
  }
  .section-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--muted); padding: 12px 4px 6px;
  }
  .card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 0; margin-bottom: 10px;
    cursor: pointer; transition: box-shadow .15s, transform .15s;
    overflow: hidden;
  }
  .card-photo-wrap {
    width: 100%; aspect-ratio: 16 / 10; max-height: 180px;
    background: #e8e8e8; overflow: hidden;
  }
  .card-photo {
    width: 100%; height: 100%; object-fit: cover; display: block;
    background: #e8e8e8;
  }
  .card-body { padding: 12px; }
  .sheet-photo {
    width: 100%; aspect-ratio: 16 / 10; object-fit: cover;
    border-radius: 12px; background: #e8e8e8; margin-bottom: 12px;
    display: block;
  }
  .popup-photo {
    width: 100%; max-width: 220px; height: 120px; object-fit: cover;
    border-radius: 8px; display: block; margin-bottom: 6px; background: #e8e8e8;
  }
  .card:hover { box-shadow: var(--shadow); }
  .card:active { transform: scale(.99); }
  .card.active { border-color: #222; box-shadow: var(--shadow); }
  .card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
  .card h3 { margin: 0; font-size: 0.95rem; font-weight: 600; }
  .badge {
    font-size: 0.65rem; font-weight: 600; padding: 3px 8px; border-radius: 999px;
    background: var(--bg-soft); color: var(--muted); white-space: nowrap;
  }
  .badge.fit { background: #e8f8ef; color: #0d7a3e; }
  .badge.stretch { background: #fff6e5; color: #a15c00; }
  .badge.dream { background: #f3e8ff; color: #7c3aed; }
  .badge.alpha { background: #e8f1ff; color: #2563eb; }
  .badge.pass { background: var(--bg-soft); color: var(--muted); }
  .blurb { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }
  .price {
    margin-top: 8px; font-size: 1rem; font-weight: 700; color: var(--text);
  }
  .meta { margin-top: 2px; font-size: 0.78rem; color: var(--muted); }
  .map-wrap { position: relative; min-height: 0; background: #e5e5e5; }
  #map { width: 100%; height: 100%; }
  .float-legend {
    position: absolute; left: 12px; bottom: 12px; z-index: 500;
    background: rgba(255,255,255,.95); border: 1px solid var(--line);
    border-radius: 12px; padding: 8px 10px; font-size: 0.7rem; color: var(--muted);
    box-shadow: var(--shadow); backdrop-filter: blur(8px);
  }
  .float-legend div { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
  .dot { width: 10px; height: 10px; border-radius: 50%; }
  .sheet {
    display: none; position: absolute; inset: 0; z-index: 1000;
    pointer-events: none;
  }
  .sheet.open { display: block; pointer-events: auto; }
  .sheet-backdrop {
    position: absolute; inset: 0; background: rgba(0,0,0,.25);
  }
  .sheet-card {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: min(78vh, 640px);
    background: #fff; border-radius: 24px 24px 0 0;
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    padding-bottom: var(--safe-b);
    animation: up .22s ease-out;
  }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
  .sheet-handle {
    width: 40px; height: 4px; border-radius: 999px; background: #ddd;
    margin: 10px auto 6px;
  }
  .sheet-head {
    padding: 4px 18px 12px; border-bottom: 1px solid var(--line);
    display: flex; justify-content: space-between; gap: 12px; align-items: start;
  }
  .sheet-head h2 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
  .sheet-head .subline { margin-top: 4px; font-size: 0.82rem; color: var(--muted); }
  .xbtn {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: var(--bg-soft); color: var(--text); font-size: 1.1rem; cursor: pointer;
    flex: 0 0 auto;
  }
  .sheet-body { overflow-y: auto; padding: 14px 18px 28px; -webkit-overflow-scrolling: touch; }
  .sheet-body h4 {
    margin: 16px 0 8px; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: .06em; color: var(--muted); font-weight: 700;
  }
  .sheet-body h4:first-child { margin-top: 0; }
  .sheet-body p, .sheet-body li { font-size: 0.9rem; line-height: 1.45; }
  .sheet-body ul { margin: 0; padding-left: 1.1rem; color: var(--muted); }
  .sheet-body li { margin-bottom: 5px; }
  .sheet-body li strong { color: var(--text); }
  .factor {
    background: var(--bg-soft); border-radius: 12px; padding: 12px; margin-bottom: 8px;
  }
  .factor .label { font-size: 0.7rem; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
  .factor .val { font-size: 0.88rem; line-height: 1.4; }
  .cta {
    display: inline-flex; align-items: center; justify-content: center;
    margin-top: 8px; background: var(--accent); color: #fff; text-decoration: none;
    font-weight: 600; font-size: 0.9rem; padding: 12px 16px; border-radius: 999px;
    width: 100%;
  }
  .mobile-toggle {
    display: none; position: absolute; left: 50%; transform: translateX(-50%);
    bottom: calc(16px + var(--safe-b)); z-index: 600;
    background: #222; color: #fff; border: none; border-radius: 999px;
    padding: 12px 18px; font-weight: 600; font-size: 0.88rem;
    box-shadow: var(--shadow-lg); cursor: pointer; gap: 8px; align-items: center;
  }
  .leaflet-popup-content-wrapper {
    border-radius: 12px; box-shadow: var(--shadow); padding: 2px;
    font-family: Inter, system-ui, sans-serif;
  }
  .leaflet-popup-content { margin: 10px 12px; font-size: 0.85rem; }
  .leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

  /* Desktop detail dock inside map */
  .desk-detail {
    display: none; position: absolute; top: 16px; right: 16px; bottom: 16px;
    width: min(380px, calc(100% - 32px)); z-index: 700;
    background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg);
    border: 1px solid var(--line); overflow: hidden; flex-direction: column;
  }
  .desk-detail.open { display: flex; }

  @media (max-width: 860px) {
    .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
    .panel {
      position: absolute; left: 0; right: 0; bottom: 0; top: auto;
      height: 42%; max-height: 48%;
      border-right: none; border-top: 1px solid var(--line);
      border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.08);
    }
    .panel.expanded { height: 78%; max-height: 85%; }
    .map-wrap { height: 100%; }
    .float-legend { bottom: calc(44% + 12px); }
    .panel.expanded ~ .map-wrap .float-legend,
    .app:has(.panel.expanded) .float-legend { bottom: calc(80% + 8px); display: none; }
    .mobile-toggle { display: inline-flex; }
    .desk-detail { display: none !important; }
    .topbar { padding-top: 8px; }
    .drag {
      width: 40px; height: 4px; border-radius: 999px; background: #ddd;
      margin: 8px auto 4px;
    }
  }
  @media (min-width: 861px) {
    .drag { display: none; }
    .sheet { display: none !important; }
  }
