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

:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --primary: #4f6ef7;
    --primary-hover: #3b57d9;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.08);
    --green: #10b981;
    --green-bg: #ecfdf5;
    --orange: #f59e0b;
    --orange-bg: #fffbeb;
    --red: #ef4444;
    --red-bg: #fef2f2;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
    line-height: 1;
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1;
}

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

.region-selector label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.region-selector select {
    padding: 6px 32px 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.region-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

.region-selector select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--bg);
}

/* ===== Channel Selector ===== */
.channel-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.channel-selector label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.channel-selector select {
    padding: 6px 32px 6px 12px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    background: var(--surface);
    color: var(--primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234f6ef7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.channel-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

/* ===== Header Right ===== */
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.rate-display {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--green-bg);
    border-radius: var(--radius-sm);
    border: 1px solid #d1fae5;
}

.rate-label {
    font-size: 11px;
    color: var(--green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.rate-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ===== Main ===== */
main {
    flex: 1;
    padding: 32px 24px 48px;
}

.container {
    max-width: 960px;
    margin: 0 auto;
}

/* ===== Tab Bar ===== */
.tab-bar {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.tab {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
    background: var(--bg);
}

.tab.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ===== Card ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 28px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.card-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.badge {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    white-space: nowrap;
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}

.badge-orange {
    background: var(--orange-bg);
    color: var(--orange);
}

/* ===== Table ===== */
.table-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    background: var(--bg);
    padding: 10px 12px;
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

tbody tr:hover {
    background: var(--bg);
}

tbody tr:last-child td {
    border-bottom: none;
}

.rank-col {
    font-weight: 700;
    color: var(--primary);
    width: 40px;
}

.coins-col strong {
    font-weight: 600;
}

.discount-col.positive {
    color: var(--green);
    font-weight: 600;
}

.cny-col {
    font-variant-numeric: tabular-nums;
}

.cny-price {
    font-size: 12px;
    color: #e74c3c;
    font-weight: 600;
}

.cny-price.na {
    color: var(--text-secondary);
    font-weight: 400;
}

.hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ===== Input Group ===== */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.input-row input {
    flex: 1;
    min-width: 180px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

.unit {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===== Button ===== */
.btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
}

.btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 110, 247, 0.3);
}

/* ===== Result Box ===== */
.result-box {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px;
    min-height: 100px;
    background: var(--bg);
}

.result-placeholder {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 20px 0;
}

.result-error {
    color: var(--red);
    font-size: 14px;
    text-align: center;
    padding: 12px 0;
    font-weight: 500;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.result-title {
    font-size: 18px;
    font-weight: 700;
}

.result-packages {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.pkg-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.pkg-row:last-child {
    border-bottom: none;
}

.pkg-name {
    font-weight: 500;
}

.pkg-count {
    font-weight: 600;
    color: var(--primary);
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
}

.stat {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 8px 12px;
    background: var(--surface);
    border-radius: var(--radius-sm);
}

.stat strong {
    color: var(--text);
    font-weight: 600;
}

.stat.extra {
    color: var(--green);
    font-weight: 600;
    grid-column: 1 / -1;
}

/* ===== Footer ===== */
footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
}

.footer-inner {
    max-width: 960px;
    margin: 0 auto;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.source-link {
    font-size: 11px;
}

.source-link a {
    color: var(--primary);
    text-decoration: none;
}

.source-link a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header-inner {
        padding: 10px 16px;
        gap: 8px;
    }

    .logo-icon {
        font-size: 24px;
    }

    .logo h1 {
        font-size: 17px;
    }

    .subtitle {
        font-size: 11px;
    }

    .header-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .channel-selector select,
    .region-selector select {
        font-size: 13px;
        padding: 5px 28px 5px 10px;
    }

    .rate-display {
        padding: 3px 10px;
    }

    .rate-value {
        font-size: 12px;
    }

    main {
        padding: 16px 12px 32px;
    }

    .tab {
        font-size: 13px;
        padding: 10px 12px;
    }

    .card {
        padding: 16px 12px;
    }

    .card-header h2 {
        font-size: 16px;
    }

    .badge {
        font-size: 11px;
        padding: 3px 10px;
    }

    .table-wrap {
        margin: 0 -12px 12px;
        padding: 0 12px;
    }

    table {
        font-size: 12px;
    }

    thead th {
        font-size: 11px;
        padding: 8px 8px;
    }

    tbody td {
        padding: 8px 8px;
    }

    .input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .input-row input {
        min-width: auto;
        font-size: 16px;
    }

    .btn {
        text-align: center;
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .stat {
        font-size: 12px;
        padding: 6px 10px;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .result-title {
        font-size: 16px;
    }

    .result-packages {
        padding: 10px 12px;
    }

    .pkg-row {
        font-size: 13px;
    }

    .footer-inner {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .header-inner {
        padding: 8px 12px;
    }

    .logo h1 {
        font-size: 15px;
    }

    .header-right {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .channel-selector,
    .region-selector {
        width: 100%;
    }

    .channel-selector select,
    .region-selector select {
        width: 100%;
    }

    .rate-display {
        justify-content: center;
    }

    .tab-bar {
        gap: 2px;
        padding: 3px;
    }

    .tab {
        font-size: 12px;
        padding: 8px 8px;
    }

    .card {
        padding: 12px 10px;
        border-radius: 8px;
    }

    main {
        padding: 12px 8px 24px;
    }

    table {
        font-size: 11px;
    }

    thead th {
        font-size: 10px;
        padding: 6px 5px;
        letter-spacing: 0.3px;
    }

    tbody td {
        padding: 6px 5px;
    }

    .rank-col {
        width: 24px;
    }

    .cny-price {
        font-size: 11px;
    }

    .result-packages {
        padding: 8px 10px;
    }

    .result-title {
        font-size: 14px;
    }
}
