/* Global Variables & Settings */
:root {
    --bg-dark: #09070f;
    --bg-card: rgba(20, 16, 32, 0.45);
    --border-card: rgba(255, 255, 255, 0.08);
    
    --primary: #4facfe;
    --primary-glow: rgba(79, 172, 254, 0.4);
    --secondary: #00f2fe;
    --secondary-glow: rgba(0, 242, 254, 0.3);
    --accent: #f35588;
    --accent-glow: rgba(243, 85, 136, 0.4);
    
    --text-main: #ffffff;
    --text-muted: #8b8996;
    --text-dim: #5c5a69;
    
    --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* Background Animations */
.space-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #150e26 0%, var(--bg-dark) 100%);
}

.stars {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(1px 1px at 20px 30px, #fff, rgba(0,0,0,0)),
        radial-gradient(1px 1px at 40px 70px, #fff, rgba(0,0,0,0)),
        radial-gradient(1.5px 1.5px at 50px 160px, rgba(255,255,255,0.8), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 80px 120px, #fff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 150px 30px, rgba(255,255,255,0.7), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 250px 210px, #fff, rgba(0,0,0,0));
    background-repeat: repeat;
    background-size: 550px 550px;
    opacity: 0.25;
}

.glowing-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.12;
    z-index: 1;
    pointer-events: none;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: var(--primary);
    top: -10%;
    right: -10%;
    animation: floatOrb 20s infinite alternate ease-in-out;
}

.orb-2 {
    width: 600px;
    height: 600px;
    background: var(--accent);
    bottom: -15%;
    left: -15%;
    animation: floatOrb 25s infinite alternate-reverse ease-in-out;
}

@keyframes floatOrb {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(80px, 50px) scale(1.1); }
}

/* Glassmorphic Panels */
.panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-card);
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    z-index: 2;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.panel:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

/* Page Layout */
.app-container {
    position: relative;
    z-index: 2;
    max-width: 1300px;
    margin: 0 auto;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    min-height: 100vh;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
}

.back-link:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.05);
}

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

.logo-coin {
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
    transition: var(--transition);
}

.logo-text:hover .logo-coin {
    transform: scale(1.1) rotate(10deg);
}

h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, var(--text-main) 30%, var(--text-muted) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.server-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.server-badge i {
    width: 15px;
    height: 15px;
    color: var(--primary);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 25px;
}

.right-panel-group {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Left Panel & Speedometer */
.main-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    min-height: 480px;
    padding: 40px;
}

.gauge-wrapper {
    position: relative;
    width: 320px;
    height: 320px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.speedometer {
    width: 100%;
    height: 100%;
    transform: rotate(0deg);
}

.gauge-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.04);
    stroke-width: 14;
    stroke-linecap: round;
}

.gauge-fill {
    fill: none;
    stroke: url(#speed-grad);
    stroke-width: 14;
    stroke-linecap: round;
    /* Circumference of r=75 circle is ~471.2. 
       Arc length for 240 deg (the speedometer arc) is 240/360 * 471.2 = 314.1 */
    stroke-dasharray: 314.1 471.2;
    stroke-dashoffset: 314.1; /* Starts empty */
    transition: stroke-dashoffset 0.15s ease-out;
    filter: drop-shadow(0 0 6px var(--primary-glow));
}

.gauge-outer-ring {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 1.5;
    stroke-dasharray: 2 6;
}

.gauge-center {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 200px;
    text-align: center;
    z-index: 3;
}

.gauge-coin-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 140px;
    height: 140px;
    opacity: 0.08;
    pointer-events: none;
    z-index: 1;
    transition: all 0.5s ease;
    filter: drop-shadow(0 4px 15px rgba(0, 0, 0, 0.3));
}

.testing-pulse .gauge-coin-watermark {
    opacity: 0.15;
    animation: slow-spin-coin 25s linear infinite;
}

@keyframes slow-spin-coin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.phase-indicator {
    position: relative;
    z-index: 2;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-main);
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    margin-bottom: 5px;
    transition: var(--transition);
}

.speed-readout {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.speed-num {
    font-size: 58px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -2px;
    color: var(--text-main);
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    font-feature-settings: "tnum";
}

.speed-unit {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 5px;
}

.speed-progress-bar-container {
    position: relative;
    z-index: 2;
    width: 100px;
    height: 3px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
    margin-top: 15px;
    overflow: hidden;
}

.speed-progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    border-radius: 2px;
    transition: width 0.3s ease;
    box-shadow: 0 0 5px var(--primary-glow);
}

/* Action Buttons */
.action-buttons {
    width: 100%;
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.btn {
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 600;
    padding: 16px 28px;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

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

.btn-primary {
    flex: 1;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #000000;
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 172, 254, 0.6);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 70%);
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
    transform: scale(0.5);
}

.btn-primary:hover .btn-glow {
    opacity: 1;
    transform: scale(1);
    animation: rotateGlow 8s linear infinite;
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.btn-secondary:active:not(:disabled) {
    transform: translateY(0);
}

/* Realtime Chart Panel */
.chart-panel {
    padding: 24px 30px;
    height: 230px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

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

.panel-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header h3 i {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.chart-legend {
    display: flex;
    gap: 15px;
    font-size: 12px;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.color-dot.down { background: var(--secondary); }
.color-dot.up { background: var(--accent); }

.chart-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: calc(100% - 30px);
}

#speed-chart {
    width: 100%;
    height: 100%;
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 20px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-card);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 130px;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.card-title span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title i {
    width: 16px;
    height: 16px;
}

.icon-down { color: var(--secondary); }
.icon-up { color: var(--accent); }
.icon-ping { color: var(--primary); }
.icon-jitter { color: #f6d365; }
.icon-loss { color: #fda085; }

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.stat-card.active .badge {
    background: rgba(79, 172, 254, 0.15);
    color: var(--primary);
    animation: blink 1s infinite alternate;
}

@keyframes blink {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.card-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-main);
    margin: 8px 0;
    font-feature-settings: "tnum";
}

.card-value small {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 2px;
}

.sub-metrics {
    display: flex;
    gap: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 10px;
    margin-top: 5px;
}

.sub-item {
    display: flex;
    flex-direction: column;
}

.sub-label {
    font-size: 11px;
    color: var(--text-dim);
}

.sub-val {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    font-feature-settings: "tnum";
}

.mini-card {
    min-height: 95px;
    padding: 16px 20px;
    grid-column: span 1;
}

.card-value.mini {
    font-size: 22px;
    margin: 4px 0 0;
}

.card-value.mini small {
    font-size: 12px;
}

/* If screen fits, span the last element or make them flex */
.stats-grid > div:nth-child(3) { grid-column: span 1; }
.stats-grid > div:nth-child(4) { grid-column: span 1; }
.stats-grid > div:nth-child(5) { grid-column: span 2; } /* Packet loss span entire row width */

/* Info Section (ISP & AIM scores) */
.info-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.info-panel h3, .score-panel h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
}

.info-panel h3 i, .score-panel h3 i {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

.info-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.info-val {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* AIM Scores */
.score-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    padding: 12px 20px;
    border-radius: 16px;
    transition: var(--transition);
}

.score-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

.score-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(79, 172, 254, 0.1);
    color: var(--primary);
}

.score-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
}

.score-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

.score-rating {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
}

/* Score rating color coding */
.rating-great { color: #00f2fe; text-shadow: 0 0 10px rgba(0, 242, 254, 0.3); }
.rating-good { color: #38ef7d; text-shadow: 0 0 10px rgba(56, 239, 125, 0.3); }
.rating-average { color: #f6d365; text-shadow: 0 0 10px rgba(246, 211, 101, 0.3); }
.rating-poor { color: #fda085; text-shadow: 0 0 10px rgba(253, 160, 133, 0.3); }
.rating-bad { color: #f35588; text-shadow: 0 0 10px rgba(243, 85, 136, 0.3); }

/* Footer */
footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 30px 0;
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

footer p {
    font-size: 12px;
    color: var(--text-dim);
}

footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary);
}

/* Animations during testing */
.testing-pulse {
    animation: testingPulse 2s infinite alternate ease-in-out;
}

@keyframes testingPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.01); border-color: var(--primary-glow); }
}

/* Media Queries for Responsiveness */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .main-panel {
        min-height: auto;
        padding: 30px;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 15px 10px;
        gap: 15px;
    }
    
    h1 {
        font-size: 20px;
    }
    
    .server-badge {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    .gauge-wrapper {
        width: 260px;
        height: 260px;
    }
    
    .speed-num {
        font-size: 44px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid > div:nth-child(5) {
        grid-column: span 1;
    }
    
    .info-section {
        grid-template-columns: 1fr;
    }
    
    .info-list {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}
