*,*::before,*::after { box-sizing: border-box; }
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --c-primary: #c4121e;
  --c-blue: #1565c0;
  --c-border: #e2e5e9;
  --c-bg: #f4f5f7;
  --c-card: #fff;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--c-bg); color: #1a1a1a; line-height: 1.55; -webkit-text-size-adjust: 100%; }

/* Layout */
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem calc(1rem + var(--safe-b));
}

header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
header svg { flex-shrink: 0; }
header h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }

/* Form */
.form-section {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .75rem;
}
.form-section .section-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #777;
  margin-bottom: .6rem;
}

.field + .field { margin-top: .6rem; }
.field label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: #444;
  margin-bottom: .2rem;
}
.field select {
  width: 100%;
  padding: .65rem .7rem;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #1a1a1a;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 12px 7px;
  transition: border-color .15s;
}
.field select:focus {
  outline: none;
  border-color: var(--c-blue);
  box-shadow: 0 0 0 3px rgba(21,101,192,.12);
}
.field select:disabled { opacity: .45; background-color: #fafafa; }

/* Buttons */
.btn-route {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  padding: .85rem 1rem;
  margin-top: .25rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--c-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-route:active:not(:disabled) { transform: scale(.97); }
.btn-route:disabled { opacity: .4; cursor: not-allowed; }
.btn-route svg { flex-shrink: 0; }

.err {
  color: #b00020;
  font-size: .85rem;
  margin-top: .5rem;
  text-align: center;
}

/* Spinner */
.spinner-wrap {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
}
.spinner-wrap.active { display: flex; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result */
#result { display: none; }
#result.visible { display: block; animation: fadeUp .3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.route-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin: 1.25rem 0 .75rem;
}
.route-title .arrow { color: var(--c-primary); }

/* Summary bar */
.summary-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: .75rem;
  font-size: .82rem;
  color: #555;
}
.summary-bar .item {
  display: flex;
  align-items: center;
  gap: .3rem;
}
.summary-bar .item strong { color: #1a1a1a; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}
.stat {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: .6rem .4rem;
  text-align: center;
  position: relative;
}
.stat .n { font-size: 1.4rem; font-weight: 800; }
.stat .n.red { color: var(--c-primary); }
.stat .n.blue { color: var(--c-blue); }
.stat .n.orange { color: #e67e22; }
.stat .l { font-size: .65rem; color: #666; margin-top: .1rem; line-height: 1.2; }

/* City list */
.city-list {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-top: .75rem;
  font-size: .85rem;
}
.city-item { padding: .5rem 0; }
.city-item + .city-item { border-top: 1px solid #f0f0f0; }
.city-name { display: block; margin-bottom: .25rem; font-weight: 500; color: #1a1a1a; }
.city-item.has-radar { border-left: 3px solid var(--c-primary); padding-left: .65rem; margin-left: -.25rem; }
.city-badges { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .72rem;
  font-weight: 700;
  padding: .18rem .5rem;
  border-radius: 6px;
}
.badge svg { flex-shrink: 0; }
.badge-red { background: #fdecea; color: var(--c-primary); }
.badge-green { background: #e8f5e9; color: #2e7d32; }

/* Map */
.map-wrap {
  position: relative;
  margin-top: .75rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--c-border);
}
#map {
  height: 50vh;
  min-height: 260px;
  max-height: 480px;
  z-index: 0;
}

.map-fs-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.map-fs-btn:hover { background: #f5f5f5; }
.map-fs-btn .icon-shrink { display: none; }
.map-fs-btn .icon-expand { display: block; }

.map-wrap.fullscreen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9998;
  margin: 0;
  border: none;
  border-radius: 0;
}
.map-wrap.fullscreen #map {
  height: 100vh;
  max-height: none;
  min-height: 0;
  border-radius: 0;
}
.map-wrap.fullscreen .map-fs-btn {
  top: max(10px, env(safe-area-inset-top, 0px));
  left: max(10px, env(safe-area-inset-left, 0px));
}
.map-wrap.fullscreen .map-fs-btn .icon-expand { display: none; }
.map-wrap.fullscreen .map-fs-btn .icon-shrink { display: block; }

body.map-fs-open { overflow: hidden; }

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  justify-content: center;
  margin-top: .6rem;
  font-size: .72rem;
  color: #666;
}
.legend-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend-line { width: 20px; height: 3px; border-radius: 2px; }
.legend-dash { width: 20px; height: 0; border-top: 3px dashed var(--c-primary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px rgba(0,0,0,.25); }
.legend-radar-zone {
  width: 18px; height: 18px;
  background: var(--c-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 6px rgba(196,18,30,.35);
}
.legend-radar-zone::after {
  content: "";
  width: 8px; height: 8px;
  background: #fff;
  border-radius: 50%;
}

/* Radar zone map marker */
.radar-zone-marker {
  width: 28px; height: 28px;
  background: var(--c-primary);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 8px rgba(196,18,30,.4);
  display: flex; align-items: center; justify-content: center;
  animation: radarPulse 2s ease-in-out infinite;
}
@keyframes radarPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(196,18,30,.4); }
  50% { box-shadow: 0 0 16px rgba(196,18,30,.6); }
}


/* Tunnel panel — accordion */
.tunnel-panel {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-top: .75rem;
  font-size: .82rem;
  overflow: hidden;
}
.tunnel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .75rem 1rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #777;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tunnel-toggle svg {
  transition: transform .2s;
  flex-shrink: 0;
}
.tunnel-toggle.open svg { transform: rotate(180deg); }
.tunnel-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
  padding: 0 1rem;
}
.tunnel-body.open {
  max-height: 2000px;
  padding: 0 1rem .75rem;
}
.tunnel-item { padding: .45rem 0; }
.tunnel-item + .tunnel-item { border-top: 1px solid #f0f0f0; }
.tunnel-item .t-name { font-weight: 600; color: #1a1a1a; margin-bottom: .15rem; }
.tunnel-item .t-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  font-size: .75rem;
  color: #666;
}
.tunnel-item .t-meta span { display: flex; align-items: center; gap: .2rem; }

/* Tooltip */
.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-left: 3px;
  font-size: .6rem;
  font-weight: 700;
  color: #999;
  border: 1px solid #ccc;
  border-radius: 50%;
  cursor: help;
  vertical-align: middle;
  flex-shrink: 0;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  font-size: .7rem;
  font-weight: 400;
  line-height: 1.35;
  padding: .45rem .65rem;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 220px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 100;
}
.tip:hover::after,
.tip:focus::after {
  opacity: 1;
}
@media (max-width: 520px) {
  .tip::after { left: auto; right: -8px; transform: none; }
}

/* Source & Footer */
.source {
  margin-top: .75rem;
  padding-bottom: .5rem;
  font-size: .68rem;
  color: #aaa;
  text-align: center;
}

.action-row {
  display: flex;
  justify-content: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .75rem;
}
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.1rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--c-blue);
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active { transform: scale(.97); }
.btn-secondary:hover { background: #eef3fb; border-color: var(--c-blue); }
.btn-secondary svg { flex-shrink: 0; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  font-size: .82rem;
  padding: .55rem 1.2rem;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 9999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.site-footer {
  margin-top: 1.5rem;
  padding: 1rem 1rem calc(1rem + var(--safe-b));
  text-align: center;
  border-top: 1px solid var(--c-border);
}
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-size: .75rem;
  color: #aaa;
}
.footer-link {
  color: #888;
  text-decoration: none;
  font-weight: 600;
  transition: color .15s;
}
.footer-link:hover { color: var(--c-primary); }

@media (min-width: 520px) {
  .wrap { padding: 1.5rem; }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
  .form-row .form-section { margin-bottom: 0; }
  .stat .n { font-size: 1.6rem; }
  .stat .l { font-size: .72rem; }
}
