:root {
  --brand: #1478ff;
  --brand-dark: #0c4ec2;
  --danger: #e5484d;
  --ok: #16a36a;
  --warning: #f59a23;
  --text: #17202f;
  --muted: #6d7787;
  --line: #e6eaf0;
  --bg: #edf2f8;
  --surface: #ffffff;
  --shadow: 0 18px 40px rgba(18, 32, 55, 0.14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  background: #d9e2ec;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.phone-shell {
  position: relative;
  width: min(100vw, 430px);
  min-height: 100vh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.42), 0 24px 80px rgba(17, 32, 58, 0.18);
}

.app {
  min-height: 100vh;
}

.page {
  display: none;
  min-height: 100vh;
  padding: calc(18px + env(safe-area-inset-top)) 18px 24px;
  animation: pageIn 180ms ease;
}

.page.active {
  display: block;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.home-header {
  padding: 28px 4px 22px;
}

.home-header span {
  color: var(--muted);
  font-size: 14px;
}

.home-header h1 {
  margin: 10px 0 8px;
  font-size: 34px;
  letter-spacing: 0;
}

.home-header p {
  margin: 0;
  color: var(--muted);
}

.home-cards {
  display: grid;
  gap: 16px;
}

.home-card {
  position: relative;
  min-height: 132px;
  padding: 22px;
  border: 0;
  border-radius: 8px;
  text-align: left;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.home-card::after {
  content: "";
  position: absolute;
  right: -34px;
  bottom: -44px;
  width: 128px;
  height: 128px;
  border: 18px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
}

.home-card span,
.home-card strong {
  position: relative;
  z-index: 1;
  display: block;
}

.home-card span {
  margin-bottom: 18px;
  font-size: 15px;
  opacity: 0.82;
}

.home-card strong {
  font-size: 28px;
  letter-spacing: 0;
}

.status-card {
  background: linear-gradient(135deg, #1478ff, #0f5bd9);
}

.route-card {
  background: linear-gradient(135deg, #12a785, #08755f);
}

.history-card {
  background: linear-gradient(135deg, #f59a23, #d56617);
}

.page-header {
  display: grid;
  grid-template-columns: 44px 1fr 80px;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin-bottom: 18px;
}

.page-header h2 {
  margin: 0;
  text-align: center;
  font-size: 20px;
}

.back-btn,
.text-btn {
  min-height: 40px;
  border: 0;
  color: var(--brand);
  background: transparent;
  cursor: pointer;
}

.back-btn {
  width: 44px;
  border-radius: 50%;
  color: var(--text);
  font-size: 36px;
  line-height: 1;
}

.text-btn {
  padding: 0;
  text-align: right;
  font-size: 14px;
}

.status-hero {
  display: grid;
  place-items: center;
  min-height: 198px;
  margin-bottom: 16px;
  border-radius: 8px;
  color: #fff;
  background: radial-gradient(circle at 50% 34%, rgba(255,255,255,0.28), transparent 34%), #e5484d;
  box-shadow: var(--shadow);
}

.status-hero span {
  align-self: end;
  font-size: 15px;
  opacity: 0.86;
}

.status-hero strong {
  font-size: 76px;
  line-height: 0.9;
}

.status-hero small {
  align-self: start;
  font-size: 16px;
  opacity: 0.8;
}

.info-stack,
.history-list {
  display: grid;
  gap: 12px;
}

.info-panel,
.history-item {
  padding: 18px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(18, 32, 55, 0.07);
}

.info-panel span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.info-panel strong {
  display: block;
  font-size: 16px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.primary-btn,
.ghost-btn,
.tool-btn {
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}

.primary-btn {
  border: 0;
  color: #fff;
  background: var(--brand);
}

.primary-btn.wide {
  width: 100%;
  margin-top: 18px;
}

.ghost-btn,
.tool-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: #fff;
}

.tool-btn.active {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.route-page {
  padding: 0;
  background: #dce7ef;
}

.route-header {
  position: absolute;
  top: env(safe-area-inset-top);
  left: 14px;
  right: 14px;
  z-index: 5;
  margin: 12px 0 0;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(18, 32, 55, 0.12);
  backdrop-filter: blur(10px);
}

.route-map-wrap {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.route-map-wrap.preview-3d {
  perspective: 820px;
  background: #bfcfdb;
}

.route-map-wrap.preview-3d .route-map {
  transform: rotateX(58deg) translateY(-9%);
  transform-origin: 50% 58%;
  box-shadow: 0 42px 80px rgba(15, 35, 64, 0.28);
}

.route-map {
  position: absolute;
  inset: 0;
  z-index: 1;
  transition: transform 260ms ease;
}

.map-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.32) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.32) 1px, transparent 1px),
    #dce8ec;
  background-size: 34px 34px;
}

.route-sheet {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 4;
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.route-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.route-summary strong {
  font-size: 20px;
}

.route-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.route-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.history-lock {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #8a3c00;
  background: #fff2d5;
}

.history-item {
  width: 100%;
  border: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.history-item:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.history-time {
  margin-bottom: 8px;
  font-weight: 700;
}

.history-address {
  margin-bottom: 8px;
  color: #394454;
  line-height: 1.5;
}

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

.state-tip {
  padding: 80px 12px;
  color: var(--muted);
  text-align: center;
}

.alert-banner {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: min(398px, calc(100vw - 28px));
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(229, 72, 77, 0.96);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.alert-banner p {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.45;
  opacity: 0.9;
}

.alert-actions {
  display: grid;
  gap: 8px;
}

.alert-actions button {
  min-width: 58px;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

#alert-view-btn {
  color: var(--danger);
  background: #fff;
}

#alert-ignore-btn {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(390px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 32, 47, 0.92);
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

@media (min-width: 760px) {
  body {
    padding: 24px 0;
  }

  .phone-shell {
    min-height: calc(100vh - 48px);
    border-radius: 28px;
  }

  .page,
  .route-map-wrap {
    min-height: calc(100vh - 48px);
  }
}
