:root {
    --brand-color: #2563eb;
    --brand-hover-color: #1d4ed8;

    --page-background: #ffffff;
    --surface-color: #ffffff;
    --soft-surface: #f2f2f2;
    --hover-color: #e8e8e8;
    --border-color: #dedede;

    --primary-text: #0f0f0f;
    --secondary-text: #606060;

    --success-background: #ecfdf3;
    --success-border: #a7f3d0;
    --success-text: #067647;

    --error-background: #fff1f0;
    --error-border: #f3b7b3;
    --error-text: #b42318;

    --warning-background: #fffaeb;
    --warning-border: #fedf89;
    --warning-text: #93370d;

    --information-background: #eff8ff;
    --information-border: #b2ddff;
    --information-text: #175cd3;

    --topbar-height: 75px;
    --drawer-width: 300px;
    --content-max-width: 1720px;

    --site-font:
        Tahoma,
        "Segoe UI",
        Arial,
        sans-serif;
}


/* =========================================================
   Global reset
   ========================================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    direction: rtl;
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    direction: rtl;
    overflow-x: hidden;
    background: var(--page-background);
    color: var(--primary-text);
    font-family: var(--site-font);
    text-align: start;
}

body.drawer-open {
    overflow: hidden;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

input,
textarea,
select {
    color: var(--primary-text);
    text-align: start;
}

input[type="email"],
input[type="url"],
input[type="tel"] {
    direction: ltr;
    text-align: left;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.32);
    outline-offset: 2px;
}

::selection {
    background: rgba(37, 99, 235, 0.2);
}


/* =========================================================
   Top navigation
   ========================================================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;

    display: grid;
    grid-template-columns:
        auto
        auto
        minmax(260px, 1fr)
        auto;
    align-items: center;
    gap: 24px;

    width: 100%;
    min-height: var(--topbar-height);
    padding: 11px 28px;

    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.97);

    backdrop-filter: blur(12px);
}

.topbar-without-search {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.topbar-start,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-start {
    justify-self: start;
}

.topbar-actions {
    justify-self: end;
}

.topbar-navigation {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: max-content;
}

.topbar-navigation-link { display: inline-flex; align-items: center; min-height: 44px; padding: 9px 13px; border-radius: 11px; color: #4b5565; font-size: .9rem; font-weight: 750; white-space: nowrap; }
a.topbar-navigation-link:hover { background: var(--soft-surface); color: var(--primary-text); }
.topbar-navigation-link.active { background: #eaf2ff; color: var(--brand-color); }
.topbar-navigation-link.disabled { color: #a0a6af; cursor: default; }

.learning-status {
    display: flex;
    align-items: center;
    gap: 7px;
    direction: rtl;
}

.learning-stat {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    gap: 5px;
    padding: 7px 11px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 3px 10px rgba(15, 23, 42, .035);
    white-space: nowrap;
}

.learning-stat-icon {
    display: grid;
    width: 25px;
    height: 25px;
    place-items: center;
    border-radius: 8px;
    font-size: .96rem;
}

.learning-stat strong {
    color: #344054;
    font-size: .88rem;
    font-variant-numeric: tabular-nums;
}

.learning-stat small {
    color: #98a2b3;
    font-size: .66rem;
    font-weight: 800;
}

.streak-stat .learning-stat-icon {
    background: #fff4e5;
    filter: grayscale(.32);
}

.xp-stat .learning-stat-icon {
    background: #edf3ff;
    color: #2563eb;
}


/* =========================================================
   Reusable icon buttons
   ========================================================= */

.icon-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;

    width: 46px;
    height: 46px;
    padding: 0;

    border: 0;
    border-radius: 50%;

    background: transparent;
    color: var(--primary-text);

    cursor: pointer;

    transition:
        background-color 140ms ease,
        transform 140ms ease;
}

.icon-button:hover {
    background: var(--soft-surface);
}

.icon-button:active {
    transform: scale(0.96);
}


/* =========================================================
   Hamburger menu
   ========================================================= */

.menu-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 21px;
}

.menu-lines span {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}


/* =========================================================
   Text-only brand
   The blue play icon is intentionally hidden.
   ========================================================= */

.site-brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    color: var(--primary-text);
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

/*
 * The old blue play mark remains harmlessly in the HTML,
 * but it is not displayed.
 */
.brand-mark {
    display: none !important;
}


/* =========================================================
   Search
   ========================================================= */

.site-search {
    display: flex;
    width: 100%;
    min-width: 0;
    height: 48px;
    overflow: hidden;
    border: 1px solid #c6c6c6;
    border-radius: 24px;
    background: var(--surface-color);
    transition:
        border-color 140ms ease,
        box-shadow 140ms ease;
}

.site-search:focus-within {
    border-color: var(--brand-color);
    box-shadow:
        0 0 0 1px var(--brand-color);
}

.site-search input {
    min-width: 0;
    flex: 1;
    height: 100%;
    padding: 0 20px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--primary-text);
    text-align: start;
}

.site-search input::placeholder {
    color: #777777;
    opacity: 1;
}

.site-search input::-webkit-search-cancel-button {
    cursor: pointer;
}

.search-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 66px;
    padding: 0;
    border: 0;
    border-inline-start: 1px solid #c6c6c6;
    background: #f8f8f8;
    color: var(--primary-text);
    cursor: pointer;
    transition: background-color 140ms ease;
}

.search-button:hover {
    background: var(--hover-color);
}

.search-button svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}


/* =========================================================
   Topbar actions
   ========================================================= */

.upload-button,
.login-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 9px 17px;
    border: 1px solid var(--border-color);
    border-radius: 21px;
    background: var(--surface-color);
    font-size: .86rem;
    font-weight: 750;
    white-space: nowrap;
    transition:
        border-color 140ms ease,
        background-color 140ms ease,
        color 140ms ease;
}

.upload-button:hover,
.login-button:hover {
    background: var(--soft-surface);
}

.login-button {
    border-color: rgba(37, 99, 235, 0.65);
    color: var(--brand-color);
}

.login-button:hover {
    border-color: var(--brand-color);
    background: rgba(37, 99, 235, 0.07);
}


/* =========================================================
   Account button and popover
   ========================================================= */

.account-menu {
    position: relative;
    flex: 0 0 auto;
}

.account-button,
.large-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 0;
    border-radius: 50%;
    background: var(--brand-color);
    color: #ffffff;
    font-weight: 700;
}

.account-button {
    width: 46px;
    height: 46px;
    padding: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition:
        box-shadow 140ms ease,
        transform 140ms ease;
}

.account-button:hover {
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.13);
}

.account-button:active {
    transform: scale(0.96);
}

.large-avatar {
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    font-size: 1.05rem;
}

.account-button img,
.large-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.account-popover {
    position: absolute;
    top: calc(100% + 10px);
    inset-inline-end: 0;
    z-index: 1300;

    width: 285px;
    overflow: hidden;

    border: 1px solid var(--border-color);
    border-radius: 14px;

    direction: rtl;
    background: var(--surface-color);

    box-shadow:
        0 12px 35px rgba(0, 0, 0, 0.16);
}

.account-information {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    text-align: start;
}

.account-information > div {
    min-width: 0;
}

.account-information strong,
.account-information small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-information strong {
    font-size: 0.94rem;
}

.account-information small {
    margin-top: 4px;
    color: var(--secondary-text);
    font-size: 0.78rem;
    text-align: start;
}

.account-popover > a,
.account-popover form button {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
    border: 0;
    background: var(--surface-color);
    color: var(--primary-text);
    text-align: start;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.account-popover > a:hover,
.account-popover form button:hover {
    background: var(--soft-surface);
}

.account-popover form {
    margin: 0;
    border-top: 1px solid var(--border-color);
}


/* =========================================================
   Drawer backdrop
   ========================================================= */

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(1px);
}


/* =========================================================
   Main drawer
   ========================================================= */

.site-drawer {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 1200;

    display: flex;
    flex-direction: column;

    width: min(var(--drawer-width), 88vw);
    overflow: hidden;

    visibility: hidden;
    direction: rtl;

    border-inline-end: 1px solid var(--border-color);
    background: var(--surface-color);

    transform: translateX(100%);

    transition:
        transform 190ms ease,
        visibility 0s linear 190ms;
}

html[dir="rtl"] .site-drawer {
    box-shadow:
        -8px 0 30px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
}

html[dir="ltr"] .site-drawer {
    box-shadow:
        8px 0 30px rgba(0, 0, 0, 0.18);
    transform: translateX(-100%);
}

.site-drawer.open,
html[dir="rtl"] .site-drawer.open,
html[dir="ltr"] .site-drawer.open {
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
}


/* =========================================================
   Drawer header
   ========================================================= */

.drawer-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
}

.drawer-close-button {
    font-size: 2rem;
    font-weight: 300;
    line-height: 1;
}


/* =========================================================
   Drawer navigation
   ========================================================= */

.drawer-navigation {
    flex: 1;
    padding: 10px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.drawer-group {
    padding: 8px 0 13px;
    border-bottom: 1px solid var(--border-color);
}

.drawer-group:last-child {
    border-bottom: 0;
}

.drawer-group h2 {
    margin: 8px 12px;
    color: var(--secondary-text);
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.5;
    text-align: start;
}

.drawer-link {
    display: grid;
    grid-template-columns:
        34px
        minmax(0, 1fr)
        auto;
    align-items: center;
    gap: 10px;

    min-height: 46px;
    padding: 7px 12px;

    border-radius: 10px;

    color: var(--primary-text);
    font-size: 0.9rem;
    text-align: start;

    transition:
        background-color 120ms ease,
        color 120ms ease;
}

a.drawer-link:hover {
    background: var(--soft-surface);
}

.drawer-link.active {
    background: var(--soft-surface);
    font-weight: 700;
}

.drawer-link.disabled {
    color: #969696;
    cursor: not-allowed;
    opacity: 0.82;
}

.drawer-link small {
    color: var(--secondary-text);
    font-size: 0.68rem;
}

.drawer-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-height: 28px;
    font-size: 1.25rem;
}


/* =========================================================
   Drawer footer
   ========================================================= */

.drawer-footer {
    flex: 0 0 auto;
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
}

.drawer-footer p {
    margin: 0 0 12px;
    color: var(--secondary-text);
    font-size: 0.84rem;
    line-height: 1.7;
    text-align: start;
}

.drawer-footer form {
    margin: 0;
}

.drawer-footer form button {
    width: 100%;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 21px;
    background: var(--surface-color);
    color: var(--primary-text);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.drawer-footer form button:hover {
    background: var(--soft-surface);
}

.drawer-footer .login-button {
    width: 100%;
}


/* =========================================================
   Main page layout
   ========================================================= */

.site-main {
    min-height:
        calc(100vh - var(--topbar-height));
}

.site-main:focus {
    outline: none;
}

.page-width {
    width: min(
        var(--content-max-width),
        calc(100% - 48px)
    );
    margin-inline: auto;
    padding-block: 28px;
}


/* =========================================================
   Django messages
   ========================================================= */

.messages {
    display: grid;
    gap: 10px;

    width: min(
        var(--content-max-width),
        calc(100% - 48px)
    );

    margin: 16px auto 0;
}

.message {
    padding: 13px 16px;
    border: 1px solid var(--success-border);
    border-radius: 10px;
    background: var(--success-background);
    color: var(--success-text);
    font-size: 0.9rem;
    line-height: 1.7;
}

.message-error {
    border-color: var(--error-border);
    background: var(--error-background);
    color: var(--error-text);
}

.message-warning {
    border-color: var(--warning-border);
    background: var(--warning-background);
    color: var(--warning-text);
}

.message-info {
    border-color: var(--information-border);
    background: var(--information-background);
    color: var(--information-text);
}


/* =========================================================
   Shared form card
   ========================================================= */

.form-card {
    width: min(520px, 100%);
    margin: 30px auto;
    padding: 28px;

    border: 1px solid var(--border-color);
    border-radius: 16px;

    direction: rtl;
    background: var(--surface-color);

    box-shadow:
        0 8px 28px rgba(0, 0, 0, 0.05);

    text-align: start;
}

.form-card h1,
.form-card h2 {
    margin-block-start: 0;
    line-height: 1.5;
}

.form-card p {
    line-height: 1.8;
}

.form-card label {
    display: block;
    margin-block-end: 7px;
    font-size: 0.9rem;
    font-weight: 700;
}

.form-card input,
.form-card textarea,
.form-card select {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;

    border: 1px solid #bdbdbd;
    border-radius: 9px;

    outline: none;
    background: var(--surface-color);

    transition:
        border-color 140ms ease,
        box-shadow 140ms ease;
}

.form-card textarea {
    min-height: 110px;
    resize: vertical;
}

.form-card input:focus,
.form-card textarea:focus,
.form-card select:focus {
    border-color: var(--brand-color);
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-card button[type="submit"] {
    min-height: 42px;
    padding: 8px 20px;

    border: 0;
    border-radius: 22px;

    background: var(--brand-color);
    color: #ffffff;

    font-weight: 700;

    cursor: pointer;

    transition:
        background-color 140ms ease,
        transform 140ms ease;
}

.form-card button[type="submit"]:hover {
    background: var(--brand-hover-color);
}

.form-card button[type="submit"]:active {
    transform: scale(0.98);
}

.form-card .helptext {
    display: block;
    margin-block-start: 6px;
    color: var(--secondary-text);
    font-size: 0.75rem;
    line-height: 1.7;
}

.form-card .errorlist {
    margin: 7px 0;
    padding-inline-start: 20px;
    color: var(--error-text);
    font-size: 0.82rem;
    line-height: 1.7;
}


/* =========================================================
   Responsive topbar
   ========================================================= */

@media (max-width: 900px) {
    .topbar {
        grid-template-columns:
            auto
            minmax(180px, 1fr)
            auto;

        gap: 12px;
        padding-inline: 14px;
    }

    .upload-text {
        display: none;
    }

    .learning-stat {
        padding-inline: 8px;
    }

    .topbar-navigation { display: none; }

    .topbar-without-search {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .upload-button {
        width: 42px;
        height: 42px;
        padding: 0;
        border-radius: 50%;
    }

    .page-width,
    .messages {
        width: min(
            var(--content-max-width),
            calc(100% - 28px)
        );
    }
}

@media (max-width: 680px) {
    :root {
        --topbar-height: 65px;
    }

    .topbar {
        grid-template-columns:
            auto
            minmax(0, 1fr)
            auto;

        gap: 8px;
        min-height: var(--topbar-height);
        padding: 8px 10px;
    }

    .topbar-start,
    .topbar-actions {
        gap: 4px;
    }

    .learning-status {
        gap: 2px;
    }

    .learning-stat {
        min-height: 38px;
        gap: 3px;
        padding: 4px 6px;
        border-color: transparent;
        box-shadow: none;
    }

    .learning-stat-icon {
        width: 21px;
        height: 21px;
        background: transparent;
    }

    .learning-stat small {
        display: none;
    }

    .site-brand {
        font-size: 1.16rem;
    }

    .icon-button,
    .account-button,
    .upload-button {
        width: 42px;
        height: 42px;
    }

    .site-search {
        height: 44px;
    }

    .site-search input {
        padding-inline: 11px;
    }

    .search-button {
        width: 46px;
    }

    .account-popover {
        position: fixed;
        top: calc(var(--topbar-height) + 7px);
        right: 10px;
        left: 10px;
        width: auto;
        max-height:
            calc(100vh - var(--topbar-height) - 20px);
        overflow-y: auto;
    }

    .page-width {
        padding-block-start: 20px;
    }

}

@media (max-width: 540px) {
    /*
     * On very small displays, the text brand is hidden
     * so the search field still has enough space.
     */
    .topbar .site-brand {
        display: none;
    }

    .menu-button {
        width: 38px;
        height: 38px;
    }

    .site-search input {
        min-width: 0;
    }

    .search-button {
        width: 42px;
    }

    .form-card {
        margin-block: 18px;
        padding: 20px;
        border-radius: 13px;
    }
}

@media (max-width: 420px) {
    .topbar {
        gap: 6px;
        padding-inline: 8px;
    }

    .topbar .upload-button {
        display: none;
    }

    .site-search input {
        padding-inline: 9px;
    }

    .page-width,
    .messages {
        width: calc(100% - 20px);
    }
}


/* =========================================================
   Reduced motion
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .icon-button,
    .account-button,
    .upload-button,
    .login-button,
    .site-search,
    .site-drawer,
    .drawer-link,
    .form-card input,
    .form-card textarea,
    .form-card select,
    .form-card button {
        transition: none;
    }
}
