/**
 * 网络测速网站样式表
 * 半圆形表盘设计
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
    background: #2d2d2d; /* 暗灰色背景 */
    min-height: 100vh;
    padding: 40px 20px;
    color: #e0e0e0; /* 浅色文字 */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #3a3a3a; /* 稍亮的暗灰色容器 */
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* 顶部控制按钮 */
.header-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
}

.btn {
    padding: 12px 32px;
    border: 2px solid #1890ff;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #ffffff;
    color: #1890ff;
}

.btn:hover:not(:disabled) {
    background: #1890ff;
    color: #ffffff;
}

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

.btn-primary {
    border-color: #1890ff;
    color: #1890ff;
}

.btn-secondary {
    border-color: #52c41a;
    color: #52c41a;
}

.btn-secondary:hover:not(:disabled) {
    background: #52c41a;
    color: #ffffff;
}

/* IP地址显示 */
.ip-display {
    text-align: center;
    margin-bottom: 40px;
    font-size: 16px;
    color: #e0e0e0;
}

.ip-label {
    margin-right: 8px;
    color: #b0b0b0;
}

.ip-value {
    font-weight: 600;
    color: #4a9eff;
}

/* 指标网格 */
.metrics-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 900px;
    margin: 0 auto;
}

/* 表盘行（两个表盘在同一行） */
.gauges-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* 指标卡片 */
.metric-card {
    background: #2d2d2d; /* 暗灰色卡片 */
    border: 1px solid #4a4a4a; /* 暗色边框 */
    border-radius: 12px;
    padding: 20px 15px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.metric-card:not(.speed-card) {
    min-height: 120px;
}

.metric-label {
    font-size: 14px; /* 减少30%: 16px * 0.7 = 11.2px ≈ 14px (保持可读性) */
    color: #b0b0b0; /* 浅灰色标签 */
    margin-bottom: 10px; /* 减少30%: 15px * 0.7 = 10.5px ≈ 10px */
    font-weight: 500;
}

/* 延迟显示（在表盘下方） */
.latency-display {
    margin-top: 10px;
    text-align: center;
}

.latency-label {
    font-size: 14px;
    color: #b0b0b0; /* 浅灰色标签 */
    margin-bottom: 5px;
    font-weight: 500;
}

.latency-value {
    font-size: 24px; /* 减少30%: 28px * 0.7 = 19.6px ≈ 24px (保持可读性) */
    font-weight: 700;
    color: #8b4513;
    margin-bottom: 3px;
    line-height: 1.2;
}

.latency-unit {
    font-size: 12px;
    color: #999;
    margin-top: 3px;
}

/* 速度卡片（带表盘） */
.speed-card {
    position: relative;
    padding: 15px; /* 减少30%: 20px * 0.7 = 14px ≈ 15px */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.speed-gauge {
    position: relative;
    width: 100%;
    height: 98px; /* 减少30%: 140px * 0.7 = 98px */
    display: flex;
    align-items: center;
    justify-content: center;
}

.gauge-svg {
    width: 100%;
    height: 100%;
    max-width: 154px; /* 减少30%: 220px * 0.7 = 154px */
    max-height: 98px; /* 减少30%: 140px * 0.7 = 98px */
}

/* 表盘弧线 */
.gauge-background {
    opacity: 0.3;
}

.gauge-arc {
    transition: stroke-dashoffset 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: 100px 100px;
    will-change: stroke-dashoffset;
}

.download-arc {
    stroke: #764ba2;
}

.upload-arc {
    stroke: #38ef7d;
}

/* 指针 */
.pointer-group {
    transform-origin: 100px 100px;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.pointer {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    stroke: #333;
    stroke-width: 3;
}

.pointer-center {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    fill: #333;
}

/* 指针跳动动画 */
@keyframes pointerBounce {
    0%, 100% {
        transform: rotate(var(--pointer-angle, -90deg)) scale(1) translateY(0);
    }
    25% {
        transform: rotate(var(--pointer-angle, -90deg)) scale(1.05) translateY(-2px);
    }
    50% {
        transform: rotate(var(--pointer-angle, -90deg)) scale(1.1) translateY(-3px);
    }
    75% {
        transform: rotate(var(--pointer-angle, -90deg)) scale(1.05) translateY(-2px);
    }
}

.pointer-group.animating {
    animation: pointerBounce 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

/* 速度数值显示 */
.speed-value-container {
    position: absolute;
    bottom: 10px; /* 减少30%: 15px * 0.7 = 10.5px ≈ 10px */
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 10;
}

.speed-value-large {
    font-size: 22px; /* 减少30%: 32px * 0.7 = 22.4px ≈ 22px */
    font-weight: 700;
    color: #e0e0e0; /* 浅色文字 */
    line-height: 1;
    margin-bottom: 2px; /* 减少30%: 3px * 0.7 = 2.1px ≈ 2px */
}

.speed-unit {
    font-size: 8px; /* 减少30%: 12px * 0.7 = 8.4px ≈ 8px */
    color: #999;
    font-weight: 500;
}

/* 状态消息 */
.status-message {
    text-align: center;
    margin-top: 30px;
    padding: 15px;
    font-size: 14px;
    color: #b0b0b0;
    min-height: 20px;
}

.status-message.testing {
    color: #4a9eff;
    font-weight: 500;
}

.status-message.error {
    color: #ff6b6b;
}

.status-message.success {
    color: #51cf66;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .gauges-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .header-controls {
        flex-direction: column;
        align-items: center;
    }

    .btn {
        width: 200px;
    }

    .speed-value-large {
        font-size: 20px;
    }

    .latency-value {
        font-size: 20px;
    }
    
    .speed-gauge {
        height: 85px;
    }
    
    .gauge-svg {
        max-width: 135px;
        max-height: 85px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 20px 10px;
    }

    .speed-value-large {
        font-size: 32px;
    }

    .metric-value {
        font-size: 24px;
    }

    .gauge-svg {
        max-width: 250px;
        max-height: 150px;
    }
}

/* 测试中的加载动画 */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.metric-card.testing {
    animation: pulse 2s ease-in-out infinite;
}

/* 历史记录区域 */
.history-section {
    margin-top: 40px;
    padding: 25px;
    background: #2d2d2d;
    border-radius: 15px;
    border: 1px solid #4a4a4a;
}

.history-section h3 {
    color: #e0e0e0;
    margin-bottom: 20px;
    font-size: 1.3em;
    text-align: center;
}

.history-container {
    background: #3a3a3a;
    border-radius: 10px;
    padding: 20px;
    max-height: 500px;
    overflow-y: auto;
}

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

.history-table thead {
    background: #2d2d2d;
    position: sticky;
    top: 0;
    z-index: 10;
}

.history-table th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    color: #e0e0e0;
    border-bottom: 2px solid #4a4a4a;
}

.history-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #4a4a4a;
    color: #e0e0e0;
}

.history-table tbody tr:hover {
    background: #2d2d2d;
}

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

.history-loading,
.history-empty,
.history-error {
    text-align: center;
    padding: 30px;
    color: #b0b0b0;
    font-size: 14px;
}

.history-empty p {
    margin: 10px 0;
}

.history-empty p:first-child {
    font-size: 16px;
    font-weight: 500;
    color: #e0e0e0;
}

.history-hint {
    color: #4a9eff;
    font-size: 14px;
}

.history-ip-info {
    color: #b0b0b0;
    font-size: 13px;
    margin-top: 15px;
}

.history-note {
    color: #888;
    font-size: 12px;
    font-style: italic;
    margin-top: 10px;
}

.history-error {
    color: #ff4d4f;
}

.history-error p {
    margin: 8px 0;
}

.error-hint {
    color: #b0b0b0;
    font-size: 13px;
}

.debug-info {
    margin-top: 10px;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 4px;
    font-size: 12px;
    color: #333;
    text-align: left;
}

/* 表盘数值更新动画 */
@keyframes numberUpdate {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.speed-value-large.updating,
.metric-value.updating {
    animation: numberUpdate 0.3s ease;
}

/* 响应式布局 - 移动设备优化 */
@media (max-width: 768px) {
    .container {
        padding: 20px 15px;
    }

    .header-controls {
        flex-direction: column;
        gap: 10px;
    }

    .btn {
        width: 100%;
        padding: 14px 20px;
    }

    .gauges-row {
        flex-direction: column;
    }

    .speed-card {
        width: 100%;
    }

    /* 历史记录表格 - 移动端卡片式布局 */
    .history-table {
        display: none; /* 隐藏表格 */
    }

    .history-container {
        padding: 15px;
    }

    /* 创建卡片式布局 */
    .history-table-mobile {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    .history-card {
        background: #2d2d2d;
        border-radius: 8px;
        padding: 15px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .history-card-row {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid #4a4a4a;
    }

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

    .history-card-label {
        color: #b0b0b0;
        font-size: 13px;
    }

    .history-card-value {
        color: #e0e0e0;
        font-weight: 500;
        font-size: 14px;
    }

    .history-card-timestamp {
        color: #4a9eff;
        font-size: 12px;
        margin-bottom: 10px;
        padding-bottom: 10px;
        border-bottom: 2px solid #4a4a4a;
    }
}

/* 平板设备优化 */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 30px 20px;
    }

    .history-table {
        font-size: 13px;
    }

    .history-table th,
    .history-table td {
        padding: 8px 6px;
    }
}

/* 大屏幕优化 */
@media (min-width: 1400px) {
    .container {
        max-width: 1400px;
    }

    .metrics-grid {
        max-width: 1100px;
    }
}

/* 加载动画 */
.history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #4a4a4a;
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: #b0b0b0;
    font-size: 14px;
}

/* 骨架屏加载效果 */
.skeleton-table {
    width: 100%;
    border-collapse: collapse;
}

.skeleton-row {
    display: flex;
    gap: 10px;
    padding: 15px 0;
    border-bottom: 1px solid #4a4a4a;
}

.skeleton-cell {
    height: 20px;
    background: linear-gradient(90deg, #3a3a3a 25%, #4a4a4a 50%, #3a3a3a 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

.skeleton-cell.timestamp {
    flex: 2;
}

.skeleton-cell.speed {
    flex: 1;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* 帮助图标 */
.help-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    background: #4a9eff;
    color: #fff;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.3s ease;
}

.help-icon:hover {
    background: #1890ff;
    transform: scale(1.1);
}

/* 帮助弹窗 */
.help-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.3s ease;
}

.help-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.help-modal-content {
    background-color: #3a3a3a;
    color: #e0e0e0;
    padding: 30px;
    border-radius: 10px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.help-modal-close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #b0b0b0;
    cursor: pointer;
    transition: color 0.3s ease;
}

.help-modal-close:hover {
    color: #ff4d4f;
}

.help-modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #4a9eff;
    font-size: 24px;
}

.help-content h4 {
    color: #e0e0e0;
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 16px;
}

.help-content p {
    margin: 10px 0;
    line-height: 1.6;
    color: #b0b0b0;
}

.help-content ul {
    margin: 10px 0;
    padding-left: 25px;
}

.help-content li {
    margin: 8px 0;
    line-height: 1.6;
    color: #b0b0b0;
}

.help-content strong {
    color: #e0e0e0;
}

/* 移动端帮助弹窗优化 */
@media (max-width: 768px) {
    .help-modal-content {
        width: 95%;
        padding: 20px;
        max-height: 90vh;
    }

    .help-modal-content h3 {
        font-size: 20px;
        padding-right: 30px;
    }

    .help-content h4 {
        font-size: 15px;
    }

    .help-content p,
    .help-content li {
        font-size: 14px;
    }
}

/* 首次访问引导 */
.first-visit-guide {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.first-visit-guide.fade-out {
    animation: fadeOut 0.3s ease;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.guide-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 40px;
    border-radius: 15px;
    max-width: 600px;
    width: 90%;
    color: #fff;
    animation: slideIn 0.5s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.guide-content h3 {
    margin-top: 0;
    margin-bottom: 30px;
    font-size: 28px;
    text-align: center;
}

.guide-steps {
    margin: 30px 0;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 25px;
}

.step-number {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    margin-right: 20px;
    flex-shrink: 0;
}

.step-text {
    flex: 1;
}

.step-text strong {
    display: block;
    font-size: 18px;
    margin-bottom: 5px;
}

.step-text p {
    margin: 0;
    opacity: 0.9;
    font-size: 14px;
    line-height: 1.5;
}

.guide-note {
    background: rgba(255, 255, 255, 0.15);
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    font-size: 14px;
    text-align: center;
}

.guide-close-btn {
    width: 100%;
    padding: 15px;
    background: #fff;
    color: #667eea;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.guide-close-btn:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 移动端首次访问引导优化 */
@media (max-width: 768px) {
    .guide-content {
        padding: 30px 20px;
        width: 95%;
    }

    .guide-content h3 {
        font-size: 22px;
        margin-bottom: 20px;
    }

    .step-number {
        width: 35px;
        height: 35px;
        font-size: 18px;
        margin-right: 15px;
    }

    .step-text strong {
        font-size: 16px;
    }

    .step-text p {
        font-size: 13px;
    }

    .guide-note {
        font-size: 13px;
        padding: 12px;
    }
}
