:root {
  color-scheme: dark;
  --bg: #050807;
  --panel: rgba(7, 12, 12, 0.86);
  --panel-strong: rgba(10, 16, 17, 0.96);
  --line: rgba(142, 255, 207, 0.18);
  --text: #f6fff9;
  --muted: #9aa6a1;
  --green: #00f060;
  --yellow: #ffe713;
  --orange: #ff8b16;
  --red: #ff2445;
  --blue: #00a3ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: Inter, "Segoe UI", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 640px;
  background: radial-gradient(circle at 50% 40%, rgba(16, 82, 64, 0.2), transparent 40%), var(--bg);
}

.map-stage,
#map {
  position: absolute;
  inset: 0;
}

#map {
  z-index: 1;
  background: #07100e;
}

.leaflet-container {
  font: inherit;
  background: #07100e;
}

.leaflet-control-attribution {
  display: none;
}

.top-bar,
.filter-rail,
.map-tools,
.legend-panel,
.recorder-panel,
.bottom-nav,
.detail-sheet,
.history-panel {
  position: absolute;
  z-index: 5;
}

.top-bar {
  top: max(18px, env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  font-size: clamp(20px, 4.5vw, 28px);
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 0 18px rgba(0, 240, 96, 0.32);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--green);
  border-radius: 50%;
  color: var(--green);
  font-weight: 900;
  box-shadow: 0 0 22px rgba(0, 240, 96, 0.6);
}

.icon-button,
.round-button {
  display: grid;
  position: relative;
  place-items: center;
  background: rgba(5, 9, 10, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.top-bar .icon-button:first-child {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.icon-button span {
  display: block;
  width: 24px;
  height: 2px;
  margin: 0;
  background: var(--text);
  border-radius: 2px;
}

.icon-button.search::before {
  position: absolute;
  top: 45%;
  left: 45%;
  width: 18px;
  height: 18px;
  border: 3px solid var(--text);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.icon-button.search::after {
  position: absolute;
  top: 61%;
  left: 62%;
  width: 11px;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  content: "";
  transform: translate(-50%, -50%) rotate(45deg);
}

.filter-rail {
  top: calc(max(18px, env(safe-area-inset-top)) + 62px);
  left: 18px;
  right: 18px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.pill,
.segment button {
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  background: rgba(8, 12, 13, 0.8);
  color: #d4ddd8;
  white-space: nowrap;
  backdrop-filter: blur(14px);
}

.pill {
  border-radius: 22px;
  font-weight: 800;
}

.pill.active,
.segment button.active {
  background: linear-gradient(180deg, #09d65c, #037e34);
  color: white;
  box-shadow: 0 0 22px rgba(0, 240, 96, 0.48);
}

.segment {
  display: flex;
  margin-left: auto;
  border-radius: 14px;
  overflow: hidden;
}

.segment button {
  border-radius: 0;
}

.map-tools {
  top: 190px;
  right: 18px;
  display: grid;
  gap: 12px;
}

.round-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.round-button.active {
  border-color: rgba(0, 240, 96, 0.6);
  box-shadow: 0 0 22px rgba(0, 240, 96, 0.25), var(--shadow);
}

.locate::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 21px;
  height: 21px;
  border: 3px solid var(--text);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.locate::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--text);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.layers::before,
.layers::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  border: 2px solid var(--text);
  content: "";
  transform: translate(-50%, -58%) rotate(45deg);
}

.layers::after {
  opacity: 0.55;
  transform: translate(-50%, -34%) rotate(45deg);
}

.tune::before,
.tune::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 3px;
  background: var(--text);
  border-radius: 4px;
  content: "";
  transform: translate(-50%, -50%);
}

.tune::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.legend-panel {
  left: 18px;
  bottom: calc(98px + env(safe-area-inset-bottom));
  width: min(310px, calc(100vw - 36px));
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.legend-panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.heat-scale {
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, #005fff, #00e5ff, #7eff4f, #fff600, #ff8a00, #ff1748);
  box-shadow: 0 0 16px rgba(255, 231, 19, 0.35);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.recorder-panel {
  left: 18px;
  right: 18px;
  bottom: calc(174px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.recorder-panel > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dce8e2;
  font-weight: 800;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
}

.is-recording .status-dot {
  background: var(--red);
  box-shadow: 0 0 16px rgba(255, 36, 69, 0.8);
}

.record-button {
  min-height: 42px;
  padding: 0 20px;
  border-radius: 8px;
  background: linear-gradient(180deg, #09d65c, #037e34);
  font-weight: 900;
}

.bottom-nav {
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  height: calc(78px + env(safe-area-inset-bottom));
  padding: 6px 12px env(safe-area-inset-bottom);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(7, 10, 11, 0.94);
  box-shadow: 0 -12px 42px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
}

.bottom-nav button {
  display: grid;
  min-width: 0;
  place-items: center;
  gap: 4px;
  background: transparent;
  color: #aeb8b3;
  font-size: 12px;
  font-weight: 800;
}

.bottom-nav button.active {
  color: var(--green);
}

.bottom-nav span {
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
}

.nav-map::before,
.nav-pin::before,
.nav-clock::before,
.nav-user::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 3px solid currentColor;
  border-radius: 5px;
  content: "";
  transform: translate(-50%, -50%);
}

.nav-clock::before {
  border-radius: 50%;
}

.nav-pin::before {
  border-radius: 50% 50% 50% 0;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.nav-user::before {
  border-radius: 50%;
}

.main-action {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 66px;
  margin: -28px auto 0;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  border-radius: 50%;
  background: linear-gradient(180deg, #262b2d, #111415) !important;
  color: white !important;
  font-size: 43px !important;
  line-height: 0.9;
  box-shadow: var(--shadow);
}

.detail-sheet,
.history-panel {
  right: 14px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transform: translateY(calc(100% + 120px));
  transition: transform 220ms ease;
}

.detail-sheet.open,
.history-panel.open {
  transform: translateY(0);
}

.detail-sheet {
  max-height: min(440px, calc(100dvh - 150px));
  padding: 10px 18px 18px;
  overflow: auto;
}

.sheet-handle {
  width: 54px;
  height: 5px;
  margin: 0 auto 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
}

.route-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.route-hero p,
.history-panel p {
  margin: 0 0 4px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
}

.route-hero h1,
.history-panel h2 {
  margin: 0;
  font-size: clamp(26px, 7vw, 38px);
}

.route-hero span {
  color: var(--muted);
}

.favorite-button {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #5d6462;
  font-size: 30px;
}

.favorite-button.active {
  color: var(--red);
  text-shadow: 0 0 16px rgba(255, 36, 69, 0.7);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.stat-grid article {
  min-width: 0;
  padding: 13px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  text-align: center;
}

.stat-grid span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-grid strong {
  display: block;
  margin-top: 5px;
  color: white;
  font-size: 22px;
}

.route-description {
  margin: 16px 0 0;
  color: #d6e0db;
  line-height: 1.7;
}

.history-panel {
  top: max(68px, calc(env(safe-area-inset-top) + 60px));
  padding: 18px;
  overflow: auto;
}

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

.text-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.history-item strong {
  display: block;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: calc(95px + env(safe-area-inset-bottom));
  left: 18px;
  max-width: 420px;
  margin: 0 auto;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  text-align: center;
  box-shadow: var(--shadow);
}

.heat-label {
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(3, 7, 8, 0.8);
  color: white;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.current-marker {
  width: 22px;
  height: 22px;
  border: 4px solid white;
  border-radius: 50%;
  background: #2388ff;
  box-shadow: 0 0 0 10px rgba(35, 136, 255, 0.24), 0 0 26px rgba(35, 136, 255, 0.75);
}

@media (min-width: 860px) {
  .app-shell {
    max-width: 520px;
    margin: 0 auto;
    border-inline: 1px solid rgba(255, 255, 255, 0.12);
  }
}

@media (max-width: 420px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .segment {
    margin-left: 0;
  }

  .filter-rail {
    padding-bottom: 2px;
  }
}
