/* ========== 基础 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  --text-main: #1f2937;
  --text-sub: #4b5563;
  --card-bg: rgba(255, 255, 255, 0.55);
  --card-border: rgba(255, 255, 255, 0.45);
  --card-shadow: 0 8px 32px rgba(31, 41, 55, 0.16);
  --tile-bg: rgba(255, 255, 255, 0.28);

  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text-main);
  background: linear-gradient(165deg, #5f7291 0%, #8fa1b8 55%, #b8c6d4 100%);
  background-attachment: fixed;
}

/* 夜间统一加深：文字转浅色、卡片透明度降低 */
body.night {
  --text-main: #f2f6fc;
  --text-sub: rgba(242, 246, 252, 0.72);
  --card-bg: rgba(255, 255, 255, 0.12);
  --card-border: rgba(255, 255, 255, 0.18);
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --tile-bg: rgba(255, 255, 255, 0.08);
}

/* ========== 天气主题背景：晴=蓝天系、多云/阴=灰蓝、雨=深灰蓝、雪=浅冷灰、雾=灰白、雷暴=深紫灰 ========== */
body.theme-clear { background: linear-gradient(165deg, #3d7dc8 0%, #6ea8dc 45%, #aad2f0 100%); }
body.theme-clear.night { background: linear-gradient(165deg, #0e1c38 0%, #1d3055 55%, #2d4571 100%); }
body.theme-cloudy { background: linear-gradient(165deg, #5f7291 0%, #8fa1b8 55%, #b8c6d4 100%); }
body.theme-cloudy.night { background: linear-gradient(165deg, #1b2330 0%, #2e3948 55%, #425061 100%); }
body.theme-rain { background: linear-gradient(165deg, #37475c 0%, #4f6178 55%, #6e8096 100%); }
body.theme-rain.night { background: linear-gradient(165deg, #121b26 0%, #1f2c3a 55%, #2c3c4d 100%); }
body.theme-snow { background: linear-gradient(165deg, #8ba3ba 0%, #b7c8d8 50%, #e1eaf2 100%); }
body.theme-snow.night { background: linear-gradient(165deg, #2b394b 0%, #45586c 55%, #5e7187 100%); }
body.theme-fog { background: linear-gradient(165deg, #a7b0b8 0%, #c6cdd4 55%, #e5e9ed 100%); }
body.theme-fog.night { background: linear-gradient(165deg, #2a3037 0%, #454c55 55%, #5d656e 100%); }
body.theme-thunder { background: linear-gradient(165deg, #322b47 0%, #4a4066 55%, #675c87 100%); }
body.theme-thunder.night { background: linear-gradient(165deg, #16132a 0%, #252040 55%, #342d55 100%); }

.hidden {
  display: none !important;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* ========== 顶部与搜索 ========== */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.app-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-right: auto;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.search-box {
  position: relative;
  width: 100%;
  max-width: 340px;
}

#searchInput {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  color: #1f2937;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  outline: none;
  box-shadow: 0 4px 16px rgba(31, 41, 55, 0.12);
}

#searchInput::placeholder {
  color: #9ca3af;
}

#searchInput:focus {
  border-color: rgba(255, 255, 255, 0.95);
  background: #ffffff;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  list-style: none;
  background: #ffffff;
  color: #1f2937;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  overflow-y: auto;
  max-height: 320px;
}

.search-result-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.search-result-item:hover {
  background: #eaf2fc;
}

.search-result-name {
  font-weight: 600;
  white-space: nowrap;
}

.search-result-sub {
  font-size: 12px;
  color: #6b7280;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-message {
  padding: 12px 14px;
  font-size: 13px;
  color: #6b7280;
  text-align: center;
}

/* ========== 玻璃拟态卡片 ========== */
.glass-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: var(--card-shadow);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  padding: 20px;
}

/* ========== 加载与错误 ========== */
.loading {
  text-align: center;
  padding: 72px 0;
}

.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border: 4px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 15px;
  color: var(--text-main);
}

.error-box {
  text-align: center;
  padding: 36px 20px;
  max-width: 420px;
  margin: 40px auto 0;
}

.error-emoji {
  font-size: 34px;
  margin-bottom: 10px;
}

.error-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
}

#retryBtn {
  margin-top: 16px;
  padding: 9px 30px;
  font-size: 15px;
  font-family: inherit;
  color: #1f2937;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#retryBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

#retryBtn:focus-visible {
  outline: 2px solid #ffffff;
}

/* ========== 布局：移动端单列，≥768px 左侧当前+逐小时、右侧 7 天侧栏 ========== */
.weather-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* ========== 当前天气卡 ========== */
.current-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.city-name {
  font-size: 24px;
  font-weight: 700;
}

.update-time {
  font-size: 12px;
  color: var(--text-sub);
}

.current-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin: 14px 0 16px;
}

.current-emoji {
  font-size: 58px;
  line-height: 1;
}

.current-temp {
  font-size: 76px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -2px;
}

.current-desc {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.desc-text {
  font-size: 20px;
  font-weight: 600;
}

.feels-like {
  font-size: 14px;
  color: var(--text-sub);
}

.current-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.detail-item {
  flex: 1 1 150px;
  background: var(--tile-bg);
  border-radius: 12px;
  padding: 12px 14px;
}

.detail-label {
  display: block;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 16px;
  font-weight: 600;
}

/* ========== 逐小时横滑条 ========== */
.section-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.hourly-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.hourly-scroll::-webkit-scrollbar {
  height: 8px;
}

.hourly-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.45);
  border-radius: 4px;
}

.hourly-item {
  flex: 0 0 auto;
  width: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border-radius: 12px;
  background: var(--tile-bg);
}

.hourly-item.is-now {
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.65) inset;
}

body.night .hourly-item.is-now {
  background: rgba(255, 255, 255, 0.2);
}

.hourly-hour {
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
}

.hourly-emoji {
  font-size: 20px;
  line-height: 1;
}

.hourly-temp {
  font-size: 15px;
  font-weight: 600;
}

.hourly-pop {
  font-size: 11px;
  color: var(--text-sub);
  min-height: 1em;
  white-space: nowrap;
}

/* ========== 7 天列表 ========== */
.daily-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.daily-item {
  display: grid;
  grid-template-columns: 48px 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--tile-bg);
}

.daily-day {
  font-size: 14px;
  font-weight: 600;
}

.daily-emoji {
  font-size: 18px;
  text-align: center;
}

.daily-temps {
  font-size: 14px;
  white-space: nowrap;
}

.daily-pop {
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
}

/* ========== 响应式 ========== */
@media (min-width: 768px) {
  .app {
    padding: 28px 24px 56px;
  }

  .weather-content {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }

  .current-card {
    grid-column: 1;
  }

  .hourly-section {
    grid-column: 1;
  }

  .daily-section {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .current-temp {
    font-size: 84px;
  }
}
