/* ============================================================
 * Craft Tools · 组件层
 * ============================================================ */

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    border-radius: var(--r-pill);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: 550;
    letter-spacing: -0.01em;
    white-space: nowrap;
    transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
        transform var(--fast) var(--ease), color var(--fast) var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.98); }

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}
.btn--primary:hover { background: var(--ink-soft); }

.btn--ghost {
    background: transparent;
    border-color: var(--line-strong);
}
.btn--ghost:hover { background: var(--surface-3); }

.btn--icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--r-md);
}

.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 32%, var(--line-strong)); }
.btn--danger:hover { background: var(--danger-soft); }

.btn--lg { padding: 0.72rem 1.5rem; font-size: var(--fs-md); }
.btn--block { width: 100%; }

/* ===== 搜索与工具条 ===== */
.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}
.search {
    position: relative;
    flex: 1 1 240px;
    min-width: 0;
}
.search__icon {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--faint);
    pointer-events: none;
}
.search input {
    width: 100%;
    padding: 0.62rem 0.9rem 0.62rem 2.4rem;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-sm);
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.search input::placeholder { color: var(--faint); }
.search input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-wash);
}

.toolbar__ctrl { display: flex; align-items: center; gap: 8px; }

.sortwrap { position: relative; display: inline-flex; align-items: center; }
.sortwrap select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0.55rem 2rem 0.55rem 0.8rem;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
}
.sortwrap .sort-chev {
    position: absolute;
    right: 0.55rem;
    color: var(--faint);
    pointer-events: none;
}

.seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: var(--r-md);
    background: var(--surface-3);
    border: 1px solid var(--line);
}
.seg button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    width: 32px;
    height: 28px;
    border-radius: var(--r-sm);
    color: var(--muted);
    transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--sh-1);
}

/* ===== 分类筛选 ===== */
.chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px 0 8px;
    margin-bottom: 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.8rem;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 500;
    transition: all var(--fast) var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}
.chip .mono { opacity: 0.65; }

.metaline {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    font-size: var(--fs-xs);
    color: var(--muted);
    letter-spacing: 0.02em;
}
.metaline b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== 资源卡 ===== */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
    gap: var(--gap);
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: var(--card-pad, 1.05rem);
    border-radius: var(--r-lg);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--sh-1);
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease),
        border-color var(--fast) var(--ease);
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--sh-2);
    border-color: var(--line-strong);
}

.card__glyph {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--r-md);
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--gold);
}
.card__glyph .icon { width: 22px; height: 22px; }

.card__body { min-width: 0; }
.card__title {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 1rem;
    color: var(--text);
    transition: color var(--fast) var(--ease);
    font-weight: 650;
    letter-spacing: -0.02em;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.card__title:hover { color: var(--gold); }
.card__meta {
    margin-top: 3px;
    font-size: 0.8125rem;
    color: var(--muted);
    overflow-wrap: anywhere;
}
.card__meta .sep { color: var(--faint); margin: 0 0.3rem; }

.card__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    padding-top: 0.55rem;
}
.card__actions .btn { padding: 0.4rem 0.8rem; font-size: var(--fs-xs); }

.fav {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--faint);
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.fav:hover { color: var(--text); background: var(--surface-3); }
.fav[aria-pressed="true"] { color: var(--gold); }
.fav[aria-pressed="true"] .icon { fill: currentColor; }

.pwchip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.4rem;
    border-radius: var(--r-xs);
    background: var(--gold-wash);
    color: var(--gold);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
}

/* 深色下卡片里的下载按钮不用纯白，否则一屏几个白块太抢视线（弹层里的主按钮保持白色） */
[data-theme="dark"] .card__actions .btn--primary {
    background: rgba(236, 233, 227, 0.1);
    border-color: rgba(236, 233, 227, 0.18);
    color: var(--text);
}

/* 手机：工具条与计数也收紧 */
@media (max-width: 640px) {
    .toolbar { margin-bottom: 8px; }
    .chips { padding-bottom: 4px; margin-bottom: 2px; }
    .metaline { margin-bottom: 8px; }
}

/* 手机：卡片收紧，一屏能多看两条 */
@media (max-width: 640px) {
    .cards { grid-template-columns: 1fr; }
    .card { padding: 0.85rem; gap: 0.32rem; border-radius: var(--r-md); }
    .card__glyph { width: 36px; height: 36px; border-radius: var(--r-sm); }
    .card__glyph .icon { width: 18px; height: 18px; }
    .card__title { font-size: 0.9375rem; }
    .card__actions { padding-top: 0.45rem; }
    .card__actions .btn { padding: 0.45rem 0.85rem; }
    .fav { top: 0.35rem; right: 0.35rem; width: 30px; height: 30px; }
}

/* 列表布局 */
[data-layout="list"] .cards { grid-template-columns: 1fr; }
[data-layout="list"] .card {
    flex-direction: row;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 1rem;
}
[data-layout="list"] .card__glyph {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
}
[data-layout="list"] .card__glyph .icon { width: 19px; height: 19px; }
[data-layout="list"] .card__body { flex: 1 1 auto; }
[data-layout="list"] .card__actions { margin: 0; padding: 0; flex: 0 0 auto; }
[data-layout="list"] .fav { position: static; flex: 0 0 auto; }

/* ===== 分类列表 ===== */
.catgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--gap);
}
.catrow {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--line);
    text-align: left;
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease),
        border-color var(--fast) var(--ease);
}
.catrow:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
    box-shadow: var(--sh-2);
}
.catrow__glyph {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: var(--r-sm);
    background: var(--surface-3);
    color: var(--gold);
}
.catrow__text { flex: 1 1 auto; min-width: 0; }
.catrow__name {
    display: block;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.catrow__count { display: block; font-size: var(--fs-xs); color: var(--muted); }
.catrow__chev { color: var(--faint); flex: 0 0 auto; }

/* ===== 空状态 ===== */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 3.5rem 1rem;
    text-align: center;
    color: var(--faint);
}
.empty__icon { color: var(--line-strong); }
.empty__icon .icon { width: 36px; height: 36px; }
.empty__title { font-size: 0.9375rem; font-weight: 600; color: var(--muted); }
.empty__hint { font-size: var(--fs-xs); max-width: 24rem; }

/* ===== 设置 ===== */
.settings {
    display: flex;
    flex-direction: column;
    gap: 26px;
    max-width: 660px;
    margin: 0 auto;
}
.group__title {
    margin: 0 0 8px 0.35rem;
    font-size: 0.6875rem;
    font-weight: 650;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
}
.gcard {
    border-radius: var(--r-lg);
    background: var(--surface);
    border: 1px solid var(--line);
    overflow: hidden;
}
.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    min-height: 54px;
}
.row + .row { border-top: 1px solid var(--line); }
.row__text { flex: 1 1 auto; min-width: 0; }
.row__label { font-size: 0.9375rem; font-weight: 550; }
.row__desc { margin-top: 1px; font-size: var(--fs-xs); color: var(--muted); }
.row__ctrl { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.row--stack { flex-direction: column; align-items: stretch; }
.row__actions { display: flex; gap: 8px; margin-top: 8px; }
.row__actions > * { flex: 1 1 0; }

/* 开关 */
.switch {
    position: relative;
    display: inline-flex;
    width: 46px;
    height: 27px;
    flex: 0 0 auto;
}
.switch input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.switch__track {
    position: absolute;
    inset: 0;
    border-radius: var(--r-pill);
    background: var(--line-strong);
    transition: background var(--fast) var(--ease);
    pointer-events: none;
}
.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
    transition: transform var(--fast) var(--ease);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(19px); }
.switch input:focus-visible + .switch__track {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* 分段选择 */
.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--r-md);
    background: var(--surface-3);
    border: 1px solid var(--line);
}
.segmented button {
    padding: 0.26rem 0.62rem;
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
    transition: all var(--fast) var(--ease);
}
/* 整行铺开的分段控件（设置项里的多选一） */
.segmented--wide {
    display: flex;
    width: 100%;
    margin-top: 10px;
}
.segmented--wide button {
    flex: 1 1 0;
    text-align: center;
    padding: 0.4rem 0.3rem;
}

.segmented button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--sh-1);
}

.input {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--fs-sm);
}
.input::placeholder { color: var(--faint); }
.input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-wash);
}

/* ===== 详情弹层 ===== */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(20, 16, 8, 0.44);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
.sheet-overlay[data-open="true"] { display: flex; animation: fadeIn 0.18s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
    position: relative;
    width: 100%;
    max-width: 430px;
    max-height: min(88vh, 760px);
    overflow-y: auto;
    padding: 22px;
    border-radius: var(--r-xl);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--sh-3);
    animation: sheetIn 0.26s var(--ease);
}
@keyframes sheetIn {
    from { opacity: 0; transform: translateY(18px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

.sheet__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--muted);
    background: var(--surface-3);
}
.sheet__close:hover { color: var(--text); }

.sheet__glyph {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: var(--r-md);
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--gold);
}
.sheet__glyph .icon { width: 26px; height: 26px; }

.sheet__title {
    margin-top: 14px;
    padding-right: 2.2rem;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.sheet__desc {
    margin-top: 6px;
    font-size: var(--fs-sm);
    color: var(--muted);
}
.sheet__tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.55rem;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    font-size: var(--fs-xs);
    color: var(--muted);
}
.tag--gold {
    color: var(--gold);
    border-color: color-mix(in srgb, var(--gold) 34%, transparent);
    background: var(--gold-wash);
}

.specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
}
.spec {
    padding: 0.55rem 0.7rem;
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--line);
}
.spec__k {
    display: block;
    font-size: 0.625rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
}
.spec__v {
    display: block;
    margin-top: 2px;
    font-size: var(--fs-sm);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.sheet__acts {
    display: flex;
    gap: 8px;
    margin-top: 18px;
}
.sheet__acts .btn { padding: 0.62rem 1rem; font-size: var(--fs-sm); }
.sheet__acts .btn--primary { flex: 1 1 auto; }

/* ===== Toast ===== */
.toasts {
    position: fixed;
    left: 50%;
    bottom: calc(26px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: min(92vw, 420px);
    pointer-events: none;
}
@media (max-width: 859px) {
    .toasts { bottom: calc(var(--dock-h) + 26px + env(safe-area-inset-bottom, 0px)); }
}

.toast {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.95rem;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: var(--accent-ink);
    font-size: var(--fs-sm);
    font-weight: 500;
    box-shadow: var(--sh-2);
    animation: toastIn 0.22s var(--ease);
}
.toast .icon { width: 16px; height: 16px; }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
.toast--out { animation: toastOut 0.2s var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }
