/* ============ 咩知天气 · 新国潮敦煌风 ============ */
:root {
  --ink: #3A3024;
  --ink-60: rgba(58, 48, 36, .62);
  --ink-40: rgba(58, 48, 36, .4);
  --paper: #FAF4E6;
  --card: #FFFFFF;
  --mint: #54B9A3;
  --mint-soft: #E6F5F1;
  --gold: #E2B95F;
  --gold-soft: #FCF1D6;
  --coral: #E8795F;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(93, 74, 38, .08);
  /* 天空色（由场景状态覆盖） */
  --sky-a: #7EC8F5;
  --sky-b: #D4EEFF;
  --glow: rgba(255, 214, 120, .55);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  overscroll-behavior-y: contain;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--paper);
  position: relative;
  overflow: hidden;
}

.page { min-height: 100vh; }
.sub-page {
  position: absolute; inset: 0; z-index: 40;
  background: var(--paper);
  animation: slideIn .25s ease;
  overflow-y: auto;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }

/* ============ 场景 ============ */
.scene {
  position: relative;
  height: 52vh;
  min-height: 380px;
  overflow: hidden;
  border-radius: 0 0 30px 30px;
  background: linear-gradient(180deg, var(--sky-a), var(--sky-b));
  transition: background .8s ease;
}
/* 小羊身后的光晕 */
.scene::after {
  content: "";
  position: absolute;
  top: 4%; left: 50%;
  width: 130%; aspect-ratio: 1;
  transform: translateX(-50%);
  background: radial-gradient(circle, var(--glow) 0%, transparent 60%);
  pointer-events: none;
}

.sheep {
  position: absolute;
  left: 50%; bottom: 30px;
  height: 88%;
  transform: translateX(-50%);
  z-index: 3;
  user-select: none;
  -webkit-user-drag: none;
  animation: floaty 4.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 10px rgba(40, 35, 25, .18));
  cursor: pointer;
}
@keyframes floaty {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-9px); }
}
.scene.shake .sheep { animation: shake .5s ease, floaty 4.2s .5s infinite; }
@keyframes shake {
  0%,100% { margin-left: 0; }
  20% { margin-left: -5px; } 40% { margin-left: 5px; }
  60% { margin-left: -4px; } 80% { margin-left: 4px; }
}

/* 道具 */
.prop { position: absolute; z-index: 4; pointer-events: none; }
.prop-umbrella {
  width: 42%; top: 7%; right: 3%;
  transform: rotate(-8deg);
  animation: sway 3.6s ease-in-out infinite;
  transform-origin: 70% 80%;
}
.prop-scarf {
  width: 34%; top: 53%; left: 50%;
  transform: translateX(-50%) rotate(5deg);
}
@keyframes sway {
  0%,100% { transform: rotate(-10deg); }
  50% { transform: rotate(-4deg); }
}

/* 太阳 / 月亮 */
.celestial {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top));
  right: 22px;
  width: 64px; height: 64px;
  z-index: 1;
  display: none;
}
.sun {
  display: block;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF3C4, #FFD166 60%, #FFB347);
  box-shadow: 0 0 36px 12px rgba(255, 200, 90, .55);
  position: relative;
}
.sun::before {
  content: "";
  position: absolute; inset: -22px;
  border-radius: 50%;
  background: conic-gradient(from 0deg,
    rgba(255,210,110,.55) 0 6deg, transparent 6deg 45deg,
    rgba(255,210,110,.55) 45deg 51deg, transparent 51deg 90deg,
    rgba(255,210,110,.55) 90deg 96deg, transparent 96deg 135deg,
    rgba(255,210,110,.55) 135deg 141deg, transparent 141deg 180deg,
    rgba(255,210,110,.55) 180deg 186deg, transparent 186deg 225deg,
    rgba(255,210,110,.55) 225deg 231deg, transparent 231deg 270deg,
    rgba(255,210,110,.55) 270deg 276deg, transparent 276deg 315deg,
    rgba(255,210,110,.55) 315deg 321deg, transparent 321deg 360deg);
  animation: spin 26s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.moon {
  display: block;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: #F6F0D6;
  box-shadow: 0 0 26px 8px rgba(230, 235, 255, .45), inset -12px -8px 0 #D8D2B8;
}
.star {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #FFF;
  animation: twinkle 2.6s ease-in-out infinite;
}
@keyframes twinkle { 0%,100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.25); } }

/* 云 */
.clouds { position: absolute; inset: 0; z-index: 2; display: none; }
.cloud {
  position: absolute;
  width: 150px; height: 46px;
  background: rgba(255,255,255,.92);
  border-radius: 30px;
  filter: blur(.4px);
}
.cloud::before, .cloud::after {
  content: ""; position: absolute;
  background: inherit; border-radius: 50%;
}
.cloud::before { width: 64px; height: 64px; left: 22px; top: -30px; }
.cloud::after { width: 44px; height: 44px; right: 26px; top: -18px; }
.c1 { top: 15%; left: -40%; animation: drift 38s linear infinite; }
.c2 { top: 27%; left: -60%; transform: scale(.7); opacity: .8; animation: drift 52s linear infinite -18s; }
.c3 { top: 10%;  left: -30%; transform: scale(1.15); opacity: .7; animation: drift 64s linear infinite -40s; }
@keyframes drift { from { left: -45%; } to { left: 120%; } }

/* 闪电 */
.lightning {
  position: absolute; inset: 0; z-index: 5;
  background: #fff; opacity: 0;
  pointer-events: none;
}
.lightning.flash { animation: bolt .7s ease; }
@keyframes bolt {
  0%,100% { opacity: 0; }
  8% { opacity: .9; } 16% { opacity: .1; } 26% { opacity: .75; } 40% { opacity: 0; }
}

.particles { position: absolute; inset: 0; z-index: 2; pointer-events: none; }

/* 场景顶部栏 */
.scene-top {
  position: absolute;
  top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
}
.city-btn {
  display: flex; align-items: center; gap: 6px;
  background: rgba(20, 28, 45, .28);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff; font-size: 16px; font-weight: 600;
  padding: 7px 13px; border-radius: 20px;
  backdrop-filter: blur(8px);
  max-width: 62%;
}
.city-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #7BFFD0; box-shadow: 0 0 6px #7BFFD0;
  flex: none;
}
.caret { font-size: 11px; opacity: .85; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(20, 28, 45, .28);
  color: #fff; font-size: 17px;
  backdrop-filter: blur(8px);
}
.icon-btn:active { transform: scale(.92); }

/* 温度玻璃条 */
#now-glance {
  position: absolute;
  left: 50%; bottom: calc(14px + env(safe-area-inset-bottom) * .4);
  transform: translateX(-50%);
  z-index: 10;
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 18px;
  border-radius: 22px;
  background: rgba(18, 26, 42, .32);
  border: 1px solid rgba(255,255,255,.28);
  backdrop-filter: blur(10px);
  color: #fff;
  white-space: nowrap;
}
#now-temp { font-size: 34px; font-weight: 700; line-height: 1; }
#now-text { font-size: 15px; font-weight: 600; }
#now-feels { font-size: 12px; opacity: .82; }

/* 台词气泡 */
.bubble {
  position: absolute;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  z-index: 11;
  max-width: 74%;
  background: #fff; color: var(--ink);
  font-size: 13.5px; line-height: 1.45;
  padding: 9px 14px; border-radius: 16px;
  box-shadow: 0 6px 16px rgba(40,35,25,.18);
  text-align: center;
  animation: pop .25s ease;
}
.bubble::after {
  content: ""; position: absolute;
  left: 50%; bottom: -7px; transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #fff; border-bottom: 0;
}
@keyframes pop { from { transform: translateX(-50%) scale(.7); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* ============ 场景状态配色 ============ */
.state-sunny_day  { --sky-a: #6FC3F7; --sky-b: #D6EEFF; --glow: rgba(255,216,120,.6); }
.state-clear_night{ --sky-a: #0E1838; --sky-b: #2C3E6B; --glow: rgba(170,190,255,.35); }
.state-cloudy     { --sky-a: #93A6B8; --sky-b: #D9E2EA; --glow: rgba(255,255,255,.4); }
.state-rain       { --sky-a: #556E86; --sky-b: #93A8BA; --glow: rgba(180,200,220,.25); }
.state-thunder    { --sky-a: #333845; --sky-b: #5C6373; --glow: rgba(200,205,220,.22); }
.state-snow       { --sky-a: #AFC7DC; --sky-b: #EAF2F8; --glow: rgba(255,255,255,.6); }
.state-fog        { --sky-a: #AEB6BC; --sky-b: #E2E6E8; --glow: rgba(255,255,255,.28); }

.state-sunny_day .celestial, .state-clear_night .celestial { display: block; }

.state-cloudy .clouds, .state-rain .clouds,
.state-snow .clouds, .state-thunder .clouds { display: block; }
.state-rain .cloud, .state-thunder .cloud { background: rgba(225,230,238,.9); }
.state-thunder .clouds { opacity: .85; }
.state-snow .cloud { opacity: .65; }

.state-clear_night .sheep { filter: brightness(.88) drop-shadow(0 8px 12px rgba(20,30,80,.35)); }
.state-fog .sheep { filter: saturate(.75) brightness(1.04); }

/* 雾层 */
.state-fog::before, .state-fog .sheep-fog {
  content: "";
  position: absolute; inset: auto 0 0 0;
  height: 70%;
  background:
    radial-gradient(ellipse at 20% 70%, rgba(255,255,255,.7), transparent 55%),
    radial-gradient(ellipse at 80% 50%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(ellipse at 50% 90%, rgba(255,255,255,.6), transparent 55%);
  z-index: 6; pointer-events: none;
  animation: fogmove 14s ease-in-out infinite alternate;
}
@keyframes fogmove { from { transform: translateX(-4%); } to { transform: translateX(4%); } }

/* ============ 预警 ============ */
#warning-banner {
  margin: 12px 12px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #F4845F, #E0533D);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 6px 16px rgba(224,83,61,.28);
}
#warning-banner b { display: block; font-size: 14.5px; margin-bottom: 2px; }

/* ============ 卡片 ============ */
#cards { padding: 12px 12px calc(28px + env(safe-area-inset-bottom)); }

.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.metric {
  background: var(--card);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.metric .m-ico { font-size: 17px; }
.metric .m-val { font-size: 15px; font-weight: 700; margin-top: 2px; }
.metric .m-label { font-size: 11px; color: var(--ink-60); margin-top: 1px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 13px;
  color: var(--ink-60);
  font-weight: 600;
  margin-bottom: 10px;
  letter-spacing: .5px;
}

/* 逐时 */
.hourly-scroll {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.hourly-scroll::-webkit-scrollbar { display: none; }
.hour {
  flex: none;
  width: 52px;
  text-align: center;
  padding: 4px 0;
  border-radius: 12px;
}
.hour:nth-child(odd) { background: #FBF7EE; }
.hour .h-time { font-size: 11.5px; color: var(--ink-60); }
.hour .h-ico { font-size: 20px; margin: 4px 0; }
.hour .h-temp { font-size: 14px; font-weight: 700; }

/* 7天 */
.day-row {
  display: flex; align-items: center;
  padding: 9px 0;
  border-bottom: 1px dashed #EFE7D6;
  gap: 8px;
}
.day-row:last-child { border-bottom: none; }
.day-name { width: 64px; font-size: 14px; font-weight: 600; flex: none; }
.day-name small { display: block; font-weight: 400; color: var(--ink-60); font-size: 10.5px; }
.day-ico { font-size: 19px; width: 26px; text-align: center; flex: none; }
.day-text { flex: 1; font-size: 12.5px; color: var(--ink-60);; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-temps { width: 78px; text-align: right; font-size: 13.5px; flex: none; }
.day-temps .lo { color: var(--ink-40); }
.day-temps .hi { font-weight: 700; color: var(--coral); }

/* 空气 */
#air { display: flex; align-items: center; gap: 16px; }
.aqi-num {
  width: 74px; height: 74px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 800; color: #fff;
  flex: none;
}
.aqi-meta b { font-size: 17px; }
.aqi-meta p { font-size: 12.5px; color: var(--ink-60); margin-top: 3px; }

/* 指数 */
.indices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.index-item {
  background: #FBF7EE;
  border-radius: 12px;
  padding: 10px 12px;
}
.index-item .i-name { font-size: 11.5px; color: var(--ink-60); }
.index-item .i-cat { font-size: 15px; font-weight: 700; color: var(--mint); margin: 2px 0; }
.index-item .i-text { font-size: 11.5px; color: var(--ink-60); line-height: 1.4; }

/* 日出日落 */
.astro-card { display: flex; justify-content: space-around; }
.astro-item { font-size: 12.5px; color: var(--ink-60); display: flex; gap: 4px; align-items: center; }
.astro-item b { color: var(--ink); font-size: 13.5px; }

.credit {
  text-align: center;
  font-size: 11px;
  color: var(--ink-40);
  padding: 6px 0 0;
}

/* ============ 城市页 ============ */
.sub-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(250,244,230,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #EFE7D6;
}
.sub-header h2 { font-size: 17px; }
.back-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: #F0E8D7;
  font-size: 20px; color: var(--ink); line-height: 1;
}
.search-box { padding: 12px 14px 6px; }
#city-search {
  width: 100%;
  border: 1.5px solid #EADFC9;
  background: #fff;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
  outline: none;
  color: var(--ink);
}
#city-search:focus { border-color: var(--mint); }

.search-results { padding: 0 14px; }
.result-item, .city-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.result-item:active, .city-card:active { background: #FBF7EE; }
.result-info b { font-size: 15px; }
.result-info p { font-size: 12px; color: var(--ink-60); margin-top: 2px; }
.add-btn {
  border: none; flex: none;
  background: var(--mint-soft); color: var(--mint);
  font-weight: 700; font-size: 13px;
  padding: 7px 14px; border-radius: 16px;
}
.add-btn.added { background: #EEE7D8; color: var(--ink-40); }

.section-label {
  font-size: 12.5px; color: var(--ink-60);
  padding: 10px 18px 4px; letter-spacing: .5px;
}
.city-card .city-temp { font-size: 20px; font-weight: 800; flex: none; width: 52px; text-align: right; }
.city-temp small { font-size: 12px; font-weight: 400; color: var(--ink-60); display: block; }
.del-btn {
  border: none; background: none;
  color: #C9BFA8; font-size: 17px;
  padding: 4px 6px; flex: none;
}
.empty-tip {
  text-align: center;
  color: var(--ink-40);
  font-size: 13px;
  padding: 30px 20px;
  line-height: 1.8;
}

/* 设置 */
.settings { padding: 14px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  box-shadow: var(--shadow);
}
.setting-row input { width: 22px; height: 22px; accent-color: var(--mint); }
.setting-hint { font-size: 12px; color: var(--ink-60); line-height: 1.6; margin: 8px 4px 18px; }
.setting-block {
  background: #fff; border-radius: 14px;
  padding: 14px 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.setting-block h3 { font-size: 15px; margin-bottom: 6px; }
.setting-block p { font-size: 13px; color: var(--ink-60); line-height: 1.7; }

/* 加载与提示 */
.toast {
  position: fixed;
  left: 50%; bottom: 12%;
  transform: translateX(-50%);
  background: rgba(30, 26, 20, .9);
  color: #fff; font-size: 13.5px;
  padding: 10px 20px; border-radius: 20px;
  z-index: 99;
  animation: pop .2s ease;
  max-width: 80%;
  text-align: center;
}
.loading-mask {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  color: rgba(255,255,255,.9);
  font-size: 13.5px;
  background: rgba(20,28,45,.18);
  backdrop-filter: blur(2px);
}
.spinner {
  width: 26px; height: 26px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 8px;
}

@media (prefers-reduced-motion: reduce) {
  .sheep, .prop, .sun::before, .cloud, .star, .state-fog::before { animation: none !important; }
}
