:root {
  --bg: var(--tg-theme-bg-color, #101214);
  --fg: var(--tg-theme-text-color, #f2f3f5);
  --muted: var(--tg-theme-hint-color, #9aa3ad);
  --link: var(--tg-theme-link-color, #6aa8ff);
  --button-bg: var(--tg-theme-button-color, #2f80ff);
  --button-fg: var(--tg-theme-button-text-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #1b1f24);
  --surface-2: color-mix(in srgb, var(--surface) 76%, var(--bg));
  --line: rgba(255, 255, 255, 0.08);
  --soft-line: rgba(255, 255, 255, 0.05);
  --ok: #55d68b;
  --warn: #f3b760;
  --danger: #ff6b73;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  letter-spacing: 0;
}

button {
  font: inherit;
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--soft-line);
}

.app-top h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 760;
}

.app-top p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#refresh-button,
.mini-button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--button-bg);
  color: var(--button-fg);
  font-weight: 650;
  cursor: pointer;
}

#root {
  flex: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
}

.loading,
.empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}

.tabbar button {
  height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.tabbar button.active {
  background: color-mix(in srgb, var(--button-bg) 20%, transparent);
  border-color: color-mix(in srgb, var(--button-bg) 42%, transparent);
  color: var(--fg);
}

.hero {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.26);
}

.hero.image-loading::before,
.hero.image-failed::before,
.photo-card.image-loading::before,
.photo-card.image-failed::before,
.sheet.image-loading::before,
.sheet.image-failed::before {
  content: "图片加载中";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, white), var(--surface));
}

.hero.image-failed::before,
.photo-card.image-failed::before,
.sheet.image-failed::before {
  content: "图片加载失败，点刷新重试";
}

.hero img {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  object-position: center top;
  display: block;
  background: var(--surface);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent 28%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.72), transparent 62%);
  pointer-events: none;
}

.hero.image-loading::after,
.hero.image-failed::after,
.photo-card.image-loading::after,
.photo-card.image-failed::after {
  display: none;
}

.hero-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  padding: 18px;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.34);
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 650;
}

.hero-title {
  margin: 10px 0 6px;
  font-size: clamp(24px, 8vw, 42px);
  line-height: 1.02;
  font-weight: 780;
  letter-spacing: 0;
}

.hero-text {
  margin: 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  max-width: 38em;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 16px;
}

.status-tile {
  min-height: 82px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.value {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 720;
}

.subvalue {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.section {
  margin-top: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0 2px 10px;
}

.section-title {
  margin: 0;
  font-size: 17px;
  font-weight: 760;
}

.section-meta {
  color: var(--muted);
  font-size: 12px;
}

.photo-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(132px, 42%);
  gap: 10px;
  overflow-x: auto;
  padding: 0 2px 4px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.photo-rail::-webkit-scrollbar { display: none; }

.photo-card {
  position: relative;
  min-height: 198px;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  padding: 0;
  scroll-snap-align: start;
  text-align: left;
  cursor: pointer;
}

.photo-card.image-loading .photo-caption,
.photo-card.image-failed .photo-caption {
  display: none;
}

.photo-card img {
  width: 100%;
  height: 100%;
  min-height: 198px;
  object-fit: cover;
  display: block;
}

.photo-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.7), transparent 58%);
  pointer-events: none;
}

.photo-caption {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 9px;
  z-index: 1;
}

.photo-caption strong {
  display: block;
  color: white;
  font-size: 13px;
  line-height: 1.25;
}

.photo-caption span {
  display: block;
  color: rgba(255, 255, 255, 0.74);
  font-size: 11px;
  margin-top: 3px;
}

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

.row {
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 10px;
  padding: 13px 14px;
  border-top: 1px solid var(--soft-line);
}

.row:first-child { border-top: 0; }

.row dt {
  color: var(--muted);
  font-size: 12px;
}

.row dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 700;
}

.badge.ok { background: rgba(85, 214, 139, 0.16); color: var(--ok); }
.badge.warn { background: rgba(243, 183, 96, 0.17); color: var(--warn); }
.badge.danger { background: rgba(255, 107, 115, 0.16); color: var(--danger); }
.badge.neutral { background: rgba(154, 163, 173, 0.15); color: var(--muted); }

.plan-list {
  display: grid;
  gap: 9px;
}

.slot {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.slot.current {
  border-color: color-mix(in srgb, var(--ok) 42%, transparent);
  background: color-mix(in srgb, var(--ok) 10%, var(--surface));
}

.slot-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.slot-name {
  font-weight: 740;
}

.slot-activity {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.grid-feed .photo-card {
  min-height: 236px;
}

.grid-feed .photo-card img {
  min-height: 236px;
}

#map-container {
  height: min(64vh, 520px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--surface);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.52);
  display: flex;
  align-items: flex-end;
}

.sheet {
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
}

.sheet img {
  width: 100%;
  max-height: 58vh;
  object-fit: contain;
  object-position: center top;
  border-radius: var(--radius);
  display: block;
  background: var(--surface);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
}

.sheet h2 {
  margin: 0;
  font-size: 18px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--fg) 10%, transparent);
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.72);
  color: white;
  font-size: 13px;
}

@media (min-width: 680px) {
  #root { padding-left: 18px; padding-right: 18px; }
  .hero img { max-height: 76vh; }
  .photo-rail { grid-auto-columns: 190px; }
  .grid-feed { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sheet {
    max-width: 640px;
    margin: 0 auto;
    border-radius: 8px 8px 0 0;
  }
}
