:root {
  --paper: #FFF7ED;
  --ink: #0F172A;
  --see: #0891B2;
  --eat: #EA580C;
  --card: #FFFFFF;
  --muted: #475569;
  --line: #FCEAE1;
  --visited: #64748B;
  --wash: #FDF4F0;
  --visited-card: #F8FAFC;
  --ok-bg: #E2E8F0;
  --radius: 18px;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --sheet-visible: 45dvh;
  --focus: 0 0 0 3px #0891B2;
}

:root[data-theme="dark"] {
  --paper: #0F172A;
  --ink: #FFF7ED;
  --see: #67E8F9;
  --eat: #FB923C;
  --card: #1E293B;
  --muted: #CBD5E1;
  --line: #334155;
  --visited: #94A3B8;
  --wash: #334155;
  --visited-card: #162032;
  --ok-bg: #334155;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 3px #67E8F9;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, a, input { font: inherit; }

button { color: inherit; cursor: pointer; }

:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--see);
  outline-offset: 2px;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--paper);
}

.side {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: min(400px, calc(100vw - 96px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.side > * { pointer-events: auto; }

.topbar,
.sheet,
.search-results,
.ctrl-btn,
.loading,
.toast,
.maplibregl-popup-content {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: var(--radius);
  padding: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 32%, #fff 0 18%, transparent 19%),
    linear-gradient(135deg, var(--see), var(--eat));
}

.brand-name {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.2px;
}

.search { position: relative; }

#search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}

#search-input:focus-visible { box-shadow: var(--focus); }

#search-input::placeholder { color: var(--muted); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 14px;
  z-index: 30;
}

.search-results li button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}

.search-results li button:hover,
.search-results li button.active { background: var(--wash); }

.search-results .res-name { font-weight: 700; overflow-wrap: anywhere; }
.search-results .res-sub { display: block; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.search-results .res-type {
  flex-shrink: 0;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
}
.search-results .res-empty { padding: 12px; color: var(--muted); }

.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.breadcrumb button {
  min-height: 44px;
  border: 0;
  background: var(--paper);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.breadcrumb button[aria-current="true"] {
  background: var(--eat);
  color: #000000;
}

.breadcrumb .sep { color: var(--muted); font-size: 13px; }

.sheet {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
}

.sheet-grip { display: none; }

.sheet-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 16px 16px 8px;
}

.icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.sheet-titles { min-width: 0; flex: 1; }

.sheet-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--see);
}

.sheet-title {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.sheet-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.sheet-stats {
  display: flex;
  gap: 8px;
  padding: 4px 16px 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.stat strong { display: block; font-size: 22px; font-weight: 800; color: var(--eat); overflow-wrap: anywhere; }
.stat span { display: block; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 12px 16px;
  -webkit-overflow-scrolling: touch;
}

.section-title {
  margin: 12px 4px 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  margin: 8px 4px 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--wash);
  border: 1px dashed var(--line);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.row {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--paper);
  text-align: left;
}

.row:hover { border-color: var(--line); }
.row:active { background: var(--wash); }
.row.empty { opacity: 0.55; }

.row .dot {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  box-shadow: 0 0 0 1px var(--line);
}

.row .row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .row-name,
.row .row-sub { overflow-wrap: anywhere; }
.row .row-name { font-weight: 700; }
.row .row-sub { margin-top: 2px; font-size: 13px; color: var(--muted); }

.badge {
  flex-shrink: 0;
  min-width: 32px;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--eat);
  color: #000000;
  font-weight: 800;
  font-size: 13px;
  text-align: center;
}

.badge.zero { background: var(--paper); color: var(--muted); border: 1px solid var(--line); }

.storage {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.storage-text { margin: 0; font-size: 14px; line-height: 1.45; color: var(--muted); }

.card {
  padding: 14px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
}

.card.visited {
  background: var(--visited-card);
  border-color: var(--line);
}

.card-top { display: flex; align-items: flex-start; gap: 10px; }

.card-num {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--eat);
  color: #000000;
  font-weight: 800;
  font-size: 14px;
}

.card.visited .card-num { background: var(--visited); color: #FFFFFF; }

.card-name { margin: 0; font-size: 17px; font-weight: 800; overflow-wrap: anywhere; }

.card-hood { margin: 2px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }

.chip {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--paper);
  color: var(--ink);
}

.chip-ver { background: var(--see); color: #000000; }
.chip-comer { background: var(--eat); color: #000000; }

.card-desc { margin: 10px 0 12px; font-size: 15px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }

.card.visited .card-desc,
.card.visited .card-name { color: var(--visited); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  flex: 1 1 8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  overflow-wrap: anywhere;
}

.btn.primary { background: var(--eat); border-color: var(--eat); color: #000000; }
.btn.ok { background: var(--ok-bg); border-color: var(--visited); color: var(--visited); }

.maplibregl-popup-content {
  padding: 0;
  border-radius: 16px;
  font-family: var(--font);
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--card); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--card); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--card); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--card); }

.maplibregl-popup-close-button {
  color: var(--ink);
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 0 16px 0 10px;
}

.popup { padding: 16px; width: min(300px, calc(100vw - 48px)); }
.popup h3 { margin: 0 36px 0 0; font-size: 17px; font-weight: 800; overflow-wrap: anywhere; }
.popup p { margin: 10px 0 12px; font-size: 15px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.popup .place { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.map-controls {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 25;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
}

.ctrl-btn:active { background: var(--paper); }

.loading {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  width: min(320px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 14px;
  z-index: 40;
}

.loading p { margin: 0 0 8px; font-size: 14px; font-weight: 700; }

.loading-bar { height: 8px; border-radius: 999px; background: var(--paper); overflow: hidden; }

.loading-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--eat);
  transition: width 0.2s;
}

.loading.indeterminate .loading-bar span {
  width: 35% !important;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(300%); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.4;
  z-index: 50;
}

.maplibregl-ctrl-attrib { font-size: 11px; background: color-mix(in srgb, var(--paper) 90%, transparent); color: var(--muted); }

@media (min-width: 1024px) {
  .side { width: 400px; }
}

@media (max-width: 767px) {
  .side { display: contents; }

  .topbar {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    left: 10px;
    right: calc(10px + 44px + 8px);
    padding: 10px;
    z-index: 20;
  }

  .brand { display: none; }

  .breadcrumb { margin-top: 8px; }

  .map-controls {
    top: calc(10px + env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }

  .sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 88dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    transform: translateY(calc(100% - var(--sheet-visible)));
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 15;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sheet.dragging { transition: none; }

  .sheet-grip {
    display: grid;
    place-items: center;
    height: 28px;
    touch-action: none;
    cursor: grab;
  }

  .sheet-grip span {
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: var(--muted);
  }

  .sheet-header { padding-top: 0; touch-action: none; }

  .sheet-body { touch-action: none; }

  .sheet[data-snap="full"] .sheet-body {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  .sheet-title { font-size: 22px; }

  .toast { bottom: calc(var(--sheet-visible) + 12px); }

  .loading { top: auto; bottom: calc(var(--sheet-visible) + 12px); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet,
  .loading-bar span,
  .row,
  .btn,
  .ctrl-btn { transition: none; }

  .loading.indeterminate .loading-bar span { animation: none; }
}
