/* ========================================================
   HalloDeutsch - Mobile-First Duolingo-Grade Styling
   ======================================================== */

:root {
    --primary: #58cc02;
    --primary-dark: #46a302;
    --primary-light: #d7ffb8;
    --blue: #1cb0f6;
    --blue-dark: #1899d6;
    --blue-light: #ddf4ff;
    --orange: #ff9600;
    --orange-dark: #e68600;
    --orange-light: #fff0d4;
    --red: #ff4b4b;
    --red-dark: #d63838;
    --red-light: #ffdfe0;
    --purple: #ce82ff;
    --purple-dark: #b562e8;
    --yellow: #ffc800;
    --gray-bg: #f7f9fa;
    --gray-border: #e5e5e5;
    --gray-text: #777777;
    --gray-light: #f1f3f4;
    --dark-text: #3c3c3c;
    --surface: #ffffff;
    --shadow-3d: 0 4px 0;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 9999px;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --app-max-width: 520px;
}

/* Dark Mode Overrides */
body.dark-mode {
    --gray-bg: #131f24;
    --surface: #1e2c33;
    --gray-border: #2e3e47;
    --dark-text: #f0f3f5;
    --gray-text: #8aa2ae;
    --gray-light: #25363f;
    --primary-light: #1f3f1e;
    --red-light: #3f1f23;
    --blue-light: #183344;
}

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

body {
    font-family: var(--font-stack);
    background-color: var(--gray-bg);
    color: var(--dark-text);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

#main-layout-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    min-width: 0;
}

/* App Container (Mobile viewport priority, scales gracefully) */
#app-shell {
    width: 100%;
    max-width: var(--app-max-width);
    margin: 0 auto;
    min-width: 0;
    min-height: 100vh;
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.06);
    padding-bottom: 75px; /* Room for bottom navigation */
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ----------------------------------------------------
   3D Tactile Buttons (Duolingo signature tactile press)
   ---------------------------------------------------- */
.btn-3d {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 13px 20px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
    user-select: none;
    text-decoration: none;
    outline: none;
    width: 100%;
    position: relative;
}

.btn-3d:active, .btn-3d.pressed {
    transform: translateY(3px);
}

/* Primary Green Button */
.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
    box-shadow: var(--shadow-3d) var(--primary-dark);
}
.btn-primary:active, .btn-primary.pressed {
    box-shadow: 0 1px 0 var(--primary-dark);
}

/* Sky Blue Button */
.btn-blue {
    background-color: var(--blue);
    color: #ffffff;
    box-shadow: var(--shadow-3d) var(--blue-dark);
}
.btn-blue:active, .btn-blue.pressed {
    box-shadow: 0 1px 0 var(--blue-dark);
}

/* Outline / Secondary Button */
.btn-outline {
    background-color: var(--surface);
    color: var(--dark-text);
    border: 2px solid var(--gray-border);
    box-shadow: var(--shadow-3d) var(--gray-border);
}
.btn-outline:active, .btn-outline.pressed {
    box-shadow: 0 1px 0 var(--gray-border);
}

/* Danger Red Button */
.btn-danger {
    background-color: var(--red);
    color: #ffffff;
    box-shadow: var(--shadow-3d) var(--red-dark);
}
.btn-danger:active, .btn-danger.pressed {
    box-shadow: 0 1px 0 var(--red-dark);
}

/* Disabled State */
.btn-3d:disabled, .btn-3d.disabled {
    background-color: #e5e5e5;
    color: #afafaf;
    box-shadow: var(--shadow-3d) #cccccc;
    cursor: not-allowed;
    transform: none;
}

/* ----------------------------------------------------
   Top Header Bar
   ---------------------------------------------------- */
.top-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--surface);
    border-bottom: 2px solid var(--gray-border);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    gap: 8px;
}

/* CEFR Level Selector Pill */
.level-picker-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background-color: var(--gray-light);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-pill);
    padding: 5px 10px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.level-picker-pill:hover {
    background-color: var(--gray-border);
}

/* Dual Voice Selector Pill */
.voice-picker-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--blue-light);
    border: 2px solid var(--blue);
    color: var(--blue-dark);
    border-radius: var(--radius-pill);
    padding: 5px 11px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    user-select: none;
    box-shadow: 0 2px 0 var(--blue);
}
.voice-picker-pill:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}
.voice-picker-pill:active {
    transform: translateY(2px);
    box-shadow: none;
}
.voice-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffffff;
    border: 2px solid var(--blue);
    border-radius: var(--radius-pill);
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 800;
    color: var(--blue-dark);
    cursor: pointer;
    box-shadow: 0 2px 0 var(--blue);
    transition: all 0.1s ease;
}
.voice-switch-btn:hover {
    background: var(--blue-light);
}
.voice-switch-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

/* Stats Badges (Streak, Gems, Hearts) */
.header-stats {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 800;
    font-size: 14px;
}
.stat-pill.streak { color: var(--orange); }
.stat-pill.gems { color: var(--blue); }
.stat-pill.hearts { color: var(--red); }

.stat-pill .icon {
    font-size: 16px;
    line-height: 1;
    display: inline-block;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.stat-pill.streak:hover .icon {
    transform: scale(1.25) rotate(-5deg);
}

/* ----------------------------------------------------
   Tab Navigation & Page Views
   ---------------------------------------------------- */
.tab-content {
    display: none;
    flex: 1;
    padding: 16px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}
.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

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

/* ----------------------------------------------------
   Unit / Day Path View (Duolingo-style tree)
   ---------------------------------------------------- */
.unit-banner {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px 18px;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 6px 16px rgba(88, 204, 2, 0.25);
}
.unit-info h2 {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 4px;
}
.unit-info p {
    font-size: 13px;
    opacity: 0.92;
    line-height: 1.35;
}

.path-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 10px 0 30px 0;
    position: relative;
}

/* Node positions for curved path illusion */
.path-node-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    transition: transform 0.2s ease;
}
.path-node-wrapper:nth-child(even) { transform: translateX(35px); }
.path-node-wrapper:nth-child(3n+1) { transform: translateX(-35px); }
.path-node-wrapper:nth-child(3n) { transform: translateX(0); }

.path-circle {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--primary);
    box-shadow: 0 6px 0 var(--primary-dark);
    color: white;
    cursor: pointer;
    position: relative;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    user-select: none;
}
.path-circle:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--primary-dark);
}

.path-circle.locked {
    background-color: #e5e5e5;
    box-shadow: 0 6px 0 #cccccc;
    color: #afafaf;
    cursor: not-allowed;
}
.path-circle.locked:active {
    transform: none;
    box-shadow: 0 6px 0 #cccccc;
}

.path-circle.completed {
    background-color: var(--yellow);
    box-shadow: 0 6px 0 #d9a300;
}
.path-circle.completed:active {
    box-shadow: 0 2px 0 #d9a300;
}

.path-circle .day-num {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.path-circle .day-icon {
    font-size: 26px;
    line-height: 1;
    margin-top: 2px;
}

.path-stars {
    position: absolute;
    bottom: -10px;
    background: #ffffff;
    border: 2px solid var(--gray-border);
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    color: var(--yellow);
    font-weight: 800;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

.path-node-label {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 800;
    color: var(--dark-text);
    text-align: center;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Gift chest indicator */
.gift-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--orange);
    color: white;
    font-size: 12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 0 var(--orange-dark);
}

/* ----------------------------------------------------
   Exercise Runner (Interactive Duolingo Engine)
   ---------------------------------------------------- */
#exercise-runner-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--surface);
    z-index: 1000;
    flex-direction: column;
}
#exercise-runner-modal.active {
    display: flex;
}

.runner-top-bar {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--gray-border);
}

.close-runner-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gray-text);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 50%;
}
.close-runner-btn:hover {
    color: var(--dark-text);
    background-color: var(--gray-light);
}

/* Curved Progress Bar */
.runner-progress-track {
    flex: 1;
    height: 16px;
    background-color: var(--gray-light);
    border-radius: var(--radius-pill);
    overflow: hidden;
    position: relative;
}

.runner-progress-fill {
    height: 100%;
    width: 0%;
    background-color: var(--primary);
    border-radius: var(--radius-pill);
    transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}
.runner-progress-fill::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 6px;
    right: 6px;
    height: 4px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: var(--radius-pill);
}

.runner-hearts {
    font-weight: 800;
    color: var(--red);
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
}

.runner-body {
    flex: 1;
    padding: 24px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    max-width: var(--app-max-width);
    margin: 0 auto;
    width: 100%;
}

.exercise-question-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--dark-text);
    margin-bottom: 20px;
    line-height: 1.3;
}

/* Audio Dictation Speaker Card */
.audio-speaker-card {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.big-speaker-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--blue);
    box-shadow: 0 5px 0 var(--blue-dark);
    color: white;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.big-speaker-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--blue-dark);
}

.turtle-speaker-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--yellow);
    box-shadow: 0 4px 0 #cca000;
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.turtle-speaker-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #cca000;
}

/* MCQ Options Grid */
.mcq-options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.mcq-card {
    background-color: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-3d) var(--gray-border);
    padding: 16px 18px;
    font-size: 16px;
    font-weight: 700;
    color: var(--dark-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.1s ease;
    user-select: none;
}
.mcq-card:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--gray-border);
}

.mcq-card.selected {
    border-color: var(--blue);
    background-color: var(--blue-light);
    color: var(--blue-dark);
    box-shadow: var(--shadow-3d) var(--blue);
}

.mcq-card .key-badge {
    width: 28px;
    height: 28px;
    border: 2px solid var(--gray-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    color: var(--gray-text);
}
.mcq-card.selected .key-badge {
    border-color: var(--blue);
    color: var(--blue);
    background: #ffffff;
}

/* Fill-in-the-gaps Input & German Characters */
.fill-gap-container {
    margin-top: 14px;
}
.gap-input {
    width: 100%;
    padding: 16px;
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font-stack);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    outline: none;
    background-color: var(--surface);
    color: var(--dark-text);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
    transition: border-color 0.15s ease;
}
.gap-input:focus {
    border-color: var(--blue);
}

/* German Umlaut Bar */
.german-char-bar {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}
.char-btn {
    flex: 1;
    min-width: 38px;
    padding: 8px 0;
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 3px 0 var(--gray-border);
    background: var(--surface);
    font-weight: 800;
    font-size: 16px;
    cursor: pointer;
    text-align: center;
    transition: all 0.1s ease;
}
.char-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 var(--gray-border);
    background: var(--gray-light);
}

/* Left-to-Right Matching Pairs */
.matching-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 10px;
}

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

.matching-card {
    background-color: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-3d) var(--gray-border);
    padding: 14px 12px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: all 0.12s ease;
    user-select: none;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.matching-card:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--gray-border);
}

.matching-card.selected {
    border-color: var(--blue);
    background-color: var(--blue-light);
    color: var(--blue-dark);
    box-shadow: var(--shadow-3d) var(--blue);
}

.matching-card.matched {
    border-color: #a5d6a7;
    background-color: #e8f5e9;
    color: #a5d6a7;
    box-shadow: none;
    cursor: default;
    opacity: 0.6;
    transform: scale(0.98);
}

.matching-card.mismatch {
    animation: shake 0.35s ease-in-out;
    border-color: var(--red);
    background-color: var(--red-light);
    color: var(--red-dark);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* Runner Bottom Action Bar */
.runner-footer {
    padding: 16px 20px;
    border-top: 2px solid var(--gray-border);
    background: var(--surface);
    max-width: var(--app-max-width);
    margin: 0 auto;
    width: 100%;
}

/* ----------------------------------------------------
   Instant Feedback Bottom Drawer (Duolingo style slide-up)
   ---------------------------------------------------- */
.feedback-drawer {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1100;
    padding: 20px;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.12);
    animation: slideUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.feedback-drawer.active {
    display: block;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.feedback-inner {
    max-width: var(--app-max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.feedback-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.feedback-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: white;
    flex-shrink: 0;
}

.feedback-text h3 {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 4px;
}
.feedback-text p {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
}

/* Correct state */
.feedback-drawer.correct {
    background-color: var(--primary-light);
    color: #1b5e20;
}
.feedback-drawer.correct .feedback-icon {
    background-color: var(--primary);
}

/* Incorrect state */
.feedback-drawer.incorrect {
    background-color: var(--red-light);
    color: #b71c1c;
}
.feedback-drawer.incorrect .feedback-icon {
    background-color: var(--red);
}

.explanation-box {
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    margin-top: 6px;
    border-left: 3px solid currentColor;
}

/* ----------------------------------------------------
   Post-Lesson Celebration & Reward Screen
   ---------------------------------------------------- */
.reward-modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.65);
    z-index: 1200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.reward-modal-backdrop.active {
    display: flex;
    animation: fadeIn 0.25s ease;
}

.reward-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    padding: 28px 24px;
    text-align: center;
    box-shadow: 0 16px 36px rgba(0,0,0,0.2);
    position: relative;
    animation: popUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popUp {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.reward-trophy {
    font-size: 64px;
    margin-bottom: 8px;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

.reward-card h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--dark-text);
    margin-bottom: 4px;
}
.reward-card p.subtitle {
    font-size: 14px;
    color: var(--gray-text);
    margin-bottom: 20px;
}

/* Stat Rewards Grid */
.rewards-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.metric-box {
    background-color: var(--gray-light);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    padding: 12px 6px;
}
.metric-box .metric-icon {
    font-size: 20px;
}
.metric-box .metric-val {
    font-size: 16px;
    font-weight: 800;
    color: var(--dark-text);
    margin: 2px 0;
}
.metric-box .metric-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-text);
    text-transform: uppercase;
}

/* Unlocked Lesson Gifts Section */
.gifts-unlock-container {
    background: #f0fdf4;
    border: 2px dashed var(--primary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    text-align: left;
}
.gifts-unlock-title {
    font-size: 14px;
    font-weight: 800;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.gift-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.gift-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 2px solid #bbf7d0;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #15803d;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}
.gift-btn:hover {
    background: #dcfce7;
    border-color: var(--primary);
}

/* ----------------------------------------------------
   Leaderboard View
   ---------------------------------------------------- */
.leaderboard-header {
    text-align: center;
    margin-bottom: 20px;
}
.leaderboard-header h2 {
    font-size: 22px;
    font-weight: 800;
}
.leaderboard-header p {
    font-size: 13px;
    color: var(--gray-text);
}

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

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    gap: 12px;
    transition: transform 0.1s ease;
}
.leaderboard-row.is-me {
    border-color: var(--primary);
    background-color: var(--primary-light);
    box-shadow: 0 4px 12px rgba(88, 204, 2, 0.15);
}

.rank-badge {
    width: 28px;
    font-weight: 800;
    font-size: 16px;
    text-align: center;
    color: var(--gray-text);
}
.rank-badge.gold { color: #f59e0b; font-size: 20px; }
.rank-badge.silver { color: #94a3b8; font-size: 18px; }
.rank-badge.bronze { color: #b45309; font-size: 18px; }

.player-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--blue-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--gray-border);
}

.player-info {
    flex: 1;
}
.player-name {
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.player-meta {
    font-size: 12px;
    color: var(--gray-text);
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.player-xp {
    font-weight: 800;
    font-size: 15px;
    color: var(--orange);
}

/* ----------------------------------------------------
   Community Forum View
   ---------------------------------------------------- */
.forum-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
}
.forum-header h2 {
    font-size: 20px;
    font-weight: 800;
    margin: 0;
    min-width: 0;
}
.forum-header .btn-primary {
    white-space: nowrap;
    flex-shrink: 0;
}

.level-filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.level-filter-chips::-webkit-scrollbar { display: none; }

.chip {
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    border: 2px solid var(--gray-border);
    font-size: 13px;
    font-weight: 700;
    background: var(--surface);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.chip.active {
    background: var(--dark-text);
    color: var(--surface);
    border-color: var(--dark-text);
}

.forum-topic-card {
    background: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: transform 0.1s ease, border-color 0.15s ease;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}
.forum-topic-card:hover {
    border-color: var(--blue);
}

.topic-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--gray-text);
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 4px;
}

.level-tag {
    background: #e0f2fe;
    color: #0369a1;
    font-weight: 800;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    flex-shrink: 0;
}

.topic-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--dark-text);
    margin-bottom: 6px;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: break-word;
}

.topic-excerpt {
    font-size: 13px;
    color: var(--gray-text);
    line-height: 1.4;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

.topic-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-text);
}
.topic-footer .action-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
}
.topic-footer .action-btn.upvoted {
    color: var(--orange);
}

/* ----------------------------------------------------
   Profile View
   ---------------------------------------------------- */
.profile-card {
    background: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
}
.profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0 auto 12px;
    background: var(--blue-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 38px;
    border: 3px solid var(--blue);
}
.profile-username {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 4px;
}
.profile-role-badge {
    display: inline-block;
    padding: 2px 10px;
    background: var(--gray-light);
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-text);
}

.profile-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}
.profile-stat-box {
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.profile-stat-icon {
    font-size: 28px;
}
.profile-stat-value {
    font-size: 18px;
    font-weight: 800;
}
.profile-stat-label {
    font-size: 12px;
    color: var(--gray-text);
    font-weight: 600;
}

/* ----------------------------------------------------
   Bottom Mobile Navigation Bar
   ---------------------------------------------------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-max-width);
    height: 70px;
    background-color: var(--surface);
    border-top: 2px solid var(--gray-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 90;
    padding: 0 10px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--gray-text);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    transition: color 0.15s ease, transform 0.1s ease;
    user-select: none;
}
.nav-item:active { transform: scale(0.92); }

.nav-item .nav-icon {
    font-size: 22px;
    line-height: 1;
}
.nav-item .nav-label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.nav-item.active {
    color: var(--primary);
}

/* ----------------------------------------------------
   Generic Modal Dialogs (Auth, Level Select, Video, Forum)
   ---------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-window {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: popUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-title {
    font-size: 20px;
    font-weight: 800;
}
.modal-close-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--gray-text);
    cursor: pointer;
}

.form-group {
    margin-bottom: 16px;
    text-align: left;
}
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--dark-text);
    margin-bottom: 6px;
}
.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
    background: var(--surface);
    color: var(--dark-text);
}
.form-input:focus {
    border-color: var(--blue);
}

/* Responsive Iframe for Video Gifts */
.video-responsive-wrap {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000000;
    margin-bottom: 16px;
}
.video-responsive-wrap iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ----------------------------------------------------
   Word Bank Tiles (Duolingo Sentence Builder)
   ---------------------------------------------------- */
.word-tile-btn {
    background: var(--surface);
    border: 2px solid var(--gray-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 0 var(--gray-border);
    padding: 10px 18px;
    font-size: 16px;
    font-weight: 700;
    color: var(--dark-text);
    cursor: pointer;
    user-select: none;
    transition: transform 0.08s ease, box-shadow 0.08s ease, border-color 0.1s ease;
    outline: none;
}
.word-tile-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--gray-border);
}
.word-tile-btn.in-tray {
    border-color: var(--blue);
    background-color: var(--blue-light);
    color: var(--blue-dark);
    box-shadow: 0 4px 0 var(--blue);
}

/* ----------------------------------------------------
   Desktop Enhancements (Side Quests & Widgets)
   ---------------------------------------------------- */
#desktop-side-panel {
    display: none;
}

@media (min-width: 900px) {
    body {
        background-color: #f0f4f7;
        padding: 24px 0;
    }
    body.dark-mode {
        background-color: #0b1317;
    }
    #main-layout-wrapper {
        display: flex;
        gap: 30px;
        max-width: 960px;
        width: 100%;
        margin: 0 auto;
        align-items: flex-start;
    }
    #app-shell {
        border-radius: var(--radius-lg);
        border: 2px solid var(--gray-border);
    }
    #desktop-side-panel {
        display: flex;
        flex-direction: column;
        gap: 20px;
        width: 360px;
        flex-shrink: 0;
    }
    .side-widget {
        background: var(--surface);
        border: 2px solid var(--gray-border);
        border-radius: var(--radius-lg);
        padding: 20px;
        box-shadow: 0 4px 14px rgba(0,0,0,0.04);
    }
    .side-widget-title {
        font-size: 16px;
        font-weight: 800;
        margin-bottom: 12px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .quest-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 0;
        border-bottom: 1px solid var(--gray-border);
    }
    .quest-item:last-child {
        border-bottom: none;
    }
    .quest-icon {
        font-size: 26px;
    }
    .quest-details {
        flex: 1;
    }
    .quest-name {
        font-size: 13px;
        font-weight: 700;
        color: var(--dark-text);
        margin-bottom: 4px;
    }
    .quest-bar {
        height: 8px;
        background: var(--gray-light);
        border-radius: var(--radius-pill);
        overflow: hidden;
    }
    .quest-fill {
        height: 100%;
        background: var(--orange);
        border-radius: var(--radius-pill);
        transition: width 0.3s ease;
    }
}

/* ----------------------------------------------------
   Mobile Viewport Fine-Tuning (< 420px & < 360px)
   Prevents any horizontal overflow on small phones
   ---------------------------------------------------- */
@media (max-width: 420px) {
    .forum-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .forum-header h2 {
        font-size: 18px;
    }
    .forum-header .btn-primary {
        font-size: 12px;
        padding: 7px 12px;
    }
    .top-header {
        padding: 8px 12px;
        gap: 6px;
    }
    .header-stats {
        gap: 8px;
    }
    .stat-pill {
        font-size: 13px;
    }
}

@media (max-width: 360px) {
    .top-header {
        padding: 6px 8px;
        gap: 4px;
    }
    .level-picker-pill {
        padding: 4px 6px;
        font-size: 12px;
    }
    .header-stats {
        gap: 5px;
    }
    .stat-pill {
        font-size: 12px;
        gap: 2px;
    }
    .tab-content {
        padding: 12px 10px;
    }
}


