:root {
    /* Mathico Quest — light */
    --bg-primary: #E8F4F2;
    --bg-card: #FFFcf7;
    --bg-secondary: #D8EBE8;
    --text-primary: #0F2E2B;
    --text-secondary: #5A7A75;
    --accent-color: #0D7377;
    --accent-hover: #095E61;
    --accent-citrus: #F4A261;
    --accent-citrus-hover: #E08E4A;
    --border-color: rgba(13, 115, 119, 0.14);
    --shadow-card: 0 8px 28px rgba(15, 46, 43, 0.08);
    --font-family: "Nunito Sans", "Nunito", system-ui, sans-serif;
    --font-display: "Fredoka", "Nunito", system-ui, sans-serif;
    --header-bg: rgba(255, 252, 247, 0.88);
    --bg-input-focus: #FFFFFF;
    --success-color: #2A9D8F;
    --error-color: #E76F51;
    --warning-color: #E9C46A;
    --spring-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
    --quest-glow: rgba(244, 162, 97, 0.35);

    /* Legacy aliases used by modals / map / shop */
    --card-bg: var(--bg-card);
    --bg-color: var(--bg-primary);
    --text-color: var(--text-primary);
    --surface-color: var(--bg-card);
}

[data-theme="dark"] {
    --bg-primary: #071A19;
    --bg-card: #0F2A28;
    --bg-secondary: #163634;
    --text-primary: #F3F7F6;
    --text-secondary: #9BB5B1;
    --accent-color: #2A9D8F;
    --accent-hover: #3DB5A6;
    --accent-citrus: #F4A261;
    --accent-citrus-hover: #FFB57A;
    --border-color: rgba(255, 255, 255, 0.12);
    --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.35);
    --header-bg: rgba(15, 42, 40, 0.9);
    --bg-input-focus: #163634;
    --success-color: #2A9D8F;
    --error-color: #E76F51;
    --warning-color: #E9C46A;
    --quest-glow: rgba(42, 157, 143, 0.35);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(ellipse 80% 50% at 10% -10%, rgba(42, 157, 143, 0.18), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(244, 162, 97, 0.14), transparent 50%),
        radial-gradient(circle at 80% 90%, rgba(13, 115, 119, 0.08), transparent 40%);
    color: var(--text-primary);
    color-scheme: light;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

[data-theme="dark"] body,
html[data-theme="dark"] body {
    color-scheme: dark;
}

h1, h2, h3, .main-title, .app-title, .leaderboard-title, .wm-world-title {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

/* Floating Numbers Canvas - Behind everything */
.screen {
    flex: 1 1 auto;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

#confetti,
#floatingNumbersCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Container */
.container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 1;
    /* Above canvas */
}

/* Header */
.app-header,
.login-header {
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0 0 20px 20px;
    box-shadow: var(--shadow-card);
}

.login-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 0 0 20px 20px;
    margin-bottom: 24px;
}

.main-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
    flex-wrap: nowrap;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto; /* не се свива — иначе „Игра“ се качва върху Класация */
    min-width: 0;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

#userName {
    font-weight: 600;
    font-size: 0.95rem;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.theme-toggle-btn:hover {
    background: rgba(128, 128, 128, 0.1);
}

.logout-btn {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Cards */
.card,
.glass-card,
.auth-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Buttons */
.btn-primary {
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-display);
    width: 100%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 6px 16px rgba(13, 115, 119, 0.28);
    transition: background 0.2s, transform 0.2s var(--spring-easing), box-shadow 0.2s;
}

.btn-primary:active {
    transform: scale(0.96);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-citrus {
    background: linear-gradient(135deg, var(--accent-citrus), #E76F51);
    box-shadow: 0 8px 22px var(--quest-glow);
}

.btn-citrus:hover {
    background: linear-gradient(135deg, var(--accent-citrus-hover), #E76F51);
}

/* Compare buttons (< = >) за ниво Сравняване */
.compare-btn {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    border: none;
    background: var(--accent-color);
    color: #fff;
    font-size: 2rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(13, 115, 119, 0.3);
    font-family: var(--font-family);
}

.compare-btn:hover {
    background: var(--accent-hover, #0056b3);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 122, 255, 0.4);
}

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

/* Shape Display (нива 9 и 10) */
#shapeDisplay {
    justify-content: center;
    align-items: center;
    margin: 8px auto;
    min-height: 160px;
}

#shapeDisplay svg {
    width: 160px;
    height: 160px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

/* Shape Choice Buttons (ниво 9) */
#shapeButtons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 12px 0;
}

.shape-btn {
    padding: 14px 10px;
    border-radius: 16px;
    border: 2px solid transparent;
    background: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
    font-family: var(--font-family);
    text-align: center;
}

.shape-btn:hover {
    background: var(--accent-color, #007AFF);
    color: #fff;
    border-color: var(--accent-color, #007AFF);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.3);
}

.shape-btn:active {
    transform: scale(0.96);
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
    width: 100%;
    padding: 16px;
    /* Increased padding */
    border-radius: 14px;
    /* More rounded */
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.05rem;
    /* Slightly larger font */
    line-height: 1.5;
    /* Better spacing */
    letter-spacing: 0.01em;
    margin-bottom: 20px;
    /* More space between inputs */
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    /* Fix Lint: Appearance */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input:focus {
    border-color: var(--accent-color);
    background: var(--bg-input-focus) !important;
    color: var(--text-primary) !important;
    /* Theme aware background */
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

/* Specific overrides for Dark Mode to ensure contrast */
[data-theme="dark"] input,
[data-theme="dark"] input:focus,
[data-theme="dark"] #answerInput,
[data-theme="dark"] #answerInput:focus {
    background-color: #2C2C2E !important;
    background: #2C2C2E !important;
    color: #FFFFFF !important;
    -webkit-text-fill-color: #FFFFFF !important;
}

/* Fix for Webkit Autofill in Dark Mode */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px #2C2C2E inset !important;
    -webkit-text-fill-color: #FFFFFF !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: auto;
    /* Push to bottom */
}

/* Rest Screen Styles */
.rest-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.rest-content {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 30px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
}

.rest-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.rest-level-msg {
    color: var(--accent-color);
    font-size: 1.2rem;
    font-weight: 700;
    margin: 10px 0;
    min-height: 1.5em;
}

.rest-timer-c {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 20px auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.rest-bg-circle {
    stroke: var(--border-color);
    stroke-width: 10;
}

.rest-progress-circle {
    stroke: var(--accent-color);
    stroke-width: 10;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 1s linear;
    stroke-dasharray: 440;
    /* 2 * PI * 70 */
    stroke-dashoffset: 0;
}

.rest-time-text {
    position: absolute;
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-primary);
}

.rest-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.rest-btn {
    padding: 12px 24px;
    border-radius: 16px;
    border: none;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.1s, opacity 0.2s;
}

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

.rest-btn.pause {
    background: var(--warning-color);
    color: white;
}

.rest-btn.skip {
    background: var(--bg-primary);
    color: var(--text-primary);
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.hidden {
    display: none !important;
}

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

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

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

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

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 8px 0;
}

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

/* Tabs */
.tabs {
    background: var(--bg-primary);
    padding: 4px;
    border-radius: 14px;
    display: flex;
    position: relative;
    margin-bottom: 20px;
}

.tab-glider {
    position: absolute;
    top: 4px;
    left: 4px;
    bottom: 4px;
    width: 50%;
    background: var(--bg-card);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(13, 115, 119, 0.15);
    transition: transform 0.35s var(--spring-easing);
    z-index: 1;
}

.tab-btn {
    flex: 1;
    position: relative;
    z-index: 2;
    background: none;
    border: none;
    padding: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s;
}

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

/* Game Page Specifics */
.game-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow-card);
    font-weight: 600;
}

.question-box {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    margin: 40px 0;
}

/* Текстови задачи — по-малък шрифт, ляво наравняване */
.question-box.word-mode {
    font-size: 1.35rem;
    font-weight: 600;
    text-align: left;
    line-height: 1.55;
    margin: 20px 0;
    padding: 16px 20px;
    background: rgba(13, 115, 119, 0.08);
    border-radius: 16px;
    border-left: 4px solid var(--accent-color);
    color: var(--text-primary);
}

/* Timer Circle */
#timerContainer {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 30px;
}

.timer-circle {
    fill: none;
    stroke: var(--success-color);
    stroke-width: 8;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

#timerText {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Auth Card Height Animation */
.auth-card {
    overflow: hidden;
    transition: height 0.3s var(--spring-easing);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-message {
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    text-align: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.auth-message.error {
    color: var(--error-color);
    border-color: rgba(255, 59, 48, 0.2);
    background: rgba(255, 59, 48, 0.05);
}

.auth-message.success {
    color: var(--success-color);
    border-color: rgba(52, 199, 89, 0.2);
    background: rgba(52, 199, 89, 0.05);
}

/* Google Button */
.btn-google {
    background: #fff;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: 1px solid var(--border-color);
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.btn-google:hover {
    background: #f8f9fa;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

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

/* Checkbox Group */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    cursor: pointer;
    font-size: 1rem;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.checkbox-group small {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: 30px;
    /* Align with text */
    display: block;
}

.divider {
    text-align: center;
    margin: 24px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    position: relative;
    font-weight: 500;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 42%;
    height: 1px;
    background: var(--border-color);
}

.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 0;
    width: 42%;
    height: 1px;
    background: var(--border-color);
}

.guest-mode {
    margin-top: 24px;
    text-align: center;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 600;
    width: 100%;
}

.btn-secondary:hover {
    background: var(--bg-primary);
}

.forgot-password {
    display: block;
    text-align: right;
    margin-top: 8px;
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9rem;
}

.level-selector {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.level-btn {
    flex: 0 0 calc(25% - 8px);
    min-width: 70px;
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    padding: 10px 8px;
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.35;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    font-family: var(--font-display);
}

.level-btn:hover {
    border-color: var(--accent-color);
    background: rgba(13, 115, 119, 0.08);
}

.level-btn:active {
    transform: scale(0.96);
}

.level-btn.active {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

/* Game Page Specific Styles */
.game-container {
    max-width: 600px;
    margin: 0 auto;
}

.game-card {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
}

/* Profile Link */
.profile-link {
    text-decoration: none;
    padding: 8px 16px;
    font-size: 0.9rem;
    margin-right: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-weight: 600;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.profile-link:hover {
    background: var(--border-color);
}

/* Improved Stats */
.game-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 32px;
}

.stat-box {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
}

.stat-sublabel {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Progress Bar */
.progress-bar-container {
    background: rgba(0, 0, 0, 0.05);
    height: 8px;
    border-radius: 4px;
    margin-top: 24px;
    overflow: hidden;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--success-color);
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* Hide number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Question Box */
.question-box {
    font-size: 2.85rem;
    font-weight: 700;
    font-family: var(--font-display);
    text-align: center;
    margin: 32px 0;
    color: var(--text-primary);
}

/* Result Message */
.result-message {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 16px;
    min-height: 30px;
    margin-top: 16px;
    min-height: 30px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    position: relative;
    z-index: 10;
}

.result-message.show {
    opacity: 1;
    transform: translateY(0);
}

.result-message.correct {
    color: var(--success-color);
}

.result-message.wrong {
    color: var(--error-color);
}

/* ── Money / Coin Styles ── */
.coin-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 20px;
}

.coin-wrapper {
    animation: dropIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

.coin-svg {
    width: 80px;
    height: 80px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
    transition: transform 0.2s;
    cursor: pointer;
}

.coin-svg:hover {
    transform: scale(1.1) rotate(5deg);
}

.coin-copper circle {
    fill: #f8af92;
    stroke: #b05c3c;
}

/* Overriden by SVG inline styles usually */
.coin-gold circle {
    fill: #fcd34d;
    stroke: #d97706;
}

.coin-bicolor circle {
    stroke: #9ca3af;
}

.money-text {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 10px;
}

@keyframes dropIn {
    from {
        transform: translateY(-50px) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .coin-svg {
        width: 60px;
        height: 60px;
    }
}

/* Mobile Optimization */
@media (max-width: 600px) {
    .mobile-hide {
        display: none !important;
    }

    .app-header {
        padding: 10px 15px;
    }

    .header-content {
        gap: 10px;
    }

    .user-info {
        gap: 8px;
    }

    .user-name {
        display: none !important;
    }

    .app-title,
    .main-title {
        font-size: 1.1rem;
    }

    .btn-secondary,
    .logout-btn {
        padding: 6px 10px;
        font-size: 1rem;
    }

    /* Keep header on one row — no wrap/scroll */
    .app-header {
        height: auto;
        flex-wrap: nowrap;
        overflow: hidden;
    }

    .mobile-compact {
        padding: 6px 10px !important;
        text-decoration: none;
        width: auto;
    }
}

/* ── Mobile Hamburger Menu ── */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0 4px;
}

.mobile-dropdown {
    display: none;
    position: absolute;
    top: 65px;
    right: 15px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 12px;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    min-width: 180px;
}

.mobile-dropdown.show {
    display: flex;
    animation: slideDown 0.3s ease;
}

.mobile-dropdown .btn {
    width: 100%;
    justify-content: flex-start;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 700px) {
    .desktop-only {
        display: none !important;
    }

    .hamburger-btn {
        display: block;
    }
}

/* ── Canvas World Map ────────────────────────────────────────────── */
.wm-canvas-container {
    width: 100%;
    flex: 1;
    background: linear-gradient(180deg, #d8efe9 0%, #b7ddd6 45%, #9ecfc6 100%);
    position: relative;
    border-radius: 0 0 20px 20px;
    overflow: hidden;
    box-shadow: inset 0 2px 14px rgba(13, 115, 119, 0.12);
    min-height: 60vh;
}

@media (prefers-color-scheme: dark) {
    .wm-canvas-container {
        background: linear-gradient(180deg, #0a2422 0%, #0f2e2b 50%, #13403c 100%);
        box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.35);
    }
}

[data-theme="dark"] .wm-canvas-container {
    background: linear-gradient(180deg, #0a2422 0%, #0f2e2b 50%, #13403c 100%);
    box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.35);
}

/* --- Measurement Levels (Length & Weight) --- */

.measurement-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    width: 100%;
}

/* Ruler Level */
.ruler-wrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 20px 0;
}

.measured-object {
    position: absolute;
    bottom: 50px;
    left: 0;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 5px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    transition: width 0.5s ease;
}

.object-icon {
    font-size: 24px;
}

.ruler {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 48px;
    background: #fcd34d;
    border: 2px solid #d97706;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.ruler-tick {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.tick-mark {
    width: 2px;
    height: 20px;
    background: #451a03;
}

.ruler-tick:nth-child(5n+1) .tick-mark {
    height: 30px;
    /* longer tick for 0, 5, 10, 15 */
}

.tick-number {
    font-size: 14px;
    font-weight: bold;
    color: #451a03;
    margin-top: 2px;
}

/* Balance Scale Level */
.balance-scale {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 250px;
    margin: 20px 0;
}

.scale-center {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2;
}

.scale-center-top {
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-bottom: 50px solid #94a3b8;
}

.scale-center-base {
    width: 60px;
    height: 90px;
    background: #64748b;
    border-radius: 5px 5px 0 0;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.scale-pans {
    position: absolute;
    top: 50px;
    left: 0;
    width: 100%;
    height: 150px;
}

.scale-arm {
    position: absolute;
    top: 46px;
    left: 60px;
    right: 60px;
    height: 10px;
    background: #475569;
    border-radius: 5px;
    z-index: 1;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.scale-pan {
    position: absolute;
    top: 0;
    width: 120px;
    height: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.left-pan {
    left: 0;
}

.right-pan {
    right: 0;
}

.pan-line {
    position: absolute;
    top: 0;
    width: 2px;
    height: 90px;
    background: #cbd5e1;
}

.pan-line-left {
    left: 20px;
    transform: rotate(-20deg);
    transform-origin: top;
}

.pan-line-right {
    right: 20px;
    transform: rotate(20deg);
    transform-origin: top;
}

.pan-base {
    width: 100px;
    height: 20px;
    background: #e2e8f0;
    border-radius: 0 0 40px 40px;
    position: relative;
    z-index: 3;
    border: 2px solid #94a3b8;
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
}

.scale-items {
    position: relative;
    z-index: 4;
    display: flex;
    gap: 4px;
    align-items: flex-end;
    justify-content: center;
    margin-bottom: -5px;
    /* rest inside the pan */
    min-height: 40px;
    flex-wrap: wrap-reverse;
    padding-bottom: 5px;
}

.scale-item {
    animation: dropIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.weight-block {
    width: 40px;
    height: 40px;
    background: #3b82f6;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: bold;
    font-size: 16px;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid #1d4ed8;
}

.weight-block span {
    font-size: 10px;
    font-weight: normal;
    text-transform: uppercase;
}

.object-to-weigh {
    font-size: 60px;
    line-height: 1;
    filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.3));
}

@keyframes dropIn {
    0% {
        transform: translateY(-30px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}
/* ═══════════════════════════════════════════════════════════
   Mathico Quest — icons, login hero, chrome, motion
   ═══════════════════════════════════════════════════════════ */

.mi {
    width: 1.15em;
    height: 1.15em;
    display: inline-block;
    vertical-align: -0.2em;
    flex-shrink: 0;
}

.mi-lg { width: 1.5em; height: 1.5em; }
.mi-sm { width: 1em; height: 1em; }

.brand-mark {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.brand-mati {
    width: 112px;
    height: 148px;
    animation: matiFloat 3.2s ease-in-out infinite;
    filter: drop-shadow(0 12px 24px rgba(13, 115, 119, 0.28));
}

@keyframes matiFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.login-header {
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    margin-bottom: 8px;
    padding-top: 28px;
}

.main-title {
    font-size: 2.4rem;
    font-weight: 600;
    background: linear-gradient(120deg, var(--accent-color), #2A9D8F 45%, var(--accent-citrus));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    font-size: 1rem;
    max-width: 280px;
    text-align: center;
    line-height: 1.35;
}

.auth-card {
    border-radius: 24px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
    position: relative;
    z-index: 1;
}

.coin-display {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #FFE8C2, #F4A261);
    color: #0F2E2B;
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 800;
    font-family: var(--font-display);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(244, 162, 97, 0.35);
    transition: transform 0.2s var(--spring-easing);
}

.coin-display:active { transform: scale(0.95); }
.coin-display .mi { color: #9A5B12; }

.header-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: var(--font-display);
    cursor: pointer;
    text-decoration: none;
    color: #fff;
    background: var(--accent-color);
    box-shadow: 0 4px 12px rgba(13, 115, 119, 0.25);
    transition: transform 0.2s var(--spring-easing), background 0.2s;
}

.header-chip:hover { background: var(--accent-hover); }
.header-chip:active { transform: scale(0.96); }
.header-chip.duel {
    background: linear-gradient(135deg, var(--accent-citrus), #E76F51);
    box-shadow: 0 4px 12px rgba(244, 162, 97, 0.35);
}
.header-chip.ghost {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.app-title {
    font-size: 1.35rem;
    font-weight: 600;
    background: linear-gradient(120deg, var(--accent-color), var(--accent-citrus));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: inline-block;
    margin: 0;
    line-height: 1.2;
    white-space: nowrap;
}

.app-title-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-family: var(--font-family);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent-color);
    line-height: 1.2;
    flex: 0 0 auto;
    white-space: nowrap;
}

/* На десктоп баджът се залепва за „Класация“ — оставяме го само на тесни екрани */
@media (min-width: 701px) {
    .app-title-badge {
        display: none !important;
    }
}

@media (max-width: 600px) {
    .app-title-badge {
        font-size: 0.68rem;
        padding: 3px 8px;
    }
}

.lb-empty {
    text-align: center;
    padding: 28px 16px;
    color: var(--text-secondary);
}
.lb-empty-art {
    width: 88px;
    height: 88px;
    margin: 0 auto 12px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 30% 30%, #FFE8C2, #CFEDEA);
    color: var(--accent-color);
}
.lb-empty-art .mi { width: 40px; height: 40px; }
.lb-empty strong {
    display: block;
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 1.1rem;
    margin-bottom: 6px;
}

.theme-toggle-btn {
    color: var(--accent-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.theme-toggle-btn .mi { width: 1.35em; height: 1.35em; }

.hamburger-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    cursor: pointer;
}
.hamburger-btn .mi { width: 1.25em; height: 1.25em; }

.profile-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
}

.logout-btn {
    font-family: var(--font-display);
}

@media (prefers-reduced-motion: reduce) {
    .brand-mati { animation: none; }
    .btn-primary, .header-chip, .coin-display, .tab-glider {
        transition: none;
    }
}

.guest-warning {
    margin-top: 16px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
}

.login-header .theme-toggle-btn {
    position: absolute;
    top: 12px;
    right: 12px;
}

.checkbox-group {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 16px;
}
.checkbox-group label span {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 2px;
}

/* ── Mobile numpad (no system keyboard) ── */
.answer-display {
    display: none;
    min-height: 56px;
    padding: 12px 16px;
    border-radius: 16px;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    text-align: center;
    position: relative;
    font-family: var(--font-display);
}

.answer-display-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.04em;
    min-height: 1.2em;
    display: block;
}

.answer-display-hint {
    display: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.answer-display:not(.has-value) .answer-display-hint {
    display: block;
}

.answer-display:not(.has-value) .answer-display-value {
    display: none;
}

.num-pad {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 12px 0 8px;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.num-key {
    min-height: 52px;
    border: none;
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 0 color-mix(in srgb, var(--text-primary) 12%, transparent);
    border: 1.5px solid var(--border-color);
    transition: transform 0.12s var(--spring-easing, cubic-bezier(0.34, 1.56, 0.64, 1)),
        background 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.num-key:active {
    transform: scale(0.94);
    background: rgba(13, 115, 119, 0.12);
    border-color: var(--accent-color);
}

.num-key-action {
    font-size: 1.35rem;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--bg-primary) 80%, var(--border-color));
}

.num-key-submit {
    background: var(--accent-color);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 3px 0 color-mix(in srgb, var(--accent-color) 70%, #000);
    font-size: 1.55rem;
}

.num-key-submit:active {
    background: var(--accent-hover, #0a5c5f);
    border-color: transparent;
}

body.numpad-mode #answerInput {
    display: none !important;
}

body.numpad-mode #answerDisplay {
    display: block;
}

body.numpad-mode #numPad:not([hidden]) {
    display: grid;
}

body.numpad-mode #submitBtn {
    display: none !important;
}

body.numpad-mode #gameScreen .footer,
body.numpad-mode .footer {
    display: none;
}

@media (max-width: 768px) {
    body.numpad-mode #gameScreen .game-card {
        padding: 12px 14px 16px;
    }

    body.numpad-mode #gameScreen .game-stats {
        gap: 8px;
        margin-bottom: 12px;
    }

    body.numpad-mode #gameScreen .stat-box {
        padding: 8px 6px;
        gap: 2px;
    }

    body.numpad-mode #gameScreen .stat-label {
        font-size: 0.7rem;
    }

    body.numpad-mode #gameScreen .stat-value {
        font-size: 1.25rem;
    }

    body.numpad-mode #gameScreen .stat-sublabel {
        font-size: 0.7rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    body.numpad-mode #timerContainer {
        width: 64px;
        height: 64px;
        margin: 0 auto 8px;
    }

    body.numpad-mode #timerContainer .timer-svg {
        width: 64px;
        height: 64px;
    }

    body.numpad-mode #timerText {
        font-size: 1.25rem;
    }

    body.numpad-mode #timerContainer .timer-circle,
    body.numpad-mode #timerContainer .timer-circle-bg {
        stroke-width: 7;
    }

    body.numpad-mode #gameScreen .question-box {
        font-size: 2.1rem;
        margin: 8px 0 12px;
    }

    body.numpad-mode #gameScreen .question-box.word-mode {
        font-size: 1.15rem;
        margin: 8px 0;
        padding: 12px 14px;
    }

    body.numpad-mode #gameScreen .progress-bar-container {
        margin-top: 10px;
    }

    body.numpad-mode #gameScreen .progress-text {
        font-size: 0.85rem;
        margin-top: 4px;
    }

    body.numpad-mode #gameScreen .result-message {
        font-size: 1rem;
        margin-top: 8px;
        min-height: 24px;
    }
}


/* Sync / guest status bar */
.sync-banner {
    width: 100%;
    padding: 10px 16px;
    font-family: 'Nunito Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    z-index: 40;
}
.sync-banner-guest {
    background: #fff3cd;
    color: #7a4e00;
    border-bottom: 1px solid #f0d78c;
}
.sync-banner-guest a {
    color: #0D7377;
    text-decoration: underline;
}
.sync-banner-ok {
    background: #d1f2eb;
    color: #0f5132;
    border-bottom: 1px solid #9ad9c7;
}
.mobile-account-label {
    width: 100%;
    text-align: center;
    font-weight: 800;
    padding: 8px 0 4px;
    color: var(--text-primary, #0f2e2b);
}
@media (max-width: 768px) {
    .user-name {
        display: none !important;
    }

    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .app-header {
        padding: 8px 10px;
        overflow: hidden;
        max-width: 100vw;
    }

    .header-content {
        gap: 6px;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
    }

    .header-left {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
        flex: 0 1 auto; /* на мобилен може леко да се свие */
        overflow: hidden;
    }

    .user-info {
        gap: 5px;
        flex: 1 1 auto;
        min-width: 0;
        max-width: 62%;
        justify-content: flex-end;
        overflow: hidden;
    }

    .app-title {
        font-size: 1.05rem !important;
        gap: 5px;
        min-width: 0;
        max-width: 100%;
    }

    .app-title-badge {
        font-size: 0.58rem;
        padding: 2px 6px;
        flex-shrink: 0;
    }

    .coin-display {
        padding: 4px 8px;
        gap: 4px;
        font-size: 0.8rem;
        flex-shrink: 0;
    }

    .coin-display .mi {
        width: 1em;
        height: 1em;
    }

    .daily-streak-badge {
        padding: 4px 7px !important;
        margin-right: 0 !important;
        font-size: 11px !important;
        gap: 2px !important;
        flex-shrink: 0;
        max-width: 72px;
        overflow: hidden;
    }

    .daily-streak-badge .dq-mini {
        font-size: 10px !important;
    }

    .hamburger-btn {
        display: block !important;
        flex-shrink: 0;
        padding: 0 2px;
        font-size: 24px;
    }

    .sync-banner {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
}
