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

:root {
    --stats-bg: #030611;
    --stats-card: rgba(10, 15, 32, 0.9);
    --stats-border: rgba(255, 255, 255, 0.08);
    --stats-text: #f2f5ff;
    --stats-muted: rgba(239, 244, 255, 0.7);
    --stats-accent: #4cf5ff;
    --stats-secondary: #8f9bbf;
    --stats-surface: rgba(255, 255, 255, 0.04);
    --stats-success: #6dd4b1;
}

[data-theme='light'] {
    --stats-bg: #f6f8ff;
    --stats-card: rgba(255, 255, 255, 0.9);
    --stats-border: rgba(15, 35, 71, 0.12);
    --stats-text: #0b1f3f;
    --stats-muted: rgba(11, 31, 63, 0.6);
    --stats-accent: #2f6df4;
    --stats-secondary: rgba(11, 31, 63, 0.5);
    --stats-surface: rgba(255, 255, 255, 0.85);
    --stats-success: #0f9f7c;
}

body.stats-body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Noto Kufi Arabic', 'Inter', sans-serif;
    background:
        radial-gradient(circle at top, rgba(76, 245, 255, 0.08), rgba(3, 6, 17, 0.95)),
        var(--stats-bg);
    color: var(--stats-text);
    padding: 2rem clamp(1rem, 4vw, 3rem);
    position: relative;
    padding-top: 90px;
}

.stats-gridlines {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 120px 120px;
    pointer-events: none;
    z-index: 0;
}

.unified-nav {
    position: fixed;
    top: 18px;
    left: 18px;
    right: auto;
    z-index: 10;
    background: rgba(3, 6, 17, 0.45);
    border: 1px solid var(--stats-border);
    border-radius: 22px;
    padding: 0.35rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.unified-nav[dir='rtl'] {
    left: auto;
    right: 18px;
}

.unified-nav__toggle {
    border: 1px solid var(--stats-border);
    background: rgba(4, 9, 23, 0.92);
    color: var(--stats-text);
    border-radius: 20px;
    padding: 0.45rem 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    width: 100%;
    justify-content: space-between;
}

.unified-nav[dir='rtl'] .unified-nav__toggle {
    flex-direction: row-reverse;
}

.unified-nav__dots {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.unified-nav__dot {
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: currentColor;
}

.unified-nav__context {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.unified-nav__panel {
    position: absolute;
    top: 62px;
    left: 0;
    right: auto;
    width: 260px;
    padding: 1rem;
    border-radius: 20px;
    border: 1px solid var(--stats-border);
    background: rgba(4, 9, 23, 0.98);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    display: none;
    transform-origin: top left;
}

.unified-nav[dir='rtl'] .unified-nav__panel {
    left: auto;
    right: 0;
    transform-origin: top right;
}

.unified-nav.is-open .unified-nav__panel {
    display: block;
    animation:
        fadeSlide 0.25s ease,
        scaleDrop 0.3s ease;
}

.unified-nav__panel-head {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.unified-nav__panel-head strong {
    display: block;
    font-size: 0.85rem;
}

.unified-nav__panel-head span {
    color: var(--stats-secondary);
    font-size: 0.75rem;
}

.unified-nav[dir='ltr'] .unified-nav__panel-head,
.unified-nav[dir='ltr'] .unified-nav__status,
.unified-nav[dir='ltr'] .unified-nav__languages,
.unified-nav[dir='ltr'] .unified-nav__link {
    text-align: left;
}

.unified-nav[dir='ltr'] .unified-nav__languages-list {
    justify-content: flex-start;
}

.unified-nav__link {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    text-decoration: none;
    color: var(--stats-text);
    transition:
        background 0.2s,
        color 0.2s,
        border-color 0.2s;
    border: 1px solid transparent;
}

.unified-nav__link:hover {
    background: rgba(76, 245, 255, 0.15);
    color: var(--stats-accent);
}

.unified-nav__link--action {
    border: 1px solid rgba(255, 255, 255, 0.12);
    margin-bottom: 0.35rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.08);
    color: var(--stats-text);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

[data-theme='light'] .unified-nav__link--action {
    background: rgba(11, 31, 63, 0.05);
    border-color: rgba(11, 31, 63, 0.2);
    color: #0b1f3f;
}

.unified-nav__theme-switch {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.55rem 0.65rem;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    color: var(--stats-text);
    font-size: 0.85rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

[data-theme='light'] .unified-nav__theme-switch {
    background: rgba(11, 31, 63, 0.05);
    border-color: rgba(11, 31, 63, 0.2);
    color: #0b1f3f;
}

.unified-nav__theme-switch-icon {
    width: 32px;
    height: 32px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.unified-nav__theme-switch-icon svg {
    width: 22px;
    height: 22px;
    position: absolute;
    transition:
        opacity 0.3s ease,
        transform 0.3s ease;
}

.unified-nav__moon {
    color: #7cf5ff;
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 6px rgba(124, 245, 255, 0.4));
}

.unified-nav__sun {
    color: #ffa24c;
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
    filter: drop-shadow(0 0 6px rgba(255, 162, 76, 0.4));
}

[data-theme='light'] .unified-nav__moon {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

[data-theme='light'] .unified-nav__sun {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.unified-nav__link--google {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-start;
    text-align: left;
}

.unified-nav[dir='rtl'] .unified-nav__link--google {
    flex-direction: row-reverse;
    text-align: right;
}

.unified-nav[dir='ltr'] .unified-nav__link--google {
    flex-direction: row;
}

.unified-nav__google-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.unified-nav__status {
    padding: 0.55rem 0.65rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: 0.4rem;
}

.unified-nav__status strong {
    display: block;
    font-size: 0.8rem;
}

.unified-nav__status span {
    display: block;
    font-size: 0.75rem;
    color: var(--stats-secondary);
}

.unified-nav__languages {
    margin-top: 0.5rem;
}

.unified-nav__languages span {
    font-size: 0.75rem;
    color: var(--stats-secondary);
}

.unified-nav__languages-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.35rem;
}

.unified-nav__language {
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-decoration: none;
    color: var(--stats-text);
    font-size: 0.78rem;
}

.unified-nav__language.is-active {
    background: rgba(76, 245, 255, 0.18);
    border-color: rgba(76, 245, 255, 0.45);
}

[data-theme='light'] .unified-nav__language {
    border-color: rgba(15, 35, 71, 0.2);
    color: #0b1f3f;
}

[data-theme='light'] .unified-nav__language.is-active {
    background: rgba(47, 109, 244, 0.15);
    border-color: rgba(47, 109, 244, 0.4);
}

.unified-nav__link--google {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    justify-content: center;
}

.unified-nav__google-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    color: #4285f4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

@keyframes scaleDrop {
    from {
        transform: scale(0.96);
    }
    to {
        transform: scale(1);
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

[data-theme='light'] .unified-nav__toggle {
    background: rgba(255, 255, 255, 0.9);
    color: #0b1f3f;
}

[data-theme='light'] .unified-nav__panel {
    background: rgba(255, 255, 255, 0.95);
    color: #0b1f3f;
}

.stats-header {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stats-badge {
    display: inline-flex;
    padding: 0.25rem 0.8rem;
    border-radius: 999px;
    background: rgba(76, 245, 255, 0.12);
    color: var(--stats-accent);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.stats-header h1 {
    margin: 0.2rem 0;
    font-size: clamp(1.5rem, 2vw, 2rem);
}

.stats-header p {
    margin: 0;
    color: var(--stats-muted);
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.header-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.5rem;
    border-radius: 999px;
    border: 1px solid var(--stats-border);
    color: var(--stats-text);
    text-decoration: none;
    font-size: 0.95rem;
    transition:
        background 0.3s,
        border-color 0.3s;
}

.header-link:hover {
    border-color: var(--stats-accent);
    background: rgba(76, 245, 255, 0.1);
}

.header-link--ghost {
    background: transparent;
    color: var(--stats-muted);
}

.card {
    position: relative;
    z-index: 1;
    background: var(--stats-card);
    border: 1px solid var(--stats-border);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: 0 15px 40px rgba(3, 6, 17, 0.55);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.summary-card p {
    margin: 0;
    color: var(--stats-muted);
    font-size: 0.95rem;
}

.summary-card strong {
    display: block;
    margin: 0.8rem 0 0.4rem;
    font-size: 2rem;
    color: var(--stats-accent);
    font-variant-numeric: tabular-nums;
}

.summary-card span {
    color: var(--stats-secondary);
    font-size: 0.85rem;
}

/* Social Share Card Styles */
.summary-card--social {
    background: linear-gradient(135deg, rgba(76, 245, 255, 0.08) 0%, rgba(76, 245, 255, 0.02) 100%);
}

.summary-card--social .social-share-content {
    margin-top: 0.75rem;
}

/* Streak Card Styles */
.summary-card--streak {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.08) 0%, rgba(251, 191, 36, 0.02) 100%);
    border-color: rgba(251, 191, 36, 0.25);
}

.summary-card--streak .streak-number {
    color: #f59e0b;
    font-size: 2.5rem;
}

.summary-card--streak .streak-best {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(251, 191, 36, 0.12);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--stats-muted);
}

.summary-card--streak .streak-best strong {
    color: #f59e0b;
    font-size: 1.1rem;
    display: inline;
    margin: 0;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    min-height: 0;
    height: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-frame {
    flex: 1;
    min-height: 0;
    height: 240px;
}

.chart-frame canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.card-head h2 {
    margin: 0;
    font-size: 1.1rem;
}

.card-head span {
    color: var(--stats-secondary);
    font-size: 0.9rem;
}

[data-theme='light'] .card-head span {
    color: rgba(11, 31, 63, 0.75);
}

.phrase-table-card {
    margin-bottom: 2rem;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 480px;
}

thead th {
    text-align: right;
    padding: 0.75rem 0.5rem;
    color: var(--stats-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--stats-border);
    vertical-align: middle;
}

tbody td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    text-align: right;
    vertical-align: top;
}

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

tbody td strong {
    display: block;
    font-weight: 700;
    line-height: 1.4;
}

tbody td span {
    display: block;
    color: var(--stats-secondary);
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Ensure numeric columns align properly */
thead th.number-ltr,
tbody td.number-ltr {
    font-variant-numeric: tabular-nums;
    text-align: left;
}

tbody td.number-ltr {
    vertical-align: middle;
}

.number-ltr {
    direction: ltr;
    font-variant-numeric: tabular-nums;
}

.stats-empty {
    text-align: center;
}

.stats-empty h2 {
    margin-top: 0;
}

.stats-empty p {
    color: var(--stats-muted);
}

.empty-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.time-range-selector {
    margin-bottom: 2rem;
}

.time-range-selector h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--stats-text);
}

.range-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.range-btn {
    padding: 0.65rem 1.35rem;
    border-radius: 999px;
    border: 1px solid var(--stats-border);
    background: var(--stats-surface);
    color: var(--stats-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.25s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.range-btn:hover {
    border-color: var(--stats-accent);
    background: rgba(76, 245, 255, 0.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 245, 255, 0.15);
}

.range-btn--active {
    background: rgba(76, 245, 255, 0.18);
    border-color: var(--stats-accent);
    color: var(--stats-accent);
    box-shadow: 0 0 0 2px rgba(76, 245, 255, 0.1);
    font-weight: 600;
}

.range-btn--active:hover {
    transform: none;
}

[data-theme='light'] .range-btn {
    background: rgba(11, 31, 63, 0.03);
}

[data-theme='light'] .range-btn:hover {
    border-color: var(--stats-accent);
    background: rgba(47, 109, 244, 0.08);
    box-shadow: 0 4px 12px rgba(47, 109, 244, 0.12);
}

[data-theme='light'] .range-btn--active {
    background: rgba(47, 109, 244, 0.15);
    border-color: var(--stats-accent);
    color: var(--stats-accent);
    box-shadow: 0 0 0 2px rgba(47, 109, 244, 0.08);
}

.stats-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    color: var(--stats-secondary);
    font-size: 0.85rem;
}

@media (max-width: 720px) {
    .stats-header {
        flex-direction: column;
    }

    .card {
        padding: 1.25rem;
    }
}

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

/* Streak Section */
.streak-section {
    margin: 2rem 0;
}

.streak-card {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.08) 0%, rgba(251, 191, 36, 0.02) 100%);
    border: 2px solid rgba(251, 191, 36, 0.25);
}

.streak-header {
    padding: 1.5rem 2rem 0;
}

.streak-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f59e0b;
    margin: 0;
}

.streak-content {
    padding: 2rem;
}

.streak-current {
    text-align: center;
}

.streak-number-large {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1;
    background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.streak-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.streak-message {
    font-size: 1.125rem;
    line-height: 1.7;
    color: var(--text-primary);
    max-width: 500px;
    margin: 0 auto 1.5rem;
}

.streak-record {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(251, 191, 36, 0.12);
    border-radius: 12px;
    border: 1px solid rgba(251, 191, 36, 0.2);
    margin-top: 1.5rem;
}

.streak-record span {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.streak-record strong {
    font-size: 1.5rem;
    font-weight: 800;
    color: #f59e0b;
}

.streak-empty {
    text-align: center;
    padding: 2rem 1rem;
}

.streak-empty p {
    font-size: 1.125rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin: 0 0 1.5rem;
}
