:root {
  --bg: #fff8ee;
  --card: rgba(255, 251, 245, 0.9);
  --card-solid: #fffbf5;
  --text: #2a211a;
  --muted: #7a6a5c;
  --line: rgba(80, 55, 30, 0.12);
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(228, 87, 46, 0.12);
  --gold: #f4a259;
  --shadow: 0 10px 30px rgba(60, 35, 10, 0.16), 0 2px 6px rgba(60, 35, 10, 0.08);
  --radius: 18px;
  --sheet-peek: 196px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #16130f;
    --card: rgba(30, 25, 20, 0.88);
    --card-solid: #1e1914;
    --text: #f6ece0;
    --muted: #b3a291;
    --line: rgba(255, 230, 200, 0.1);
    --accent: #ff6b3d;
    --accent-soft: rgba(255, 107, 61, 0.16);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
    --icon-filter: invert(0.9);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.card {
  background: var(--card);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- brand + search ------------------------------------------------------------ */

.brand {
  position: fixed;
  top: 14px;
  left: 14px;
  width: min(380px, calc(100vw - 28px));
  padding: 14px;
  z-index: 3;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  font-size: 26px;
  flex: none;
  box-shadow: 0 4px 12px rgba(228, 87, 46, 0.35);
}

.brand-text {
  flex: 1;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.search {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-field svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
}

#search {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-solid);
  outline: none;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: scale(0.97);
}

.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.btn[aria-busy='true'] svg {
  animation: spin 1s linear infinite;
}

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

.suggestions {
  list-style: none;
  margin: 8px 0 0;
  padding: 4px;
  max-height: 50vh;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.suggestions li[aria-selected='true'],
.suggestions li:hover {
  background: var(--accent-soft);
}

.suggestions .s-icon {
  width: 22px;
  text-align: center;
  flex: none;
}

.suggestions .s-main {
  flex: 1;
  min-width: 0;
}

.suggestions .s-title,
.suggestions .s-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestions .s-sub {
  color: var(--muted);
  font-size: 12.5px;
}

.suggestions .s-count {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.suggestions .s-empty {
  color: var(--muted);
  cursor: default;
}

/* ---- rankings panel ------------------------------------------------------------ */

.panel {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: 360px;
  display: flex;
  flex-direction: column;
  padding: 14px 14px 6px;
  z-index: 2;
}

.grabber {
  display: none;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-height: 22px;
  font-size: 12.5px;
  color: var(--muted);
}

.crumbs button {
  padding: 2px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.crumbs button:hover {
  background: var(--accent-soft);
}

.crumbs .sep {
  opacity: 0.5;
}

.region-title {
  margin: 2px 0 2px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.stats {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.stats strong {
  color: var(--text);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tabs,
.segmented {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--accent-soft);
}

.tabs button,
.segmented button {
  padding: 0 12px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}

.tabs [aria-selected='true'],
.segmented [aria-pressed='true'] {
  background: var(--card-solid);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.segmented {
  margin-top: 8px;
}

.tabs button,
.segmented button {
  flex: 1;
}

.hint {
  margin: 10px 2px 4px;
  color: var(--muted);
  font-size: 12.5px;
}

.ranking {
  list-style: none;
  margin: 0 -8px;
  padding: 0 0 8px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
}

.ranking li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 4px 10px;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.ranking li:hover,
.ranking li:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.ranking li:nth-child(-n + 3) .rank {
  background: linear-gradient(135deg, var(--gold), var(--accent));
  color: #fff;
}

.r-name {
  min-width: 0;
}

.r-title,
.r-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.r-title {
  font-weight: 600;
}

.r-sub {
  color: var(--muted);
  font-size: 12.5px;
}

.r-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.r-value strong {
  display: block;
  font-size: 16px;
}

.r-value span {
  color: var(--muted);
  font-size: 11.5px;
}

.r-bar {
  grid-column: 2 / 4;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.r-bar i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
}

.ranking .empty {
  display: block;
  padding: 20px 10px;
  color: var(--muted);
  cursor: default;
}

/* ---- ramen score card ---------------------------------------------------------- */

.score {
  position: fixed;
  left: 14px;
  bottom: 54px;
  width: min(380px, calc(100vw - 28px));
  max-height: 46vh;
  overflow: auto;
  padding: 16px;
  z-index: 3;
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 18px;
  font-weight: 400;
}

.score-head {
  display: flex;
  gap: 14px;
  align-items: center;
  padding-right: 30px;
}

.score-number {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  flex: none;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  color: #fff;
  text-align: center;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(228, 87, 46, 0.35);
}

.score-number strong {
  font-size: 34px;
  font-variant-numeric: tabular-nums;
}

.score-number span {
  margin-top: -14px;
  font-size: 11px;
  opacity: 0.9;
}

.tier {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.score-text {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.nearby {
  list-style: none;
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
}

.nearby li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.nearby li:hover {
  background: var(--accent-soft);
}

.nearby .n-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby .n-dist {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---- legend, toast, popups ----------------------------------------------------- */

.legend {
  position: fixed;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  z-index: 1;
}

.ramp {
  width: 110px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255, 214, 150, 0.6), #f9a24b, #ef6a2f, #c8102e, #6d0019);
}

.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.maplibregl-popup-content {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--card-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  font: inherit;
  min-width: 220px;
  max-width: 300px;
}

.maplibregl-popup-tip {
  border-top-color: var(--card-solid) !important;
  border-bottom-color: var(--card-solid) !important;
}

.maplibregl-popup-close-button {
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 18px;
}

.shop h3 {
  margin: 0 22px 2px 0;
  font-size: 16px;
  line-height: 1.25;
}

.shop .alt {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.shop .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0;
}

.shop .chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.shop p {
  margin: 4px 0;
  font-size: 13px;
}

.shop .muted {
  color: var(--muted);
}

.shop .links {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
}

.shop .links a {
  text-decoration: none;
}

.maplibregl-ctrl-group {
  border-radius: 12px !important;
  overflow: hidden;
  background: var(--card-solid) !important;
  box-shadow: var(--shadow) !important;
}

.maplibregl-ctrl-group button + button {
  border-top-color: var(--line) !important;
}

.maplibregl-ctrl button .maplibregl-ctrl-icon {
  filter: var(--icon-filter, none);
}

.maplibregl-ctrl-attrib {
  background: var(--card) !important;
  color: var(--muted);
  border-radius: 999px !important;
}

.maplibregl-ctrl-attrib-inner {
  color: var(--muted);
}

.maplibregl-ctrl-attrib a {
  color: var(--muted) !important;
}

.maplibregl-ctrl-attrib-button {
  filter: var(--icon-filter, none);
}

.stats .nowrap {
  white-space: nowrap;
}

.maplibregl-ctrl-bottom-right {
  right: 384px;
}

/* ---- about dialog -------------------------------------------------------------- */

.about {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

.about::backdrop {
  background: rgba(20, 12, 5, 0.45);
  backdrop-filter: blur(2px);
}

.about h2 {
  margin: 0 0 8px;
}

.about h3 {
  margin: 18px 0 4px;
  font-size: 15px;
}

.about p,
.about li {
  color: var(--muted);
  font-size: 14px;
}

.about ul {
  padding-left: 20px;
}

.about code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- phones: rankings become a bottom sheet ------------------------------------ */

@media (max-width: 760px) {
  .brand {
    top: 10px;
    left: 10px;
    width: calc(100vw - 20px);
    padding: 12px;
  }

  .tagline {
    display: none;
  }

  .logo {
    width: 36px;
    height: 36px;
    font-size: 21px;
    border-radius: 11px;
  }

  h1 {
    font-size: 18px;
  }

  .search {
    margin-top: 10px;
  }

  .btn span {
    display: none;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 72vh;
    padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    transform: translateY(calc(100% - var(--sheet-peek)));
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .panel.open {
    transform: none;
  }

  .panel.dragging {
    transition: none;
  }

  /* the whole header is the drag handle */
  .sheet-head {
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
  }

  .grabber {
    display: block;
    width: 100%;
    height: 20px;
    margin-bottom: 2px;
    border: 0;
    background: transparent;
    cursor: grab;
  }

  .grabber::before {
    content: '';
    display: block;
    width: 44px;
    height: 5px;
    margin: 0 auto;
    border-radius: 3px;
    background: var(--line);
    box-shadow: inset 0 0 0 10px rgba(128, 100, 70, 0.3);
  }

  .score {
    left: 10px;
    bottom: calc(var(--sheet-peek) + 10px);
    width: calc(100vw - 20px);
    max-height: 40vh;
  }

  .legend {
    display: none;
  }

  .maplibregl-ctrl-bottom-right {
    right: 0;
    bottom: var(--sheet-peek);
  }
}
