/* ========================================
   CSS Variables & Theme
   ======================================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-card: #ffffff;
    --bg-muted: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-muted: rgba(226, 232, 240, 0.5);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-muted: rgba(59, 130, 246, 0.1);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #a855f7;
    --orange: #f97316;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.1);
}

body.dark {
    --bg-primary: #0a0a0f;
    --bg-secondary: #0f0f17;
    --bg-card: #12121a;
    --bg-muted: #1a1a24;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #1e293b;
    --border-muted: rgba(30, 41, 59, 0.5);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-muted: rgba(59, 130, 246, 0.15);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========================================
   Background Effects
   ======================================== */
.background-effects {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.bg-blur {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
}

.bg-blur-1 {
    top: -15%;
    left: -10%;
    width: 50%;
    height: 50%;
    background: var(--primary-muted);
}

.bg-blur-2 {
    bottom: -15%;
    right: -10%;
    width: 50%;
    height: 50%;
    background: var(--primary-muted);
}

/* ========================================
   Container & Layout
   ======================================== */
.container {
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 24px;
    z-index: 1;
}

@media (max-width: 768px) {
    .container {
        padding: 20px 16px;
    }
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 48px;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Header
   ======================================== */
.header {
    text-align: center;
}

.header-content {
    position: relative;
}

.title-section {
    margin-bottom: 24px;
}

.main-title {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
}

.main-title .highlight {
    color: var(--primary);
    font-style: italic;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.8;
}

.header-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

@media (min-width: 768px) {
    .header-actions {
        position: absolute;
        right: 0;
        top: 0;
        margin-top: 0;
    }
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-muted);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: var(--primary-muted);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 12px;
}

.btn-ghost:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-muted);
    border-radius: 50%;
}

.btn-icon:hover {
    border-color: var(--primary);
    background: var(--primary-muted);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-xs {
    padding: 4px 10px;
    font-size: 11px;
}

/* ========================================
   Icons
   ======================================== */
.icon {
    width: 20px;
    height: 20px;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.icon-blue { color: #60a5fa; }
.icon-orange { color: #fb923c; }
.icon-purple { color: #c084fc; }
.icon-red { color: #f87171; }
.icon-primary { color: var(--primary); }

/* Theme Toggle Icons */
#themeToggle {
    position: relative;
}

.sun-icon, .moon-icon {
    position: absolute;
    transition: opacity 0.3s, transform 0.3s;
}

body.dark .sun-icon {
    opacity: 1;
    transform: rotate(0deg);
}

body.dark .moon-icon {
    opacity: 0;
    transform: rotate(-90deg);
}

body:not(.dark) .sun-icon {
    opacity: 0;
    transform: rotate(90deg);
}

body:not(.dark) .moon-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* ========================================
   IP Display Section
   ======================================== */
.ip-display-section {
    text-align: center;
    padding: 32px 0;
}

.ip-main {
    margin-bottom: 32px;
}

.ip-address {
    font-size: clamp(2.5rem, 12vw, 6rem);
    font-weight: 900;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Consolas', monospace;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
    word-break: break-all;
}

.ip-location {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.flag-emoji {
    font-size: 2.5rem;
}

.flag-placeholder {
    width: 48px;
    height: 36px;
    background: var(--bg-muted);
    border-radius: 4px;
}

/* ========================================
   Search Box
   ======================================== */
.search-box {
    display: flex;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-card);
    border: 1px solid var(--border-muted);
    border-radius: 9999px;
    padding: 4px;
    box-shadow: var(--shadow);
}

.search-box input {
    flex: 1;
    padding: 12px 20px;
    font-size: 14px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ========================================
   Main Grid
   ======================================== */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}

@media (min-width: 1024px) {
    .main-grid {
        grid-template-columns: 2fr 1fr;
    }
}

.left-column, .right-column {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-muted);
    border-radius: 24px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

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

.card-content {
    padding: 24px;
}

/* ========================================
   Info Card
   ======================================== */
.info-card {
    padding: 20px 24px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 48px;
}

@media (min-width: 768px) {
    .info-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-muted);
}

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

.info-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.info-label .icon {
    width: 18px;
    height: 18px;
}

.info-value {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.link-text {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
    transition: color 0.2s;
}

.link-text:hover {
    color: var(--primary);
}

/* ========================================
   Latency Card
   ======================================== */
.latency-card .card-content {
    padding: 0 24px 24px;
}

.avg-latency {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
}

.latency-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

@media (min-width: 640px) {
    .latency-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.latency-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.latency-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.latency-icon {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    object-fit: contain;
}

.latency-name {
    font-size: 13px;
    font-weight: 700;
    opacity: 0.8;
}

.latency-tag {
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 9999px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.latency-tag.cn {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.15);
}

.latency-tag.global {
    color: #10b981;
    background: rgba(16, 185, 129, 0.15);
}

.latency-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.latency-value {
    font-size: 13px;
    font-family: monospace;
    font-weight: 700;
}

.latency-value.fast { color: #10b981; }
.latency-value.medium { color: #f59e0b; }
.latency-value.slow { color: #ef4444; }

.latency-dots {
    display: flex;
    gap: 4px;
}

.latency-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bg-muted);
}

.latency-dot.active.fast { background: #10b981; }
.latency-dot.active.medium { background: #f59e0b; }
.latency-dot.active.slow { background: #ef4444; }

/* ========================================
   Server IP Card
   ======================================== */
.server-ip-card .card-content {
    padding: 16px;
}

.ip-source-item {
    padding: 20px;
    background: var(--bg-muted);
    border-radius: 16px;
}

.ip-source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.ip-source-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ip-source-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-family: monospace;
    margin-bottom: 16px;
}

.ip-source-detail {
    margin-bottom: 16px;
}

.detail-label {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
}

.ip-source-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.meta-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meta-value {
    font-size: 14px;
    font-weight: 500;
}

/* ========================================
   Sources Card
   ======================================== */
.sources-card .card-content {
    padding: 0 24px;
}

.sources-list {
    display: flex;
    flex-direction: column;
}

.source-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-color);
}

.source-item:last-child {
    border-bottom: none;
}

.source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.source-name {
    font-size: 14px;
    font-weight: 700;
}

.source-ip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.source-ip-label {
    font-size: 12px;
    font-family: monospace;
    color: var(--text-muted);
    font-weight: 600;
}

.source-ip-value {
    font-size: 14px;
    font-family: monospace;
    font-weight: 700;
}

.source-location {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ========================================
   Visitor Card
   ======================================== */
.visitor-info {
    margin-bottom: 20px;
}

.visitor-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.visitor-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.visitor-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.visitor-card-img {
    width: 100%;
    height: auto;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-muted);
}

.code-section {
    margin-bottom: 20px;
}

.code-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.code-input-group {
    display: flex;
    gap: 8px;
}

.code-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 12px;
    font-family: monospace;
    background: var(--bg-muted);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
}

.code-block {
    margin-bottom: 16px;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.code-header span {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.code-pre {
    padding: 14px;
    background: var(--bg-muted);
    border-radius: 8px;
    overflow-x: auto;
}

.code-pre code {
    font-size: 12px;
    font-family: 'SF Mono', Monaco, monospace;
    color: var(--text-secondary);
    word-break: break-all;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 0;
    opacity: 0.4;
}

.footer-line {
    width: 96px;
    height: 1px;
    background: var(--border-color);
}

.footer-text {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3em;
    text-align: center;
    color: var(--text-muted);
}

/* ========================================
   Skeleton Loading
   ======================================== */
.skeleton {
    display: inline-block;
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-secondary) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-sm { width: 80px; height: 16px; }
.skeleton-md { width: 140px; height: 24px; }
.skeleton-lg { width: 300px; height: 48px; }

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

/* ========================================
   Utilities
   ======================================== */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

/* ========================================
   Toast
   ======================================== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}