/* ================================================================
   TypoBlitz — Premium UI Overhaul
   Dark glassmorphism, violet/cyan accent, micro-animations
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;500;600&display=swap');

/* ---- Design Tokens ---- */
:root {
    --bg:            #0a0a0f;
    --bg-2:          #0f0f18;
    --surface:       #13131f;
    --surface-2:     #1a1a2e;
    --surface-3:     #1f1f35;
    --border:        rgba(255,255,255,0.07);
    --border-glow:   rgba(139,92,246,0.4);

    --primary:       #8b5cf6;
    --primary-light: #a78bfa;
    --primary-dark:  #6d28d9;
    --cyan:          #06d6d6;
    --cyan-dim:      rgba(6,214,214,0.15);
    --gold:          #f59e0b;

    --text-1:        #f1f0ff;
    --text-2:        #9997b3;
    --text-3:        #5a5875;

    --correct:       #06d6d6;
    --correct-dim:   rgba(6,214,214,0.12);
    --wrong:         #f43f5e;
    --wrong-dim:     rgba(244,63,94,0.18);

    --font-ui:   'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;

    --radius-sm:  8px;
    --radius-md:  14px;
    --radius-lg:  20px;
    --radius-xl:  28px;

    --shadow-sm:  0 2px 12px rgba(0,0,0,0.4);
    --shadow-md:  0 8px 32px rgba(0,0,0,0.6);
    --shadow-lg:  0 20px 60px rgba(0,0,0,0.7);
    --glow-v:     0 0 30px rgba(139,92,246,0.25);
    --glow-c:     0 0 30px rgba(6,214,214,0.2);
}

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

html { scroll-behavior: smooth; }

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(139,92,246,0.12), transparent),
        radial-gradient(ellipse 50% 40% at 80% 80%, rgba(6,214,214,0.06), transparent);
    color: var(--text-1);
    font-family: var(--font-ui);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 12px;
    line-height: 1.6;
}

/* ---- Sidebar Ads ---- */
.ad-sidebar {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    height: 600px;
    background: rgba(255,255,255,0.02);
    border: 1px dashed rgba(255,255,255,0.08);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-3);
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.8;
    z-index: 100;
    letter-spacing: 0.5px;
}
.ad-sidebar-left  { left: 10px; }
.ad-sidebar-right { right: 10px; }

/* ---- App Container ---- */
.app-container {
    max-width: 860px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ---- Header ---- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    gap: 1rem;
    backdrop-filter: blur(12px);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1;
}
.logo h1 .typo { color: var(--text-1); }
.accent { color: var(--primary-light); }

nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
nav a {
    color: var(--text-2);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 30px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}
nav a:hover {
    color: var(--text-1);
    background: rgba(255,255,255,0.06);
}
nav a.active {
    color: var(--primary-light);
    background: rgba(139,92,246,0.12);
    font-weight: 600;
}

/* ---- Card base ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

/* ---- Config Bar ---- */
.config-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.name-input {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text-1);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    width: 230px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.name-input::placeholder { color: var(--text-3); }
.name-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.15);
}

/* Stopwatch */
.stopwatch-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(139,92,246,0.08);
    border: 1px solid rgba(139,92,246,0.25);
    padding: 8px 20px;
    border-radius: 40px;
    transition: box-shadow 0.3s;
}
.stopwatch-display.running {
    border-color: rgba(139,92,246,0.5);
    box-shadow: var(--glow-v);
}
.sw-icon { font-size: 1.1rem; }
#stopwatch-time {
    font-family: var(--font-mono);
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--primary-light);
    min-width: 76px;
    text-align: center;
    letter-spacing: 1px;
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- CTA Panel ---- */
.cta-panel {
    text-align: center;
    padding: 1.5rem 0 0.5rem;
    animation: fadeIn 0.3s ease;
}
.cta-hint {
    color: var(--text-2);
    font-size: 0.95rem;
    margin-bottom: 1.2rem;
}

/* ---- Typing Shell ---- */
.typing-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s;
    position: relative;
}
.typing-container.active-typing {
    border-color: rgba(139,92,246,0.35);
    box-shadow: var(--glow-v), var(--shadow-md);
}

/* Progress bar at top of typing area */
.typing-progress-bar {
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--cyan));
    width: 0%;
    transition: width 0.15s linear;
    border-radius: 3px 3px 0 0;
}

/* ---- Text Display ---- */
.text-display {
    font-family: var(--font-mono);
    font-size: 1.45rem;
    line-height: 2;
    letter-spacing: 0.3px;
    max-height: 320px;
    overflow-y: auto;
    color: var(--text-2);
    padding: 2rem 2.5rem;
    user-select: none;
    cursor: text;
    scroll-behavior: smooth;
    word-break: break-word;
}

.text-display::-webkit-scrollbar { width: 4px; }
.text-display::-webkit-scrollbar-track { background: transparent; }
.text-display::-webkit-scrollbar-thumb {
    background: rgba(139,92,246,0.3);
    border-radius: 2px;
}

.text-display span { transition: color 0.06s; }

.text-display span.correct {
    color: var(--correct);
}
.text-display span.incorrect {
    color: var(--wrong);
    background: var(--wrong-dim);
    border-radius: 3px;
}
.text-display span.cursor {
    border-left: 2px solid var(--primary-light);
    animation: blink 0.85s steps(1) infinite;
}
@keyframes blink {
    50% { border-color: transparent; }
}

/* Hidden Input */
#hidden-input {
    opacity: 0;
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 1px;
    z-index: 1;
    pointer-events: none;
}

/* Typing Footer */
.typing-footer {
    padding: 1rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.75rem;
}
.char-counter {
    font-size: 0.8rem;
    color: var(--text-3);
    font-family: var(--font-mono);
}

/* ---- Action Buttons ---- */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,0.04);
    color: var(--text-2);
    border: 1px solid var(--border);
    padding: 9px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
}
.action-btn:hover {
    color: var(--text-1);
    border-color: rgba(139,92,246,0.4);
    background: rgba(139,92,246,0.08);
    transform: translateY(-1px);
}
.action-btn:active { transform: translateY(0); }
.action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    font-weight: 700;
    box-shadow: 0 4px 18px rgba(109,40,217,0.4);
    font-size: 1rem;
    padding: 12px 28px;
}
.primary-btn:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    box-shadow: 0 6px 24px rgba(139,92,246,0.5);
    color: #fff;
    border-color: transparent;
    transform: translateY(-2px);
}

/* ---- Results ---- */
.results-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.results-container h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--text-2);
    letter-spacing: -0.5px;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-size: 0.85rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-box {
    background: var(--surface-2);
    padding: 1.4rem 1rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid var(--border);
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}
.stat-box::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--cyan));
    opacity: 0;
    transition: opacity 0.2s;
}
.stat-box:hover { transform: translateY(-4px); border-color: var(--border-glow); }
.stat-box:hover::after { opacity: 1; }

.stat-label {
    font-size: 0.72rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0.6rem;
    font-weight: 600;
}
.stat-value {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--text-1);
    font-family: var(--font-mono);
    line-height: 1;
}
.stat-box:nth-child(1) .stat-value { color: var(--primary-light); }
.stat-box:nth-child(2) .stat-value { color: var(--cyan); }

.rating-box {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.2rem 2rem;
    margin: 0 auto 1.8rem;
    max-width: 420px;
}
.rating-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}
.rating-msg {
    color: var(--text-2);
    font-size: 0.9rem;
}

.submit-section { margin-top: 1.5rem; }
.submit-hint {
    color: var(--text-3);
    font-size: 0.88rem;
    margin-bottom: 1rem;
    transition: color 0.3s;
}
.result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---- Ad Placeholder ---- */
.ad-placeholder {
    width: 100%;
    background: rgba(255,255,255,0.02);
    border: 1px dashed rgba(255,255,255,0.07);
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-3);
    font-size: 0.85rem;
    border-radius: var(--radius-md);
    min-height: 90px;
}

/* ---- Leaderboard ---- */
.leaderboard-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.8rem;
}
.leaderboard-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.lb-tabs {
    display: flex;
    gap: 0.4rem;
    background: var(--bg-2);
    padding: 4px;
    border-radius: 30px;
    border: 1px solid var(--border);
}
.lb-tab {
    background: transparent;
    border: none;
    color: var(--text-3);
    padding: 6px 18px;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s;
}
.lb-tab:hover { color: var(--text-1); }
.lb-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px rgba(139,92,246,0.4);
}

.lb-loading {
    text-align: center;
    color: var(--text-3);
    padding: 2rem;
    font-size: 0.9rem;
    display: none;
}
.lb-loading::after {
    content: '';
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-left: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.table-responsive { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}
thead tr {
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--text-3);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 0 14px 12px;
}
td {
    padding: 13px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 0.92rem;
    color: var(--text-2);
}
tbody tr {
    transition: background 0.15s;
}
tbody tr:hover td { background: rgba(255,255,255,0.025); }
tbody tr:last-child td { border-bottom: none; }

.top-rank td { color: var(--text-1); }
.top-rank:nth-child(1) td:first-child { color: #fbbf24; }
.top-rank:nth-child(2) td:first-child { color: #94a3b8; }
.top-rank:nth-child(3) td:first-child { color: #cd7c3a; }

.rank-cell {
    font-size: 1.05rem;
    text-align: center;
    width: 56px;
}
.wpm-cell {
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--primary-light) !important;
}

.empty-state {
    text-align: center;
    color: var(--text-3);
    font-size: 0.9rem;
    padding: 3rem;
}

/* ---- Footer ---- */
footer {
    text-align: center;
    color: var(--text-3);
    font-size: 0.85rem;
    padding: 1rem 0 0.5rem;
}
footer a {
    color: var(--primary-light);
    text-decoration: none;
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Subpages ---- */
.subpage-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease;
}
.subpage-content h2 {
    margin-bottom: 1.2rem;
    color: var(--primary-light);
    font-size: 1.5rem;
    font-weight: 700;
}
.subpage-content h3 {
    margin-top: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-1);
    font-size: 1rem;
    font-weight: 600;
}
.subpage-content p {
    color: var(--text-2);
    margin-bottom: 1rem;
    line-height: 1.8;
    font-size: 0.95rem;
}
.subpage-content ul {
    color: var(--text-2);
    margin-left: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1.9;
    font-size: 0.95rem;
}
.subpage-content a { color: var(--primary-light); text-decoration: none; }
.subpage-content a:hover { text-decoration: underline; }

/* ---- Contact Form ---- */
.contact-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}
.contact-form input,
.contact-form textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text-1);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.contact-form input::placeholder,
.contact-form textarea::placeholder { color: var(--text-3); }
.contact-form input:focus,
.contact-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
    .ad-sidebar { display: none; }
}

@media (max-width: 700px) {
    body { padding: 16px 10px; }
    .text-display { font-size: 1.15rem; padding: 1.5rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .config-bar { flex-direction: column; align-items: stretch; }
    .name-input { width: 100%; }
    header { flex-direction: column; text-align: center; }
    nav { margin-top: 6px; }
    nav a { margin: 0 6px; }
    .leaderboard-header { flex-direction: column; align-items: flex-start; }
    #stopwatch-time { font-size: 1.15rem; }
    .typing-footer { padding: 0.75rem 1.5rem; }
    .results-container { padding: 1.5rem 1rem; }
}

@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .app-container { gap: 1rem; }
    .stat-value { font-size: 1.9rem; }
}
