/* ===== 主题变量 ===== */
:root {
  --color-primary: #6c5ce7;
  --color-primary-dark: #5641e0;
  --color-primary-light: #a29bfe;
  --color-accent: #fd79a8;
  --color-success: #00b894;
  --color-warning: #fdcb6e;
  --color-danger: #ff7675;

  --color-bg: #f5f3ff;
  --color-bg-elevated: #ffffff;
  --color-bg-muted: #ece8ff;
  --color-text: #2d3436;
  --color-text-muted: #636e72;
  --color-text-on-primary: #ffffff;
  --color-border: #e0d8ff;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 3px rgba(108, 92, 231, 0.08);
  --shadow-md: 0 4px 12px rgba(108, 92, 231, 0.12);
  --shadow-lg: 0 8px 24px rgba(108, 92, 231, 0.18);

  --header-h: 56px;
  --fab-size: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1625;
    --color-bg-elevated: #251f35;
    --color-bg-muted: #2a2440;
    --color-text: #ece8ff;
    --color-text-muted: #a29bfe;
    --color-border: #3a3358;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

/* ===== 重置 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: 16px; }
a { color: var(--color-primary); text-decoration: none; }
svg { display: block; }

/* ===== 顶部导航 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(8px);
}

.app-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
  flex: 1;
  text-align: center;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background .15s, color .15s;
}
.icon-btn:active { background: var(--color-bg-muted); color: var(--color-primary); }
.icon-btn[hidden] { display: none !important; }

/* ===== 主内容区 ===== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.loading, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  text-align: center;
  color: var(--color-text-muted);
  flex: 1;
}

.empty-state__icon { font-size: 48px; margin-bottom: 12px; opacity: .6; }
.empty-state__title { font-size: 16px; font-weight: 600; color: var(--color-text); margin-bottom: 8px; }
.empty-state__desc { font-size: 14px; line-height: 1.5; max-width: 280px; }

/* ===== 浮动按钮 ===== */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform .15s, background .15s;
  z-index: 50;
}
.fab:active { transform: scale(.92); background: var(--color-primary-dark); }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
}
.toast--error { background: var(--color-danger); color: #fff; }
.toast--success { background: var(--color-success); color: #fff; }
.toast--out { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ===== 模态层 ===== */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}
.modal-root > * { pointer-events: auto; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in .2s ease;
}
@keyframes modal-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

/* ===== 工具类 ===== */
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--color-text-muted); }
.center { text-align: center; }
