/* Mobile-First Professional Math Game */

:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);

    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);

    --top-bar-height: calc(60px + var(--safe-top));
    --bottom-nav-height: calc(65px + var(--safe-bottom));
    --app-height: 100vh;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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

html {
    width: 100%;
    height: var(--app-height, 100vh);
    min-height: var(--app-height, 100vh);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body {
    width: 100%;
    height: var(--app-height, 100vh);
    min-height: var(--app-height, 100vh);
    overflow: hidden;
    position: relative; /* Changed from fixed to relative for iOS compatibility */
    margin: 0;
    padding: 0;
}

/* App Layout */
#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: var(--app-height, 100vh);
    min-height: var(--app-height, 100vh);
    overflow: hidden;
    position: relative;
}

/* Top Bar */
.top-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    padding-top: var(--safe-top);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    display: flex;
    align-items: center;
    padding-left: max(16px, var(--safe-left));
    padding-right: max(16px, var(--safe-right));
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    position: relative;
}

/* Add subtle shine effect to top bar */
.top-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, transparent 100%);
    pointer-events: none;
}

.top-bar h1 {
    font-size: 1.3rem;
    font-weight: 800;
    flex: 1;
    text-align: center;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.icon-btn {
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 1;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

/* Profile button special styling */
#profileBtn {
    font-size: 1.4rem;
}

/* Coins button styling */
#coinsBtn {
    border-radius: 22px;
    padding: 0 12px;
    min-width: auto;
    font-weight: 600;
    font-size: 0.95rem;
}

#coinsCount {
    margin-left: 2px;
}

/* XP Bar */
.xp-bar-container {
    position: sticky;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    background: var(--surface);
    padding: 10px max(16px, var(--safe-left)) 14px max(16px, var(--safe-right));
    z-index: 99;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.xp-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
}

#playerLevel {
    color: var(--primary);
    font-size: 0.95rem;
}

#xpProgress {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}

.xp-bar {
    height: 10px;
    background: var(--bg);
    border-radius: 5px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 5px;
    transition: width 0.5s ease;
    position: relative;
    box-shadow: 0 1px 3px rgba(102, 126, 234, 0.4);
}

/* Add shine effect to XP fill */
.xp-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, transparent 100%);
    border-radius: 5px 5px 0 0;
}

.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.hidden {
    display: none !important;
}

/* Pages Container */
.pages-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}

/* Page */
.page {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    padding-bottom: calc(var(--bottom-nav-height) + 20px);
    background: var(--bg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s;
    /* Fix for keyboard on iOS - prevent layout shift */
    min-height: 0;
    max-height: 100%;
}

.page.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 12px var(--shadow);
    z-index: 100;
    border-top: 1px solid var(--border);
    transition: transform 0.3s ease, opacity 0.3s ease;
    /* iOS Safari fixes for true bottom sticky */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: transform;
    /* Force GPU acceleration for smoother animation */
    -webkit-perspective: 1000;
    perspective: 1000;
}

.bottom-nav.nav-hidden {
    /* Use display:none for iOS keyboard - most reliable method */
    display: none !important;
    transform: translateY(200vh) translateZ(0);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 52px;
    padding: 6px 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.7rem;
    font-weight: 500;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn svg {
    width: 24px;
    height: 24px;
}

.nav-btn:active {
    transform: scale(0.95);
}

/* Card */
.card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
    margin-bottom: 16px;
}

.card.gradient {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.home-hero-card {
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: right;
}

.home-hero-card .hero-avatar {
    font-size: 2.5rem;
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 14px;
}

.home-hero-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.home-hero-title {
    font-size: 1.15rem !important;
    margin: 0;
    font-weight: 600;
}

.home-hero-meta {
    font-size: 0.9rem;
    opacity: 0.9;
}

.guest-prompt {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    text-align: center;
    border: 2px dashed rgba(102, 126, 234, 0.3);
}

.guest-prompt-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.guest-prompt-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.guest-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.guest-btn {
    padding: 10px 20px;
    border-radius: 12px;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.guest-btn:active {
    transform: translateY(1px);
}

.guest-btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.guest-btn-secondary {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary);
}

.battle-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.04) 100%);
    padding: 16px;
}

.battle-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    direction: rtl;
}

.battle-card-header > div {
    flex: 1;
    text-align: right;
}

.battle-card-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.battle-card-header p {
    margin: 2px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.battle-card-icon {
    font-size: 2rem;
    background: white;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
    flex-shrink: 0;
}

.battle-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.battle-btn {
    padding: 12px 10px;
    border-radius: 12px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-align: center;
    direction: rtl;
}

.battle-btn:active {
    transform: translateY(1px);
}

.battle-btn.create {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    grid-column: 1 / -1;
}

.battle-btn.join {
    background: white;
    color: var(--primary);
    border: 2px solid rgba(102, 126, 234, 0.25);
}

.battle-match-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.battle-scoreboard {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.16) 0%, rgba(118, 75, 162, 0.08) 100%);
}

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

.battle-score .label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.battle-score .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.battle-score.opponent-score .value {
    color: #fa709a;
}

.battle-info {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.battle-match-content {
    border-radius: 18px;
    background: white;
    padding: 20px;
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.15);
    min-height: 220px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    justify-content: center;
}

.battle-question-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.battle-question-text {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.battle-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.battle-choice {
    padding: 14px;
    border-radius: 14px;
    border: 2px solid transparent;
    background: rgba(102, 126, 234, 0.08);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, border 0.15s ease, background 0.15s ease;
}

.battle-choice:active:not(:disabled) {
    transform: translateY(1px);
}

.battle-choice.selected {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.2);
}

.battle-choice.selected.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.18);
}

.battle-choice.selected.incorrect {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.18);
}

.battle-choice.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.18);
}

.battle-choice:disabled {
    opacity: 0.75;
    cursor: default;
}

.battle-status-hint {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.battle-opponent-status {
    text-align: center;
    font-size: 0.95rem;
    color: var(--primary);
}

.battle-waiting,
.battle-spectator,
.battle-results {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.battle-waiting .emoji,
.battle-spectator .emoji {
    font-size: 2.5rem;
}

.battle-results-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.battle-results-winner {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary);
}

.battle-results-scores {
    font-size: 1rem;
    color: var(--text-secondary);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-chip {
    padding: 8px 14px;
    border-radius: 20px;
    border: 2px solid rgba(102, 126, 234, 0.25);
    background: white;
    color: var(--text-secondary);
    cursor: pointer;
    transition: transform 0.15s ease, border 0.15s ease, color 0.15s ease;
}

.filter-chip.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(102, 126, 234, 0.15);
}

.filter-chip:active {
    transform: translateY(1px);
}

.battle-history-list {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.battle-history-card {
    padding: 18px;
    border-radius: 18px;
    background: white;
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.12);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.battle-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
}

.badge-win {
    background: rgba(67, 233, 123, 0.18);
    color: var(--success);
}

.badge-loss {
    background: rgba(250, 112, 154, 0.18);
    color: var(--error);
}

.badge-draw {
    background: rgba(118, 75, 162, 0.18);
    color: var(--primary);
}

.battle-history-card .opponent {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
}

.battle-history-card .avatar {
    font-size: 1.8rem;
}

.battle-history-card .summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.battle-history-card .scoreline {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
}

.battle-history-card .stats-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.history-actions {
    display: flex;
    justify-content: flex-end;
}

.battle-history-empty {
    padding: 32px;
    text-align: center;
    color: var(--text-secondary);
}

.battle-mode-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.battle-mode-options label {
    position: relative;
    cursor: pointer;
}

.battle-mode-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.battle-mode-tile {
    background: rgba(102, 126, 234, 0.08);
    border: 2px solid transparent;
    border-radius: 14px;
    padding: 12px;
    text-align: center;
    transition: border 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.battle-mode-options input:checked + .battle-mode-tile {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.18);
    transform: translateY(-2px);
}

.battle-type-options {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.battle-mode-tile .title {
    font-weight: 700;
    margin-bottom: 4px;
}

.battle-mode-tile .desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.battle-lobby-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.battle-code-display {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.battle-code-text {
    text-align: center;
    padding: 14px;
    border-radius: 12px;
    background: rgba(102, 126, 234, 0.08);
    font-weight: 600;
    font-size: 1.1rem;
}

.battle-code-text strong {
    font-size: 1.5rem;
    color: var(--primary);
    letter-spacing: 2px;
    display: block;
    margin-top: 4px;
}

.battle-share-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.battle-share-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 12px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 0.9rem;
    min-height: 70px;
}

.battle-share-btn .btn-icon {
    font-size: 1.8rem;
    display: block;
}

.battle-share-btn .btn-text {
    display: block;
}

.battle-share-btn.code {
    background: white;
    color: var(--primary);
    border: 2px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.battle-share-btn.code:hover {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.05);
}

.battle-share-btn.code:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.battle-share-btn.link {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.battle-share-btn.link:hover {
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
    transform: translateY(-1px);
}

.battle-share-btn.link:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.battle-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.battle-meta-pill {
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.12);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--primary-dark);
}

.battle-mode-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.battle-players {
    display: flex;
    gap: 12px;
    flex-direction: column;
}

.battle-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.03);
}

.battle-player.ready {
    border: 2px solid rgba(67, 233, 123, 0.45);
    background: rgba(67, 233, 123, 0.08);
}

.battle-player .avatar {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.battle-player .info {
    flex: 1;
}

.battle-player .name {
    font-weight: 600;
    margin-bottom: 4px;
}

.battle-ready {
    color: var(--success);
    font-weight: 600;
    font-size: 0.95rem;
}

.battle-wait {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.battle-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.battle-status {
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.battle-start-btn {
    margin-top: 8px;
}

.battle-start-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}


/* Button */
.btn {
    min-height: 52px;
    padding: 14px 28px;
    border-radius: 16px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn.loading {
    cursor: default;
    opacity: 0.85;
    pointer-events: none;
}

.btn-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.35);
    border-top-color: rgba(255, 255, 255, 0.95);
    animation: btn-spin 0.8s linear infinite;
}

.btn:not(.btn-primary) .btn-spinner {
    border-color: rgba(102, 126, 234, 0.25);
    border-top-color: var(--primary);
}

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

/* Battle Loading Overlay */
.battle-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15000;
}

.battle-loading-content {
    text-align: center;
    animation: fadeInScale 0.3s ease-out;
}

.battle-loading-spinner {
    width: 80px;
    height: 80px;
    margin: 0 auto;
    border-radius: 50%;
    border: 8px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    animation: btn-spin 1s linear infinite;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:active {
    background: rgba(102, 126, 234, 0.1);
}

/* Action List Item */
.action-item {
    background: var(--surface);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 2px 6px var(--shadow);
    margin-bottom: 12px;
    border: none;
    width: 100%;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 68px;
    text-align: right;
}

.action-item:active {
    transform: scale(0.98);
    box-shadow: 0 4px 12px var(--shadow);
}

.action-item.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(102, 126, 234, 0.35);
}

.action-icon {
    font-size: 2.2rem;
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

.action-item.primary .action-icon {
    background: rgba(255, 255, 255, 0.2);
}

.action-content {
    flex: 1;
}

.action-content h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.action-content p {
    font-size: 0.85rem;
    opacity: 0.85;
}

/* Character Grid */
.character-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.character-card {
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.character-card:active {
    transform: scale(0.95);
}

.character-card.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.character-emoji {
    font-size: 3.5rem;
}

.character-card h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-box {
    background: var(--surface);
    border-radius: 14px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 2px 6px var(--shadow);
}

.stat-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Game Screen */
.game-screen {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    min-height: 100%;
}

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

.game-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.info-badge {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
}

.character-display {
    text-align: center;
    margin-bottom: 16px;
}

.character-sprite {
    font-size: 5rem;
    margin-bottom: 8px;
}

.speech-bubble {
    background: white;
    color: var(--text);
    border-radius: 16px;
    padding: 12px 20px;
    margin: 0 auto;
    max-width: 85%;
    font-size: 0.95rem;
    box-shadow: 0 2px 8px var(--shadow);
    position: relative;
}

.question-container {
    background: white;
    border-radius: 20px;
    padding: 32px 20px;
    text-align: center;
    box-shadow: 0 4px 16px var(--shadow);
    margin-bottom: 20px;
}

.question {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text);
}

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

.answer-btn {
    min-height: 70px;
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: 16px;
    background: white;
    color: var(--text);
    border: 3px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px var(--shadow);
}

.answer-btn:active {
    transform: scale(0.95);
}

.answer-btn.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.answer-btn.incorrect {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* Leaderboard */
.leaderboard-item {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px var(--shadow);
}

.rank {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

.rank.top {
    font-size: 2rem;
}

.rank.gold { color: #FFD700; }
.rank.silver { color: #C0C0C0; }
.rank.bronze { color: #CD7F32; }

.player-info {
    flex: 1;
}

.player-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.player-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.player-score {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}

/* Game page specific styles */
#page-game #question,
#question {
    font-size: 2.5rem !important;
    font-weight: 700 !important;
    color: #1f2937 !important;
    text-align: center !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    direction: ltr !important;
}

#page-game .question-container {
    background: white !important;
    border-radius: 20px !important;
    padding: 24px !important;
    margin-bottom: 20px !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
    min-height: 100px !important;
}

/* Ensure question container is never hidden */
.question-container {
    display: block !important;
    visibility: visible !important;
}

/* Answer buttons - for game page */
#answers {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
    min-height: 160px !important;
}

/* Make sure answers container is never hidden */
#answers:empty::after {
    content: "טוען תשובות...";
    display: block;
    text-align: center;
    color: white;
    padding: 20px;
}

#answers .answer-btn {
    min-height: 70px !important;
    font-size: 1.8rem !important;
    font-weight: 700 !important;
    border-radius: 16px !important;
    background: white !important;
    color: #1f2937 !important;
    border: 3px solid transparent !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    direction: ltr !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#answers .answer-btn:active {
    transform: scale(0.95) !important;
}

#answers .answer-btn.correct {
    background: #10b981 !important;
    color: white !important;
    border-color: #10b981 !important;
}

#answers .answer-btn.wrong {
    background: #ef4444 !important;
    color: white !important;
    border-color: #ef4444 !important;
}

/* Utility Classes */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* Section Title */
.section-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

.section-subtitle {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    margin-top: 24px;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    font-size: 2rem;
}

/* Color Palettes */
[data-palette="default"] {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
}

[data-palette="ocean"] {
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --secondary: #06b6d4;
}

[data-palette="forest"] {
    --primary: #10b981;
    --primary-dark: #059669;
    --secondary: #34d399;
}

[data-palette="sunset"] {
    --primary: #f59e0b;
    --primary-dark: #d97706;
    --secondary: #ef4444;
}

[data-palette="purple"] {
    --primary: #a855f7;
    --primary-dark: #9333ea;
    --secondary: #ec4899;
}

[data-palette="rose"] {
    --primary: #f43f5e;
    --primary-dark: #e11d48;
    --secondary: #fb7185;
}

[data-palette="mint"] {
    --primary: #14b8a6;
    --primary-dark: #0d9488;
    --secondary: #2dd4bf;
}

[data-palette="indigo"] {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
}

[data-palette="amber"] {
    --primary: #f59e0b;
    --primary-dark: #d97706;
    --secondary: #fbbf24;
}

[data-palette="emerald"] {
    --primary: #059669;
    --primary-dark: #047857;
    --secondary: #10b981;
}

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

.animate-in {
    animation: fadeIn 0.3s ease;
}

/* Accessibility - High Contrast Mode */
[data-high-contrast="true"] {
    --primary: #0000ff;
    --primary-dark: #0000cc;
    --secondary: #000080;
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #000000;
    --text-secondary: #000000;
    --border: #000000;
}

[data-high-contrast="true"] .btn,
[data-high-contrast="true"] .action-item {
    border: 2px solid #000000;
}

/* Colorblind Modes */
[data-colorblind="protanopia"] {
    filter: url('#protanopia-filter');
}

[data-colorblind="deuteranopia"] {
    filter: url('#deuteranopia-filter');
}

[data-colorblind="tritanopia"] {
    filter: url('#tritanopia-filter');
}

/* Reduce Motion */
[data-reduce-motion="true"] * {
    animation-duration: 0.01s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01s !important;
}

[data-reduce-motion="true"] .animate-in {
    animation: none;
}
.profile-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border-radius: 18px;
    padding: 14px 16px;
    box-shadow: 0 2px 6px var(--shadow);
    margin-bottom: 12px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.profile-card-row.active {
    border: 2px solid var(--primary);
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.35);
}

.profile-card-row:active {
    transform: scale(0.98);
}

.profile-card-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.profile-card-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: rgba(102, 126, 234, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.profile-card-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: right;
}

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

.profile-action-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: rgba(102, 126, 234, 0.12);
    color: var(--primary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.profile-action-btn.danger {
    background: rgba(244, 63, 94, 0.12);
    color: #f43f5e;
}

.profile-action-btn:active {
    transform: scale(0.95);
}

.profile-action-btn:hover {
    background: rgba(102, 126, 234, 0.18);
}

.profile-action-btn.danger:hover {
    background: rgba(244, 63, 94, 0.2);
}

.profile-card-name {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text);
}

.profile-card-meta {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.profile-delete-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: rgba(244, 63, 94, 0.12);
    color: #f43f5e;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.profile-delete-btn:active {
    transform: scale(0.95);
}

.profile-delete-btn:hover {
    background: rgba(244, 63, 94, 0.2);
}

.profile-form-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 20px;
    z-index: 11000;
    overflow-y: auto;
}

.profile-form-card {
    background: white;
    border-radius: 24px;
    width: 100%;
    max-width: 420px;
    padding: 24px;
    direction: rtl;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

.profile-form-card h3 {
    margin-bottom: 16px;
    color: var(--primary);
}

.profile-form-field {
    margin-bottom: 18px;
}

.profile-form-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-secondary);
}

.profile-form-input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.avatar-option {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    border: 2px solid transparent;
    background: rgba(102, 126, 234, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    cursor: pointer;
    transition: border 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.avatar-option.selected {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.18);
    transform: translateY(-2px);
}

.profile-form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.profile-form-actions button {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.profile-form-actions button:active {
    transform: translateY(1px);
}

.profile-form-save {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.profile-form-cancel {
    background: #e5e7eb;
    color: #374151;
}

.battle-btn.history {
    background: rgba(255, 255, 255, 0.85);
    color: #343a40;
    border: 2px dashed rgba(102, 126, 234, 0.35);
}

/* Leaderboard Tabs */
.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--surface);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 2px 6px var(--shadow);
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
