:root {
  --ink: #1c1915;
  --muted: #6b6258;
  --paper: #f6f1e7;
  --paper-2: #fffaf3;
  --line: #e4d9c8;
  --cinnabar: #9d341f;
  --cinnabar-deep: #7a2918;
  --pine: #1f6b5a;
  --shadow: 0 12px 40px rgba(40, 28, 16, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}

.brand strong {
  display: block;
  font-size: 16px;
  letter-spacing: 0.06em;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.search { position: relative; }

#q {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #d9cdb8;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

#q:focus {
  outline: 2px solid var(--cinnabar);
  outline-offset: 1px;
  border-color: transparent;
}

#suggest {
  position: absolute;
  z-index: 8;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

#suggest button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#suggest button.on,
#suggest button:hover { background: #f6efe4; }

.s-plate { color: var(--muted); font-size: 13px; }

#suggest .empty {
  padding: 8px 10px;
  color: var(--muted);
}

.mode {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

#tip {
  position: absolute;
  z-index: 4;
  max-width: 220px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(28, 25, 21, 0.9);
  color: #fffaf3;
  pointer-events: none;
  font-size: 12px;
}

#tip strong { display: block; font-size: 13px; }
#tip span { display: block; opacity: 0.9; }

#legend {
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: 28px;
  width: 168px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 250, 243, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(40, 28, 16, 0.08);
}

.legend-title { font-size: 12px; margin-bottom: 6px; }
.bar {
  height: 8px;
  border-radius: 99px;
  background: linear-gradient(90deg, #1f6b5a, #7ea89a, #f4f0e6, #e09a78, #b6402a);
}
.legend-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}
.legend-none {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}
.legend-none i {
  width: 18px;
  height: 8px;
  border-radius: 99px;
  background: #c4beb4;
}
.route-flag {
  padding: 0 6px;
  border: 1px solid #9d341f;
  border-radius: 999px;
  background: #fffaf3;
  color: #9d341f;
  font: 700 12px/1.6 "PingFang SC", "Noto Sans SC", sans-serif;
  pointer-events: none;
  white-space: nowrap;
}

.fac-pin {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.fac-pin-name {
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #9d341f;
  color: #fffaf3;
  font: 700 13px/1.45 "PingFang SC", "Noto Sans SC", sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(40, 28, 16, 0.28);
}

.fac-pin-dot {
  width: 18px;
  height: 18px;
  border: 3px solid #fffaf3;
  border-radius: 99px;
  background: #9d341f;
  box-shadow: 0 0 0 2px #9d341f, 0 4px 10px rgba(157, 52, 31, 0.45);
}

#panel {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(247, 243, 234, 0.96);
  box-shadow: var(--shadow);
}

.grabber { display: none; }

.panel-top {
  display: flex;
  justify-content: flex-end;
  padding: 8px 8px 0;
}

#panel-close {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

#panel-body {
  overflow: auto;
  min-height: 0;
  padding: 4px 16px 18px;
}

h2 {
  margin: 0 0 2px;
  font-size: 22px;
  line-height: 1.25;
}

.sub { margin: 0 0 10px; color: var(--muted); }

.chip, .tag, .badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  vertical-align: 1px;
}

.chip {
  margin-left: 6px;
  background: var(--cinnabar);
  color: #fff8ef;
  letter-spacing: 0.04em;
}

.price-note {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #e7b2a4;
  border-radius: 10px;
  background: #fff1ea;
  color: var(--cinnabar-deep);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.price {
  margin: 0;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.price small { font-size: 14px; font-weight: 500; color: var(--muted); }
.price-month { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.stat {
  padding: 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(228, 217, 200, 0.9);
}

.stat .k { display: block; color: var(--muted); font-size: 12px; }
.stat .v { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.wide { grid-column: 1 / -1; }

.up { color: var(--cinnabar); }
.down { color: var(--pine); }
.flat { color: var(--muted); }

.near-note { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

h3 {
  margin: 16px 0 8px;
  font-size: 15px;
}

.class-block { margin: 0 0 10px; }
.class-name {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
}

.fac {
  display: block;
  width: 100%;
  margin: 0 0 4px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.fac:hover {
  border-color: #e0c2b4;
  background: #fff;
}

.fac.on,
.fac.on:hover {
  border-color: var(--cinnabar);
  background: #fff1ea;
  box-shadow: inset 3px 0 0 var(--cinnabar);
}

.fac .nm { display: block; }
.fac .mins {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tag {
  margin-left: 4px;
  background: #efe6d4;
  color: #5c4d32;
}

.badge.high { background: #d7efe6; color: #145744; }
.badge.medium { background: #fdecc8; color: #6a4b05; }
.badge.low { background: #eeeae4; color: #5c564e; }

.school {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.school .stage { color: var(--muted); font-size: 12px; }
.source, .foot {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

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

.maplibregl-ctrl-attrib { font-size: 11px; }

@media (min-width: 761px) {
  .maplibregl-ctrl-bottom-right { right: 420px; }
}

@media (max-width: 760px) {
  header {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand mode" "search search";
  }
  .brand { grid-area: brand; }
  .mode { grid-area: mode; }
  .search { grid-area: search; }

  #panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 64vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(110%);
    transition: transform 180ms ease;
    padding-bottom: env(safe-area-inset-bottom);
  }

  #panel.open {
    transform: translateY(0);
  }

  #panel.open.peek {
    max-height: 40vh;
  }

  .grabber {
    display: block;
    width: 42px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 99px;
    background: #d9d0c2;
  }

  body:has(#panel.open) .maplibregl-ctrl-bottom-right {
    bottom: calc(64vh + 8px);
  }

  body:has(#panel.open) #legend {
    bottom: calc(64vh + 10px);
  }

  body:has(#panel.open.peek) .maplibregl-ctrl-bottom-right {
    bottom: calc(40vh + 8px);
  }

  body:has(#panel.open.peek) #legend {
    bottom: calc(40vh + 10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
}
