/* Hallmark · modern-minimal · built: the project · redesign: polish · navigation directory */
/* ============================================================
   Joker X 中转站 · 样式表
   方向：纸面工作台。浅暖纸底 + 细网格 + 标签槽图标卡片。
   强调色：苹果蓝（浅色 #0071e3 / 深色 #0a84ff；文字用 accent-ink）。
   节奏：4px 网格；计数 / 时钟 / 域名用等宽字体。
   圆角：8 / 10 / 12，卡片不再使用大圆角与浮空阴影。
   ============================================================ */

/* 品牌艺术衬线：Playfair Display（本地文件，wght 变量轴；斜体 600 用于字标） */
@font-face {
  font-family: 'Playfair Display';
  src: url('./assets/fonts/playfair-display.woff2') format('woff2');
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Playfair Display';
  src: url('./assets/fonts/playfair-display-italic.woff2') format('woff2');
  font-weight: 400 900;
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* 纸面底色与网格 */
  --bg: #f4f4f1;
  --bg-grid: rgba(55, 68, 95, 0.025);

  /* 卡片与文字 */
  --card: #ffffff;
  --card-hover: #fbfbfa;
  --ink: #1d1d1f;
  --ink-2: #5f6368;
  --ink-3: #66666c;

  --card-border: #e3e5ea;
  --card-border-hover: #cfd3da;
  --input-border: #7c8590;
  --selection-ink: #fff;
  --icon-bg: #f2f3f5;
  --line: #e3e5ea;

  /* 唯一强调色 */
  --accent: var(--ui-accent);
  --accent-ink: #0062c4;
  --focus-ring: var(--ui-focus-ring);

  /* 工作台圆角 */
  --r-1: 8px;
  --r-2: 10px;
  --r-3: 12px;

  --font: var(--ui-font-sans);
  --font-en: 'Playfair Display', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0f1114;
  --bg-grid: rgba(255, 255, 255, 0.023);

  --card: #181a1e;
  --card-hover: #1d2025;
  --ink: #f2f2f4;
  --ink-2: #b4b4bb;
  --ink-3: #8e8e96;

  --card-border: rgba(255, 255, 255, 0.10);
  --card-border-hover: rgba(255, 255, 255, 0.18);
  --input-border: #858d98;
  --selection-ink: #0b0d14;
  --icon-bg: #202226;
  --line: rgba(255, 255, 255, 0.10);

  --accent: var(--ui-accent);
  --accent-ink: #409cff;
  --focus-ring: var(--ui-focus-ring);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* hidden 属性必须生效：若有元素自带 display（如 .weather 的 inline-flex），
   会覆盖浏览器对 [hidden] 的默认隐藏；这条统一兜底。 */
[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, var(--bg-grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--bg-grid) 1px, transparent 1px);
  background-size: 64px 64px;
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--accent);
  color: var(--selection-ink);
}

html[data-theme="dark"] ::selection {
  background: var(--accent-ink);
  color: var(--selection-ink);
}

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  overflow-x: clip;
}

/* ---------- 主容器 ---------- */
.app {
  position: relative;
  z-index: 2;
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 28px 56px;
}

/* ---------- 顶栏：左字标，右侧状态与工具 ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-en);
  font-style: italic;
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.02em;
  line-height: 1;
}

.brand-sub {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
}

.clock {
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.greeting {
  color: var(--ink-3);
  font-size: 12px;
}

/* 天气小组件（open-meteo）：线描图标 + 温度，可选城市名 */
.weather {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-2);
}

.weather-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
}

.weather-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.weather-temp {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.weather-city {
  margin-left: 2px;
  color: var(--ink-3);
  font-size: 11px;
}

/* 主题 / 视图切换：无边框、无阴影的小工具按钮 */
.theme-toggle,
.view-toggle {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-1);
  color: var(--ink-2);
  cursor: pointer;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
}

@media (max-width: 600px) {
  .theme-toggle, .view-toggle {
    min-width: 44px;
    min-height: 44px;
  }
}

.theme-toggle:active,
.view-toggle:active {
  transform: scale(0.96);
}

@media (hover: hover) {
  .theme-toggle:hover,
  .view-toggle:hover {
    color: var(--ink);
    background: var(--icon-bg);
    border-color: var(--card-border);
  }
}

.theme-icon {
  width: 16px;
  height: 16px;
}

.theme-icon--sun { display: block; }
.theme-icon--moon { display: none; }

html[data-theme="dark"] .theme-icon--sun { display: none; }
html[data-theme="dark"] .theme-icon--moon { display: block; }

.view-icon {
  width: 16px;
  height: 16px;
}

.view-icon--cards { display: block; }
.view-icon--grid { display: none; }

html[data-view="icons"] .view-icon--cards { display: none; }
html[data-view="icons"] .view-icon--grid { display: block; }

/* ---------- 搜索条 ---------- */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 12px;
  pointer-events: none;
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--ink-3);
}

.search-input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 76px 0 36px;
  border: 1px solid var(--input-border);
  border-radius: var(--r-1);
  background: var(--card);
  font: inherit;
  color: var(--ink);
}

.search-input:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

.search-input::placeholder {
  color: var(--ink-3);
}

.search-clear,
.sort-toggle {
  flex: none;
  height: 40px;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.search-clear {
  position: absolute;
  right: 32px;
  padding: 0 8px;
}

.sort-toggle {
  min-width: 72px;
  height: 48px;
  border: 1px solid var(--card-border);
  background: var(--card);
  padding: 0 12px;
}

.search-clear:hover,
.sort-toggle:hover {
  color: var(--accent-ink);
  background: var(--icon-bg);
}

.sort-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--icon-bg);
}

.search-kbd {
  position: absolute;
  right: 12px;
  min-width: 18px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--icon-bg);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

@media (max-width: 640px), (hover: none), (pointer: coarse) {
  .search-kbd {
    display: none;
  }

  .search-clear {
    right: 4px;
  }

  .search-input {
    padding-right: 52px;
  }
}

/* ---------- 目录分区 ---------- */
.sections {
  margin-top: 24px;
}

.group + .group {
  margin-top: 32px;
}

.group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.group-name {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
}

.group-count {
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* 同组入口共享一个边框。站内工具仍保留独立图标卡片。 */
.card-grid:has(.card-host--external) {
  gap: 0;
  border: 1px solid var(--card-border);
  border-radius: var(--r-3);
  background: var(--card);
  color: var(--ink);
}

.card-grid:has(.card-host--external) .card {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform: none;
}

.card-grid:has(.card-host--external) > li {
  box-shadow: inset 0 -1px var(--line);
}

.card-grid:has(.card-host--external) > li:last-child {
  box-shadow: none;
}

.card-grid:has(.card-host--external) a:focus-visible,
.card-grid:has(.card-host--external) .kbd-active {
  outline-offset: -3px;
}

@media (hover: hover) {
  .card-grid:has(.card-host--external) .card:hover {
    background: var(--card-hover);
  }
}

@media (min-width: 641px) {
  .card-grid:has(.card-host--external) > li:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .card-grid:has(.card-host--external) > li:nth-last-child(2):nth-child(odd) {
    box-shadow: none;
  }
}

/* ---------- 卡片 ---------- */
.card-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.card-grid > li {
  display: flex;
}

.card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 16px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-border);
  border-radius: var(--r-3);
  box-shadow: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
}

@media (hover: hover) {
  .card:hover {
    background: var(--card-hover);
    border-color: var(--card-border-hover);
  }
}

.card:active {
  transform: scale(0.98);
}

/* 图标位：40px 标签槽，品牌图标 / favicon 按原比例放入 */
.card-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 10px;
  background: var(--icon-bg);
  color: var(--ink-3);
  font-size: 16px;
  font-weight: 600;
}

.card-icon img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: contain;
}

/* 深色主题下反转单色图标（如 GitHub 黑标 → 白标） */
html[data-theme="dark"] .card-icon img.mark-invert {
  filter: invert(1);
}

.card-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-desc {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-host {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 图标视图 ---------- */
.icon-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-2);
  box-shadow: none;
  min-width: 0;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
}

@media (hover: hover) {
  .icon-item:hover {
    background: var(--card-hover);
    border-color: var(--card-border-hover);
  }
}

.icon-item:active {
  transform: scale(0.98);
}

.icon-item .card-icon {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  background: transparent;
  border-radius: var(--r-2);
  font-size: 18px;
}

.icon-name {
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink);
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 手动置顶 ---------- */
.card-grid > li,
.icon-grid > li {
  position: relative;
}

.pin-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: var(--card);
  color: var(--ink-3);
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.15s var(--ease), color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.pin-btn svg {
  width: 14px;
  height: 14px;
}

.card-grid > li:hover .pin-btn,
.card-grid > li:focus-within .pin-btn,
.icon-grid > li:hover .pin-btn,
.icon-grid > li:focus-within .pin-btn,
.pin-btn.is-pinned {
  opacity: 1;
}

.pin-btn:hover {
  color: var(--accent-ink);
  background: var(--icon-bg);
}

.pin-btn.is-pinned {
  color: var(--accent-ink);
}

.icon-grid .pin-btn {
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
}

.icon-grid .pin-btn svg {
  width: 12px;
  height: 12px;
}

.card-grid .card-body {
  padding-right: 16px;
}

@media (hover: none) {
  .pin-btn {
    opacity: 0.8;
  }
}

@media (pointer: coarse) {
  .theme-toggle,
  .view-toggle,
  .sort-toggle,
  .search-clear {
    min-height: 44px;
  }

  .search-clear {
    min-width: 44px;
  }

  .theme-toggle,
  .view-toggle {
    min-width: 44px;
  }

  .pin-btn,
  .icon-grid .pin-btn {
    top: 4px;
    right: 4px;
    width: 44px;
    height: 44px;
    opacity: 1;
  }

  .pin-btn svg,
  .icon-grid .pin-btn svg {
    width: 16px;
    height: 16px;
  }

  .card-grid .card-body {
    padding-right: 32px;
  }

  .icon-grid .icon-item {
    padding-top: 40px;
  }
}

/* 置顶分区标题 */
.group--pinned .group-name {
  color: var(--accent-ink);
}

.group-pin {
  width: 12px;
  height: 12px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* 搜索键盘导航的选中态 */
a.kbd-active {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- 空状态 ---------- */
.empty {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 40px;
}

.empty-text {
  color: var(--ink-2);
  font-size: 13px;
}

.empty-clear {
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--r-1);
  background: var(--card);
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.empty-clear:hover {
  border-color: var(--card-border-hover);
  color: var(--ink);
}

.load-error {
  color: var(--ink-2);
  font-size: 14px;
}

/* ---------- 页脚 ---------- */
.footer {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12px;
}

.footer a:hover {
  color: var(--accent-ink);
}

/* ---------- 手机端适配 ---------- */
@media (max-width: 640px) {
  .app {
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  }

  .topbar {
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
  }

  .brand {
    flex-direction: column;
    gap: 2px;
  }

  .brand-title {
    font-size: 26px;
  }

  .brand-sub {
    padding-left: 0;
    border-left: 0;
    font-size: 11px;
  }

  .toolbar {
    width: auto;
    gap: 4px;
  }

  .status {
    gap: 8px;
  }

  .greeting {
    display: none;
  }

  .weather {
    display: none;
  }

  .search-wrap {
    margin-top: 12px;
  }

  .search-input {
    font-size: 16px; /* 避免 iOS 聚焦时自动放大页面 */
  }

  .sections {
    margin-top: 24px;
  }

  .group + .group {
    margin-top: 24px;
  }

  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .card {
    padding: 12px;
  }

  .card-icon {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
    padding: 4px;
    font-size: 15px;
  }

  .card-host {
    display: none;
  }

  .card-host--external {
    display: block;
    font-size: 11px;
  }

  .icon-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }

  .icon-item {
    padding: 12px 8px;
  }

  .icon-item .card-icon {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
  }



  .card-name {
    font-size: 14px;
  }

  .card-desc {
    font-size: 12.5px;
  }

  .footer {
    margin-top: 32px;
  }
}

/* ---------- 动效收敛 ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
