<script setup>
import { ref } from 'vue'
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { logRuntimeEnv } from './services/request.js'
import analytics from './services/analytics.js'

const statusBarHeight = ref(0)
const safeAreaTop = ref(0)
const safeAreaBottom = ref(0)

const hydrateSafeArea = () => {
  try {
    const windowInfo = uni.getWindowInfo ? uni.getWindowInfo() : uni.getSystemInfoSync()
    statusBarHeight.value = windowInfo.statusBarHeight || 20
    safeAreaTop.value = windowInfo.safeAreaInsets?.top || windowInfo.statusBarHeight || 20
    safeAreaBottom.value = windowInfo.safeAreaInsets?.bottom || 0
    uni.setStorageSync('statusBarHeight', statusBarHeight.value)
    uni.setStorageSync('safeAreaTop', safeAreaTop.value)
    uni.setStorageSync('safeAreaBottom', safeAreaBottom.value)
  } catch (error) {
    statusBarHeight.value = 20
    safeAreaTop.value = 20
    safeAreaBottom.value = 0
  }
}

onLaunch(() => {
  console.log('App Launch')
  analytics.initAnalytics()
  logRuntimeEnv('app:onLaunch')
  hydrateSafeArea()
})

onShow(() => {
  console.log('App Show')
  analytics.track('app_show', {}, { eventType: 'app' })
})

onHide(() => {
  console.log('App Hide')
  analytics.track('app_hide', {}, { eventType: 'app' })
  analytics.flush()
})
</script>

<style>
page {
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: #f8f4ff;
  background: #050615;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 28rpx;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button {
  padding: 0;
  margin: 0;
  border: 0;
  color: inherit;
  background: transparent;
  line-height: normal;
  font: inherit;
}

button::after {
  border: 0;
}

input,
textarea {
  color: #f8f4ff;
  font: inherit;
}

::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.safe-area-bottom {
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}

.safe-area-top {
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
}

.kos-page {
  min-height: 100vh;
  color: #f8f4ff;
  background:
    radial-gradient(circle at 78% 10%, rgba(111, 55, 255, 0.32), transparent 28%),
    radial-gradient(circle at 14% 34%, rgba(36, 124, 255, 0.17), transparent 28%),
    linear-gradient(180deg, #07091b 0%, #07031a 46%, #04030f 100%);
}

.kos-card {
  border: 1rpx solid rgba(163, 92, 255, 0.38);
  background:
    linear-gradient(145deg, rgba(31, 23, 76, 0.78), rgba(8, 8, 30, 0.9)),
    radial-gradient(circle at 90% 20%, rgba(139, 78, 255, 0.14), transparent 38%);
  box-shadow:
    inset 0 0 44rpx rgba(147, 92, 255, 0.08),
    0 22rpx 64rpx rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(24rpx);
  -webkit-backdrop-filter: blur(24rpx);
}

.kos-pill {
  border: 1rpx solid rgba(157, 108, 255, 0.34);
  background: rgba(255, 255, 255, 0.055);
  box-shadow: inset 0 0 20rpx rgba(160, 96, 255, 0.08);
}

.kos-primary {
  color: #fff;
  background:
    radial-gradient(circle at 68% 20%, rgba(255, 255, 255, 0.28), transparent 22%),
    linear-gradient(135deg, #b045ff 0%, #612eff 56%, #2b1aff 100%);
  box-shadow: 0 18rpx 42rpx rgba(129, 66, 255, 0.38), inset 0 0 20rpx rgba(255, 255, 255, 0.1);
}

.placeholder {
  color: rgba(213, 199, 239, 0.42);
}
</style>
