:root {
  --bg: #000000;
  --glass: rgba(255, 255, 255, 0.14);
  --glass-border: rgba(255, 255, 255, 0.22);
  --text: #ffffff;
  --text-dark: #1a1a1a;
  --accent: #4f76e3;
  --accent-light: #90caf9;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  --radius: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* 桌面 */
.desktop {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  position: relative;
}

.desktop-bg {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 0;
  pointer-events: none;
}

/* 登出按钮 */
.desktop-logout {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  z-index: 10;
  padding: 8px 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s, opacity 0.2s;
  user-select: none;
}
.desktop-logout:active {
  opacity: 0.6;
}

.desktop-grid {
  display: flex;
  width: min(88vw, 720px);
  z-index: 1;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

.desktop-page {
  flex: 0 0 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(16px, 4vmin, 48px);
  padding: 0 2px;
}

.app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, 1.8vmin, 14px);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  user-select: none;
}

.app-icon:active {
  transform: scale(0.92);
}

.app-icon:hover {
  transform: scale(1.05);
}

.app-icon-body {
  width: clamp(72px, 16vmin, 124px);
  height: clamp(72px, 16vmin, 124px);
  border-radius: clamp(18px, 3.6vmin, 28px);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(34px, 8vmin, 62px);
}

.app-icon-label {
  font-size: clamp(12px, 2.8vmin, 17px);
  font-weight: 500;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.desktop-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 22px;
  opacity: 0.85;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2;
}

.desktop-arrow:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.08);
}

.desktop-arrow.left {
  left: 16px;
}

.desktop-arrow.right {
  right: 16px;
}

.desktop-arrow.hidden {
  display: none;
}

.desktop-dots {
  position: absolute;
  bottom: calc(28px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 2;
}

.desktop-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  transition: background 0.25s, transform 0.25s;
}

.desktop-dot.active {
  background: var(--text);
  transform: scale(1.25);
}

/* 应用遮罩层 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.app-container {
  width: min(96vw, 860px);
  height: min(92vh, min(96vw * 1.15, 980px));
  max-height: 92vh;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.86) translateY(40px);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.22, 1.4, 0.36, 1), opacity 0.35s ease;
}

@media (max-aspect-ratio: 4/3) {
  .app-container {
    width: min(98vw, 860px);
    height: min(90vh, min(98vw * 1.25, 980px));
  }
}

.overlay.visible .app-container {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
}

.app-back {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--glass-border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.15s, background 0.2s;
}

.app-back:active {
  transform: scale(0.9);
}

.app-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 聊天应用 */
.chat-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.chat-latest {
  font-size: clamp(26px, 6vw, 44px);
  line-height: 1.45;
  text-align: center;
  font-weight: 500;
  max-width: 90%;
  word-break: break-word;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  transition: opacity 0.2s;
}

.chat-latest.waiting {
  opacity: 0.55;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.8;
  }
}

.chat-history-toggle {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 42px;
  height: 28px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.chat-history-toggle:active {
  transform: translateX(-50%) scale(0.92);
}

.chat-history-toggle svg {
  width: 18px;
  height: 18px;
  fill: var(--text);
  transition: transform 0.3s;
}

.chat-history-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(72%, 520px);
  max-height: 72%;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  border-radius: 24px 24px 0 0;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  z-index: 3;
}

.chat-history-panel.open {
  transform: translateY(0);
  animation: releaseBounce 0.55s cubic-bezier(0.22, 1.5, 0.36, 1);
}

@keyframes releaseBounce {
  0% {
    transform: translateY(100%);
  }
  60% {
    transform: translateY(-4%);
  }
  80% {
    transform: translateY(1.5%);
  }
  100% {
    transform: translateY(0);
  }
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 15px;
  font-weight: 600;
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-history-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  max-width: 85%;
}

.chat-history-item.user {
  align-self: flex-end;
  background: var(--accent);
}

.chat-history-item.assistant {
  align-self: flex-start;
}

.chat-history-role {
  font-size: 11px;
  opacity: 0.75;
}

.chat-history-text {
  font-size: 15px;
  line-height: 1.45;
}

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px 18px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.12);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 16px;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.chat-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
  font-size: 20px;
}

.chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-send:active:not(:disabled) {
  transform: scale(0.92);
}

.voice-toggle {
  position: absolute;
  left: 18px;
  bottom: calc(82px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  user-select: none;
  z-index: 2;
  transition: background 0.2s;
}

.voice-toggle.on {
  background: rgba(79, 118, 227, 0.55);
}

.voice-toggle svg {
  width: 20px;
  height: 20px;
  fill: var(--text);
}

.voice-toggle span {
  font-size: 13px;
}

/* 店铺查询应用 */
.store-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 24px;
  text-align: center;
}

.store-mic {
  width: clamp(120px, 30vw, 180px);
  height: clamp(120px, 30vw, 180px);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-light), var(--accent));
  box-shadow: 0 10px 40px rgba(79, 118, 227, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(48px, 12vw, 80px);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s;
  animation: micIdle 2.6s ease-in-out infinite;
}

.store-mic:active {
  transform: scale(0.92);
}

.store-mic.listening {
  animation: micPulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 12px rgba(79, 118, 227, 0.2);
}

@keyframes micIdle {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

@keyframes micPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(79, 118, 227, 0.25);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 18px rgba(79, 118, 227, 0.08);
  }
}

.store-hint {
  font-size: clamp(18px, 4.5vw, 26px);
  font-weight: 500;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  min-height: 1.6em;
}

.store-input-wrap {
  width: min(92%, 520px);
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.store-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 18px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.store-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.store-send-btn {
  padding: 12px 20px;
  border-radius: 18px;
  border: 1px solid var(--glass-border);
  background: rgba(79, 118, 227, 0.55);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.store-send-btn:active {
  transform: scale(0.96);
}

.store-card {
  width: 100%;
  max-width: 520px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 20px;
  text-align: left;
  display: none;
  flex-direction: column;
  gap: 10px;
  max-height: 62vh;
  overflow-y: auto;
}

.store-card.visible {
  display: flex;
  animation: cardIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.store-card h3 {
  margin: 0 0 6px;
  font-size: 20px;
}

.store-card-row {
  display: flex;
  gap: 10px;
  font-size: 14px;
  line-height: 1.4;
}

.store-card-row strong {
  flex-shrink: 0;
  min-width: 5em;
  opacity: 0.8;
}

/* 目标识别应用 */
.detect-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 16px;
  position: relative;
}

.detect-video-wrap {
  position: relative;
  width: min(90vw, 760px);
  max-width: 90vw;
  max-height: 62vh;
  aspect-ratio: 4 / 3;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

@media (max-aspect-ratio: 4/3) {
  .detect-video-wrap {
    width: min(96vw, 760px);
    max-height: 55vh;
    aspect-ratio: 4 / 3;
  }
}

@media (min-aspect-ratio: 16/9) {
  .detect-video-wrap {
    width: min(76vw, 760px);
    max-height: 68vh;
    aspect-ratio: 16 / 9;
  }
}

.detect-video-wrap video,
.detect-video-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detect-video-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}

.detect-shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
  flex-shrink: 0;
}

.detect-shutter:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.55);
}

.detect-hint {
  font-size: 15px;
  opacity: 0.85;
  text-align: center;
}

.detect-result-actions {
  display: flex;
  gap: 14px;
}

.detect-btn {
  padding: 10px 18px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.detect-btn:active {
  transform: scale(0.95);
}

.detect-btn.primary {
  background: var(--accent);
  border-color: transparent;
}

/* 下载应用 */
.download-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 18px;
  text-align: center;
}

.download-icon {
  font-size: clamp(56px, 14vw, 96px);
  filter: drop-shadow(0 8px 24px rgba(79, 118, 227, 0.4));
}

.download-title {
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 600;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.download-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  opacity: 0.85;
  line-height: 1.5;
  min-height: 66px;
  justify-content: center;
  word-break: break-all;
}

.download-info.error {
  color: #ff6b6b;
  opacity: 1;
}

.download-btn {
  padding: 14px 44px;
  border-radius: 24px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 10px 30px rgba(79, 118, 227, 0.35);
  transition: transform 0.15s, opacity 0.2s;
  user-select: none;
}

.download-btn:active {
  transform: scale(0.94);
  opacity: 0.85;
}

/* 通用 */
.hidden {
  display: none !important;
}

.loading-ring {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.fade-in {
  animation: fadeIn 0.35s ease forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
}

/* 登录覆盖层 */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.auth-box {
  width: min(320px, 84vw);
  padding: 28px 24px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-box h2 {
  margin: 0 0 6px;
  font-size: 22px;
  text-align: center;
  font-weight: 600;
}

.auth-error {
  min-height: 18px;
  color: #ff6b6b;
  font-size: 13px;
  text-align: center;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.auth-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.auth-buttons {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.auth-btn {
  flex: 1;
  padding: 12px 0;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.auth-btn:active {
  transform: scale(0.96);
}

.auth-btn.primary {
  background: var(--accent);
  border-color: transparent;
}
