/* ============================================================
 * ADB Keycode Reference — 样式表
 * 主题：Light / Dark / Auto（跟随系统）
 * 使用 CSS 变量管理颜色，data-theme 属性驱动切换
 * ============================================================ */

/* ---------- 1. 主题变量 ---------- */
:root {
  /* 浅色主题（默认） */
  --bg:            #f5f6f8;
  --bg-elevated:   #ffffff;
  --bg-subtle:     #eef0f3;
  --bg-hover:      #e6e9ee;
  --bg-active:     #dde1e8;

  --text:          #1a1d21;
  --text-secondary:#5a6169;
  --text-muted:    #8b9199;

  --border:        #dfe3e8;
  --border-strong: #c8cdd4;

  --accent:        #0a84ff;
  --accent-hover:  #0070e0;
  --accent-soft:   rgba(10, 132, 255, 0.10);
  --accent-text:   #ffffff;

  --success:       #30a46c;
  --success-soft:  rgba(48, 163, 108, 0.12);

  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md:     0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg:     0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.05);

  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     14px;
  --radius-full:   999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas,
               "Liberation Mono", monospace;

  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* 深色主题 */
[data-theme="dark"] {
  --bg:            #0f1115;
  --bg-elevated:   #181b21;
  --bg-subtle:     #1f232a;
  --bg-hover:      #262b33;
  --bg-active:     #2d333c;

  --text:          #e8eaed;
  --text-secondary:#a8aeb8;
  --text-muted:    #6b7280;

  --border:        #2a2f38;
  --border-strong: #3a4049;

  --accent:        #409cff;
  --accent-hover:  #5aabff;
  --accent-soft:   rgba(64, 156, 255, 0.14);
  --accent-text:   #ffffff;

  --success:       #3dd68c;
  --success-soft:  rgba(61, 214, 140, 0.14);

  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md:     0 2px 8px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-lg:     0 8px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.30);
}

/* Auto 模式：跟随系统 */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg:            #0f1115;
    --bg-elevated:   #181b21;
    --bg-subtle:     #1f232a;
    --bg-hover:      #262b33;
    --bg-active:     #2d333c;

    --text:          #e8eaed;
    --text-secondary:#a8aeb8;
    --text-muted:    #6b7280;

    --border:        #2a2f38;
    --border-strong: #3a4049;

    --accent:        #409cff;
    --accent-hover:  #5aabff;
    --accent-soft:   rgba(64, 156, 255, 0.14);
    --accent-text:   #ffffff;

    --success:       #3dd68c;
    --success-soft:  rgba(61, 214, 140, 0.14);

    --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-md:     0 2px 8px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-lg:     0 8px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.30);
  }
}

/* ---------- 2. 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input { font-family: inherit; font-size: inherit; }

/* 焦点可见性（无障碍） */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- 3. 工具栏 ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.toolbar__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.toolbar__logo {
  width: 24px;
  height: 24px;
  fill: var(--accent);
  flex-shrink: 0;
}

.toolbar__title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar__controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ---------- 4. 分段控件 ---------- */
.segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
}

.segmented__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  user-select: none;
}

.segmented__btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  display: block;
}

.segmented__btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.segmented__btn[aria-pressed="true"] {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- 5. 搜索栏 ---------- */
.searchbar {
  position: sticky;
  top: 57px;
  z-index: 90;
  background: var(--bg);
  padding: 16px 20px 8px;
  transition: background-color var(--transition);
}

.searchbar__inner {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}

.searchbar__icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  fill: var(--text-muted);
  pointer-events: none;
}

.searchbar__input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  transition: all var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.searchbar__input::placeholder {
  color: var(--text-muted);
}

.searchbar__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.searchbar__input::-webkit-search-cancel-button { display: none; }

.searchbar__clear {
  position: absolute;
  right: 10px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.searchbar__clear svg { width: 16px; height: 16px; fill: currentColor; }
.searchbar__clear:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- 6. 主体 ---------- */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 20px 40px;
}

.content { display: flex; flex-direction: column; gap: 32px; }

/* 分类区块 */
.category { scroll-margin-top: 120px; }

.category__header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.category__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.category__count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* 卡片网格 */
.category__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

/* 单个 Keycode 卡片 */
.keycode {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keycode:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.keycode__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 可复制的代码片段按钮 */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid transparent;
  background: var(--bg-subtle);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copy-btn:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

.copy-btn:active { transform: scale(0.97); }

.copy-btn--value {
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  justify-content: center;
  flex-shrink: 0;
}

.copy-btn--name {
  font-size: 12px;
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  text-align: left;
}

.copy-btn__icon {
  width: 12px;
  height: 12px;
  fill: currentColor;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.copy-btn:hover .copy-btn__icon { opacity: 0.6; }

/* 复制成功短暂反馈 */
.copy-btn.is-copied {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
  color: var(--success);
}

.keycode__desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* 空状态 */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- 7. 页脚 ---------- */
.footer {
  text-align: center;
  padding: 24px 20px 32px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer strong {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.footer__hint { font-size: 12px; opacity: 0.8; }

/* ---------- 8. Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg-elevated);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: calc(100vw - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1000;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 9. 响应式 ---------- */
@media (max-width: 640px) {
  .toolbar__inner {
    padding: 10px 16px;
    gap: 10px;
  }

  .toolbar__title { font-size: 15px; }

  .toolbar__controls {
    width: 100%;
    justify-content: space-between;
  }

  .searchbar {
    top: 0;
    padding: 12px 16px 6px;
  }

  .main { padding: 8px 16px 32px; }

  .category__grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .keycode {
    padding: 11px 12px;
  }

  .toast { bottom: 20px; font-size: 13px; }
}

/* 小屏工具栏按钮组垂直排列（按需求） */
@media (max-width: 380px) {
  .toolbar__controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .segmented {
    width: 100%;
    justify-content: space-between;
  }

  .segmented__btn { flex: 1; }
}

/* ---------- 10. 减少动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 11. 打印样式 ---------- */
@media print {
  .toolbar, .searchbar, .footer, .toast { display: none; }
  body { background: #fff; color: #000; }
  .keycode { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
