/* ===== Kalamatic Design System ===== */
/* Variables are imported from tokens via base/variables.css */

/* ===== Custom Scrollbar - Hide in Modals ===== */

/* Hide scrollbar completely in modals for cleaner look */
.modal-content,
.modal-body,
.stats-body,
.leaderboard-list,
.policy-body,
.help-body,
.settings-body {
    -ms-overflow-style: none !important;  /* IE and Edge */
    scrollbar-width: none !important;  /* Firefox */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Hide WebKit scrollbar in modals */
.modal-content::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.stats-body::-webkit-scrollbar,
.leaderboard-list::-webkit-scrollbar,
.policy-body::-webkit-scrollbar,
.help-body::-webkit-scrollbar,
.settings-body::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
}

/* ===== Global Header with Coin Balance ===== */
.global-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height, 48px);
    max-width: var(--max-app-width);
    margin: 0 auto;
    padding: 0 12px;
    padding-top: var(--safe-area-top);
    background: var(--tg-bg);
    border-bottom: 0.5px solid var(--tg-separator);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Coins on the right (start in RTL) */
}

/* Position header relative to app container */
#app {
    position: relative;
    padding-top: calc(var(--header-height, 48px) + var(--safe-area-top));
}

.coin-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--tg-bg-secondary);
    border-radius: 20px;
    padding: 6px 12px 6px 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.coin-display:hover {
    transform: scale(1.02);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}

.coin-display:active {
    transform: scale(0.98);
}

.header-coin-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--tg-text);
}

.coin-balance {
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-text);
    min-width: 24px;
    text-align: center;
}

/* Animate coin balance changes */
.coin-balance.updating {
    animation: coinPulse 0.3s ease;
}

@keyframes coinPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); color: var(--color-correct); }
}

/* Note: Dark theme variables are defined in tokens/_colors.css */

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

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
    background-color: var(--tg-bg-secondary);
    color: var(--tg-text);
    direction: rtl;
    height: 100%;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== App Container ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    width: 100%;
    max-width: var(--max-app-width);
    margin: 0 auto;
    background: var(--tg-bg);
    position: relative;
    overflow: hidden;
    padding-bottom: calc(88px + var(--safe-area-bottom)); /* keep content above fixed nav */
}

/* iPad & Desktop centering */
@media (min-width: 768px) {
    body {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 20px;
    }

    #app {
        max-height: min(900px, calc(100vh - 40px));
        max-height: min(900px, calc(100dvh - 40px));
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-card), 0 0 0 1px var(--tg-separator);
        overflow: hidden;
    }
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 6px 16px;
    min-height: 44px;
    background: var(--tg-bg);
    border-bottom: 0.5px solid var(--tg-separator);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--tg-text);
}

.header-buttons {
    display: flex;
    gap: 4px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-link);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.icon-btn:active {
    background: var(--tg-bg-secondary);
}

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

.icon-btn .header-icon {
    width: 24px;
    height: 24px;
    opacity: 0.8;
}

/* Dark theme icon filter */
.dark-theme .icon-btn .header-icon,
body[data-theme="dark"] .icon-btn .header-icon {
    filter: invert(1) brightness(0.9);
}

/* ===== Main Game Container ===== */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    gap: 12px;
    overflow: visible;
    min-height: 0;
}

.game-container.hidden {
    display: none !important;
}

/* ===== Word Info & Countdown ===== */
.word-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--tg-hint);
}

.word-info.hidden {
    display: none !important;
}

.word-info .separator {
    opacity: 0.5;
}

#word-number {
    font-weight: 600;
    color: var(--tg-text);
}

#countdown {
    font-weight: 700;
    color: var(--color-correct);
    font-variant-numeric: tabular-nums;
    direction: ltr;
}

/* ===== Hint Area ===== */
.hint {
    text-align: center;
    padding: 10px 16px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: var(--max-board-width);
}

/* Compact hint for more game space */
.hint.compact {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
}

.hint.compact #hint-text {
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.3;
}

#hint-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--tg-text);
    line-height: 1.5;
}

/* ===== Game Board ===== */
.board {
    display: flex;
    flex-direction: column;
    gap: var(--tile-gap);
    width: fit-content;
    max-width: 100%;
    overflow: visible;
    /* Board scales to fit available space when JS sets --tile-size-dynamic */
}

.row {
    display: flex;
    gap: var(--tile-gap);
    perspective: 1000px;
}

.tile {
    width: var(--tile-size-dynamic, var(--tile-size));
    height: var(--tile-size-dynamic, var(--tile-size));
    border: 2px solid var(--tg-hint);
    border-radius: var(--tile-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--tile-font-size) * 1.4);
    font-weight: 900;
    background: var(--tg-bg);
    color: var(--tg-text);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.tile.filled {
    border-color: var(--border-filled);
    animation: tilePop 0.1s ease;
}

@keyframes tilePop {
    50% { transform: scale(1.05); }
}

.tile.correct {
    background: var(--color-correct);
    border-color: transparent;
    color: white;
}

.tile.present {
    background: var(--color-present);
    border-color: transparent;
    color: white;
}

.tile.absent {
    background: var(--color-absent);
    border-color: transparent;
    color: white;
}

/* ===== Native Input (Hidden) ===== */
.native-input {
    position: absolute;
    top: -9999px;
    left: -9999px;
    opacity: 0;
    width: 1px;
    height: 1px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
}

/* ===== Keyboard Toggle ===== */
.keyboard-toggle {
    display: none;
    justify-content: center;
    padding: 8px 16px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
}

.keyboard-toggle.visible {
    display: flex;
}

.keyboard-toggle.hidden {
    display: none !important;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid var(--tg-separator);
    border-radius: 20px;
    background: var(--tg-bg);
    color: var(--tg-hint);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-btn:active {
    background: var(--tg-bg-secondary);
}

.toggle-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Keyboard ===== */
.keyboard-container {
    padding: 6px 4px;
    padding-bottom: calc(18px + var(--safe-area-bottom));
    background: var(--tg-bg-secondary);
    flex-shrink: 0;
    margin-bottom: calc(76px + var(--safe-area-bottom)); /* clear bottom nav/Telegram bar */
}

.keyboard-container.hidden {
    display: none !important;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: var(--max-keyboard-width);
    margin: 0 auto;
    width: 100%;
}

.keyboard-row {
    display: flex;
    flex-direction: row-reverse;
    justify-content: center;
    gap: 3px;
    padding: 0 2px;
}

.key {
    font-family: 'Vazirmatn', sans-serif;
    font-size: var(--key-font-size);
    font-weight: 600;
    height: var(--key-height);
    min-width: 0;
    padding: 0 4px;
    border: none;
    border-radius: var(--key-radius);
    background: var(--tg-bg);
    color: var(--tg-text);
    box-shadow: var(--shadow-key);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    max-width: 44px;
    transition: transform var(--transition-fast), background var(--transition-fast);
}

.key:active {
    transform: scale(0.95);
    background: var(--tg-bg-secondary);
}

.key.wide {
    flex: 1.5;
    max-width: 64px;
    font-size: 0.85rem;
    padding: 0 6px;
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.key.wide:active {
    background: var(--tg-link);
}

.key.correct {
    background: var(--color-correct);
    color: white;
    box-shadow: none;
}

.key.present {
    background: var(--color-present);
    color: white;
    box-shadow: none;
}

.key.absent {
    background: var(--color-absent);
    color: white;
    box-shadow: none;
}

/* Backspace key - in last letter row */
.key.backspace-key {
    flex: 1.3;
    font-size: 1.4rem;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
}

.key.backspace-key:active {
    background: var(--color-absent);
    color: white;
}

/* Keyboard toolbar - Backspace left, OK right */
/* Uses same flex structure as keyboard-row with 11 units for perfect alignment */
.keyboard-toolbar {
    display: flex;
    direction: ltr; /* Force LTR so backspace is left, OK is right */
    justify-content: space-between;
    align-items: center;
    gap: 3px; /* Same gap as keyboard-row */
    padding: 0 2px; /* Same padding as keyboard-row */
    width: 100%;
}

/* Action buttons (OK and Backspace) - styled like letter keys */
.key-action {
    /* flex: 2 = width of 2 keys, max-width = 2 keys + 1 gap between them */
    flex: 2;
    max-width: calc(44px * 2 + 3px);
    min-width: 0;
    height: var(--key-height);
    padding: 0 4px; /* Same padding as regular keys */
    border: none;
    border-radius: var(--key-radius);
    background: rgba(255, 255, 255, 0.1); /* Semi-transparent background */
    box-shadow: var(--shadow-key);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), background var(--transition-fast);
}

/* OK button - base styling with text and icon */
.key-ok {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: opacity var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.key-ok-text {
    font-size: 14px;
    font-weight: 600;
}

/* OK button - disabled state (before 5 letters filled) */
.key-ok.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* OK button - enabled state (when 5 letters filled) */
.key-ok.enabled {
    opacity: 1;
    background: var(--color-correct);
    color: white;
}

.key-ok.enabled:active {
    background: var(--color-correct);
    transform: scale(0.95);
}

/* Backspace button */
.key-back:active {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.95);
}

/* Icon styling inside action buttons */
.key-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Make icons white */
    transition: filter var(--transition-fast);
}

/* Inline SVG icon styling */
.key-icon-svg {
    width: 22px;
    height: 22px;
    color: #fff; /* White icons */
}

/* Flip icon horizontally for RTL backspace */
.key-icon-svg.flip {
    transform: scaleX(-1);
}

/* ===== Toast Message ===== */
.message {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: rgba(30, 30, 30, 0.95);
    color: #fff;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 6000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    min-width: 150px;
    max-width: calc(100vw - 32px);
    width: max-content;
    text-align: center;
    white-space: nowrap;
    direction: rtl;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Dark theme toast */
.dark-theme .message {
    background: rgba(255, 255, 255, 0.95);
    color: #1c1c1d;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.message.show {
    transform: translateX(-50%) translateY(calc(60px + var(--safe-area-top, 0px)));
    opacity: 1;
}

.message.hidden {
    display: none;
}

/* Small screens - more compact toast */
@media (max-width: 380px) {
    .message {
        font-size: 0.8rem;
        padding: 8px 14px;
        border-radius: 16px;
        max-width: calc(100vw - 32px);
    }
}

/* ===== Win Message Overlay ===== */
/* Main styling is in toast.css - this is kept for fallback */
.win-message {
    position: fixed;
    bottom: 18%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.5rem;
    font-weight: 900;
    color: white;
    text-align: center;
    opacity: 0;
    z-index: 3000;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

/* ===== Modals - Telegram Bottom Sheet Style ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, background 0.3s ease, backdrop-filter 0.3s ease, visibility 0s linear 0.3s;
}

.modal.visible {
    opacity: 1;
    visibility: visible;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.3s ease, background 0.3s ease, backdrop-filter 0.3s ease, visibility 0s linear 0s;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--tg-bg);
    border-radius: var(--radius-xl);
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    transform: translateY(24px) scale(0.96);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--tg-separator) transparent;
    max-width: 420px;
    width: min(420px, calc(100% - 24px));
    box-shadow: var(--shadow-modal);
}

/* Styled scrollbar for modals */
.modal-content::-webkit-scrollbar {
    width: 4px;
}

.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
    background: var(--tg-separator);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--tg-hint);
}

/* Raise profile modal above other panels (e.g., team details) */
#user-profile-modal {
    z-index: 2100;
}

.modal.visible .modal-content {
    transform: translateY(0) scale(1);
}

/* iPad: Center modals */
@media (min-width: 768px) {
    .modal {
        justify-content: center;
        align-items: center;
        padding: 20px;
    }

    .modal-content {
        border-radius: var(--radius-xl);
        max-width: 420px;
        width: 100%;
        max-height: 80vh;
        max-height: 80dvh;
        transform: translateY(30px) scale(0.95);
        opacity: 0;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s ease;
    }

    .modal.visible .modal-content {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-handle {
    width: 36px;
    height: 5px;
    background: var(--tg-hint);
    opacity: 0.3;
    border-radius: 3px;
    margin: 8px auto;
}

@media (min-width: 768px) {
    .modal-handle {
        display: none;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px 10px;
    position: sticky;
    top: 0;
    background: var(--tg-bg);
    z-index: 1;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tg-text);
}

.close-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--tg-bg-secondary);
    border-radius: 50%;
    cursor: pointer;
    color: var(--tg-hint);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.close-btn:active {
    background: var(--tg-separator);
}

.modal-body {
    padding: 0 16px 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
}

/* Section Title */
.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--tg-hint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ===== Stats Modal ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 24px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 14px 8px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
}

.stat-value {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    color: var(--tg-text);
}

.stat-label {
    font-size: clamp(0.65rem, 2vw, 0.75rem);
    color: var(--tg-hint);
    margin-top: 4px;
}

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

.dist-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dist-badge {
    width: 40px;
    min-width: 40px;
    height: 32px;
    border-radius: 10px;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-weight: 700;
    display: grid;
    place-items: center;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 6px 16px rgba(0,0,0,0.18);
}

.dist-bar-track {
    flex: 1;
    height: 32px;
    border-radius: 10px;
    background: var(--tg-bg-secondary);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    /* RTL: use flexbox to position fill on right */
    display: flex;
    justify-content: flex-start; /* In RTL, flex-start is right */
}

.dist-bar-fill {
    height: 100%;
    background: var(--tg-button);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 12px;
    color: var(--tg-button-text);
    font-weight: 800;
    font-size: 0.95rem;
    border-radius: 10px;
    min-width: 0;
    width: 0; /* Start at 0, animate to target */
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dist-bar-fill:not(.active) {
    background: var(--tg-hint);
    color: var(--tg-bg);
    opacity: 0.5;
}

.dist-bar-fill.highlight {
    background: var(--tg-button);
    color: var(--tg-button-text);
    filter: brightness(1.1);
}

.dist-count {
    min-width: 16px;
}

/* ===== Help Modal - Redesigned ===== */
.help-content {
    max-width: 400px;
}

.help-content .modal-body {
    padding: 12px 16px 16px;
}

.help-hero {
    text-align: center;
    padding: 14px;
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.1), rgba(255, 149, 0, 0.1));
    border-radius: var(--radius-lg);
    margin-bottom: 14px;
}

.help-hero-icon {
    font-size: 2rem;
    margin-bottom: 4px;
}

.help-hero p {
    font-size: 0.9rem;
    color: var(--tg-text);
    line-height: 1.5;
    margin: 0;
}

.help-hero strong {
    color: var(--color-correct);
}

.help-section {
    margin-bottom: 14px;
}

/* Color Guide */
.color-guide {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.color-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
}

.color-tile {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.color-tile.correct {
    background: var(--color-correct);
}

.color-tile.present {
    background: var(--color-present);
}

.color-tile.absent {
    background: var(--color-absent);
}

.color-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.color-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--tg-text);
}

.color-desc {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

/* Example Word */
.example-word {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 10px;
}

.example-word .tile {
    width: 38px;
    height: 38px;
    font-size: 1.15rem;
}

.example-desc {
    text-align: center;
    font-size: 0.8rem;
    color: var(--tg-hint);
    line-height: 1.4;
    margin: 0;
}

/* Timer Info */
.help-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    border-radius: var(--radius-md);
    color: white;
    margin-bottom: 12px;
}

.help-timer svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.help-timer span {
    font-size: 0.9rem;
    font-weight: 500;
}

.help-timer strong {
    font-weight: 700;
}

/* ===== NYT Wordle Style Onboarding ===== */
.onboarding-style {
    max-width: 420px;
}

.onboarding-style .modal-header {
    border-bottom: none;
    padding-bottom: 4px;
}

.onboarding-style .modal-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.onboarding-body {
    padding: 0 20px 24px !important;
}

.onboarding-subtitle {
    font-size: 1rem;
    color: var(--tg-text);
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.onboarding-rules {
    margin: 0 0 20px 0;
    padding-inline-start: 20px;
    list-style: disc;
}

.onboarding-rules li {
    font-size: 0.9rem;
    color: var(--tg-text);
    line-height: 1.6;
    margin-bottom: 6px;
}

.onboarding-examples {
    margin-bottom: 20px;
}

.examples-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--tg-text);
    margin: 0 0 16px 0;
}

.example-row {
    margin-bottom: 16px;
}

.example-row:last-child {
    margin-bottom: 0;
}

.example-row .example-word {
    justify-content: flex-start;
    margin-bottom: 6px;
}

.example-row .example-word .tile {
    width: 42px;
    height: 42px;
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    border-radius: 6px;
}

/* Outlined example tiles - visible border like game cells */
.example-row .example-word.outlined .tile {
    width: 42px;
    height: 42px;
    font-size: 1.5rem;
    border: none;
    background: var(--tg-bg-secondary);
    color: white !important;
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 700;
    border-radius: 6px;
}

.example-row .example-word .tile.correct,
.example-word.outlined .tile.correct {
    background: var(--color-correct);
    border: none;
    color: white;
}

.example-row .example-word .tile.present,
.example-word.outlined .tile.present {
    background: var(--color-present);
    border: none;
    color: white;
}

.example-row .example-word .tile.absent,
.example-word.outlined .tile.absent {
    background: var(--color-absent);
    border: none;
    color: white;
}

.example-explanation {
    font-size: 0.85rem;
    color: var(--tg-text);
    line-height: 1.5;
    margin: 0;
    text-align: end;
}

.example-explanation strong {
    font-weight: 700;
}

/* Letter in guillemets - super bold, same size */
.example-explanation .letter-highlight {
    font-weight: 900;
    font-family: 'Vazirmatn', sans-serif;
}

.onboarding-divider {
    border: none;
    border-top: 1px solid var(--tg-hint);
    margin: 20px 0;
}

.onboarding-footer {
    font-size: 0.85rem;
    color: var(--tg-hint);
    line-height: 1.6;
    margin: 0;
    margin-bottom: 20px;
}

.onboarding-footer strong {
    color: var(--tg-text);
    font-weight: 600;
}

.onboarding-footer a {
    color: var(--color-correct);
    text-decoration: underline;
    font-weight: 500;
}

/* Help Start Button - for first-time users */
.help-start-btn {
    width: 100%;
    margin-top: 16px;
    padding: 14px 20px;
    font-size: 1rem;
}

/* App Link */
.app-promo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--tg-text);
    transition: background var(--transition-fast);
}

.app-promo:active {
    background: var(--tg-separator);
}

.app-promo-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    object-fit: cover;
}

.app-promo-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-promo-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.app-promo-desc {
    font-size: 0.75rem;
    color: var(--tg-hint);
}

.app-promo-arrow {
    color: var(--tg-hint);
    flex-shrink: 0;
    transform: rotate(180deg);
}

/* Legacy support */
.help-app-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--tg-text);
    transition: background var(--transition-fast);
}

.help-app-link:active {
    background: var(--tg-separator);
}

.help-app-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    overflow: hidden;
}

.help-app-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.help-app-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.help-app-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.help-app-desc {
    font-size: 0.75rem;
    color: var(--tg-hint);
}

.help-app-arrow {
    color: var(--tg-hint);
    flex-shrink: 0;
    transform: rotate(180deg);
}

/* ===== Leaderboard Modal - Redesigned ===== */
.leaderboard-content {
    max-width: 420px;
}

.leaderboard-content .modal-header {
    padding: 6px 14px 8px;
}

.leaderboard-content .modal-header h2 {
    font-size: 0.95rem;
}

.leaderboard-content .modal-body {
    padding: 0 12px 16px;
}

/* Telegram-style Segmented Control */
.leaderboard-tabs {
    display: flex;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
    margin-bottom: 12px;
}

.tab-btn {
    flex: 1;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--tg-hint);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab-btn.active {
    background: var(--tg-bg);
    color: var(--tg-text);
    box-shadow: var(--shadow-key);
}

/* My Rank Card */
.my-rank-section {
    margin-bottom: 12px;
}

.my-rank-section.hidden {
    display: none;
}

.my-rank-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    border-radius: var(--radius-md);
    color: white;
}

.my-rank-info {
    display: flex;
    flex-direction: column;
    gap: 0;
    line-height: 1.2;
}

.my-rank-label {
    font-size: 0.65rem;
    font-weight: 600;
    opacity: 0.85;
}

.my-rank-value {
    font-size: 0.9rem;
    font-weight: 800;
}

.my-rank-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    line-height: 1.2;
}

.my-score-label {
    font-size: 0.65rem;
    font-weight: 600;
    opacity: 0.85;
}

.my-score-value {
    font-size: 0.9rem;
    font-weight: 700;
}

/* Global Stats */
.leaderboard-stats {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 10px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.lb-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.lb-stat-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--tg-text);
}

.lb-stat-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--tg-hint);
    margin-top: 1px;
}

.lb-stat-divider {
    width: 1px;
    height: 24px;
    background: var(--tg-separator);
}

/* Leaderboard List */
.leaderboard-list {
    max-height: 280px;
    overflow-y: auto;
    border-radius: var(--radius-md);
    background: var(--tg-bg-secondary);
    overscroll-behavior: contain;
}

.leaderboard-list::-webkit-scrollbar {
    width: 4px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: transparent;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--tg-hint);
    opacity: 0.3;
    border-radius: 2px;
}

.lb-entry {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 10px;
    background: var(--tg-bg);
    border-bottom: 0.5px solid var(--tg-separator);
}

.lb-entry:last-child {
    border-bottom: none;
}

.lb-entry.highlight,
.lb-entry.me {
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--tg-link) 20%, transparent);
    background: rgba(46, 166, 255, 0.18); /* fallback */
    border: 1px solid color-mix(in srgb, var(--tg-link) 60%, transparent);
    border-color: rgba(46, 166, 255, 0.35); /* fallback */
}

.lb-entry {
    cursor: pointer;
    transition: background 0.15s ease;
}

.lb-entry:active {
    background: var(--tg-bg-secondary);
}

.lb-rank {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.7rem;
    border-radius: 50%;
    background: var(--tg-bg-secondary);
    color: var(--tg-hint);
    flex-shrink: 0;
}

.lb-rank.gold {
    background: linear-gradient(135deg, #ffd700, #ffb700);
    color: white;
}

.lb-rank.silver {
    background: linear-gradient(135deg, #e8e8e8, #b8b8b8);
    color: #555;
}

.lb-rank.bronze {
    background: linear-gradient(135deg, #cd7f32, #b87333);
    color: white;
}

.lb-info {
    flex: 1;
    min-width: 0;
}

.lb-name {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-name .premium-badge {
    display: inline-block;
    margin-inline-start: 3px;
    font-size: 0.7rem;
}

.lb-name .lb-username-tag {
    display: none; /* Hide TG tag */
}

.lb-details {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--tg-hint);
    display: flex;
    gap: 6px;
    margin-top: 1px;
}

.lb-score {
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--tg-link);
    flex-shrink: 0;
}

/* Loading Spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
    color: var(--tg-hint);
    font-size: 0.9rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--tg-separator);
    border-top-color: var(--tg-link);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.empty-leaderboard {
    text-align: center;
    padding: 40px 20px;
    color: var(--tg-hint);
}

/* ===== End Game Modal - Redesigned ===== */
.end-content {
    max-width: 340px;
}

.end-hero {
    text-align: center;
    padding: 16px 16px 12px;
    background: linear-gradient(180deg, var(--tg-bg-secondary) 0%, var(--tg-bg) 100%);
}

.end-emoji {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 8px;
    animation: bounce 0.6s ease;
}

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

.end-hero.lost .end-emoji {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.end-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tg-text);
    margin-bottom: 4px;
}

.end-hero.won .end-title {
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.end-subtitle {
    font-size: 0.9rem;
    color: var(--tg-hint);
    margin: 0;
}

/* Correct word display (lose only) */
.end-word {
    text-align: center;
    font-size: 1rem;
    padding: 8px 0;
    margin: 0 0 8px;
    display: none;
}

.end-word strong {
    color: var(--color-correct);
    font-weight: 700;
}

/* Timer */
.end-timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 8px;
}

.end-timer-label {
    font-size: 0.75rem;
    color: var(--tg-theme-hint-color, var(--tg-hint));
    margin-bottom: 2px;
}

.end-timer-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tg-theme-text-color, var(--tg-text));
    font-variant-numeric: tabular-nums;
    direction: ltr;
}

/* Social buttons row - matches home page waiting-actions style */
.social-buttons-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 8px;
    width: 200px;
    margin-inline: auto;
    flex-direction: column;
    align-items: center;
}

/* Share with friends button - matches home page share-btn */
.btn-share-main {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 700;
    font-family: 'Vazirmatn', sans-serif;
    cursor: pointer;
    background: var(--tg-button, #007aff);
    color: var(--tg-button-text, #fff);
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.btn-share-main:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Social icons container in end modal - matches home page */
.social-buttons-row .social-icons {
    display: flex;
    gap: 8px;
    width: 100%;
}

/* Social icon buttons in end modal - matches home page */
.social-buttons-row .social-icon-btn {
    flex: 1;
    height: 48px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.social-buttons-row .social-icon-btn:active {
    transform: scale(0.98);
    background: var(--tg-separator);
}

.social-buttons-row .social-icon-btn svg,
.social-buttons-row .social-icon-btn img {
    width: 18px;
    height: 18px;
    filter: invert(1);
}

.dark-theme .social-buttons-row .social-icon-btn img,
body[data-theme="dark"] .social-buttons-row .social-icon-btn img {
    filter: none;
}

/* App Promo in End Modal */
.end-content .app-promo {
    margin-top: 16px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
}

/* Action Buttons */
.end-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn svg {
    flex-shrink: 0;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    color: white;
}

.btn-secondary {
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
}

.btn-ghost {
    background: transparent;
    color: var(--tg-text);
    border: 1px solid var(--tg-separator);
}

/* End Modal App Promo - hidden on small screens */
.end-app-promo {
    margin-top: 12px;
    display: none; /* Hide by default to save space */
}

/* Show app promo only on taller screens */
@media (min-height: 650px) {
    .end-app-promo {
        display: flex;
    }
}

.end-actions {
    margin-top: 10px;
}

/* ===== Finished Game View ===== */
.finished-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: var(--tg-bg);
    z-index: 50;
}

.finished-view.hidden {
    display: none !important;
}

.finished-card {
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 300px;
    text-align: center;
}

.finished-title {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.finished-message {
    font-size: 0.9rem;
    color: var(--tg-hint);
    margin-bottom: 20px;
}

.finished-next {
    background: var(--tg-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
}

.finished-next-label {
    font-size: 0.8rem;
    color: var(--tg-hint);
    margin-bottom: 4px;
}

.finished-countdown {
    font-size: 1.75rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--color-correct);
    direction: ltr;
}

/* Share button in finished view */
.finished-card .finished-share {
    width: 100%;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.finished-card .finished-share .btn-icon {
    width: 20px;
    height: 20px;
}

/* Stats button in finished view */
.finished-card .finished-stats {
    width: 100%;
    padding: 14px 20px;
    font-size: 0.95rem;
    margin-bottom: 12px;
}

/* App promo in finished view */
.finished-card .app-promo {
    margin-top: 0;
}

/* ===== Animation Support ===== */
.gsap-animating {
    transition: none !important;
}

/* Modal open state */
.modal-open .game-container,
.modal-open .keyboard-container,
.modal-open .keyboard-toggle {
    pointer-events: none;
}

/* ===== Responsive Breakpoints ===== */

/* Small phones (< 350px) - iPhone SE 1st gen, etc */
@media (max-width: 350px) {
    :root {
        /* Larger tiles for small screens */
        --tile-size: clamp(38px, 13vw, 42px);
        --tile-gap: 2px;
        --tile-font-size: clamp(0.9rem, 3.5vw, 1.1rem);
        /* Compact keyboard on small screens */
        --key-height: clamp(38px, 10vw, 44px);
        --key-font-size: clamp(0.95rem, 3.5vw, 1.1rem);
        --key-radius: 6px;
    }

    .header {
        padding: 6px 12px;
        min-height: 48px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .logo {
        width: 30px;
        height: 30px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }

    .game-container {
        padding: 8px 12px;
        gap: 8px;
    }

    .hint {
        padding: 4px 10px;
    }

    .hint.compact {
        padding: 3px 8px;
    }

    .hint.compact #hint-text {
        font-size: 0.65rem;
    }

    #hint-text {
        font-size: 0.75rem;
    }

    .word-info {
        font-size: 0.75rem;
    }

    /* Keyboard adjustments for very small screens */
    .keyboard-container {
        padding: 4px 2px;
        padding-bottom: calc(4px + var(--safe-area-bottom));
    }

    .keyboard {
        gap: 4px;
    }

    .keyboard-row {
        gap: 2px;
        padding: 0;
    }

    .key {
        padding: 0 1px;
        border-radius: 5px;
    }

    .key.wide {
        font-size: 0.8rem;
        max-width: 56px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-body {
        padding: 0 16px 20px;
    }

    .color-tile {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }

    .example-word .tile {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }
}

/* iPhone SE / Small phones (350px - 390px) */
@media (min-width: 351px) and (max-width: 390px) {
    :root {
        /* Larger tiles */
        --tile-size: clamp(40px, 11vw, 48px);
        --tile-gap: 2px;
        --tile-font-size: clamp(1rem, 3vw, 1.2rem);
        /* Compact keyboard */
        --key-height: clamp(40px, 10vw, 46px);
        --key-font-size: clamp(1rem, 3vw, 1.15rem);
        --key-radius: 6px;
    }

    .keyboard-container {
        padding: 5px 3px;
        padding-bottom: calc(5px + var(--safe-area-bottom));
    }

    .keyboard-row {
        gap: 3px;
        padding: 0 1px;
    }

    .key.wide {
        font-size: 0.9rem;
        max-width: 60px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Standard phones (391px - 480px) */
@media (min-width: 391px) and (max-width: 480px) {
    :root {
        /* Larger tiles */
        --tile-size: clamp(42px, 11vw, 50px);
        --tile-gap: 3px;
        --tile-font-size: clamp(1.1rem, 3.5vw, 1.35rem);
        /* Compact keyboard */
        --key-height: clamp(42px, 10vw, 48px);
        --key-font-size: clamp(1.05rem, 3vw, 1.2rem);
    }

    .keyboard-row {
        gap: 4px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large phones / Small tablets (481px - 768px) */
@media (min-width: 481px) and (max-width: 767px) {
    :root {
        /* Larger tiles */
        --tile-size: clamp(46px, 10vw, 54px);
        --tile-gap: 3px;
        --tile-font-size: clamp(1.2rem, 2.5vw, 1.5rem);
        /* Compact keyboard */
        --key-height: clamp(44px, 10vw, 50px);
        --key-font-size: 1.15rem;
    }
}

/* iPad Mini / iPad (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        /* Larger tiles */
        --tile-size: 52px;
        --tile-gap: 4px;
        --tile-font-size: 1.4rem;
        /* Compact keyboard */
        --key-height: 48px;
        --key-font-size: 1.2rem;
        --max-app-width: 480px;
    }

    .keyboard {
        max-width: 460px;
    }

    .key {
        max-width: 46px;
    }

    .key.wide {
        max-width: 72px;
    }
}

/* iPad Pro / Desktop (> 1024px) */
@media (min-width: 1025px) {
    :root {
        /* Smaller tiles */
        --tile-size: 46px;
        --tile-gap: 4px;
        --tile-font-size: 1.5rem;
        /* Compact keyboard */
        --key-height: 50px;
        --key-font-size: 1.25rem;
        --max-app-width: 500px;
    }

    .keyboard {
        max-width: 500px;
    }

    .key {
        max-width: 48px;
    }

    .key.wide {
        max-width: 76px;
    }
}

/* Short screens / Landscape phones */
@media (max-height: 600px) {
    :root {
        --tile-size: clamp(36px, 8vh, 46px);
        --tile-gap: 3px;
        --tile-font-size: clamp(1.1rem, 3vh, 1.4rem);
        --key-height: clamp(38px, 7vh, 44px);
        --header-height: 48px;
    }

    .header {
        padding: 4px 12px;
        min-height: 44px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .logo {
        width: 28px;
        height: 28px;
    }

    .game-container {
        padding: 6px 12px;
        gap: 6px;
    }

    .hint {
        padding: 6px 12px;
    }

    #hint-text {
        font-size: 0.8rem;
    }

    .word-info {
        font-size: 0.75rem;
    }

    .keyboard-container {
        padding: 6px;
    }

    .keyboard {
        gap: 4px;
    }
}

/* Very short screens */
@media (max-height: 500px) {
    .word-info,
    .hint {
        display: none;
    }

    :root {
        --tile-size: clamp(32px, 7vh, 40px);
        --key-height: clamp(34px, 6vh, 40px);
    }

    .finished-card {
        padding: 16px;
    }

    .finished-title {
        font-size: 1.4rem;
    }

    .finished-countdown {
        font-size: 1.4rem;
    }
}

/* iPad specific - Portrait */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    #app {
        max-height: min(850px, calc(100vh - 60px));
    }

    .modal-content {
        max-height: 70vh;
    }
}

/* iPad specific - Landscape */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
    #app {
        max-height: min(700px, calc(100vh - 40px));
    }

    :root {
        --tile-size: clamp(44px, 7vh, 56px);
        --key-height: clamp(42px, 6vh, 50px);
    }

    .game-container {
        padding: 8px 16px;
        gap: 8px;
    }

    .modal-content {
        max-height: 85vh;
    }
}

/* Hover states for devices that support it */
@media (hover: hover) {
    .icon-btn:hover {
        background: var(--tg-bg-secondary);
    }

    .key:hover {
        background: var(--tg-bg-secondary);
    }

    .btn:hover {
        opacity: 0.9;
    }

    .tab-btn:hover:not(.active) {
        background: rgba(0, 0, 0, 0.05);
    }

    .dark-theme .tab-btn:hover:not(.active) {
        background: rgba(255, 255, 255, 0.05);
    }

    .help-app-link:hover {
        background: var(--tg-separator);
    }

    .lb-entry:hover {
        background: var(--tg-bg-secondary);
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Settings Modal ===== */
.settings-content {
    max-width: 400px;
}

.settings-body {
    padding: 0 16px 24px;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.settings-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--tg-bg);
    border: none;
    text-decoration: none;
    color: var(--tg-text);
    cursor: pointer;
    transition: background var(--transition-fast);
    text-align: end;
    font-family: 'Vazirmatn', sans-serif;
    width: 100%;
}

.settings-item:active {
    background: var(--tg-bg-secondary);
}

.settings-item.settings-danger {
    color: var(--tg-destructive);
}

.settings-item.settings-danger .settings-icon {
    color: var(--tg-destructive);
}

.settings-item.linked {
    opacity: 0.7;
    cursor: default;
}

.settings-item.linked .settings-title {
    color: var(--tg-hint);
}

.settings-item.linked .settings-arrow {
    display: none;
}

.settings-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-sm);
    color: var(--tg-link);
    flex-shrink: 0;
}

.settings-icon img {
    filter: invert(1);
}

.dark-theme .settings-icon img,
body[data-theme="dark"] .settings-icon img {
    filter: none;
}

.settings-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.settings-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.settings-desc {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

.settings-arrow {
    color: var(--tg-hint);
    flex-shrink: 0;
    transform: rotate(180deg);
}

/* Referral Settings Item */
.settings-referral {
    background: linear-gradient(135deg, rgba(var(--accent-rgb, 99, 102, 241), 0.1), rgba(var(--accent-rgb, 99, 102, 241), 0.05));
    border: 1px solid rgba(var(--accent-rgb, 99, 102, 241), 0.2);
    border-radius: var(--radius-md);
    margin: 8px 16px;
    width: calc(100% - 32px);
}

.settings-referral .settings-icon {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.settings-referral-badge {
    background: var(--tg-button);
    color: var(--tg-button-text);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Shop Referral Promo Banner */
.shop-referral-promo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(var(--accent-rgb, 99, 102, 241), 0.15), rgba(var(--accent-rgb, 99, 102, 241), 0.05));
    border: 1px solid rgba(var(--accent-rgb, 99, 102, 241), 0.25);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.shop-referral-promo:active {
    transform: scale(0.98);
}

.shop-referral-promo .promo-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.shop-referral-promo .promo-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.shop-referral-promo .promo-text strong {
    font-size: 0.95rem;
    color: var(--tg-text);
}

.shop-referral-promo .promo-text span {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

.shop-referral-promo .promo-arrow {
    color: var(--tg-hint);
    flex-shrink: 0;
    transform: rotate(180deg);
}

/* Referral Modal Styles */
.referral-content {
    max-width: 400px;
}

.referral-body {
    padding: 0 20px 20px;
}

.referral-rewards {
    display: flex;
    justify-content: space-around;
    gap: 16px;
    margin-bottom: 20px;
}

.referral-reward-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    flex: 1;
}

.referral-reward-item .reward-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
}

.referral-reward-item .reward-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.referral-reward-item .reward-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--tg-button);
}

.referral-reward-item .reward-label {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

.referral-note {
    text-align: center;
    font-size: 0.85rem;
    color: var(--tg-hint);
    margin-bottom: 20px;
    line-height: 1.5;
}

.referral-share-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 600;
}

.referral-modal-stats {
    margin-top: 20px;
}

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

.referral-stats-grid .stat-item {
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.referral-stats-grid .stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--tg-text);
    display: block;
    margin-bottom: 4px;
}

.referral-stats-grid .stat-label {
    font-size: 0.75rem;
    color: var(--tg-hint);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    padding: 8px 10px;
}

.form-group label {
    font-weight: 600;
    color: var(--tg-text);
    font-size: 0.95rem;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--tg-separator);
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-size: 0.95rem;
}

.input-hint {
    color: var(--tg-hint);
    font-size: 0.78rem;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
}

.toggle-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toggle-title {
    font-weight: 600;
    color: var(--tg-text);
    font-size: 0.95rem;
}

.toggle-desc {
    color: var(--tg-hint);
    font-size: 0.8rem;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.form-status {
    min-height: 18px;
    font-size: 0.9rem;
    color: var(--tg-hint);
}

.analytics-toggle {
    gap: 10px;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    display: inline-block;
    flex-shrink: 0;
}

.toggle-switch input {
    display: none;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--tg-bg-secondary);
    border-radius: 999px;
    transition: background var(--transition-fast);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    inset-inline-start: 3px;
    bottom: 3px;
    background: var(--tg-bg);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: inset-inline-start var(--transition-fast), background var(--transition-fast);
}

.toggle-switch input:checked + .switch-slider {
    background: var(--tg-link);
}

.toggle-switch input:checked + .switch-slider:before {
    inset-inline-start: calc(100% - 25px);
    background: #fff;
}

/* ===== Friends Modal ===== */
.friends-content {
    max-width: 480px;
}

.friends-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.friends-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.friends-actions .join-row {
    display: flex;
    flex-direction: row-reverse; /* RTL: input on right, button on left */
    gap: 8px;
}

.friends-actions .join-row .btn {
    flex: 1;
    min-width: 0;
    transition: background-color 0.2s, opacity 0.2s;
}

.friends-actions .join-row .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.friends-actions .join-row .btn.active {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.friends-actions input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    background: var(--tg-bg);
    color: var(--tg-text);
    text-align: right;
}

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

.friend-item {
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--tg-bg);
    border: 1px solid var(--tg-separator);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.friend-item .friend-name {
    font-weight: 600;
}

.friend-item .friend-meta {
    color: var(--tg-hint);
    font-size: 0.85rem;
}

.friend-item .friend-cta {
    color: var(--tg-link);
    font-size: 0.9rem;
}

.friend-item:hover {
    background: var(--tg-bg-secondary);
}

/* ===== Team Page ===== */
.team-page-content {
    padding: 20px 16px;
}

.team-page-content .page-title {
    text-align: center;
    margin-bottom: 20px;
}

.team-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.team-create-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
}

.team-create-btn svg {
    flex-shrink: 0;
}

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

.team-join-row {
    display: flex;
    flex-direction: row-reverse; /* RTL: input on right, button on left */
    gap: 8px;
}

.team-join-row .btn {
    flex: 1;
    min-width: 0;
    transition: background-color 0.2s, opacity 0.2s;
}

.team-join-row .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.team-join-row .btn.active {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.team-token-input {
    flex: 1;
    min-width: 0; /* Allow input to shrink properly in flex */
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-size: 1rem;
    font-family: 'Vazirmatn', sans-serif;
    text-align: right;
}

.team-token-input::placeholder {
    color: var(--tg-hint);
    font-size: 0.95rem;
    opacity: 0.7;
}

.team-groups-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.team-group-item {
    padding: 14px;
    border-radius: var(--radius-lg);
    background: var(--tg-bg-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.team-group-item:active {
    transform: scale(0.98);
}

.team-group-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--tg-button);
    color: var(--tg-button-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.team-group-info {
    flex: 1;
    min-width: 0;
}

.team-group-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.team-group-meta {
    color: var(--tg-hint);
    font-size: 0.85rem;
    margin-top: 2px;
}

.team-group-actions {
    display: flex;
    gap: 8px;
}

.team-group-btn {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: var(--radius-sm);
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--tg-button);
    color: var(--tg-button-text, #fff);
}

.team-group-btn.primary {
    background: var(--tg-button);
    color: var(--tg-button-text, #fff);
}

.team-group-btn.secondary {
    background: var(--tg-button);
    color: var(--tg-button-text, #fff);
    border: none;
}

.team-group-icon-btn {
    width: 18px;
    height: 18px;
    display: block;
}

.team-group-btn svg path {
    fill: currentColor;
}

.team-group-btn img {
    filter: brightness(0) invert(1);
}

.team-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--tg-hint);
}

.team-empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.team-empty-state p {
    font-size: 0.95rem;
    line-height: 1.5;
}

/* ===== Team Details Modal (Full Screen from Bottom) ===== */
#group-details-modal.slide-panel {
    justify-content: center;
    align-items: flex-end;
    z-index: 1000;
}

#group-details-modal.slide-panel .modal-content {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

#group-details-modal.slide-panel.visible .modal-content {
    transform: translateY(0);
}

/* Keep panel visible during close animation */
#group-details-modal.slide-panel.hide-out {
    opacity: 1;
    pointer-events: none;
}

#group-details-modal.slide-panel.hide-out .modal-content {
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 1, 1);
}

.group-details-content {
    max-width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
    overflow: hidden;
}

/* Team Info Card - Sticky at top */
.team-info-card {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--tg-bg);
    padding: 16px;
    padding-top: 50px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.team-close-btn {
    position: absolute;
    top: 12px;
    inset-inline-start: 12px;
}

/* Team info row - name and members side by side */
.team-info-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

/* Team name section */
.team-name-section {
    flex: 1;
}

/* Team members section */
.team-members-section {
    flex-shrink: 0;
}

.team-members-box {
    width: 48px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tg-bg-secondary);
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--tg-text);
    box-sizing: border-box;
}

.team-name-field {
    display: flex;
    align-items: center;
    position: relative;
}

.team-members-badge {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--tg-hint);
    background: var(--tg-bg-secondary);
    padding: 6px 10px;
    border-radius: var(--radius-md);
    white-space: nowrap;
    flex-shrink: 0;
}

.team-name-input {
    flex: 1;
    height: 44px;
    padding: 0 12px 0 44px;
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    text-align: end;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.team-name-input:focus {
    outline: none;
    border-color: var(--tg-button-color);
    background: var(--tg-bg);
}

.team-name-input:read-only {
    cursor: default;
}

.team-name-input::placeholder {
    color: var(--tg-hint);
    font-weight: 400;
}

.btn-icon-edit {
    position: absolute;
    inset-inline-start: 4px;
    width: 34px;
    height: 34px;
    border-radius: calc(var(--radius-md) - 2px);
    border: none;
    background: transparent;
    color: var(--tg-hint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.btn-icon-edit:hover {
    background: var(--tg-bg);
}

.btn-icon-edit:active {
    background: var(--tg-bg);
}

.btn-icon-edit.editing {
    color: var(--tg-button-color);
}

.btn-icon-edit .icon-edit,
.btn-icon-edit .icon-save {
    display: block;
}

.btn-icon-edit .icon-save.hidden,
.btn-icon-edit .icon-edit.hidden {
    display: none;
}

.team-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.team-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--tg-text);
}

.team-stat-label {
    font-size: 0.75rem;
    color: var(--tg-hint);
    font-weight: 500;
}

/* Rename section */
.team-rename-section {
    margin-bottom: 12px;
}

.group-rename-row {
    display: flex;
    gap: 8px;
}

.group-rename-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-family: inherit;
    font-size: 0.9rem;
    text-align: end;
}

.group-rename-input::placeholder {
    font-family: inherit;
    color: var(--tg-hint);
}

/* Invite section */
.team-invite-section {
    margin-bottom: 12px;
}

.team-section-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--tg-hint);
    display: block;
    margin-bottom: 6px;
}

.team-invite-field {
    display: flex;
    align-items: center;
    position: relative;
}

.team-invite-input {
    flex: 1;
    height: 44px;
    padding: 0 12px 0 44px;
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-family: monospace;
    font-size: 0.8rem;
    text-align: center;
    direction: ltr;
    box-sizing: border-box;
}

.btn-icon-copy-inside {
    position: absolute;
    inset-inline-start: 4px;
    width: 34px;
    height: 34px;
    border-radius: calc(var(--radius-md) - 2px);
    border: none;
    background: transparent;
    color: var(--tg-hint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.btn-icon-copy-inside:hover {
    background: var(--tg-bg);
}

.btn-icon-copy-inside:active {
    background: var(--tg-separator);
    color: var(--tg-button-color);
}

.btn-icon-copy {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--tg-separator);
    background: var(--tg-bg-secondary);
    color: var(--tg-hint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.btn-icon-copy:active {
    background: var(--tg-separator);
}

/* Action buttons row */
.team-actions-row {
    display: flex;
    gap: 10px;
}

.team-btn-share {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    background: var(--tg-button) !important;
    color: var(--tg-button-text) !important;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.team-btn-leave {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    background: transparent;
    color: var(--tg-destructive);
    border: 1px solid var(--tg-destructive);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.team-btn-leave:active {
    background: rgba(255, 59, 48, 0.1);
}

/* Members container - scrollable */
.team-members-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 0;
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

.team-members-container::-webkit-scrollbar {
    display: none;  /* Chrome, Safari, Opera */
}

.group-members-list {
    min-height: 200px;
}

.group-members-loading,
.group-members-error,
.group-members-empty {
    padding: 16px;
    text-align: center;
    color: var(--tg-hint);
    font-size: 0.9rem;
}

.group-members-error {
    color: var(--tg-destructive);
}

.group-member-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 10px;
    background: var(--tg-bg);
    border-bottom: 1px solid var(--tg-separator);
    cursor: pointer;
    transition: background 0.15s ease;
}

.group-member-item:last-child {
    border-bottom: none;
}

.group-member-item:active {
    background: var(--tg-bg-secondary);
}

.group-member-item.me {
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--tg-link) 20%, transparent);
    background: rgba(46, 166, 255, 0.18);
    border: 1px solid color-mix(in srgb, var(--tg-link) 60%, transparent);
    border-color: rgba(46, 166, 255, 0.35);
}

/* Member rank badge */
.member-rank {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--tg-separator);
    color: var(--tg-hint);
    flex-shrink: 0;
}

.member-rank.gold {
    background: linear-gradient(135deg, #ffd700, #ffb700);
    color: white;
}

.member-rank.silver {
    background: linear-gradient(135deg, #e8e8e8, #b8b8b8);
    color: #555;
}

.member-rank.bronze {
    background: linear-gradient(135deg, #cd7f32, #b87333);
    color: white;
}

/* Member avatar */
.member-avatar-container {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.member-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.member-avatar-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tg-link);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
}

.member-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.member-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.member-stats {
    font-size: 0.75rem;
    color: var(--tg-hint);
}

.member-score {
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--tg-link);
    flex-shrink: 0;
}

.owner-badge {
    font-size: 0.75rem;
}

.member-owner-badge {
    font-size: 0.7rem;
    background: var(--tg-button);
    color: var(--tg-button-text);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.member-premium-badge {
    font-size: 0.8rem;
}

.member-remove-btn {
    background: transparent;
    border: none;
    color: var(--tg-destructive);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
}

.member-remove-btn:hover {
    opacity: 1;
    background: rgba(255, 59, 48, 0.1);
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid var(--tg-destructive);
    color: var(--tg-destructive);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.btn-danger-outline:hover {
    background: rgba(255, 59, 48, 0.1);
}

.settings-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 0 4px;
    font-size: 0.75rem;
    color: var(--tg-hint);
}

.leaderboard-context {
    font-size: 0.85rem;
    color: var(--tg-hint);
}

.modal.slide-panel {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: flex-end;
    align-items: stretch;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.slide-panel .modal-content {
    width: min(420px, 100%);
    max-width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal.slide-panel.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal.slide-panel.visible .modal-content {
    transform: translateX(0);
}

/* Keep panel visible during close animation */
.modal.slide-panel.hide-out {
    opacity: 1;
    pointer-events: none;
}

.modal.slide-panel.hide-out .modal-content {
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 1, 1);
}

/* ===== Policy Modals (Privacy & Terms) ===== */
.policy-content {
    max-width: 420px;
}

.policy-body {
    padding: 0 20px 24px;
}

.policy-content-text {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--tg-text);
}

.policy-content-text h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--tg-text);
}

.policy-content-text h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 16px 0 8px;
    color: var(--tg-text);
}

.policy-content-text p {
    margin-bottom: 12px;
    color: var(--tg-text);
}

.policy-content-text ul {
    margin: 0 0 12px 0;
    padding-inline-start: 20px;
    list-style: disc;
}

.policy-content-text li {
    margin-bottom: 6px;
    color: var(--tg-text);
}

/* ===== Delete Account Modal ===== */
.delete-content {
    max-width: 360px;
}

.delete-body {
    padding: 0 20px 24px;
}

.delete-warning {
    text-align: center;
    padding: 20px;
    background: rgba(255, 59, 48, 0.08);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.delete-warning-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.delete-warning h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--tg-text);
    margin-bottom: 12px;
}

.delete-warning p {
    font-size: 0.9rem;
    color: var(--tg-text);
    margin-bottom: 8px;
    line-height: 1.5;
}

.delete-warning ul {
    text-align: end;
    margin: 12px 0;
    padding-inline-start: 20px;
    list-style: disc;
}

.delete-warning li {
    font-size: 0.85rem;
    color: var(--tg-hint);
    margin-bottom: 4px;
}

.delete-warning strong {
    color: var(--tg-destructive);
}

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

.delete-actions .btn {
    flex: 1;
}

.btn-danger {
    background: var(--tg-destructive);
    color: white;
}

.btn-danger:active {
    opacity: 0.8;
}

/* Dark theme button icon filter */
.dark-theme .btn-icon,
body[data-theme="dark"] .btn-icon {
    filter: invert(1);
}

/* Hover states for settings */
@media (hover: hover) {
    .settings-item:hover {
        background: var(--tg-bg-secondary);
    }
}

/* ===== Pages Container - Fade Transition ===== */
.pages-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0; /* Important for flex children */
    width: 100%;
}

.pages-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.page {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    background: var(--tg-bg);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 0;
}

.page.active {
    opacity: 1;
    visibility: visible;
    z-index: 1;
}

/* Hide scrollbar on pages for cleaner look */
.page::-webkit-scrollbar {
    display: none;
}
.page {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.page-content {
    padding: 20px 16px;
    padding-bottom: calc(90px + var(--safe-area-bottom));
    width: 100%;
    box-sizing: border-box;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--tg-text);
    text-align: center;
    margin-bottom: 20px;
    letter-spacing: -0.5px;
}

/* Home page specific - no extra padding, game fills space */
.page[data-page="home"] {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Don't scroll the home page */
    padding-bottom: 0;
}

.page[data-page="home"] .game-container {
    flex: 1;
    min-height: 0;
}

/* Page-specific settings list */
.page-settings-list {
    margin-bottom: 0;
}

/* Help page content */
.help-page-content {
    padding-top: 8px;
    padding-inline-start: 24px;
}

.help-page-content .page-title {
    text-align: end;
}

.help-page-content .onboarding-subtitle {
    text-align: end;
}

.help-page-content .onboarding-rules {
    text-align: end;
    padding-inline-start: 24px;
}

.help-page-content .examples-title {
    text-align: end;
}

.help-page-content .example-explanation {
    text-align: end;
}

.help-page-content .onboarding-footer {
    text-align: end;
}

/* Stats page distribution */
.page[data-page="stats"] .distribution {
    margin-top: 8px;
}

/* Leaderboard page list - taller */
.page[data-page="leaderboard"] .leaderboard-list {
    max-height: none;
    flex: 1;
    min-height: 200px;
    padding-bottom: 100px; /* Space for fixed my-rank section */
    background: var(--tg-bg);
}

/* Stats page styles */
.page[data-page="stats"] .stats-grid {
    margin-bottom: 24px;
}

.page[data-page="stats"] .section-title {
    margin-bottom: 12px;
}

/* Settings page footer */
.settings-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--tg-separator);
    color: var(--tg-hint);
    font-size: 0.8rem;
}

/* Leaderboard page improvements */
.page[data-page="leaderboard"] .page-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: 16px;
}

/* Season Banner */
.season-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--tg-bg-secondary);
    border: 1px solid var(--tg-separator);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.season-banner .season-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--tg-text);
}

.season-banner .season-countdown {
    font-size: 13px;
    color: var(--tg-button-text);
    background: var(--tg-button);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

.page[data-page="leaderboard"] .leaderboard-tabs {
    margin-bottom: 16px;
}

.page[data-page="leaderboard"] .my-rank-section {
    margin-bottom: 16px;
}

/* Fixed My Rank at bottom of leaderboard (above navbar) */
.page[data-page="leaderboard"] .my-rank-bottom {
    position: fixed;
    bottom: calc(90px + var(--safe-area-bottom));
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: var(--max-app-width);
    padding: 0 16px;
    z-index: 110;
    padding-top: 8px;
    padding-bottom: 8px;
    background: var(--tg-bg);
}

.page[data-page="leaderboard"] .leaderboard-stats {
    margin-bottom: 16px;
}

/* ===== Bottom Tab Navigation (Royal Match Style) ===== */
.bottom-nav {
    display: flex;
    direction: ltr; /* Force LTR for consistent tab order */
    justify-content: space-around;
    align-items: flex-end;
    padding: 8px 12px;
    padding-bottom: calc(12px + var(--safe-area-bottom));
    background: var(--tg-bg);
    border-top: 0.5px solid var(--tg-separator);
    flex-shrink: 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: var(--max-app-width);
    margin: 0 auto;
    z-index: 120;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
}

.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--tg-hint);
    font-size: 0.7rem;
    font-weight: 900;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius-md);
    min-width: 56px;
}

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

.nav-tab.active {
    color: var(--tg-text);
}

.nav-tab .nav-icon {
    width: 24px;
    height: 24px;
    opacity: 0.8;
    transition: all var(--transition-fast);
}

.nav-tab.active .nav-icon {
    opacity: 1;
}

/* Light theme nav icon - invert white to black, reduce opacity for hint color */
.nav-tab .nav-icon {
    filter: invert(1);
    opacity: 0.5;
}

.nav-tab.active .nav-icon {
    opacity: 1;
}

/* Dark theme nav icon - keep white, reduce opacity for hint color */
.dark-theme .nav-tab .nav-icon,
body[data-theme="dark"] .nav-tab .nav-icon {
    filter: none;
    opacity: 0.5;
}

.dark-theme .nav-tab.active .nav-icon,
body[data-theme="dark"] .nav-tab.active .nav-icon {
    filter: none;
    opacity: 1;
}

/* Active tab icon wrapper - theme colored circle */
.nav-icon-wrapper {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

.nav-tab.active .nav-icon-wrapper {
    background: var(--tg-button);
}

.nav-tab.active .nav-icon-wrapper .nav-icon {
    opacity: 1 !important;
    filter: none !important; /* Keep white icons on colored background */
}

/* Center Home Tab - Elevated Style */
.nav-tab[data-tab="home"] {
    position: relative;
}

.nav-tab[data-tab="home"] .nav-icon-wrapper {
    width: 48px;
    height: 48px;
    margin-top: -20px;
}

.nav-tab[data-tab="home"].active .nav-icon-wrapper {
    transform: scale(1.05);
}

.nav-tab[data-tab="home"] .nav-icon-wrapper .nav-icon {
    width: 26px;
    height: 26px;
}

.nav-tab span {
    line-height: 1;
}

/* ===== Centered Header ===== */
.logo-title.centered {
    width: 100%;
    justify-content: center;
}

/* ===== Waiting Section (Game Finished - Home Page) ===== */
.waiting-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px 16px;
    margin-top: 8px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-lg);
    max-width: var(--max-board-width);
    width: 100%;
}

.waiting-section.hidden {
    display: none !important;
}

.waiting-timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.waiting-label {
    font-size: 0.85rem;
    color: var(--tg-hint);
    font-weight: 600;
}

.waiting-countdown {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--tg-button);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    letter-spacing: 1px;
}

.waiting-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 200px;
}

.share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    background: var(--tg-button);
    color: var(--tg-button-text);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 100%;
}

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

.share-btn .btn-icon {
    width: 16px;
    height: 16px;
    filter: brightness(0) invert(1);
}

.social-icons {
    display: flex;
    gap: 8px;
    width: 100%;
}

.social-icon-btn {
    flex: 1;
    height: 48px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.social-icon-btn:active {
    transform: scale(0.98);
    background: var(--tg-separator);
}

.social-icon-btn svg,
.social-icon-btn img {
    width: 18px;
    height: 18px;
    filter: invert(1);
}

.dark-theme .social-icon-btn img,
body[data-theme="dark"] .social-icon-btn img {
    filter: none;
}

/* ===== Home Page Styles ===== */
.home-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 24px 16px;
    padding-bottom: calc(90px + var(--safe-area-bottom));
    text-align: center;
}

.home-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 40px;
}

.home-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.home-title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--tg-text);
    margin: 0;
    letter-spacing: -1px;
}

.home-subtitle {
    font-size: 1rem;
    color: var(--tg-hint);
    margin: 0;
}

/* Guest Notice Banner */
.guest-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    margin: 12px 0 20px;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: var(--radius-md);
    color: #ffc107;
    font-size: 0.85rem;
}

.guest-notice.hidden {
    display: none;
}

.guest-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--tg-hint);
}

.guest-text {
    font-weight: 500;
}

/* ===== Google Sign-In Section ===== */
.google-signin-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    width: 100%;
    max-width: 280px;
}

.google-signin-section.hidden {
    display: none;
}

.signin-divider {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 16px;
    color: var(--tg-hint);
    font-size: 0.85rem;
}

.signin-divider::before,
.signin-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--tg-separator);
}

.google-signin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    height: 48px;
    padding: 0 24px;
    border-radius: 24px;
    border: 1px solid var(--tg-separator);
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.google-signin-btn:hover {
    background: var(--tg-bg);
    border-color: var(--tg-hint);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.google-signin-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.google-signin-btn .google-icon {
    flex-shrink: 0;
}

.signin-hint {
    font-size: 0.8rem;
    color: var(--tg-hint);
    text-align: center;
    margin: 0;
}

.home-play-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: -20px;
}

.home-play-section.hidden {
    display: none !important;
}

.play-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: auto;
    min-width: 160px;
    height: 56px;
    padding: 0 32px;
    border-radius: 28px;
    border: none;
    background: var(--tg-button);
    color: var(--tg-button-text);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.play-button:active {
    transform: scale(0.95);
}

.play-button svg {
    width: 24px;
    height: 24px;
    margin-inline-start: 2px; /* Visual centering for play icon */
}

.play-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--tg-text);
}

.home-streak {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    padding: 8px 16px;
    background: var(--tg-bg-secondary);
    border-radius: 20px;
    font-size: 0.95rem;
}

.home-streak.hidden {
    display: none !important;
}

.streak-fire {
    font-size: 1.1rem;
}

#home-streak-count {
    font-weight: 700;
    color: #ff9500;
    font-size: 1.1rem;
}

.streak-label {
    color: var(--tg-hint);
    font-size: 0.85rem;
}

.home-waiting-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    margin-bottom: -40px;
}

.home-waiting-section.hidden {
    display: none !important;
}

.home-word-info {
    position: absolute;
    bottom: calc(100px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%);
    color: var(--tg-hint);
    font-size: 0.9rem;
}

/* ===== Game View Styles (Full Screen) ===== */
.page[data-page="game"] {
    padding-bottom: 0; /* No bottom nav padding */
    display: flex;
    flex-direction: column;
    height: 100%;
}

.page[data-page="game"] .game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;  /* Center board vertically */
    padding-top: 10px;
    padding-bottom: calc(290px + var(--safe-area-bottom)); /* Clear keyboard + economy buttons */
}

.page[data-page="game"] .keyboard-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: var(--max-app-width);
    margin: 0 auto;
    margin-bottom: 0 !important;
    padding: 6px 4px;
    padding-bottom: calc(12px + var(--safe-area-bottom));
    z-index: 150;
}

.page[data-page="game"].active ~ .bottom-nav {
    display: none;
}

/* Hide bottom nav when duel game is actively being played */
/* This targets the duel page when .duel-game element is present (playing state) */
.page[data-page="duel"].active:has(.duel-game) ~ .bottom-nav {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Hide bottom nav when game is active */
body.game-active .bottom-nav {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Allow keyboard to be fully visible in game view */
body.game-active #app {
    overflow: visible;
    padding-bottom: 0;
}

.game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-area-top, 0px));
    gap: 8px;
}

.game-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--tg-bg-secondary);
    color: var(--tg-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.game-header-btn:active {
    transform: scale(0.92);
    background: var(--tg-separator);
}

.game-header-icon {
    width: 19px;
    height: 19px;
    /* Icons are already white */
}

/* Hint in header - centered between buttons */
.header-hint {
    flex: 1;
    background: transparent !important;
    padding: 6px 8px;
    margin: 0;
    text-align: center;
    overflow: hidden;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-hint #hint-text {
    font-size: 0.85rem;
    color: var(--tg-hint);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Help page start game button */
.help-start-game-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 16px 24px;
    margin-top: 24px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.help-start-game-btn:active {
    transform: scale(0.97);
}

.help-start-game-btn svg {
    width: 24px;
    height: 24px;
}

/* Modal Start Game Button */
.modal-start-game-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 16px 24px;
    margin-top: 24px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--color-correct), var(--color-correct-dark));
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-start-game-btn:active {
    transform: scale(0.97);
}

.modal-start-game-btn svg {
    width: 24px;
    height: 24px;
}

.play-button.hidden {
    display: none !important;
}

/* Game finished state - fade the board */
.game-container.game-finished #board {
    opacity: 0.4;
    pointer-events: none;
}

.game-container.game-finished #hint {
    display: none;
}

.game-container.game-finished .waiting-section {
    animation: fadeSlideUp 0.4s ease-out forwards;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== User Profile Modal (Full Screen) - Compact ===== */
.user-profile-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
}

.user-profile-body {
    padding: 0 16px 24px;
    overflow-y: auto;
    height: calc(100% - 60px);
}

.user-profile-card {
    margin-bottom: 12px;
    padding: 12px;
    gap: 10px;
}

.user-profile-card .my-profile-avatar {
    width: 48px;
    height: 48px;
    font-size: 22px;
    border-width: 2px;
}

.user-profile-card .my-profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.user-profile-card .my-profile-name {
    font-size: 1rem;
}

.user-profile-card .my-profile-username {
    font-size: 0.8rem;
}

.user-profile-ranks {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 20px 0;
}

.user-profile-ranks .rank-card {
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-profile-ranks .rank-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--tg-button);
}

.user-profile-ranks .rank-label {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

/* Override slide-panel for user profile to slide from bottom */
#user-profile-modal.slide-panel {
    justify-content: center;
    align-items: flex-end;
    z-index: 1001; /* Higher than team details modal */
}

#user-profile-modal.slide-panel .modal-content {
    width: 100%;
    max-width: 500px;
    height: 90vh;
    max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

#user-profile-modal.slide-panel.visible .modal-content {
    transform: translateY(0);
}

#user-profile-modal.slide-panel.hide-out {
    opacity: 1;
    pointer-events: none;
}

#user-profile-modal.slide-panel.hide-out .modal-content {
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 1, 1);
}

/* Legacy profile modal styles (keep for compatibility) */
.profile-content {
    max-width: 320px;
}

.profile-content .modal-body {
    padding: 8px 16px 16px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0 10px;
    border-bottom: 1px solid var(--tg-bg-secondary);
    margin-bottom: 10px;
}

.profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--tg-bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.profile-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-username {
    font-size: 0.7rem;
    color: var(--tg-hint);
}

.profile-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.profile-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 2px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-sm);
}

.profile-stat-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--tg-text);
}

.profile-stat-label {
    font-size: 0.55rem;
    color: var(--tg-hint);
    text-align: center;
    margin-top: 2px;
    line-height: 1.2;
}

.profile-ranks {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.profile-rank-item {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-sm);
}

.profile-rank-label {
    font-size: 0.65rem;
    color: var(--tg-hint);
}

.profile-rank-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--tg-button);
}

.profile-distribution {
    margin-top: 2px;
}

.profile-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--tg-hint);
    margin-bottom: 6px;
}

/* Compact distribution bars for profile modal */
.profile-distribution .dist-row {
    gap: 6px;
    margin-bottom: 3px;
}

.profile-distribution .dist-badge {
    width: 20px;
    min-width: 20px;
    height: 16px;
    font-size: 0.6rem;
    border-radius: 4px;
}

.profile-distribution .dist-bar-track {
    height: 16px;
    border-radius: 4px;
}

.profile-distribution .dist-bar-fill {
    font-size: 0.55rem;
    font-weight: 700;
    padding: 0 6px;
    border-radius: 4px;
}

.profile-distribution .dist-count {
    min-width: 10px;
}

/* ===== My Profile Page (Stats Tab) - Compact ===== */
.profile-page-content {
    padding: 12px 16px;
}

/* Profile Card - Avatar + Name + Edit Button */
.profile-card {
    background: var(--tg-bg-secondary);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.my-profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tg-bg);
    border: 3px solid var(--tg-link);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    overflow: hidden;
}

.my-profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.my-profile-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.my-profile-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.my-profile-username {
    font-size: 0.8rem;
    color: var(--tg-hint);
}

/* Profile Edit Button */
.my-profile-edit-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tg-bg);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-hint);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.my-profile-edit-btn svg {
    width: 16px;
    height: 16px;
}

.my-profile-edit-btn:hover,
.my-profile-edit-btn:active {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

/* Compact Stats Grid for Profile Page */
.profile-page-content .stats-grid,
.user-profile-body .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.profile-page-content .stat-item,
.user-profile-body .stat-item {
    padding: 12px 8px;
}

.profile-page-content .stat-value,
.user-profile-body .stat-value {
    font-size: 1.4rem;
}

.profile-page-content .stat-label,
.user-profile-body .stat-label {
    font-size: 0.7rem;
    margin-top: 2px;
}

/* Compact Section Title */
.profile-page-content .section-title,
.user-profile-body .section-title {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

/* Compact Distribution for Profile */
.profile-page-content .distribution,
.user-profile-body .distribution {
    gap: 6px;
}

.profile-page-content .dist-row,
.user-profile-body .dist-row {
    gap: 8px;
}

.profile-page-content .dist-badge,
.user-profile-body .dist-badge {
    width: 32px;
    min-width: 32px;
    height: 26px;
    font-size: 0.85rem;
    border-radius: 6px;
}

.profile-page-content .dist-bar-track,
.user-profile-body .dist-bar-track {
    height: 26px;
    border-radius: 6px;
}

.profile-page-content .dist-bar-fill,
.user-profile-body .dist-bar-fill {
    border-radius: 6px;
}

.profile-page-content .dist-count,
.user-profile-body .dist-count {
    font-size: 0.8rem;
}

/* Profile Edit Modal */
.profile-edit-content {
    max-width: 300px;
}

.profile-edit-content .modal-header {
    padding: 12px 16px;
}

.profile-edit-content .modal-header h2 {
    font-size: 0.95rem;
}

.profile-edit-content .modal-body {
    padding: 12px 20px 20px;
}

.profile-edit-content .form-group {
    margin-bottom: 16px;
}

.profile-edit-content .form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 6px;
    display: block;
    text-align: end;
    color: var(--tg-hint);
}

.profile-edit-content .form-group input {
    font-size: 0.85rem;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--tg-bg-secondary);
    border: 1px solid transparent;
    width: 100%;
    text-align: end;
    color: var(--tg-text);
}

.profile-edit-content .form-group input:focus {
    border-color: var(--tg-link);
    outline: none;
}

.profile-edit-content .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--tg-bg-secondary);
}

.profile-edit-content .toggle-row:last-of-type {
    border-bottom: none;
}

.profile-edit-content .toggle-title {
    font-size: 0.8rem;
    font-weight: 500;
}

/* Smaller toggle switch for profile modal */
.profile-edit-content .toggle-switch {
    width: 40px;
    height: 22px;
}

.profile-edit-content .switch-slider:before {
    height: 16px;
    width: 16px;
    inset-inline-start: 3px;
    bottom: 3px;
}

.profile-edit-content .toggle-switch input:checked + .switch-slider:before {
    inset-inline-start: calc(100% - 19px);
}

.profile-edit-content .modal-actions {
    margin-top: 16px;
    padding: 0;
}

.profile-edit-content .modal-actions .btn {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

/* Tighter layout for profile/privacy modals */
#profile-privacy-modal .settings-body {
    padding: 12px 14px 18px;
}

#profile-privacy-modal .form-group {
    padding: 6px 8px;
    margin-bottom: 12px;
}

#profile-privacy-modal .form-group label {
    font-size: 0.85rem;
}

#profile-privacy-modal .form-group input {
    font-size: 0.85rem;
    padding: 8px 10px;
}

#profile-privacy-modal .toggle-row {
    padding: 8px 10px;
    margin-bottom: 8px;
}

#profile-privacy-modal .toggle-title {
    font-size: 0.85rem;
}

#profile-privacy-modal .toggle-desc {
    font-size: 0.75rem;
}

#profile-privacy-modal .toggle-text {
    gap: 4px;
}

#profile-privacy-modal .modal-actions .btn {
    padding: 10px 12px;
    font-size: 0.9rem;
}

#my-profile-edit-modal .modal-body {
    padding: 12px 14px 18px;
}

#my-profile-edit-modal .form-group {
    padding: 0;
    margin-bottom: 12px;
}

#my-profile-edit-modal .form-group label {
    font-size: 0.85rem;
}

#my-profile-edit-modal .form-group input {
    font-size: 0.85rem;
    padding: 9px 12px;
}

#my-profile-edit-modal .toggle-row {
    padding: 8px 10px;
    margin-bottom: 8px;
}

#my-profile-edit-modal .toggle-title {
    font-size: 0.85rem;
}

#my-profile-edit-modal .modal-actions .btn {
    padding: 10px 12px;
    font-size: 0.9rem;
}
