/* ---------- Phones and tablets ----------
   Below 1100px the zoom script in layout.php no longer scales the 1840px design down: the page is laid out at
   the real screen width and these rules make it fit. Every rule sits inside a max-width 1099px query, so
   desktop (1100px and wider) is the scaled design exactly as before. */

@media (max-width: 1099px) {
    :root {
        --stage-width: 100%;
        --hero-width: 100%;
    }
}

/* ---------- phones ---------- */
@media (max-width: 767px) {
    :root {
        --content-width: calc(100% - 20px);
    }

    /* footer: everything stacked and centred, long lines wrap */
    .footer-band {
        grid-template-columns: minmax(0, 1fr);
        padding-inline: 16px;
    }
    .footer-band > * {
        max-width: 100%;
        min-width: 0;
    }
    .footer-motto,
    .footer-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 2px;
    }
    .site-footer .sep {
        margin-inline: 6px;
    }
    .footer-links {
        column-gap: 18px;
    }
    .footer-links .sep,
    .footer-motto .sep {
        display: none;
    }
    .footer-motto {
        column-gap: 14px;
    }

    /* page numbers wrap instead of running off the screen */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 6px;
    }

    /* news archive: picture above the text */
    .news-archive {
        padding-inline: 14px;
    }
    .news-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        padding: 16px 0;
    }
    .news-card__image {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }
    .news-card h2 {
        font-size: 1.15rem;
    }

    /* home: the news and event lists no longer fill a fixed column height; just show the first 4 */
    .page-home .fit-area {
        position: static;
        min-height: 0;
    }
    .page-home .fit-area > [data-fit-list] {
        position: static;
        overflow: visible;
    }
    .page-home [data-fit-list] > li:nth-child(n+5) {
        display: none;
    }
    .page-home .news-item {
        grid-template-columns: 96px minmax(0, 1fr);
        gap: 12px;
        padding: 12px 0;
    }
    .page-home .news-item .chevron {
        display: none;
    }
    .page-home .news-thumbnail {
        width: 96px;
        height: 64px;
    }
    .page-home .news-copy h3 {
        -webkit-line-clamp: 3;
    }
    .page-home .news-copy h3 a {
        display: inline;
        min-height: 0;
    }
}

/* ---------- phones: forms and the character page ---------- */
@media (max-width: 767px) {
    /* side by side form fields (race / class / role, event forms) stack */
    .form-columns,
    .form-columns--3 {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 0;
    }

    /* character page: model on top, gear in two columns under it, panels stacked */
    .armory-head {
        flex-wrap: wrap;
        gap: 12px;
        padding: 14px 16px;
    }
    .armory-head__avatar {
        width: 56px;
        height: 56px;
    }
    .armory-head__crest {
        display: none;
    }
    .armory-head h1 {
        flex-wrap: wrap;
        gap: 8px;
        font-size: 1.5rem;
    }
    .armory-doll {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas: "model model" "left right" "bottom bottom";
        gap: 8px 10px;
        padding: 12px 12px 18px;
    }
    .armory-model {
        min-height: 360px;
    }
    .armory-model img {
        height: 540px;
        bottom: -73px;
    }
    .armory-slots--bottom {
        flex-wrap: wrap;
        gap: 8px 16px;
    }
    .armory-slot {
        gap: 8px;
    }
    .armory-icon {
        width: 40px;
        height: 40px;
    }
    .armory-slot__name {
        font-size: .85rem;
    }
    /* tooltips open on tap (the slot takes focus) and drop below the item, inside the screen */
    .armory-slot--left .armory-tip,
    .armory-slots--bottom .armory-tip {
        top: calc(100% + 6px);
        bottom: auto;
        left: 0;
        right: auto;
    }
    .armory-slot--right .armory-tip {
        top: calc(100% + 6px);
        bottom: auto;
        left: auto;
        right: 0;
    }
    .armory-tip {
        width: min(300px, calc(100vw - 32px));
    }
    .armory-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    .armory-panel {
        padding: 14px 14px 16px;
    }
}

/* ---------- tablets (768 to 1099px) ---------- */
@media (min-width: 768px) and (max-width: 1099px) {
    .armory-doll {
        grid-template-columns: minmax(0, 1fr) 280px minmax(0, 1fr);
        gap: 8px 12px;
        padding-inline: 16px;
    }
    .armory-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---------- phones and tablets: member pages ---------- */
@media (max-width: 1099px) {
    /* roster: every member becomes a card instead of a six column table row */
    .roster .panel-heading {
        flex-wrap: wrap;
        gap: 8px 12px;
    }
    .roster .panel-heading .role-counts {
        margin-left: 0;
    }
    .roster-rank {
        margin-inline: 14px;
    }
    .roster-table,
    .roster-table tbody,
    .roster-table tr,
    .roster-table td {
        display: block;
    }
    .roster-table colgroup,
    .roster-table thead {
        display: none;
    }
    .roster-table {
        width: auto;
        margin: 0 14px 6px;
    }
    .roster-table tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 12px;
        padding: 12px 0;
        border-bottom: 1px solid #5a473233;
    }
    .roster-table td {
        padding: 0;
        border: 0;
    }
    .roster-table td:first-child {
        flex: 1 1 100%;
    }
    .roster-table td:nth-child(4)::before {
        content: 'Level ';
        color: var(--muted);
    }
    .roster-table td:nth-child(5),
    .roster-table td:nth-child(6) {
        flex: 1 1 100%;
    }
    .roster-table td:nth-child(5) .prof-list {
        margin-top: 0;
    }
    .roster-table td:nth-child(6)::before {
        content: 'Alts';
        display: block;
        margin-bottom: 2px;
        color: var(--gold);
        font: 600 .65rem var(--heading-font);
        letter-spacing: .08em;
        text-transform: uppercase;
    }
    /* nothing to show: no empty "none" lines on a card */
    .roster-table td:nth-child(5):has(> .muted:only-child),
    .roster-table td:nth-child(6):has(.roster-alts > .muted:only-child) {
        display: none;
    }
    .roster-alt {
        white-space: normal;
    }
}

@media (max-width: 767px) {
    /* calendar: month navigation wraps; the month grid becomes compact (time only), the Upcoming list below has the details */
    .calendar-panel .panel-heading {
        flex-wrap: wrap;
        gap: 10px;
    }
    .calendar-nav {
        flex-wrap: wrap;
        width: 100%;
    }
    .calendar-nav .calendar-month {
        flex: 1;
        text-align: center;
    }
    .month-grid th {
        padding: 8px 2px;
        font-size: .58rem;
        letter-spacing: .03em;
        text-align: center;
    }
    .month-grid td {
        height: 64px;
        padding: 3px;
    }
    .day-number {
        font-size: .8rem;
    }
    .day-add {
        display: none;
    }
    .day-event {
        gap: 2px;
        padding: 2px 3px;
        border-left-width: 2px;
        font-size: .62rem;
    }
    .day-event__title,
    .day-event__going {
        display: none;
    }
}

@media (max-width: 767px) {
    /* forum topic: the author becomes a compact bar above the post */
    .topic-mod {
        flex-wrap: wrap;
    }
    .forum-post {
        grid-template-columns: minmax(0, 1fr);
        margin-inline: 10px;
    }
    .forum-post__author {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 10px;
        padding: 10px 12px;
        text-align: left;
        border-right: 0;
        border-bottom: 1px solid #5a473244;
    }
    .forum-post__avatar {
        width: 44px;
        height: 44px;
    }
    .forum-post__author .forum-meta {
        flex-basis: 100%;
    }
    .forum-post__head {
        flex-wrap: wrap;
        gap: 4px 12px;
        padding: 6px 12px;
    }
    .forum-post__actions {
        flex-wrap: wrap;
    }
    .forum-post__body {
        padding: 12px 12px 6px;
    }
    .forum-reply {
        margin-inline: 10px;
    }
}

@media (max-width: 767px) {
    /* forum lists: one block per forum or topic, the latest post underneath; the count columns are left out */
    .forum-table,
    .forum-table tbody,
    .forum-table tr,
    .forum-table td {
        display: block;
    }
    .forum-table colgroup,
    .forum-table thead,
    .forum-table td.num {
        display: none;
    }
    .forum-table tr {
        padding: 12px 0;
        border-bottom: 1px solid #5a473233;
    }
    .forum-table td {
        padding: 0 14px;
        border: 0;
    }
    .forum-table td:last-child {
        margin-top: 6px;
        padding-left: 70px;
        font-size: .9rem;
    }
    .forum-table td:last-child::before {
        content: 'Latest: ';
        color: var(--muted);
    }
    .forum-table td:last-child > * {
        display: inline;
        white-space: normal;
    }
    .forum-table td:last-child > * + * {
        margin-left: 6px;
    }
    /* topic lists have no forum icon in front, so no indent there */
    .forum-table td:first-child:not(:has(.forum-row)) + td + td + td {
        padding-left: 14px;
    }
}

/* ---------- talent and legacy calculators ---------- */
@media (max-width: 1099px) {
    /* trees side by side only where they fit, otherwise under each other */
    .legacy-trees {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }
    .talent-trees {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }
    .legacy-perk,
    .talent {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: manipulation;
    }
}
@media (max-width: 767px) {
    .legacy-bar {
        flex-wrap: wrap;
        gap: 10px 16px;
        padding: 10px 12px;
    }
    .legacy-bar__actions {
        margin-left: 0;
    }
    .talent-bar__preset {
        max-width: 100%;
    }
    /* class picker: three per row */
    .talent-classes {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }
    .talent-class {
        gap: 6px;
        padding: 4px 6px 4px 4px;
        font-size: .78rem;
    }
    .talent-class img {
        width: 24px;
        height: 24px;
    }
    .legacy-trees,
    .talent-trees {
        grid-template-columns: minmax(0, 1fr);
    }
    .legacy-tree,
    .talent-tree {
        padding: 12px 10px 16px;
    }
    .legacy-tree__head,
    .talent-tree__head {
        flex-wrap: wrap;
        gap: 4px 10px;
    }
    .legacy-summary [data-legacy-summary] {
        grid-template-columns: minmax(0, 1fr);
    }
    /* the tooltip sits at the bottom of the screen instead of next to the icon */
    .legacy-tip {
        position: fixed;
        top: auto !important;
        left: 10px !important;
        right: 10px;
        bottom: 54px;
        width: auto;
    }
}

@media (max-width: 767px) {
    /* calendar event: facts under the date, attendance groups under each other */
    .event-meta {
        flex-wrap: wrap;
        gap: 14px;
        padding: 14px 14px 4px;
    }
    .event-meta dl div {
        grid-template-columns: 96px minmax(0, 1fr);
        gap: 8px;
    }
    .event-text {
        padding-inline: 14px;
    }
    .attendance {
        grid-template-columns: minmax(0, 1fr);
    }
    .attendance-group {
        padding: 12px 14px;
        border-right: 0;
        border-bottom: 1px solid #5a473233;
    }
    .attendance-group:last-child {
        border-bottom: 0;
    }
}

/* ---------- phones and tablets: header, admin ---------- */
@media (max-width: 1099px) {
    /* calculator tree headers wrap when the reset link does not fit */
    .legacy-tree__head,
    .talent-tree__head {
        flex-wrap: wrap;
    }
    /* admin section tabs wrap onto more rows */
    .admin-tabs {
        flex-wrap: wrap;
    }
    /* wide admin tables scroll sideways inside the panel instead of pushing the page wider */
    .admin-table:not(.roster-table):not(.forum-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
@media (min-width: 768px) and (max-width: 1099px) {
    /* logged in: avatar without the name, so the account links fit next to the menu icons */
    .site-header {
        padding-inline: 60px;
    }
    .header-account__name span {
        display: none;
    }
}
@media (max-width: 767px) {
    .admin-tabs {
        gap: 4px;
        margin-bottom: -10px;
    }
    .admin-tabs a {
        gap: 5px;
        padding: 6px 8px;
        font-size: .68rem;
    }
}

/* ---------- account menu on touch screens ---------- */
/* Tablets: there is no hover, so the first tap on your avatar opens the menu (js/main.js adds .is-open). */
.account-menu.is-open > .account-menu__panel {
    display: block;
}
/* Phones: the account links sit right inside the opened main menu, no dropdown needed. */
@media (max-width: 767px) {
    .header-account {
        flex-wrap: wrap;
        row-gap: 4px;
    }
    .header-account .account-menu {
        flex: 1 1 100%;
        order: -1;
    }
    .account-menu:hover::after {
        display: none;
    }
    .account-menu > .account-menu__panel {
        position: static;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px;
        min-width: 0;
        margin: 6px 0 4px;
        padding: 0;
        border: 0;
        background: none;
        box-shadow: none;
        animation: none;
    }
    .header-account .account-menu__panel a {
        padding: 8px 10px;
        white-space: normal;
    }
}
