/* ============================================================
   hub.css —— 首页布局与组件结构
   设计令牌（颜色/字体/圆角/阴影）统一由 assets/css/theme.css 提供；
   多巴胺主题的质感增强见 theme-maximal.css。
   布局：顶栏 → 品牌 → 药丸搜索 → 分类网格（一级）→ 工具列表（二级）
   两套交互：clean 主题「下拉展开」/ dopamine 主题「炸开散列」
   ============================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 18px 56px;
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 0 4px;
}
.appbar-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  color: var(--text-sub);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: background-color .15s, color .15s, transform .15s;
}
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 22px; height: 22px; display: block; }

.icon-btn .dot {
  position: absolute; top: 9px; right: 10px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- 品牌 ---------- */
.brand { text-align: center; padding: 16px 0 4px; }
.brand-logo { display: flex; align-items: center; justify-content: center; min-height: 56px; }

.brand-mark {
  width: 54px; height: 54px; border-radius: 15px;
  background: linear-gradient(135deg, var(--primary), var(--a5));
  color: #fff; font-weight: 700; font-size: 20px; letter-spacing: .5px;
  display: var(--hero-logo-display);
  align-items: center; justify-content: center;
}
.brand-illo {
  width: 88px; height: 88px; object-fit: contain;
  display: var(--hero-illo-display);
}

.brand-name { margin: 10px 0 0; font-size: 30px; font-weight: 800; letter-spacing: .01em; }
.brand-sub { margin: 6px 0 0; font-size: 12.5px; color: var(--text-muted); }

/* ---------- 搜索 ---------- */
.searchbar { position: relative; margin-top: 18px; }

.search {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  padding: 14px 56px 14px 20px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search::placeholder { color: var(--text-muted); }
.search::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-ico {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-sub); pointer-events: none;
}
.search-ico svg { width: 20px; height: 20px; }

/* ---------- 一级：分类网格 ---------- */
.cat-grid {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 18px 8px;
}

.cat-tile {
  border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 6px 2px; border-radius: 16px;
  font-family: inherit; color: var(--text-sub);
  transition: transform .16s;
}
.cat-tile:hover { transform: translateY(-2px); }
.cat-tile:active { transform: scale(.95); }

.cat-tile .cat-ico {
  width: clamp(52px, 15vw, 62px); height: clamp(52px, 15vw, 62px);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px; line-height: 1;
  background: var(--cat-c, var(--primary));
  color: #fff;
  box-shadow: 0 8px 18px -8px var(--cat-c, var(--primary));
  transition: box-shadow .16s;
}
.cat-tile .cat-name { font-size: 12px; font-weight: 600; text-align: center; }

.cat-tile.is-empty { opacity: .5; }
.cat-tile.is-empty .cat-ico { filter: grayscale(.4); }
.cat-tile.is-empty .cat-name::after { content: ''; }

.cat-tile.is-active { color: var(--primary); }
.cat-tile.is-active .cat-ico {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--cat-c, var(--primary));
}

/* ---------- 二级：分类工具 / 搜索结果 ---------- */
.cat-tools { margin-top: 26px; display: none; }
.cat-tools.is-open { display: block; animation: drop-in .28s ease both; }

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cat-tools-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cat-tools-title { margin: 0; font-size: 16px; font-weight: 700; }
.cat-tools-title .muted { margin-left: 6px; font-size: 12.5px; font-weight: 500; color: var(--text-muted); }

.back-btn {
  width: 34px; height: 34px; flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel); color: var(--text-sub);
  display: grid; place-items: center; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.back-btn:hover { border-color: var(--primary); color: var(--primary); }
.back-btn svg { width: 18px; height: 18px; }

/* ---------- 工具卡片 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: all .18s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-hover);
}

.card-head { display: flex; align-items: center; gap: 11px; }

.card-icon, .card-illo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--primary-soft);
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.card-illo { background: transparent; object-fit: contain; }

.card-title { font-size: 15px; font-weight: 600; margin: 0; }
.card-ver { font-size: 11px; color: var(--text-muted); }

.card-desc { margin: 11px 0 0; font-size: 13px; color: var(--text-sub); flex: 1 1 auto; }

.card-feats { margin: 11px 0 0; padding-left: 16px; font-size: 12px; color: var(--text-muted); }
.card-feats li { margin-bottom: 2px; }

.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; color: var(--text-sub); background: var(--bg); border-radius: 5px; padding: 2px 7px; }
.card-go { font-size: 12px; color: var(--primary); font-weight: 600; white-space: nowrap; }

/* ---------- 空状态 / 页脚 ---------- */
.empty { text-align: center; color: var(--text-muted); padding: 34px 0; }
.empty[hidden] { display: none; }

.foot {
  margin-top: 40px; padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-muted);
}
.foot p { margin: 4px 0; }
.foot code {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px; font-size: 11px;
}
.foot a { color: var(--primary); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* ---------- 遮罩 ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(9, 12, 20, .45);
  opacity: 0; transition: opacity .2s;
}
.scrim.show { opacity: 1; }
.scrim[hidden] { display: none; }

/* ---------- 汉堡抽屉 ---------- */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
  width: min(80vw, 300px);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-102%);
  transition: transform .24s ease;
  display: flex; flex-direction: column;
}
.drawer.show { transform: translateX(0); }
.drawer[hidden] { display: none; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-title { font-weight: 700; font-size: 15px; }

.drawer-nav { display: flex; flex-direction: column; gap: 2px; }
.drawer-nav a, .drawer-nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 12px;
  border: 0; background: transparent;
  color: var(--text-sub); font-family: inherit; font-size: 14px;
  text-decoration: none; text-align: left; cursor: pointer;
  transition: background-color .15s, color .15s;
}
.drawer-nav a:hover, .drawer-nav button:hover { background: var(--bg); color: var(--text); }

/* ---------- 设置面板 ---------- */
.settings {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(9, 12, 20, .45);
}
.settings[hidden] { display: none; }

.settings-card {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card, 16px);
  box-shadow: var(--shadow-hover);
  padding: 18px;
  animation: pop-in .22s ease both;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.settings-head h2 { margin: 0; font-size: 16px; font-weight: 700; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 14px 0;
  border-top: 1px solid var(--line);
}
.setting-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.setting-label span { font-size: 13.5px; font-weight: 600; }
.setting-label small { font-size: 11.5px; color: var(--text-muted); line-height: 1.45; }

.seg-theme { display: inline-flex; flex: 0 0 auto; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg-theme button {
  border: 0; background: transparent; color: var(--text-sub);
  padding: 7px 14px; border-radius: 999px;
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background-color .15s, color .15s;
}
.seg-theme button[aria-checked="true"] { background: var(--primary); color: #fff; }

.setting-link { flex: 0 0 auto; color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; }
.setting-link:hover { text-decoration: underline; }

.btn-danger {
  flex: 0 0 auto;
  border: 1px solid var(--danger); background: transparent; color: var(--danger);
  border-radius: 10px; padding: 8px 14px;
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background-color .15s, color .15s;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ---------- 光束扇形炸开（多巴胺主题） ----------
   点击分类 → 分类像探照灯一样射出一道扇形光束，
   该分类下的工具沿光束范围扇形展开，每个工具还有一条光射线连回光源。 */
.burst-layer {
  position: fixed; inset: 0; z-index: 85;
  background: rgba(13, 13, 26, .38);
  animation: fade-in .18s ease both;
}
.burst-layer[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.burst-beam, .burst-core, .burst-ray { pointer-events: none; }

/* 扇形光束：以分类磁贴为圆心，朝 --a0 方向张开 --spread 度 */
.burst-beam {
  position: fixed; left: 0; top: 0;
  width: calc(var(--bl, 240px) * 2);
  height: calc(var(--bl, 240px) * 2);
  margin-left: calc(var(--bl, 240px) * -1);
  margin-top: calc(var(--bl, 240px) * -1);
  border-radius: 50%;
  background: conic-gradient(from var(--a0, 150deg),
    var(--cat-c, var(--primary)) 0deg,
    var(--cat-c, var(--primary)) calc(var(--spread, 120deg) * .62),
    var(--cat-c, var(--primary)) var(--spread, 120deg),
    transparent var(--spread, 120deg));
  -webkit-mask-image: radial-gradient(circle at 50% 50%,
    transparent 0 4%, #000 13%, rgba(0, 0, 0, .78) 44%,
    rgba(0, 0, 0, .3) 68%, transparent 84%);
  mask-image: radial-gradient(circle at 50% 50%,
    transparent 0 4%, #000 13%, rgba(0, 0, 0, .78) 44%,
    rgba(0, 0, 0, .3) 68%, transparent 84%);
  transform-origin: 50% 50%;
  opacity: .55;
  animation: beam-open .5s cubic-bezier(.14, .82, .28, 1) both;
}
@keyframes beam-open {
  from { transform: scale(.28) rotate(calc(var(--spread, 120deg) * -.12)); opacity: 0; }
  60%  { opacity: .78; }
  to   { transform: scale(1) rotate(0deg); opacity: .55; }
}

/* 光源：分类磁贴位置的一颗亮点 + 一圈扩散光环 */
.burst-core {
  position: fixed; left: 0; top: 0;
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%,
    #fff 0%, var(--cat-c, var(--primary)) 46%, transparent 74%);
  transform: translate(-50%, -50%);
  animation: core-pop .46s cubic-bezier(.2, .9, .3, 1.4) both;
}
.burst-core::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 100%; height: 100%; border-radius: 50%;
  border: 2px solid var(--cat-c, var(--primary));
  transform: translate(-50%, -50%) scale(1);
  animation: core-ring .85s ease-out .08s both;
}
@keyframes core-pop { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes core-ring {
  from { transform: translate(-50%, -50%) scale(.6); opacity: .9; }
  to   { transform: translate(-50%, -50%) scale(4.6); opacity: 0; }
}

/* 光射线：从光源连到每个工具气泡 */
.burst-ray {
  position: fixed; left: 0; top: 0; z-index: 1;
  height: 2px; width: var(--len, 120px);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--cat-c, var(--primary)) 0%, var(--cat-c, var(--primary)) 38%, transparent 100%);
  opacity: .7;
  animation: ray-out .46s cubic-bezier(.2, .8, .3, 1) both;
  animation-delay: var(--delay, 0ms);
}
@keyframes ray-out {
  from { transform: translate(var(--rx, 0px), var(--ry, 0px)) rotate(calc(var(--a, 180deg) - 90deg)) scaleX(0); opacity: 0; }
  to   { transform: translate(var(--rx, 0px), var(--ry, 0px)) rotate(calc(var(--a, 180deg) - 90deg)) scaleX(1); opacity: .7; }
}

/* 工具气泡：落在光束的扇形范围内 */
.burst-bubble {
  position: fixed; left: 0; top: 0;
  width: 84px; height: 84px;
  border-radius: 50%; border: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel); color: var(--text);
  box-shadow: var(--shadow-hover);
  cursor: pointer; font-family: inherit;
  transform: translate(-50%, -50%);
  animation: burst-out .52s cubic-bezier(.2, .9, .3, 1.3) both;
  animation-delay: var(--delay, 0ms);
  text-decoration: none;
  z-index: 2;
}
.burst-bubble .bb-ico { font-size: 26px; line-height: 1; }
.burst-bubble .bb-name { font-size: 10.5px; font-weight: 600; text-align: center; padding: 0 6px; line-height: 1.25; }

.burst-bubble.is-empty { background: var(--bg); border: 1px dashed var(--line-strong); color: var(--text-muted); box-shadow: none; }

@keyframes burst-out {
  from { transform: translate(-50%, -50%) scale(.2); opacity: 0; }
  to   { transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .burst-beam, .burst-core, .burst-core::after, .burst-ray, .burst-bubble { animation-duration: .01ms; }
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(10px);
  z-index: 120;
  max-width: 86vw;
  background: var(--text); color: var(--bg);
  font-size: 13px; padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow-hover);
  opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }
.toast[hidden] { display: none; }

/* ---------------- 平板 / 窄笔记本 ---------------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ---------------- 手机 ---------------- */
@media (max-width: 640px) {
  .app {
    padding: 0 14px calc(40px + env(safe-area-inset-bottom, 0px));
  }
  .appbar { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .brand-name { font-size: 27px; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 16px 6px; }
  .cat-tile .cat-ico { font-size: 24px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 16px; }
  .foot { margin-top: 28px; }

  /* 设置面板在窄屏改为贴底卡片，更好点 */
  .settings { align-items: flex-end; padding: 0; }
  .settings-card {
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    animation: sheet-up .26s ease both;
  }
  @keyframes sheet-up {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: none; }
  }
}

/* 超窄屏 */
@media (max-width: 360px) {
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
  .brand-name { font-size: 24px; }
  .card { padding: 14px; }
}
