:root {
  --app-width: 500px;
}

@media screen and (min-width: 500px) and (max-width: 600px) {
  :root {
    --app-width: 600px;
  }
}

@media screen and (min-width: 600px) {
  html {
    font-size: calc(var(--app-width) / (750 / 30)) !important;
    max-width: var(--app-width) !important;
    margin: 0 auto !important;
  }
}

html,
body {
  min-height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
}

#app {
  position: relative;
  width: 100%;
  max-width: var(--app-width);
  margin: 0 auto;
  background: transparent !important;
}
#app > :first-child {
  min-height: 100% !important;
}

.kg-loading {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-width);
  /* min-height: calc(100 * var(--vh)); */
  height: 100%;
  /* #kg-loading 僅作純色遮罩（background-color 由 #theme-init-styles 設置），不設 background-image。
     背景圖由 body 承載，hideFirstScreenLoading 淡出時已由 waitForBgImageDecoded 確保 decode 完成。
     關閉時由 createApp.js hideFirstScreenLoading() 通過 opacity 過渡平滑消失 */
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* 确保 loading 层在 #app 之上，因为 #kg-loading 已移到 #app 外面 */
  z-index: 9999;
  /* 過渡動畫：隱藏時平滑淡出，避免 loading → 首頁的瞬間跳變 */
  transition: opacity 0.3s ease-out;
  /* 提前聲明 will-change，避免 createApp.js 動態添加時觸發 Android WebView 重建合成層導致背景圖 re-decode 閃爍 */
  will-change: opacity;
}

@media screen and (max-width: 600px) {
  #app {
    width: 100%;
  }

  #app::-webkit-scrollbar {
    width: 0;
    background: transparent;
  }

  .kg-loading {
    width: 100%;
    /* min-height: calc(100 * var(--vh)); */
  }
}

.kg-error {
  display: none;
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  user-select: none;
  font-size: 24px;
}

.kg-error .refresh {
  /* 默認紅色主題樣式 */
  background: linear-gradient(180deg, #ffffec 0%, #fdf09c 33.65%, #b68030 71.5%, #b47d2d 83.5%, #f1bf45 100%);
  width: 60%;
  height: 40px;
  margin: 0 auto;
  margin-top: 80px;
  padding: 0 10px;
  border: 1px solid #530002;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 15px;
  color: #7b1801;
  font-size: 16px;
}

/* 藍色主題錯誤按鈕樣式 - 通過 CSS 選擇器 */
body[theme='theme2'] .kg-error .refresh,
html[data-theme='theme2'] .kg-error .refresh {
  background: linear-gradient(180deg, #4a39ad 0%, #251e5e 100%);
  border: 1px solid #4a39ad;
  color: #d6d0ff;
}

.kg-error .err {
  color: #fff;
  padding: 0 16px;
  text-align: center;
}

.toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateZ(0);
  z-index: 1; /* 確保 spinner 在 #kg-loading-bg 背景圖之上 */
  /* translateZ(0) 將 .toast 提升為獨立 GPU 合成層，
     隔離父元素 #kg-loading 因 background-color/bg-img 變更觸發的重光柵化，
     避免 Android WebView 二次啟動時 favicon 短暫消失 */
  backface-visibility: hidden;
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 30px;
  aspect-ratio: 1/1;
  img {
    width: 100%;
    height: 100%;
  }
}

.loading-container-favicon {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  max-width: 150px !important;
  width: auto !important;
}

.loading-container-favicon img {
  /* 默认自适应图片大小 */
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: 150px !important;
  display: block !important;
  margin: 0 auto !important;
}


.circle {
  border-radius: 50%;
  position: relative;
  margin: 0.2rem auto;
  animation: rotate 1s linear infinite;

  img {
    width: 54px;
    height: 54px;
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.maintain {
  padding: 0 28px;
  height: 100vh;
  display: none;
}

.maintain .content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.maintain .maintain_img {
  width: 100%;
  margin-top: 10px;
}

.maintain .maintainTitle {
  color: #d81400;
  font-size: 16px;
  line-height: 22.4px;
  margin-bottom: 30px;
}

.maintain .timeTitle {
  color: #fff;
  font-size: 16px;
  line-height: 22.4px;
}

.maintain .refresh_maintain {
  width: 93px;
  margin-bottom: 22px;
}

.maintain .maintainTime {
  color: #fff;
  font-size: 14px;
  line-height: 19.6px;
  margin-top: 7px;
}

.maintain .share_box {
  position: fixed;
  bottom: 10px;
  max-width: var(--app-width);
  width: 100%;
  left: 50%;
  transform: translateX(-50%);
  justify-content: space-between;

  @media screen and (max-width: 600px) {
    left: 0;
    transform: translate(0);
  }
}

.maintain .share_title {
  text-align: center;
  color: #fff9;
  font-size: 12px;
  line-height: 16.8px;
  margin-bottom: 15px;
}

.maintain .maintainList {
  padding: 0 12px;
  padding-bottom: 28px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.maintain .maintainList > div {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 65px;
}

.maintain .maintainList p:nth-child(1) {
  height: 54px;
  width: 54px;
  border-radius: 50%;
  background-color: #6e050c;
  display: flex;
  align-items: center;
  justify-content: center;
}

.maintain .maintainList p:nth-child(1) img {
  height: 22px;
  width: 22px;
}

.maintain .maintainList p:nth-child(2) {
  position: absolute;
  left: 50%;
  transform: translate(-50%);
  bottom: -30%;
  font-size: 11px;
  line-height: 15.4px;
  text-align: center;
  color: #d4656e;
  margin-top: 10px;
}
