.site-header {
    border-bottom: 1px solid var(--line);
    background: var(--paper);
    /* anchors the absolutely-positioned mobile .site-nav dropdown */
    position: relative;
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    padding-bottom: 16px;
}

.brand__logo {
    height: 64px;
    width: auto;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.site-nav__login {
    text-decoration: none;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
}

.site-nav .btn {
    line-height: 1;
}

.user-menu {
    position: relative;
}

.user-menu__trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    font: inherit;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.user-menu__caret {
    font-size: 12px;
    color: var(--muted);
    transition: transform 0.15s ease;
}

.user-menu__trigger[aria-expanded="true"] .user-menu__caret {
    transform: rotate(180deg);
}

.user-menu__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 12px;
    min-width: 240px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 14px;
}

.user-menu__profile-btn {
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin-bottom: 10px;
    padding: 12px 16px;
    border-radius: 6px;
    background: #3b82f6;
    color: #ffffff;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
}

.user-menu__profile-btn:hover {
    background: #2f6fd6;
}

.user-menu__logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: none;
    font: inherit;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}

.user-menu__logout:hover {
    background: var(--surface);
}

.user-menu__logout-icon {
    width: 18px;
    height: 18px;
}

/* Authenticated app header: a top row reserved for player info (just the
   user menu for now) and a lower row for logo + nav, scoped separately
   from the anonymous site-header so those pages are unaffected. */

.site-header--app .site-header__top {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.site-header--app .site-header__top-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    flex-wrap: wrap;
    /* break out of .container's centered column and hug the viewport with only a
       small margin, so this crowded info row has room and the stats sit hard
       against the left edge (further left than the logo/nav row's wider indent) */
    max-width: none;
    margin: 0;
    padding: 10px 4%;
}

/* Header per-type stats widget */
.header-stats {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px 18px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
}

.header-stats__select {
    font: inherit;
    font-weight: 700;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 5px 8px;
    max-width: 240px;
    cursor: pointer;
}

.header-stats__metrics {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: start;
    gap: 2px 20px;
}

.header-stats__metric b {
    color: var(--ink);
    font-weight: 700;
}

.site-header--app .brand__logo {
    height: 88px;
}

/* break out of .container's fixed max-width/padding so the logo and nav
   hug the actual viewport edges instead of a centered fixed-width column */
.site-header--app .site-header__main .site-header__inner {
    max-width: none;
    margin: 0;
    padding-left: 10%;
    padding-right: 10%;
}

.site-header--app .site-nav > a {
    color: #2f9e44;
    font-weight: 600;
    text-decoration: none;
}

.site-header--app .site-nav > a:hover {
    color: #1f7a33;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.nav-toggle span {
    width: 22px;
    height: 2px;
    background: var(--ink);
}

@media (max-width: 680px) {
    .nav-toggle {
        display: flex;
    }

    .site-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--paper);
        border-bottom: 1px solid var(--line);
        flex-direction: column;
        align-items: flex-start;
        padding: 16px 24px;
        gap: 16px;
        display: none;
    }

    .site-nav.is-open {
        display: flex;
    }

    /* .btn's own horizontal padding/border otherwise reads as a stray
       indent next to the unpadded .site-nav__login link when both are
       left-aligned in the stacked mobile menu; zero them out here so
       both links' text starts flush at the same left edge */
    .site-nav .btn {
        padding-left: 0;
        padding-right: 0;
        border-width: 0;
    }
}

/* Coin balance chip, grouped with the user menu on the right of the top row */
.site-header__account {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* pull the tasks calendar toward the mailbox so those two icons sit closer than
   the 16px gap the other account chips use */
.site-header__account .tasks-menu {
    margin-left: -8px;
}

/* current user's rank badge (colour comes from the level tier, set inline) */
.header-rank {
    display: inline-flex;
    align-items: center;
    padding: 5px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
}

.coin-balance {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px 5px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    text-decoration: none;
    line-height: 1;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.coin-balance:hover {
    border-color: #e0a800;
    transform: translateY(-1px);
}

.coin-balance__coin {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffe37a 0%, #f5c518 45%, #d99e00 100%);
    border: 1px solid #c88a00;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
    flex-shrink: 0;
}

.coin-balance__gem {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #a5f3fc 0%, #22b8cf 55%, #0c8599 100%);
    clip-path: polygon(50% 0%, 85% 35%, 50% 100%, 15% 35%);
    flex-shrink: 0;
}

.coin-balance--diamond:hover {
    border-color: #22b8cf;
}

.coin-balance__value {
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* Personal messages: mailbox icon with an unread-count badge, grouped with the
   currency chips / tasks calendar */
.msg-badge {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 8px;
    line-height: 0;
    text-decoration: none;
    transition: transform 0.15s ease;
}

.msg-badge:hover {
    transform: translateY(-1px);
}

.msg-badge img {
    display: block;
}

.msg-badge__count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

/* `display: inline-flex` above would otherwise override the [hidden] attribute's
   display:none, leaving a red "0" circle when there are no unread messages */
.msg-badge__count[hidden] {
    display: none;
}

/* "new friend requests" flag — a small red badge shown next to the nickname in
   the header and on the profile's Друзья tab */
.friend-alert {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    box-sizing: border-box;
    background: var(--danger);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    vertical-align: middle;
}

/* Periodic tasks: calendar trigger + dropdown, grouped with the currency chips */
.tasks-menu {
    position: relative;
    display: inline-flex;
}

.tasks-menu__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    line-height: 0;
    transition: transform 0.15s ease;
}

.tasks-menu__trigger:hover {
    transform: translateY(-1px);
}

.tasks-menu__trigger img {
    display: block;
}

.tasks-menu__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 12px;
    width: 340px;
    max-width: 92vw;
    max-height: 78vh;
    overflow-y: auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 14px;
    z-index: 20;
}

.tasks-menu__title {
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 10px;
}

.task-card {
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.task-card:first-of-type {
    border-top: none;
    padding-top: 0;
}

.task-card--done {
    opacity: 0.85;
}

.task-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.task-card__name {
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
}

.task-card__reset {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.task-card__badge {
    font-size: 11px;
    font-weight: 700;
    color: #ffffff;
    background: #2f9e44;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.task-card__goal {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.task-progress {
    flex: 1;
    height: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
}

.task-progress__fill {
    height: 100%;
    background: #2f9e44;
    border-radius: 999px;
    transition: width 0.2s ease;
}

.task-card__count {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.task-card__speed {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 10px;
}

.task-card__speed.is-met {
    color: #2f9e44;
    font-weight: 600;
}

.task-card__check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--surface);
    flex-shrink: 0;
}

.task-card__speed.is-met .task-card__check {
    background: #2f9e44;
    border-color: #2f9e44;
}

.task-card__speed.is-met .task-card__check::after {
    content: "✓";
    color: #ffffff;
    font-size: 10px;
    line-height: 1;
}

.task-card__rewards {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
}

.task-reward {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.task-reward img {
    display: block;
}

/* diamonds reward: enlarge the shared gem glyph only inside the task dropdown */
.task-reward .coin-balance__gem {
    width: 22px;
    height: 22px;
}
