:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: #ffffff;
  --text: #172033;
  --muted: #667085;
  --accent: #0f6cbd;
  --accent-strong: #0a57a0;
  --border: rgba(23, 32, 51, 0.08);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 0 14px;
}

input {
  border: 0;
  background: transparent;
  min-width: 0;
}

input:focus {
  outline: none;
}

.app-shell {
  position: relative;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  z-index: 1100;
  inset: max(12px, env(safe-area-inset-top)) 12px auto;
  display: grid;
  gap: 6px;
  width: min(720px, calc(100vw - 88px));
}

.search-shell {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 22px;
  padding: 8px;
  backdrop-filter: blur(18px);
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.search-icon {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #eef5ff;
  color: var(--accent);
  font-size: 22px;
  flex-shrink: 0;
}

#searchInput {
  width: 100%;
  font-size: 0.98rem;
  color: var(--text);
}

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

.search-button {
  min-height: 42px;
  min-width: 76px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.search-button:disabled {
  opacity: 0.7;
}

.search-results {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.search-results {
  list-style: none;
  padding: 8px;
  display: grid;
  gap: 6px;
  max-height: min(240px, 35vh);
  overflow: auto;
}

.search-results[hidden] {
  display: none;
}

.search-result-item {
  width: 100%;
  min-height: auto;
  padding: 12px 14px;
  background: #f8fafc;
  text-align: left;
  border-radius: 14px;
}

.search-result-item strong,
.search-result-item span {
  display: block;
}

.search-result-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#map {
  min-height: 100vh;
}

.floating-button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1105;
  min-height: 48px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 999px;
  line-height: 1;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  transform: rotate(-45deg);
}

.bottom-sheet {
  --sheet-offset: 0px;
  position: fixed;
  inset: auto 0 0;
  z-index: 1050;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: min(72vh, calc(100vh - max(92px, env(safe-area-inset-top) + 60px)));
  padding: 0 10px 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.94));
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(22px);
  overflow: hidden;
  transform: translateY(var(--sheet-offset));
}

.bottom-sheet.is-animating {
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.sheet-drag-handle {
  width: 100%;
  min-height: 24px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  padding: 8px 12px 0;
  color: var(--muted);
  background: transparent;
  border-radius: 24px 24px 0 0;
  cursor: ns-resize;
  touch-action: none;
}

.sheet-handle {
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(102, 112, 133, 0.4);
}

.sheet-body {
  overflow: auto;
  padding: 6px 10px calc(var(--safe-bottom) + 10px);
  -webkit-overflow-scrolling: touch;
}

.sheet-header {
  display: grid;
  gap: 10px;
}

.sheet-header > div {
  min-width: 0;
}

.eyebrow,
dt {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.code-text {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 5vw, 2.1rem);
  line-height: 1.25;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.error-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff3f0;
  color: #b42318;
  font-size: 0.92rem;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 14px;
}

.details-grid .details-wide {
  grid-column: 1 / -1;
}

.details-grid div {
  background: #f7faff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
}

.details-grid dd {
  margin: 8px 0 0;
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
}


.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.action-row button,
.text-button {
  background: #eef5ff;
  color: var(--accent);
  font-weight: 700;
  border: 1px solid rgba(15, 108, 189, 0.08);
}

.action-row button {
  min-height: 50px;
  padding: 0 12px;
  font-size: 1rem;
  border-radius: 18px;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.06);
}

.action-row .primary-action {
  background: var(--accent);
  color: #fff;
}

.action-row button:active,
.text-button:active,
.floating-button:active {
  transform: translateY(1px);
}

.saved-section {
  margin-top: 20px;
}

.saved-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.saved-header h2 {
  margin: 0;
  font-size: 1rem;
}

.text-button {
  min-height: auto;
  padding: 0;
  background: transparent;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 180px;
  overflow: auto;
}

.saved-list li {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-strong);
}

.saved-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  text-align: left;
  border-radius: 18px;
  background: transparent;
}

.saved-item strong,
.saved-item span {
  display: block;
}

.saved-item span {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
}

.empty-state {
  padding: 14px;
  border-radius: 16px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
  line-height: 1.6;
}

@media (max-width: 640px) {
  .topbar {
    inset: max(10px, env(safe-area-inset-top)) 12px auto;
    width: calc(100vw - 84px);
  }

  .search-shell {
    gap: 8px;
    padding: 8px;
    border-radius: 24px;
  }

  .search-button {
    min-height: 40px;
    min-width: 72px;
    padding: 0 14px;
  }

  .floating-button {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    min-height: 44px;
  }

  .icon-button {
    width: 44px;
    min-width: 44px;
  }

  .bottom-sheet {
    padding: 0 8px 0;
    border-radius: 24px 24px 0 0;
    max-height: min(76vh, calc(100vh - max(86px, env(safe-area-inset-top) + 52px)));
  }

  .sheet-drag-handle {
    min-height: 20px;
    padding: 8px 8px 0;
  }

  .sheet-body {
    padding: 4px 8px calc(var(--safe-bottom) + 12px);
  }

  .details-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-row button {
    min-height: 52px;
    font-size: 0.95rem;
    padding: 0 8px;
  }

  .saved-item {
    align-items: flex-start;
    flex-direction: column;
  }
}
