/* home.css — txtxs 首页（v3 重构）：搜索进顶部 sticky 栏 + 结果网格卡片
   布局与 v2 完全不同；配色仍是 Apple 风：
   #F5F5F7 底色 / 白色卡片 / #FA243C 唯一强调色 / 磨砂顶栏 / 只用 SVG 图标 */
:root {
    --tx-bg: #F5F5F7;
    --tx-card: #FFFFFF;
    --tx-text: #1D1D1F;
    --tx-muted: #86868B;
    --tx-accent: #FA243C;
    --tx-accent-soft: rgba(250, 36, 60, 0.08);
    --tx-border: rgba(0, 0, 0, 0.08);
    --tx-field: #F5F5F7;
    --tx-radius: 16px;
    --tx-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body.tx-home {
    background: var(--tx-bg);
    color: var(--tx-text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }

/* ---- 磨砂顶栏：logo + 搜索（滚动时一直可见） ---- */
.tx-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--tx-border);
}
.tx-topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    min-height: 60px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.tx-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    text-decoration: none;
}
.tx-brand img {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: block;
}
.tx-topbar-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

/* 搜索表单：三段式 + 输入框 + 红按钮，一行进栏 */
.search-form {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.tx-seg {
    display: inline-flex;
    flex-shrink: 0;
    background: var(--tx-field);
    border-radius: 999px;
    padding: 3px;
}
.tx-seg button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--tx-muted);
    font: inherit;
    font-size: 13px;
    padding: 6px 13px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}
.tx-seg button.is-active {
    background: var(--tx-card);
    color: var(--tx-text);
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.tx-input-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--tx-field);
    border-radius: 999px;
    padding: 0 14px;
    height: 40px;
}
.tx-input-wrap:focus-within { outline: 2px solid rgba(250, 36, 60, 0.35); outline-offset: 0; }
.tx-input-wrap svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: var(--tx-muted);
}
.tx-input-wrap input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    font-size: 15px;
    color: var(--tx-text);
    height: 100%;
}
.tx-input-wrap input::placeholder { color: #A1A1A6; }
.tx-search-btn {
    appearance: none;
    border: 0;
    background: var(--tx-accent);
    color: #FFFFFF;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    border-radius: 999px;
    padding: 0 20px;
    height: 40px;
    cursor: pointer;
    flex-shrink: 0;
}
.tx-search-btn:active { opacity: 0.85; }

/* ---- 主区 ---- */
.tx-main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px 20px 72px;
}

/* ---- 我的收藏：横向小卡片条 ---- */
.tx-fav { margin-bottom: 24px; }
.tx-fav-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
}
.tx-fav-head h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.tx-fav-head span { font-size: 13px; color: var(--tx-muted); }
.tx-fav-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.tx-fav-item {
    flex: 0 0 280px;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--tx-card);
    border-radius: 14px;
    box-shadow: var(--tx-shadow);
    padding: 12px 14px;
}
.tx-fav-cover {
    width: 44px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    background: var(--tx-field);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--tx-muted);
    text-align: center;
}
.tx-fav-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tx-fav-body { flex: 1; min-width: 0; }
.tx-fav-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tx-fav-sub {
    margin-top: 4px;
    font-size: 13px;
    color: var(--tx-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tx-fav-go {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--tx-accent);
    text-decoration: none;
}
.tx-fav-remove {
    appearance: none;
    border: 0;
    background: transparent;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    color: var(--tx-muted);
}
.tx-fav-remove:hover { background: var(--tx-field); }
.tx-fav-remove svg { width: 14px; height: 14px; fill: currentColor; }

/* ---- 状态与空态：空态只是一句提示 ---- */
.tx-status { margin-top: 8px; }
.tx-message {
    background: var(--tx-card);
    border-radius: var(--tx-radius);
    box-shadow: var(--tx-shadow);
    padding: 20px;
    text-align: center;
    font-size: 15px;
    color: var(--tx-muted);
}
.tx-message.error { color: #B42318; }
.tx-hint { margin-top: 40px; text-align: center; }
.tx-hint p {
    margin: 0;
    font-size: 14px;
    color: var(--tx-muted);
}

/* ---- 结果区：网格卡片 ---- */
.tx-results { margin-top: 8px; }
.tx-result-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 14px;
    padding: 0 2px;
}
.tx-keyword {
    font-size: 17px;
    font-weight: 700;
    color: var(--tx-accent);
}
.tx-result-meta span:last-child { font-size: 13px; color: var(--tx-muted); }
.tx-book-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}
.tx-book {
    display: flex;
    flex-direction: column;
    background: var(--tx-card);
    border-radius: var(--tx-radius);
    box-shadow: var(--tx-shadow);
    overflow: hidden;
}
.tx-book-cover {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: var(--tx-field);
    position: relative;
    overflow: hidden;
}
.tx-book-cover img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.tx-cover-ph {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--tx-muted);
    text-align: center;
    padding: 6px;
}
.tx-book-cover.no-cover .tx-cover-ph { display: flex; }
.tx-fav-cover .tx-cover-ph { font-size: 11px; }
.tx-fav-cover.no-cover .tx-cover-ph { display: flex; }
.tx-book-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 16px 16px;
}
.tx-book-body h2 { margin: 0; font-size: 17px; line-height: 1.4; font-weight: 600; }
.tx-book-body h2 a { text-decoration: none; }
.tx-book-body h2 a:hover { color: var(--tx-accent); }
.tx-book-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    font-size: 13px;
    color: var(--tx-muted);
}
.tx-tag {
    font-size: 12px;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--tx-accent-soft);
    color: var(--tx-accent);
    font-weight: 600;
}
.tx-book-intro {
    margin: 8px 0 0;
    font-size: 14px;
    line-height: 1.6;
    color: #6E6E73;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tx-book-actions { display: flex; gap: 10px; margin-top: auto; padding-top: 14px; }
.tx-btn {
    display: inline-block;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 999px;
    padding: 8px 18px;
    cursor: pointer;
}
.tx-btn-primary { background: var(--tx-accent); color: #FFFFFF; border: 0; }
.tx-btn-primary:active { opacity: 0.85; }
.tx-btn-ghost {
    background: transparent;
    color: var(--tx-text);
    border: 1px solid var(--tx-border);
}
.tx-btn-ghost:active { background: var(--tx-field); }

/* ---- 分页 ---- */
.tx-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 28px;
    flex-wrap: wrap;
}
.tx-page-btn, .tx-page-num {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 14px;
    text-decoration: none;
    color: var(--tx-text);
    background: var(--tx-card);
    border: 1px solid var(--tx-border);
}
.tx-page-num.is-active {
    background: var(--tx-accent);
    border-color: var(--tx-accent);
    color: #FFFFFF;
    font-weight: 600;
}
.tx-page-ellipsis { color: var(--tx-muted); padding: 0 2px; }

/* ---- 加载遮罩（原版样式，换成本站强调色） ---- */
.app-loading {
    position: fixed;
    inset: 0;
    z-index: 100050;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-loading[hidden] { display: none !important; }
.app-loading-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(245, 245, 247, 0.78);
    backdrop-filter: blur(3px);
}
.app-loading-spinner {
    position: relative;
    width: 42px;
    height: 42px;
    border: 3px solid rgba(250, 36, 60, 0.16);
    border-top-color: var(--tx-accent);
    border-radius: 50%;
    animation: app-loading-spin 0.75s linear infinite;
}
@keyframes app-loading-spin { to { transform: rotate(360deg); } }
body.is-loading { cursor: wait; }

/* ---- 断点：平板 2 列，手机 1 列；窄屏顶栏两行 ---- */
@media (max-width: 1023px) {
    .tx-book-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
    .tx-topbar-inner { flex-wrap: wrap; row-gap: 10px; padding: 10px 16px; }
    .search-form { flex: 1 1 100%; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
    .tx-seg { grid-column: 1 / -1; justify-self: start; }
    .tx-input-wrap { grid-column: 1; }
    .tx-search-btn { grid-column: 2; }
    .tx-main { padding: 20px 16px 56px; }
    .tx-fav-item { flex-basis: 260px; }
}
@media (max-width: 639px) {
    .tx-book-list { grid-template-columns: 1fr; }
    .tx-book-cover { aspect-ratio: 4 / 3; }
}
