/* ==========================================================================
   移动端与响应式样式适配 (Mobile Responsive Stylesheet)
   ========================================================================== */

/* 全局移动端基底 */
html, body {
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}

/* 键盘/触摸聚焦保持可见轮廓 */
.button:focus-visible,
.icon-button:focus-visible,
.sort-button:focus-visible,
.nav-link:focus-visible,
.source-tab:focus-visible,
.source-card:focus-visible,
.pick-card:focus-visible,
.manual-editor summary:focus-visible,
#publish-back:focus-visible,
.source-button:focus-visible,
.detail-tab:focus-visible,
.install-method-tab:focus-visible,
.hero-install-tab:focus-visible,
.hero-copy-button:focus-visible,
.page-button:focus-visible,
.auth-button:focus-visible,
.auth-user:focus-visible,
.files-toggle:focus-visible,
.auth-dropdown button:focus-visible,
.text-button:focus-visible,
.filter-option:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 针对小屏与手机设备 (≤ 768px) */
@media (max-width: 768px) {
  /* 表单输入字号优化：防止 iOS Safari 聚焦时强制缩放页面 */
  input[type="text"],
  input[type="search"],
  input[type="url"],
  input[type="email"],
  select,
  textarea,
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
  }
  /* 新增标签弹窗输入：基础规则带类选择器，特异性更高，需同特异性覆盖 */
  .tag-create-dialog input[type="text"] {
    font-size: 16px;
  }

  /* 标签下拉：窄屏放宽宽度与高度，触控目标加大 */
  .tag-picker {
    max-width: calc(100vw - 48px);
    max-height: 40vh;
  }
  .tag-picker-item {
    padding: 10px 12px;
    font-size: 13px;
  }

  /* 主按钮统一 44px 最小触控高度 */
  .button {
    min-height: 44px;
  }

  /* --------------------------------------------------------------------------
     顶部固定 Header (Topbar)
     -------------------------------------------------------------------------- */
  .topbar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    min-height: auto;
    padding: 10px 14px 8px;
    gap: 8px 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(220, 223, 234, 0.85);
  }

  .topbar .brand {
    flex: 0 1 auto;
    min-width: 0;
    gap: 8px;
  }

  .topbar .brand-logo svg {
    width: 26px;
    height: 26px;
  }

  .topbar .brand-copy {
    min-width: 0;
  }

  .topbar .brand-copy strong {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar .brand-copy small {
    display: none;
  }

  .topbar-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .auth-button {
    min-height: 44px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 8px;
  }

  .auth-user {
    min-height: 44px;
    padding: 4px;
    font-size: 13px;
    border-radius: 50%;
  }

  .auth-avatar {
    width: 22px;
    height: 22px;
  }

  .auth-dropdown button {
    min-height: 44px;
  }

  /* 移动端保留「Skill 市场」与「安装榜单」导航并整行排布 */
  .topbar nav {
    display: flex !important;
    order: 3;
    width: 100%;
    gap: 20px;
    padding-top: 6px;
    margin-top: 2px;
    border-top: 1px solid rgba(220, 223, 234, 0.6);
    justify-content: flex-start;
  }

  .topbar nav .nav-link {
    padding: 4px 0 6px;
    font-size: 14px;
    font-weight: 600;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* --------------------------------------------------------------------------
     主容器间距
     -------------------------------------------------------------------------- */
  #market-view {
    padding: 0 12px 48px;
    max-width: 100%;
  }

  #leaderboard-view {
    padding: 0 12px 48px;
    max-width: 100%;
  }

  /* --------------------------------------------------------------------------
     Hero 区（market-intro）
     -------------------------------------------------------------------------- */
  .market-intro {
    margin: 0 -12px;
    padding: 38px 16px 24px;
  }

  .intro-copy {
    font-size: 13px;
  }

  .hero-install {
    margin-top: 26px;
    padding: 0 12px 12px;
  }

  .hero-install-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 0;
    padding: 10px 0 0;
  }

  .hero-install-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .hero-install-tab {
    padding: 0 11px;
    white-space: nowrap;
    min-height: 44px;
  }

  .hero-command {
    align-items: flex-start;
  }

  .hero-command code {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .hero-copy-button {
    width: 44px;
    height: 44px;
  }

  /* --------------------------------------------------------------------------
     搜索栏与操作按钮 (Search Band & Actions)
     -------------------------------------------------------------------------- */
  .search-band {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    border-radius: 12px 12px 0 0;
  }

  .search-field {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-sizing: border-box;
  }

  .search-field input {
    font-size: 16px;
    width: 100%;
  }

  .search-field kbd {
    display: none;
  }

  .sort-control {
    width: 100%;
    height: 48px;
    padding: 2px;
    margin: 0;
    border-radius: 8px;
    display: flex;
  }

  .sort-button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    text-align: center;
    font-size: 13px;
    padding: 0 8px;
  }

  .band-actions {
    display: flex;
    width: 100%;
    margin: 0;
    gap: 8px;
  }

  .band-actions .search-publish {
    flex: 1;
    min-height: 44px;
    padding: 0 12px;
    font-size: 13px;
    justify-content: center;
    text-align: center;
    border-radius: 8px;
    margin: 0;
  }

  /* --------------------------------------------------------------------------
     筛选侧栏/底栏 (Filters)
     -------------------------------------------------------------------------- */
  .filters {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    border-radius: 0 0 12px 12px;
    min-height: auto;
    min-width: 0;
  }

  .filter-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
  }

  .filter-heading strong {
    font-size: 13px;
    color: var(--text);
    line-height: normal;
  }

  .filter-heading .text-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 4px;
  }

  .filters fieldset {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
  }

  /* 分类标签横向平滑滚动（只在容器内部滚动，不撑宽文档） */
  .filter-options {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .filter-options::-webkit-scrollbar {
    display: none;
  }

  /* 类目芯片横向滚动；相对定位收住内部绝对定位的隐藏 radio */
  .filter-option {
    position: relative;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0 14px;
    font-size: 12px;
    min-height: 44px;
    border-radius: 999px;
  }

  .author-filter-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    width: 100%;
    padding-top: 4px;
    border-top: 1px solid rgba(220, 223, 234, 0.4);
  }

  .author-filter-group .filter-label {
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--text-muted);
  }

  .author-select {
    flex: 1;
    min-width: 0;
    max-width: 200px;
    min-height: 44px;
    font-size: 16px;
    border-radius: 6px;
    padding: 0 8px;
  }

  /* 标签筛选：与分类一致改为横向滚动条，避免小屏换行撑高侧栏 */
  .tag-filter-group {
    order: 0;
    flex-basis: auto;
    margin: 0;
    padding: 4px 0 0;
    border-top: 1px solid rgba(220, 223, 234, 0.4);
    width: 100%;
    min-width: 0;
  }

  .tag-filter-group .filter-label {
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--text-muted);
  }

  .tag-filter-options {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
    scrollbar-width: none;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-bottom: 2px;
  }

  .tag-filter-options::-webkit-scrollbar {
    display: none;
  }

  .tag-filter-chip {
    flex: 0 0 auto;
    min-height: 36px;
    white-space: nowrap;
  }

  .filter-note {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    margin: 0;
    color: var(--text-faint);
  }

  /* --------------------------------------------------------------------------
     Skill 卡片网格 (Catalog & Skill Grid)
     -------------------------------------------------------------------------- */
  .catalog {
    padding: 0;
    min-width: 0;
  }

  .result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 4px 8px;
    margin: 0;
  }

  #result-summary {
    font-size: 12px;
    color: var(--text-muted);
  }

  .filter-toggle {
    display: none;
  }

  .skill-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .skill-card {
    min-height: auto;
    padding: 14px;
    border-radius: 12px;
  }

  .card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
  }

  .card-top-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }

  /* 卡片图标实际类名是 .skill-icon（.card-icon 选择器不存在于 DOM） */
  .card-top-main .skill-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 16px;
    border-radius: 8px;
  }

  .card-top-main h2,
  .card-title,
  .card-heading h2 {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card-top .card-stats {
    flex: 0 0 auto;
    font-size: 12px;
  }

  .card-description {
    min-height: auto;
    margin: 6px 0 10px;
    font-size: 13px;
    line-height: 1.5;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card-tags {
    min-height: auto;
    margin-bottom: 10px;
    gap: 4px;
  }

  .card-tag {
    padding: 2px 6px;
    font-size: 10px;
  }

  /* 页脚两端各自可收缩，超长作者名/分类名只截断自身，不顶出兄弟节点 */
  .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    gap: 8px;
  }

  .card-author {
    font-size: 11px;
    gap: 6px;
    flex: 0 1 auto;
    min-width: 0;
  }

  .author-avatar {
    width: 18px;
    height: 18px;
  }

  .author-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card-category {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg-soft);
    border-radius: 4px;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* --------------------------------------------------------------------------
     分页控制器 (Pagination)
     -------------------------------------------------------------------------- */
  .pagination {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
    padding: 12px 0;
    gap: 6px;
  }

  .page-button {
    width: 44px;
    height: 44px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* --------------------------------------------------------------------------
     安装榜单 (Leaderboard View)
     -------------------------------------------------------------------------- */
  .board-head {
    padding: 20px 14px 16px;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    border-radius: 12px;
  }

  .board-head h1 {
    font-size: 22px;
  }

  .board-head .intro-copy {
    font-size: 13px;
    margin-top: 4px;
  }

  .board-controls {
    width: 100%;
    align-items: stretch;
  }

  .board-controls .sort-control {
    width: 100%;
    height: 48px;
  }

  .board-controls .sort-button {
    flex: 1;
    min-height: 44px;
    font-size: 13px;
  }

  .board-body {
    padding-top: 16px;
  }

  .podium {
    display: grid;
    grid-template-columns: 1fr 1.12fr 1fr;
    gap: 6px;
    align-items: end;
    margin-bottom: 18px;
  }

  .podium-slot {
    padding: 24px 4px 12px;
    border-radius: 10px;
  }

  .podium-first {
    padding-top: 36px;
    padding-bottom: 16px;
  }

  .podium-medal {
    top: 6px;
    min-width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .podium-name {
    font-size: 12px;
    font-weight: 700;
    margin-top: 8px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;
  }

  .podium-author {
    font-size: 10px;
    margin-top: 2px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .podium-value {
    font-size: 16px;
    font-weight: 800;
    margin-top: 6px;
  }

  .podium-unit {
    font-size: 9px;
    margin-top: 2px;
  }

  .podium-badges {
    margin-top: 6px;
    min-height: 18px;
    justify-content: center;
  }

  .board-list {
    gap: 8px;
  }

  /* renderLeaderboard 输出 4 个子节点：名次、图标、主信息、数值 —— 需要 4 条显式轨道 */
  .board-row {
    grid-template-columns: 26px auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
  }

  .board-row .skill-icon {
    width: 32px;
    height: 32px;
    font-size: 12px;
    border-radius: 8px;
  }

  .board-rank {
    font-size: 13px;
    font-weight: 800;
  }

  .board-main {
    min-width: 0;
  }

  /* 超长标题/作者/类目就地换行，不撑宽行 */
  .board-title-line strong {
    font-size: 13px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .board-meta {
    font-size: 10px;
    overflow-wrap: anywhere;
  }

  .board-bar {
    margin-top: 6px;
    height: 4px;
  }

  .board-side {
    min-width: 0;
  }

  .board-value {
    font-size: 14px;
  }

  .board-delta {
    font-size: 10px;
    padding: 1px 6px;
  }

  /* --------------------------------------------------------------------------
     详情页面 (Detail View)
     -------------------------------------------------------------------------- */
  .detail-view {
    padding: 0;
  }

  .detail-topbar {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .detail-topbar .icon-button,
  #close-detail {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 18px;
  }

  .detail-topbar .button {
    min-height: 44px;
    padding: 0 10px;
    font-size: 13px;
  }

  .detail-brand {
    font-size: 14px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    text-align: center;
  }

  #author-actions {
    display: grid;
    gap: 8px;
  }

  #author-actions .button {
    min-height: 42px;
  }

  .detail-shell {
    display: flex;
    flex-direction: column;
    padding: 0 14px 40px;
    max-width: 100%;
  }

  .detail-summary {
    padding: 16px 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    width: 100%;
    min-width: 0;
  }

  .detail-summary h1 {
    font-size: 20px;
    margin-bottom: 8px;
  }

  .detail-tabs {
    position: sticky;
    top: 52px;
    z-index: 8;
    background: var(--bg);
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
    gap: 16px;
    border-bottom: 1px solid var(--border);
  }

  .detail-tab {
    white-space: nowrap;
    font-size: 13px;
    min-width: 44px;
    padding: 4px 10px 8px;
  }

  /* 只做就地收缩，不用 overflow:hidden —— 那会同时破坏 .detail-tabs 的 sticky */
  .detail-content {
    padding: 14px 0 40px;
    max-width: 100%;
    min-width: 0;
  }

  .skill-install-card {
    border-radius: 10px;
    max-width: 100%;
  }

  .install-card-header {
    padding: 14px 12px 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* 超长 Skill 标题在窄屏就地换行 */
  .install-card-header h2,
  #install-skill-name {
    overflow-wrap: anywhere;
  }

  .install-method-tabs {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px;
    gap: 14px;
    scrollbar-width: none;
  }

  .install-method-tab {
    white-space: nowrap;
    font-size: 12px;
    padding: 6px 0;
  }

  .install-method-panel {
    padding: 14px 12px;
  }

  .install-code-block {
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    padding: 10px;
    gap: 8px;
  }

  .install-code-block code {
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 12px;
  }

  .install-code-block .hero-copy-button,
  .install-code-block .install-copy-button {
    align-self: flex-end;
    min-height: 44px;
  }

  .install-card-footer {
    padding: 10px 12px;
  }

  /* 长段落/标题就地换行；横向滚动只保留在 pre 与 table 内部 */
  .markdown-body {
    font-size: 13px;
    line-height: 1.6;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* 窄屏优先阅读主文件，文件列表放到正文下方。 */
  .files-browser { display: block; }
  .files-sidebar { position: static; width: 100%; max-width: 100%; margin-top: 18px; z-index: auto; display: block; }
  .files-toggle { display: none; }
  .files-list {
    max-height: 280px;
    overflow: auto;
    padding: 5px;
  }

  .files-item {
    min-width: 132px;
  }

  .files-pre {
    max-height: 70vh;
  }

  .markdown-body pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 10px;
    font-size: 12px;
  }

  /* 代码块不随正文换行 —— 超出宽度时在 pre 内部横向滚动 */
  .markdown-body pre code {
    overflow-wrap: normal;
    word-break: normal;
  }

  .markdown-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
  }

  .version-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  /* --------------------------------------------------------------------------
     模态弹窗与对话框 (Dialogs & Forms)
     -------------------------------------------------------------------------- */
  .publish-dialog,
  .modal-dialog {
    width: calc(100vw - 16px);
    max-width: 100vw;
    max-height: calc(100vh - 24px);
    border-radius: 12px;
    margin: auto;
  }

  /* 表单壳层是受约束的纵向 flex 容器，body 区域 min-height:0 才能滚动，
     保证横屏/低高度下头部与底部按钮始终可达 */
  .dialog-shell,
  .dialog-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100vh - 24px);
  }

  .dialog-header {
    min-height: auto;
    flex: 0 0 auto;
    padding: 14px 16px;
    align-items: center;
  }

  .dialog-header h2 {
    font-size: 17px;
  }

  .dialog-header .icon-button {
    width: 44px;
    height: 44px;
    min-height: 44px;
    flex: 0 0 auto;
  }

  .dialog-body {
    padding: 14px 16px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    max-height: none;
  }

  .source-card {
    min-height: 56px;
    padding: 12px;
  }

  .source-card-icon {
    width: 34px;
    height: 34px;
  }

  .pick-grid {
    grid-template-columns: 1fr;
  }

  .pick-card {
    min-height: 44px;
    padding: 14px;
  }

  .publish-fields {
    padding: 14px 16px;
  }

  .manual-editor summary {
    min-height: 44px;
  }

  .manual-editor textarea {
    font-size: 16px;
  }

  .form-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .field {
    font-size: 13px;
  }

  .field-wide {
    width: 100%;
  }

  .url-import-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .url-import-row button {
    width: 100%;
    min-height: 44px;
  }

  .dialog-footer {
    padding: 12px 16px;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    align-items: stretch;
  }

  .dialog-footer span {
    font-size: 11px;
    text-align: center;
    max-width: none;
  }

  .dialog-footer > div {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .dialog-footer .button {
    flex: 1;
    min-height: 44px;
    justify-content: center;
    text-align: center;
  }

  .category-add-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .category-add-row button {
    width: 100%;
    min-height: 44px;
  }

  .subscribe-user-card {
    padding: 10px 12px;
    font-size: 13px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .dialog-intro {
    font-size: 13px;
    line-height: 1.5;
  }

  /* --------------------------------------------------------------------------
     Toast 轻提示
     -------------------------------------------------------------------------- */
  .toast {
    left: 50% !important;
    bottom: 24px !important;
    transform: translateX(-50%) !important;
    width: auto !important;
    max-width: calc(100vw - 32px);
    font-size: 13px;
    padding: 10px 16px;
    border-radius: 8px;
    text-align: center;
  }
}

/* 中屏与平板优化 (600px ~ 1024px) */
@media (min-width: 601px) and (max-width: 1024px) {
  .skill-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}
