:root {
  --bg: #0d0b1a;
  --surface: #171334;
  --surface2: #221c47;
  --line: #2e2760;
  --text: #eceaff;
  --muted: #9d96c9;
  --cyan: #26e0e6;
  --magenta: #ff3d9a;
  --green: #39d98a;
  --amber: #ffb454;
  --closed: #6b6690;
  --f: system-ui, 'Hiragino Sans', 'Noto Sans CJK JP', 'Yu Gothic UI', 'Meiryo', sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 400px at 10% -5%, rgba(255, 61, 154, 0.1), transparent),
    radial-gradient(1000px 400px at 100% 0, rgba(38, 224, 230, 0.08), transparent);
}
a {
  color: inherit;
}
.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 14px 40px;
  transition: padding-bottom 0.15s;
}
body.has-route .wrap {
  padding-bottom: 92px;
}
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(13, 11, 26, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 11px 14px 9px;
}
.hbar {
  max-width: 760px;
  margin: 0 auto;
}
.trow {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
}
.eyebrow {
  font-size: 0.64rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  font-weight: 700;
  text-transform: uppercase;
}
.title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
}
.title b {
  color: var(--magenta);
}
.sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 1px 0 8px;
}
.qrow {
  display: flex;
  gap: 7px;
}
#q {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
}
#q:focus {
  border-color: var(--cyan);
}
.qbtn {
  flex: none;
  padding: 0 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface2);
  color: var(--cyan);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.hero {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: none;
  border-radius: 11px;
  background: linear-gradient(90deg, var(--magenta), #ff7ac1 55%, var(--cyan));
  color: #0d0b1a;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.filters {
  margin-top: 9px;
}
.frow {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 4px 0;
}
.frow + .frow {
  border-top: 1px solid rgba(46, 39, 96, 0.55);
}
.flabel {
  flex: none;
  width: 34px;
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  padding-top: 8px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.chip {
  font-size: 0.77rem;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.chip[data-on='1'] {
  color: #0d0b1a;
  font-weight: 700;
  border-color: transparent;
}
.chip.g[data-on='1'] {
  background: var(--gc, #8f8ac0);
}
.chip.g {
  border-color: var(--gc, #2e2760);
}
.chip.tgl[data-on='1'] {
  background: var(--green);
  color: #062b1c;
}
.chip.late[data-on='1'] {
  background: var(--amber);
  color: #3a2600;
}
.chip.fav[data-on='1'] {
  background: #ffd24a;
  color: #3a2e00;
}
.chip.rad[data-on='1'] {
  background: var(--cyan);
  color: #04222a;
}
.chip.loc {
  background: linear-gradient(90deg, var(--magenta), #ff7ac1);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}
.chip.clear {
  color: var(--magenta);
  border-color: rgba(255, 61, 154, 0.4);
}
.locpill {
  display: none;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  color: var(--cyan);
  background: rgba(38, 224, 230, 0.1);
  border: 1px solid rgba(38, 224, 230, 0.35);
  border-radius: 999px;
  padding: 4px 6px 4px 11px;
}
.locpill b {
  color: var(--text);
  font-weight: 600;
}
.locpill button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}
select {
  font-size: 0.77rem;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  outline: none;
  max-width: 150px;
}
.viewtoggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-left: auto;
  flex: none;
}
.viewtoggle button {
  background: var(--surface);
  color: var(--muted);
  border: none;
  font-size: 0.77rem;
  padding: 5px 10px;
  cursor: pointer;
}
.viewtoggle button[data-on='1'] {
  background: var(--magenta);
  color: #fff;
  font-weight: 700;
}
.count {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 14px 2px 6px;
}
#map {
  display: none;
  position: relative;
  z-index: 0;
  isolation: isolate;
  height: 70vh;
  min-height: 340px;
  border-radius: 14px;
  overflow: hidden;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #0d0b1a;
}
.prefhead {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--cyan);
  letter-spacing: 0.05em;
  padding: 8px 2px;
  margin-top: 6px;
  border-bottom: 1px solid var(--line);
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  margin: 9px 0;
  animation: pop 0.35s ease both;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion) {
  .card {
    animation: none;
  }
}
.crow {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.cname {
  font-size: 1.02rem;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}
.ename {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 1px;
}
.star {
  background: none;
  border: none;
  color: #ffd24a;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
.rgt {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: none;
}
.badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.open {
  background: rgba(57, 217, 138, 0.16);
  color: var(--green);
  border: 1px solid rgba(57, 217, 138, 0.4);
}
.badge.soon {
  background: rgba(255, 180, 84, 0.18);
  color: var(--amber);
  border: 1px solid rgba(255, 180, 84, 0.45);
}
.badge.opensoon {
  background: rgba(38, 224, 230, 0.16);
  color: var(--cyan);
  border: 1px solid rgba(38, 224, 230, 0.42);
}
.badge.shut {
  background: rgba(107, 102, 144, 0.16);
  color: var(--closed);
  border: 1px solid rgba(107, 102, 144, 0.4);
}
.dist {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--cyan);
  white-space: nowrap;
}
.hours {
  font-size: 0.82rem;
  color: var(--text);
  margin: 5px 0 2px;
}
.hours .clk {
  color: var(--muted);
}
.week {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 1px 0 2px 1.4em;
}
.mach {
  margin: 8px 0 2px;
  font-size: 0.76rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.02);
}
.mach summary {
  cursor: pointer;
  color: var(--text);
  list-style: none;
}
.mach summary::-webkit-details-marker {
  display: none;
}
.mach summary::before {
  content: '▸ ';
  color: var(--muted);
}
.mach[open] summary::before {
  content: '▾ ';
}
.mach ul {
  margin: 6px 0 2px;
  padding-left: 1.1em;
}
.mach li {
  margin: 4px 0;
}
.mach .mn {
  color: var(--muted);
  font-size: 0.7rem;
}
.mach .src {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 4px;
}
.chip.share {
  color: var(--cyan);
  border-color: rgba(38, 224, 230, 0.4);
}
.gtags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0 2px;
}
.gt {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  color: #0d0b1a;
  background: var(--gc, #8f8ac0);
}
.gt.dim {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}
.addr {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 7px;
  overflow-wrap: anywhere;
}
.rtbtn {
  display: inline-block;
  margin-top: 9px;
}
.rtbtn[data-on='1'] {
  background: var(--magenta);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}
.cfoot {
  display: flex;
  gap: 8px;
  margin-top: 11px;
  flex-wrap: wrap;
}
.btn {
  flex: 1 1 100px;
  text-align: center;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 9px;
  border-radius: 10px;
  background: var(--magenta);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}
.btn.small {
  padding: 8px 14px;
  flex: none;
  font-size: 0.8rem;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 50px 20px;
}
.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 24px 10px 8px;
  border-top: 1px solid var(--line);
  margin-top: 20px;
}
.top {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 14px;
  text-decoration: none;
}
#routebar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1500;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
#routebar .rcount {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}
#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.82rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 2000;
  max-width: 90%;
}
#toast.show {
  opacity: 1;
}
body.has-route #toast {
  bottom: 78px;
}
.pop {
  font-family: var(--f);
  min-width: 210px;
}
.pop .pn {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 3px;
}
.pop .ph {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 2px 0;
}
.pop .rtbtn {
  font-size: 0.72rem;
  padding: 4px 9px;
}
.leaflet-container {
  font-family: var(--f);
  background: #e9e9e9;
}
/* OSM 底圖轉灰階當背景，只讓上面的鐵路圖層（OpenRailwayMap）有顏色 */
.basemap {
  filter: grayscale(1) brightness(1.08) contrast(0.9);
}
.leaflet-popup-content {
  margin: 11px 13px;
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.leaflet-container a.btn {
  color: #fff;
}
.leaflet-container a.leaflet-popup-close-button {
  color: var(--muted);
}
.leaflet-bar a,
.leaflet-bar a:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--line);
}
.leaflet-control-attribution {
  background: rgba(13, 11, 26, 0.75) !important;
  color: var(--muted);
}
.leaflet-control-attribution a {
  color: var(--muted);
}
.mc {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  /* 淺色底圖上要用實心底色，數字才看得清楚 */
  background: var(--magenta);
  border: 2px solid #fff;
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.mc.has-open {
  background: var(--green);
  color: #062b1c;
}
.legend {
  display: inline-flex;
  gap: 10px;
  margin-left: 8px;
}
.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
}
@media (max-width: 430px) {
  .flabel {
    width: 28px;
    font-size: 0.55rem;
  }
  .title {
    font-size: 1.18rem;
  }
}
noscript {
  display: block;
  padding: 20px;
  color: var(--muted);
}

/* ---------- 🏆 制霸 ---------- */
.cacts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.cacts .rtbtn {
  margin-top: 0;
}
.pop .vbtn {
  font-size: 0.72rem;
  padding: 4px 9px;
}
.vbtn[data-on='1'] {
  background: #86b6ef;
  color: #0d1b33;
  border-color: transparent;
  font-weight: 700;
}
#conquest,
#stats {
  display: none;
  margin-top: 12px;
}
.cq-tiles {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 14px;
}
.stat {
  flex: 1 1 120px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.stat .sv {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.1;
}
.stat .sv small {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}
.stat .sl {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 3px;
}
.stat .dl {
  color: var(--text);
}
.cq-map {
  display: grid;
  gap: 4px;
  aspect-ratio: 13 / 12;
  max-width: 640px;
  margin: 0 auto;
}
.ctile {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font: inherit;
  padding: 0;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  line-height: 1.15;
}
.ctile b {
  font-size: 0.72rem;
}
.ctile span {
  font-size: 0.56rem;
  opacity: 0.85;
}
.ctile.on {
  border-color: transparent;
}
.ctile:hover,
.ctile:focus-visible {
  outline: 2px solid var(--cyan);
}
.cq-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 12px 0 4px;
}
.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -2px;
}
.sw.none {
  border: 1px solid var(--line);
}
.cq-hint {
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
  margin: 8px 0;
}
.cq-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0;
}
@media (max-width: 430px) {
  .ctile b {
    font-size: 0.56rem;
  }
  .ctile span {
    display: none;
  }
}

/* ---------- 📊 統計 ---------- */
.chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 12px 0;
}
.chead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chead h3 {
  margin: 0;
  font-size: 0.95rem;
}
.ckeys {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.74rem;
  color: var(--muted);
  margin: 8px 0;
}
.ckeys i {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: 3px;
}
.cwrap {
  position: relative;
}
.chart svg {
  display: block;
  overflow: visible;
}
.chart .grid {
  stroke: var(--line);
  stroke-width: 1;
}
.chart .tick {
  fill: var(--muted);
  font-size: 11px;
}
.chart .blabel {
  fill: var(--text);
  font-size: 11px;
}
.chart .ring {
  stroke: var(--surface);
  stroke-width: 2;
}
.chart .xhair {
  stroke: var(--muted);
  stroke-width: 1;
}
.chart .bar:hover path {
  opacity: 0.85;
}
.ctip {
  position: absolute;
  pointer-events: none;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.74rem;
  color: var(--text);
  min-width: 150px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.ctip div {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ctip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.ctip span {
  margin-left: auto;
  font-weight: 700;
}
.stable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
  margin-top: 6px;
}
.stable th,
.stable td {
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  text-align: right;
}
.stable th {
  color: var(--muted);
  font-weight: 600;
}
.stable td:first-child,
.stable th:first-child {
  text-align: left;
}
#st-games {
  margin: 8px 0;
}
.chip.stg[data-on='1'] {
  background: var(--cyan);
  color: #04222a;
}
#st-more {
  margin-top: 8px;
}

/* ---------- ☁️ Google 同步 ---------- */
.sync {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 12px auto;
  max-width: 640px;
  text-align: center;
}
.sync-st {
  font-size: 0.82rem;
}
.sync-st b {
  color: var(--amber);
}
.cq-more {
  max-width: 640px;
  margin: 8px auto;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}
.cq-more summary {
  cursor: pointer;
}
