/* 天气插件样式 —— 液态玻璃风格
 *
 * 图标：Meteocons (https://github.com/basmilius/meteocons, MIT License)
 * 玻璃质感：Adapted from
 *   https://github.com/weatherwidget/weatherwidget.github.io (MIT License)
 *
 * 颜色一律使用主题的语义变量（--text-color / --heading-color 等），
 * 这样在亮色 / 暗色模式下都会自动适配。
 */

/* ============================================================ 容器 */

.weather-plugin {
  position: fixed;
  top: 0.4rem;
  right: 0.6rem;
  z-index: 1030;
  font-family: var(--bs-font-sans-serif);
  color: var(--text-color);
}

/* 折叠按钮 */
.weather-plugin__toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem 0.3rem 0.45rem;
  border: 1px solid rgb(255 255 255 / 32%);
  border-radius: 999px;
  background: rgb(255 255 255 / 45%);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 6px 20px rgb(0 0 0 / 14%), inset 0 1px 0 rgb(255 255 255 / 55%);
  color: var(--text-color);
  text-shadow: 0 1px 3px rgb(0 0 0 / 22%);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgb(0 0 0 / 18%), inset 0 1px 0 rgb(255 255 255 / 65%);
  }

  &:active {
    transform: translateY(0);
  }
}

.weather-plugin__toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
}

.weather-plugin__toggle-img {
  width: 1.4rem;
  height: 1.4rem;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgb(0 0 0 / 25%));
}

.weather-plugin__toggle-temp {
  font-variant-numeric: tabular-nums;
  min-width: 2.1rem;
}

/* 展开面板 */
.weather-plugin__panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 21rem;
  max-width: calc(100vw - 1.5rem);
  opacity: 0;
  transform: translateY(-0.5rem) scale(0.96);
  transform-origin: top right;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;

  &.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
}

/* 玻璃卡片 */
.weather-plugin__glass {
  position: relative;
  overflow: hidden;
  padding: 1rem;
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 1.25rem;
  background: linear-gradient(145deg, rgb(255 255 255 / 38%), rgb(255 255 255 / 14%));
  backdrop-filter: blur(30px) saturate(170%);
  -webkit-backdrop-filter: blur(30px) saturate(170%);
  box-shadow: 0 22px 48px rgb(0 0 0 / 22%), 0 0 0 1px rgb(255 255 255 / 16%), inset 0 1px 0 rgb(255 255 255 / 42%);
  transition: background 0.6s ease, box-shadow 0.6s ease;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 70%), transparent);
  }
}

/* 天气主题渐变 */
.weather-plugin__glass[data-scene="sunny"] {
  background: linear-gradient(145deg, rgb(251 191 36 / 32%), rgb(245 158 11 / 12%));
}

.weather-plugin__glass[data-scene="partly-cloudy"] {
  background: linear-gradient(145deg, rgb(56 189 248 / 28%), rgb(148 163 184 / 14%));
}

.weather-plugin__glass[data-scene="overcast"] {
  background: linear-gradient(145deg, rgb(148 163 184 / 32%), rgb(100 116 139 / 14%));
}

.weather-plugin__glass[data-scene="misty"] {
  background: linear-gradient(145deg, rgb(203 213 225 / 40%), rgb(148 163 184 / 18%));
}

.weather-plugin__glass[data-scene="rainy"] {
  background: linear-gradient(145deg, rgb(59 130 246 / 32%), rgb(37 99 235 / 12%));
}

.weather-plugin__glass[data-scene="stormy"] {
  background: linear-gradient(145deg, rgb(71 85 105 / 45%), rgb(30 41 59 / 24%));
}

.weather-plugin__glass[data-scene="snowy"] {
  background: linear-gradient(145deg, rgb(226 232 240 / 42%), rgb(203 213 225 / 18%));
}

/* 深色场景（夜晚 / 雷暴）下玻璃本身偏暗，无论站点处于亮色还是暗色模式，
   文字都需要强制使用浅色才能看清。 */
.weather-plugin__glass[data-scene="stormy"] {
  .weather-plugin__place,
  .weather-plugin__temp,
  .weather-plugin__desc,
  .weather-plugin__detail-value {
    color: #f1f5f9;
  }

  .weather-plugin__feels,
  .weather-plugin__clock,
  .weather-plugin__detail-label {
    color: rgb(226 232 240 / 78%);
  }

  .weather-plugin__details,
  .weather-plugin__section {
    border-top-color: rgb(255 255 255 / 20%);
  }

  .weather-plugin__lang-btn.is-active {
    background: rgb(255 255 255 / 85%);
    color: #1e293b;
  }
}

/* ============================================================ 内容 */

.weather-plugin__content {
  position: relative;
  z-index: 2;
}

/* 玻璃底上的文字需要额外的描边以保证可读性，
   颜色仍跟随主题变量，描边则始终用半透明白/黑以适配两种模式。 */
.weather-plugin__content,
.weather-plugin__loading {
  text-shadow: 0 1px 3px rgb(0 0 0 / 22%);
}

.weather-plugin__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.weather-plugin__place {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--heading-color);
}

.weather-plugin__clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.7rem;
  line-height: 1.25;
  color: var(--text-muted-color);
  font-variant-numeric: tabular-nums;
}

.weather-plugin__main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

/* 主图标容器：Meteocons 的 SVG 自带 SMIL 动画，无需额外 CSS 动画 */
.weather-plugin__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  height: 4.5rem;
}

.weather-plugin__icon-img {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgb(0 0 0 / 28%));
}

.weather-plugin__reading {
  min-width: 0;
}

.weather-plugin__temp {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--heading-color);
  font-variant-numeric: tabular-nums;
}

.weather-plugin__unit {
  font-size: 1rem;
  font-weight: 600;
  margin-left: 0.1rem;
  opacity: 0.75;
}

.weather-plugin__desc {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-color);
}

.weather-plugin__feels {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted-color);
}

/* 详情行 */
.weather-plugin__details {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0.7rem 0 0;
  padding: 0.55rem 0 0;
  border-top: 1px solid rgb(255 255 255 / 25%);
  list-style: none;

  li {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    flex: 1;
    font-size: 0.7rem;
  }

  i {
    opacity: 0.65;
    font-size: 0.8rem;
  }
}

.weather-plugin__detail-value {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--heading-color);
  font-variant-numeric: tabular-nums;
}

.weather-plugin__detail-label {
  color: var(--text-muted-color);
}

/* ============================================================ 数据区块 */

/* 近 24 小时 / 近一周 */
.weather-plugin__section {
  margin-top: 0.7rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgb(255 255 255 / 22%);
}

.weather-plugin__section-title {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted-color);
}

/* 小时级：横向滚动 */
.weather-plugin__hourly {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  scrollbar-width: thin;

  &::-webkit-scrollbar {
    height: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgb(255 255 255 / 25%);
    border-radius: 2px;
  }
}

.weather-plugin__hour {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 2.7rem;
  padding: 0.3rem 0.15rem;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 0.6rem;
  background: rgb(255 255 255 / 10%);
  transition: background 0.2s ease;

  &:hover {
    background: rgb(255 255 255 / 22%);
  }

  &.is-now {
    border-color: rgb(255 255 255 / 40%);
    background: rgb(255 255 255 / 24%);
  }
}

.weather-plugin__hour-icon {
  width: 1.6rem;
  height: 1.6rem;
  object-fit: contain;
}

.weather-plugin__hour-time {
  font-size: 0.6rem;
  color: var(--text-muted-color);
  white-space: nowrap;
}

.weather-plugin__hour-temp {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--heading-color);
  font-variant-numeric: tabular-nums;
}

.weather-plugin__hour-pop {
  font-size: 0.58rem;
  color: #60a5fa;
  font-variant-numeric: tabular-nums;
}

/* 日级：纵向列表 */
.weather-plugin__daily {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.weather-plugin__day {
  display: grid;
  grid-template-columns: 2.6rem 1.6rem 2.2rem auto;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.25rem;
  border-radius: 0.45rem;
  font-size: 0.72rem;
  transition: background 0.2s ease;

  &:hover {
    background: rgb(255 255 255 / 14%);
  }

  &.is-today {
    background: rgb(255 255 255 / 18%);
    font-weight: 600;
  }
}

.weather-plugin__day-name {
  color: var(--text-muted-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weather-plugin__day.is-today .weather-plugin__day-name {
  color: var(--heading-color);
}

.weather-plugin__day-icon {
  width: 1.6rem;
  height: 1.6rem;
  object-fit: contain;
}

.weather-plugin__day-pop {
  font-size: 0.62rem;
  color: #60a5fa;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.weather-plugin__day-range {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.35rem;
  font-variant-numeric: tabular-nums;

  b {
    color: var(--heading-color);
    font-weight: 700;
  }

  i {
    color: var(--text-muted-color);
    font-style: normal;
    min-width: 1.9rem;
    text-align: right;
  }
}

.weather-plugin__empty {
  margin: 0.3rem 0;
  font-size: 0.7rem;
  color: var(--text-muted-color);
  text-align: center;
}

/* ============================================================ 底部操作条 */

.weather-plugin__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.weather-plugin__lang {
  display: flex;
  gap: 0.15rem;
  padding: 0.15rem;
  border-radius: 0.6rem;
  background: rgb(255 255 255 / 22%);
  border: 1px solid rgb(255 255 255 / 25%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.weather-plugin__lang-btn {
  padding: 0.2rem 0.55rem;
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  color: var(--text-muted-color);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    color: var(--heading-color);
  }

  &.is-active {
    background: rgb(255 255 255 / 75%);
    color: var(--text-color);
    box-shadow: 0 1px 4px rgb(0 0 0 / 14%);
  }
}

.weather-plugin__actions {
  display: flex;
  gap: 0.25rem;
}

.weather-plugin__icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 50%;
  background: rgb(255 255 255 / 24%);
  color: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    background: rgb(255 255 255 / 50%);
    transform: translateY(-1px);
  }

  &.is-spinning i {
    animation: weather-plugin-spin 0.7s linear infinite;
  }
}

/* 加载 / 错误 */
.weather-plugin__loading {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 7.5rem;
  font-size: 0.78rem;
  color: var(--text-muted-color);
}

.weather-plugin__spinner {
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid rgb(255 255 255 / 32%);
  border-top-color: var(--link-color);
  border-radius: 50%;
  animation: weather-plugin-spin 0.8s linear infinite;
}

.weather-plugin__error {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 1rem 0.5rem;
  text-align: center;
  font-size: 0.78rem;
  color: #dc3545;
}

/* ============================================================ 背景漂浮粒子 */

.weather-plugin__particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.weather-plugin__particle {
  position: absolute;
  border-radius: 50%;
  background: rgb(255 255 255 / 40%);
  animation: weather-plugin-particle 9s ease-in-out infinite;
}

/* ============================================================ 关键帧 */

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

@keyframes weather-plugin-particle {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  20% { opacity: 0.55; }
  100% { transform: translateY(-70px) translateX(14px); opacity: 0; }
}

/* ============================================================ 响应式 */

@media (max-width: 850px) {
  .weather-plugin {
    top: 0.3rem;
    right: 0.45rem;
  }

  .weather-plugin__panel {
    width: 18.5rem;
  }

  .weather-plugin__temp {
    font-size: 2.2rem;
  }

  .weather-plugin__icon,
  .weather-plugin__icon-img {
    width: 3.6rem;
    height: 3.6rem;
  }
}

/* 尊重系统减弱动效偏好 */
@media (prefers-reduced-motion: reduce) {
  .weather-plugin__particle,
  .weather-plugin__spinner {
    animation: none !important;
  }

  .weather-plugin__panel {
    transition: opacity 0.1s linear;
  }
}
