* {
    box-sizing: border-box;
}

:root {
    --ink-900: #1f242e;
    --ink-700: #3a4250;
    --ink-500: #6b7585;
    --accent-600: #2f6fed;
    --accent-500: #3f7cff;
    --accent-100: #e8efff;
    --mint-500: #18a999;
    --peach-200: #fde7cf;
    --panel-bg: rgba(255, 255, 255, 0.9);
    --panel-border: rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 12px 30px rgba(15, 23, 42, 0.08);
    --shadow-hover: 0 18px 40px rgba(15, 23, 42, 0.14);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 10px;
    --page-pad: 1.25rem;
    --font-sans: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft Yahei", sans-serif;
    --font-display: "STKaiti", "KaiTi", "Songti SC", serif;
}

/* 全局布局 */
body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    background-color: #f3f5f8;
    background-image:
        radial-gradient(900px 520px at 12% -10%, rgba(253, 231, 207, 0.75), transparent 60%),
        radial-gradient(880px 520px at 100% 0%, rgba(63, 124, 255, 0.2), transparent 55%),
        linear-gradient(180deg, #f7f6f3 0%, #eef2f7 60%, #eef3f9 100%);
    color: var(--ink-900);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    padding: 0.8rem 0 0.4rem;
}

.header-wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 var(--page-pad);
}

.header-inner {
    width: 100%;
    background: linear-gradient(120deg, rgba(255, 255, 255, 0.92), rgba(232, 239, 255, 0.85));
    color: var(--ink-900);
    text-align: center;
    padding: 0.85rem 1rem 0.8rem;
    border-radius: 18px;
    border: 1px solid rgba(47, 111, 237, 0.18);
    box-shadow: 0 14px 26px rgba(47, 111, 237, 0.12);
    backdrop-filter: blur(10px);
}

.app-header h1 {
    margin: 0;
    font-family: var(--font-display), var(--font-emoji);
    font-size: 1.5rem;
    letter-spacing: 0.08em;
}

.app-main {
    max-width: 1080px;
    margin: 0 auto;
    padding: var(--page-pad);
    width: 100%;
    flex: 1;
}

.app-footer {
    text-align: center;
    padding: 1rem 0 2rem;
    font-size: 0.85rem;
    color: var(--ink-500);
}

/* 布局：侧边栏 + 主区域 */
.layout {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: flex-start;
}

.app-sidebar {
    width: 100%;
    min-width: 0;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.main-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Panel 通用样式 */
.panel {
    background: var(--panel-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 0.9rem 1.1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(6px);
    animation: panel-rise 0.5s ease both;
}

.panel:nth-of-type(2) {
    animation-delay: 0.05s;
}

.panel:nth-of-type(3) {
    animation-delay: 0.1s;
}

.panel:nth-of-type(4) {
    animation-delay: 0.15s;
}

.panel-controls {
    margin-top: 0.25rem;
}

.panel-sidebar {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    margin-bottom: 0;
}

.sidebar-section {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.sidebar-account {
    margin-left: auto;
}

.sidebar-section + .sidebar-section {
    margin-top: 0;
}

.sidebar-section h2 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--ink-700);
}

/* 控制区 */
.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 0.6rem;
}

.control-row-line2 {
    align-items: center;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row input[type="text"] {
    flex: 1 1 100%;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(15, 23, 42, 0.12);
    font-size: 0.98rem;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.control-row input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-500);
    box-shadow: 0 0 0 3px rgba(63, 124, 255, 0.15);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.control-group .label {
    font-size: 0.85rem;
    color: var(--ink-700);
}

#platform-select {
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(15, 23, 42, 0.12);
    font-size: 0.9rem;
    background: #fff;
}

/* IPv6 开关（侧边栏复用） */
.ipv6-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-hint {
    font-size: 0.78rem;
    color: var(--ink-500);
}

.btn-compact {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #cbd3dd;
    transition: 0.2s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .2s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background-color: var(--mint-500);
}

.switch input:checked + .slider:before {
    transform: translateX(16px);
}

.switch-label {
    font-size: 0.85rem;
    margin-left: 0.2rem;
    color: var(--ink-700);
}

/* 按钮 */
.btn {
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.55rem 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-600), var(--accent-500));
    color: #fff;
    box-shadow: 0 8px 18px rgba(47, 111, 237, 0.25);
}

.btn-primary:disabled {
    background: #9cbcff;
    cursor: default;
    box-shadow: none;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(47, 111, 237, 0.3);
}

.btn-secondary {
    background: #fff;
    color: var(--accent-600);
    border: 1px solid rgba(47, 111, 237, 0.35);
}

.btn-secondary:hover {
    background: var(--accent-100);
}

.btn-full {
    width: 100%;
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--ink-500);
    font-size: 0.85rem;
}

.btn-link {
    background: transparent;
    border: none;
    color: var(--accent-600);
    font-size: 0.9rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
}

.page-list {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

.page-btn {
    border: none;
    border-radius: 999px;
    padding: 0.5rem 1.2rem;
    background: linear-gradient(135deg, var(--accent-600), var(--accent-500));
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.04em;
    box-shadow: 0 12px 22px rgba(47, 111, 237, 0.22);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.page-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px rgba(47, 111, 237, 0.3);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: default;
    box-shadow: none;
}

.page-info {
    font-size: 0.85rem;
    color: var(--ink-500);
}

.page-number {
    border: 1px solid rgba(47, 111, 237, 0.25);
    background: #fff;
    color: var(--accent-600);
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.page-number:hover {
    transform: translateY(-1px);
    background: var(--accent-100);
}

.page-number.active {
    background: linear-gradient(135deg, var(--accent-600), var(--accent-500));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 10px 18px rgba(47, 111, 237, 0.22);
}

/* 过滤条（仿 Streamlit 单选） */
.panel-filter {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.filter-row .label {
    font-size: 0.85rem;
    color: var(--ink-700);
}

.filter-radio-group {
    display: inline-flex;
    gap: 0.4rem;
    background: #eef1f6;
    padding: 4px;
    border-radius: 999px;
}

.filter-pill {
    border: none;
    border-radius: 999px;
    padding: 0.25rem 0.85rem;
    font-size: 0.85rem;
    cursor: pointer;
    background: transparent;
    color: var(--ink-700);
}

.filter-pill.active {
    background: var(--accent-600);
    color: #fff;
    box-shadow: 0 6px 14px rgba(47, 111, 237, 0.22);
}

.filter-summary {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--ink-500);
}

/* 登录面板 */
.panel-login {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.login-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.login-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--ink-700);
}

.login-body {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-body img {
    width: 200px;
    height: 200px;
    object-fit: contain;
    margin-bottom: 0.4rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #fff;
}

.status-text {
    font-size: 0.85rem;
    margin: 0.2rem 0 0.4rem;
    color: var(--ink-700);
}

.login-actions {
    display: flex;
    gap: 0.5rem;
}

/* 结果区域 */
.panel-results {
    padding-top: 0.7rem;
    flex: 1;
}

.result-block {
    margin-bottom: 0.8rem;
    display: flex;
    flex-direction: column;
}

.result-block-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.3rem;
}

.result-block-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--ink-700);
}

.results-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.no-results {
    text-align: center;
    padding: 1.1rem 0.5rem;
    font-size: 0.9rem;
    color: var(--ink-500);
}

/* 卡片样式（仿 streamlit） */
.card {
    background: #fff;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #e9edf5;
}

.card-body {
    padding: 0.75rem 0.85rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-title {
    font-size: 0.98rem;
    font-weight: 600;
    margin: 0;
    color: var(--ink-900);
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--ink-500);
}

.badge {
    font-size: 0.78rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    color: #fff;
}

.badge.a {
    background: #e34b4b;
}

.badge.b {
    background: #2c7be5;
}

/* 下载按钮和进度 */
.card-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.btn-download-main {
    width: 100%;
}

.progress-container {
    width: 100%;
    background: #e7edf6;
    border-radius: 999px;
    overflow: hidden;
    height: 0.5rem;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4ecdc4, #2f6fed);
    transition: width 0.25s ease;
}

.progress-text {
    font-size: 0.78rem;
    color: var(--ink-500);
}

.btn:focus-visible,
.filter-pill:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid rgba(63, 124, 255, 0.5);
    outline-offset: 2px;
}

@keyframes panel-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 工具类 */
.hidden {
    display: none !important;
}

/* 响应式：侧边栏在窄屏时变为上方 */
@media (max-width: 768px) {
    :root {
        --page-pad: 1rem;
    }
    .app-sidebar {
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    .sidebar-section {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }
    .sidebar-account {
        margin-left: auto;
    }
    .app-main {
        padding: 1rem;
    }
}

/* 响应式：卡片两列 */
@media (min-width: 768px) {
    .results-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}
