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

:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --success: #00B894;
    --danger: #E17055;
    --warning: #FDCB6E;
    --bg: #F8F9FA;
    --card-bg: #FFFFFF;
    --text: #2D3436;
    --text-light: #636E72;
    --border: #DFE6E9;
    --shadow: 0 2px 10px rgba(0,0,0,0.08);
    --radius: 16px;
    --radius-sm: 10px;
}

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

/* --- Screens --- */
.screen {
    display: none;
    padding: 20px;
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 20px;
}
.header h1 {
    font-size: 22px;
    font-weight: 700;
}
.header-back {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--primary);
    padding: 5px 10px;
}

/* --- Cards --- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}
.card:active {
    transform: scale(0.98);
}
.card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}
.card-subtitle {
    font-size: 14px;
    color: var(--text-light);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
    gap: 8px;
}
.btn:active {
    transform: scale(0.97);
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: #5A4BD1;
}
.btn-success {
    background: var(--success);
    color: white;
}
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}
.btn-sm {
    padding: 10px 20px;
    font-size: 14px;
}
.btn-icon {
    width: auto;
    padding: 12px;
    border-radius: 50%;
    min-width: 48px;
    min-height: 48px;
}

/* --- Input --- */
.input-group {
    margin-bottom: 16px;
}
.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-light);
}
.input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    transition: border-color 0.15s;
    outline: none;
}
.input:focus {
    border-color: var(--primary);
}

/* --- Language Switch --- */
.lang-switch {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}
.lang-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.lang-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* --- Flashcard --- */
.flashcard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.flashcard {
    width: 100%;
    max-width: 360px;
    min-height: 220px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    cursor: pointer;
    transition: transform 0.4s;
    perspective: 1000px;
    position: relative;
}
.flashcard .word-target {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}
.flashcard .word-ru {
    font-size: 20px;
    color: var(--text-light);
    text-align: center;
}
.flashcard .word-example {
    font-size: 14px;
    color: var(--text-light);
    text-align: center;
    margin-top: 12px;
    font-style: italic;
}
.flashcard .tap-hint {
    font-size: 12px;
    color: var(--border);
    position: absolute;
    bottom: 12px;
}
.flashcard-controls {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 360px;
}
.flashcard-progress {
    text-align: center;
    font-size: 14px;
    color: var(--text-light);
}

/* --- Quiz --- */
.quiz-word {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    padding: 30px 0;
}
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.quiz-option {
    padding: 16px 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}
.quiz-option:hover {
    border-color: var(--primary-light);
}
.quiz-option.correct {
    border-color: var(--success);
    background: #E8F8F5;
}
.quiz-option.wrong {
    border-color: var(--danger);
    background: #FDECEA;
}
.quiz-option.disabled {
    pointer-events: none;
    opacity: 0.7;
}
.quiz-feedback {
    text-align: center;
    padding: 16px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
    font-size: 15px;
}
.quiz-feedback.correct {
    background: #E8F8F5;
    color: #00B894;
}
.quiz-feedback.wrong {
    background: #FDECEA;
    color: #E17055;
}

/* --- Voice button --- */
.voice-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}
.voice-btn:hover {
    transform: scale(1.05);
}
.voice-btn.recording {
    background: var(--danger);
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(225, 112, 85, 0.4); }
    50% { box-shadow: 0 0 0 15px rgba(225, 112, 85, 0); }
}

/* --- Game Lobby --- */
.lobby-players {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}
.player-tag {
    padding: 8px 16px;
    background: var(--primary-light);
    color: white;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

/* --- Scoreboard --- */
.scoreboard {
    width: 100%;
}
.score-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
}
.score-rank {
    font-size: 20px;
    font-weight: 700;
    width: 40px;
    color: var(--primary);
}
.score-name {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
}
.score-points {
    font-size: 18px;
    font-weight: 700;
    color: var(--success);
}

/* --- Game answer input --- */
.game-input-area {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding: 16px 0;
}
.game-input-area .input {
    flex: 1;
}

/* --- Timer bar --- */
.timer-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin: 10px 0;
}
.timer-bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 1s linear;
}

/* --- Badge / Level --- */
.level-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}
.level-a1 { background: #DFE6E9; color: #636E72; }
.level-a2 { background: #FFEAA7; color: #6C5CE7; }

/* --- Stats grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* --- Loading --- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Toast notification --- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: white;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    transition: transform 0.3s ease;
    white-space: nowrap;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* --- Invite / QR --- */
.qr-container {
    text-align: center;
    padding: 20px;
}
.qr-container img {
    max-width: 250px;
    border-radius: var(--radius);
}
.invite-link {
    word-break: break-all;
    font-size: 13px;
    color: var(--primary);
    padding: 10px;
    background: #F0EFFF;
    border-radius: var(--radius-sm);
    margin: 10px 0;
}

/* --- Admin table --- */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}
.admin-table th, .admin-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-table th {
    font-weight: 600;
    color: var(--text-light);
    font-size: 12px;
    text-transform: uppercase;
}

/* --- Section title --- */
.section-title {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-light);
    letter-spacing: 1px;
    margin: 20px 0 12px;
}

/* --- Responsive --- */
@media (max-width: 400px) {
    .screen { padding: 12px; }
    .flashcard .word-target { font-size: 26px; }
    .quiz-word { font-size: 24px; }
}

/* --- Rummikub tiles --- */
.rummi-tile {
    width: 40px; height: 56px; border-radius: 8px;
    background: #fff5dc;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 900;
    box-shadow: 0 2px 3px rgba(0,0,0,0.25);
    cursor: pointer; user-select: none;
    flex-shrink: 0;
}
.rummi-tile.sel { outline: 3px solid #ffd84a; transform: translateY(-4px); }
.rummi-tile.black { color: #111; }
.rummi-tile.blue { color: #1946c4; }
.rummi-tile.red { color: #c42020; }
.rummi-tile.orange { color: #e07600; }
.rummi-tile.joker { color: #8b008b; font-size: 26px; }
