:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #eceff3;
  --ink: #17191c;
  --muted: #5d6470;
  --line: #d9dde3;
  --accent: #d95f02;
  --accent-strong: #a84200;
  --link: #075eb5;
  --danger: #b42318;
  --warning-bg: #fff3d6;
  --warning-ink: #6f4300;
  --radius: 14px;
  --z-header: 20;
  --z-modal-backdrop: 40;
  --z-modal: 50;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
.leaflet-container:focus-visible {
  outline: 3px solid #1473e6;
  outline-offset: 2px;
}

.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;
}

.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(244, 245, 247, 0.96);
  border-bottom: 1px solid var(--line);
}

.header-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 680px);
  min-height: 38px;
  margin: 0 auto;
}

.header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.header-actions {
  position: absolute;
  right: 0;
}

.icon-btn,
.settings-close {
  display: inline-grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:hover,
.settings-close:hover {
  background: var(--surface-muted);
}

.main-content {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 22px 16px calc(88px + env(safe-area-inset-bottom));
}

.price-section {
  margin-bottom: 22px;
}

.section-heading,
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading {
  margin-bottom: 12px;
}

.section-title,
.map-title {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 740;
}

.refresh-btn {
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--link);
  font-size: 0.9rem;
  font-weight: 680;
  cursor: pointer;
}

.refresh-btn:hover {
  background: #e6f1fc;
}

.refresh-btn:disabled {
  color: var(--muted);
  cursor: wait;
}

.price-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.price-card {
  min-width: 0;
  padding: 17px 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.price-card.highlight {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.fuel-type {
  min-height: 1.25rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.fuel-name {
  margin-top: 13px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 780;
}

.fuel-price {
  margin-top: 2px;
  color: var(--accent-strong);
  font-size: clamp(2rem, 9vw, 2.65rem);
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  letter-spacing: -0.035em;
  line-height: 1;
}

.fuel-unit {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.price-card.highlight :is(.fuel-type, .fuel-name, .fuel-unit) {
  color: rgba(255, 255, 255, 0.88);
}

.price-card.highlight .fuel-price {
  color: #ffffff;
}

.update-info {
  min-height: 2.7rem;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.update-info.cached {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.update-info.error {
  color: var(--danger);
}

.skeleton-card {
  overflow: hidden;
}

.skeleton-line,
.skeleton-price {
  border-radius: 6px;
  background: linear-gradient(90deg, #e7eaee 30%, #f5f6f8 50%, #e7eaee 70%);
  background-size: 220% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
}

.skeleton-line {
  width: 62%;
  height: 14px;
}

.skeleton-price {
  width: 76%;
  height: 42px;
  margin-top: 28px;
}

@keyframes skeleton {
  to {
    background-position-x: -220%;
  }
}

.loading-state,
.error-state,
.map-error {
  grid-column: 1 / -1;
  padding: 34px 20px;
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: var(--danger);
}

.error-state p {
  max-width: 36ch;
  margin: 0 auto 14px;
  line-height: 1.55;
}

.error-state.compact {
  padding: 24px 16px;
}

.retry-btn {
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: 9px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.map-container {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.map-header {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.locate-btn {
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 9px;
  background: var(--link);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 720;
  cursor: pointer;
}

.locate-btn:hover {
  background: #004e99;
}

.locate-btn:disabled {
  background: #8c98a5;
  cursor: wait;
}

#map {
  width: 100%;
  height: min(44vh, 340px);
  min-height: 260px;
  background: var(--surface-muted);
}

.station-status {
  min-height: 3rem;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.station-list {
  max-height: 270px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.station-item {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.station-item:last-child {
  border-bottom: 0;
}

.station-item:hover {
  background: var(--surface-muted);
}

.station-rank {
  display: inline-grid;
  flex: 0 0 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: #ffead9;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.station-copy,
.station-name,
.station-address {
  display: block;
}

.station-copy {
  min-width: 0;
}

.station-name {
  font-size: 0.92rem;
  font-weight: 740;
}

.station-address {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.station-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 7px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 650;
}

.station-map-marker {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
}

.station-map-marker span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(31, 36, 41, 0.35);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 820;
}

.settings-menu {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 22, 25, 0.58);
}

.settings-menu.show {
  display: flex;
}

.settings-panel {
  z-index: var(--z-modal);
  width: min(100%, 500px);
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
}

.settings-header,
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-header {
  margin-bottom: 18px;
}

.settings-title {
  font-size: 1.15rem;
  font-weight: 760;
}

.settings-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.settings-label {
  font-size: 0.95rem;
  font-weight: 650;
}

.settings-item select {
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid #aeb5bf;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.version-info {
  padding-top: 18px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

@media (min-width: 620px) {
  .price-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .price-card {
    padding-inline: 13px;
  }

  .fuel-price {
    font-size: 2.15rem;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .main-content {
    width: min(100%, 980px);
    padding-top: 14px;
  }

  .price-section {
    margin-bottom: 14px;
  }

  #map {
    height: 230px;
    min-height: 230px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .price-card.highlight,
  .station-map-marker span,
  .locate-btn,
  .retry-btn {
    border: 1px solid ButtonText;
  }
}
