:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --accent: #00d2ff;
    --accent-green: #00c853;
    --accent-red: #ff1744;
    --accent-yellow: #ffd600;
    --accent-orange: #ff9100;
    --radius: 12px;
    --radius-lg: 20px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    direction: rtl;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
}

.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

.screen-content {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.screen-content.center {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.screen-header h2 {
    font-size: 20px;
    flex: 1;
}

/* ── Auth ── */
.logo {
    font-size: 64px;
    margin-bottom: 16px;
}

.screen-content h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-card);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Home ── */
.home-header {
    margin-bottom: 24px;
}

.profile-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
}

.rank-badge {
    font-size: 14px;
    color: var(--accent-yellow);
    margin-bottom: 8px;
}

.profile-card h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.score-display {
    font-size: 18px;
    color: var(--accent);
    font-weight: 600;
}

.home-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

.stat-item {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 16px 8px;
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.home-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.home-actions .btn-secondary {
    flex: 1;
}

/* ── Buttons ── */
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #0099cc);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
    width: 100%;
}

.btn-primary:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.btn-large {
    padding: 18px 32px;
    font-size: 18px;
    border-radius: var(--radius-lg);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.15s;
}

.btn-secondary:active {
    transform: scale(0.97);
}

.btn-back {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Searching ── */
.search-animation {
    position: relative;
    width: 120px;
    height: 120px;
    margin-bottom: 32px;
}

.search-ring {
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1.2s linear infinite;
}

.search-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
}

.search-dots {
    display: flex;
    gap: 8px;
    margin: 24px 0;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Match Found ── */
.match-found-icon {
    font-size: 64px;
    margin-bottom: 16px;
    animation: bounce 0.6s ease;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.opponent-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin: 24px 0;
    width: 100%;
    max-width: 300px;
}

.opponent-avatar {
    font-size: 48px;
    margin-bottom: 8px;
}

.opponent-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.opponent-games {
    color: var(--text-secondary);
    font-size: 14px;
}

.countdown-number {
    font-size: 72px;
    font-weight: 700;
    color: var(--accent);
    animation: countdownPop 0.5s ease;
    margin-top: 24px;
}

@keyframes countdownPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ── Game ── */
.game-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.game-progress {
    flex: 1;
}

.progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.progress-bar {
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.game-score {
    text-align: center;
}

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

.score-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.timer-container {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.timer-circle {
    position: relative;
    width: 72px;
    height: 72px;
}

.timer-circle svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.timer-bg {
    fill: none;
    stroke: var(--bg-secondary);
    stroke-width: 4;
}

.timer-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-fill.warning {
    stroke: var(--accent-orange);
}

.timer-fill.danger {
    stroke: var(--accent-red);
}

.timer-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}

.difficulty-badge {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.question-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    text-align: center;
}

.question-text {
    font-size: 18px;
    line-height: 1.6;
    font-weight: 500;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: 16px;
    color: var(--text-primary);
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: right;
}

.option-btn:active {
    transform: scale(0.98);
}

.option-btn.selected {
    border-color: var(--accent);
    background: rgba(0, 210, 255, 0.1);
}

.option-btn.correct {
    border-color: var(--accent-green);
    background: rgba(0, 200, 83, 0.15);
}

.option-btn.wrong {
    border-color: var(--accent-red);
    background: rgba(255, 23, 68, 0.15);
}

.option-btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.option-letter {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    font-size: 16px;
    flex-shrink: 0;
}

.option-text {
    flex: 1;
    line-height: 1.4;
}

/* ── Result ── */
.result-icon {
    font-size: 72px;
    margin-bottom: 16px;
    animation: bounce 0.6s ease;
}

.result-scoreboard {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 32px 0;
    width: 100%;
    max-width: 360px;
}

.result-player {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px 12px;
    text-align: center;
}

.result-player.you {
    border: 2px solid var(--accent);
}

.result-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.result-correct {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-green);
    margin-bottom: 4px;
}

.result-score {
    font-size: 14px;
    color: var(--accent);
}

.result-vs {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

/* ── Leaderboard ── */
.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab.active {
    background: var(--bg-card);
    color: var(--accent);
    border-color: var(--accent);
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lb-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.lb-item.top-3 {
    background: var(--bg-card);
    border: 1px solid rgba(255, 214, 0, 0.2);
}

.lb-rank {
    width: 28px;
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    color: var(--accent-yellow);
}

.lb-info {
    flex: 1;
}

.lb-name {
    font-size: 14px;
    font-weight: 500;
}

.lb-score {
    font-size: 12px;
    color: var(--text-secondary);
}

.lb-emoji {
    font-size: 18px;
}

/* ── Profile Detail ── */
.profile-detail {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.profile-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 16px;
}

.profile-section h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.profile-stat {
    text-align: center;
}

.profile-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
}

.profile-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.recent-results {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 8px;
}

.result-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.result-dot.win { background: rgba(0, 200, 83, 0.2); color: var(--accent-green); }
.result-dot.loss { background: rgba(255, 23, 68, 0.2); color: var(--accent-red); }
.result-dot.draw { background: rgba(255, 214, 0, 0.2); color: var(--accent-yellow); }

/* ── Utilities ── */
.hidden { display: none !important; }

@media (max-width: 360px) {
    .option-btn { padding: 12px; font-size: 14px; }
    .question-text { font-size: 16px; }
}
