/* Phone layout (<= 767px). Loaded after generated/output.css; desktop is untouched. */
@media only screen and (max-width: 767px) {

    body { overflow-x: hidden; }
    body { font-size: 15px; }
    img { max-width: 100%; }

    /* ---------- top bar: logo + search on one row, login / user menu on the next ---------- */
    #hamburger_button { display: none !important; }
    #header #topleft_menu {
        display: flex !important;
        flex-wrap: wrap;
        align-items: center;
        padding: 8px 0 4px;
        margin: 0 !important;
    }
    #header #topleft_menu > .left.item,
    #header #topleft_menu > .right.menu.item {
        position: static !important;
        display: flex !important;
        align-items: center;
        flex: 1 1 100%;
        padding: 0 !important;
        margin: 0 !important;
    }
    #header #topleft_menu > .left.item { padding: 0 4px !important; }
    #header #site-wide-competition-search { flex: 1 1 auto; min-width: 0; }
    #header .search-width { width: 100% !important; }
    #header #home-logo { margin: 0 8px 0 0; flex: 0 0 auto; }
    #header #topleft_menu > .right.menu.item {
        justify-content: flex-end;
        flex-wrap: wrap;
        padding: 4px 0 0 !important;
    }
    #header #topleft_menu > .right.menu.item > .item { font-size: .95em; padding: .6em .8em !important; }
    #header #topleft_menu .ui.button.item { margin: 0 0 0 .4em !important; }
    #header .organization-logos { display: none !important; }
    #header #jumbo_logo { width: 55%; margin-top: 8px; }

    /* ---------- page container ---------- */
    #page_content.ui.container.grid { margin: 0 !important; padding: 0 8px; width: 100% !important; }
    #page_content > .row { padding-left: 0; padding-right: 0; }
    #page_content > .row > [class*="wide"].column { width: 100% !important; margin-left: 0 !important; margin-right: 0 !important; }
    #page_content .ui.input { max-width: 100%; }
    .ui.container { width: auto !important; margin-left: 8px !important; margin-right: 8px !important; }
    #header .ui.container { margin-left: 8px !important; margin-right: 8px !important; }

    /* ---------- home ---------- */
    .home-wrap { min-height: 0; }
    .home-wrap .segment-container { margin: 1.2em 0 !important; }
    .home-wrap .vert-wrap { margin-right: 0; min-width: 0; max-width: 100%; width: 100%; }
    .home-wrap .column-wrap { width: 100%; }
    #action-container { margin: 0 !important; }
    #action-container .container-content { display: block; padding: 1em; }
    #action-container .container-content > .column { margin-bottom: 1.4em; }
    .container-content { padding: 1em; }
    #about-container { margin: 1.2em 0 !important; max-width: 100%; }
    #about-container .container-content { padding: 1em; }
    #about-container p { text-align: left !important; }
    #general-stats { width: 100% !important; margin: 1em 0 !important; padding: 1em 0 !important; }
    #general-stats .ui.statistic .value { font-size: 2.6rem !important; }
    #general-stats .ui.statistic .label { font-size: .8em; }

    /* competition tiles in the list */
    public-list .tile-wrapper, .tile-wrapper { min-width: 0 !important; flex-wrap: wrap !important; display: flex !important; }
    public-list .comp-info, .comp-info { width: calc(100% - 84px) !important; flex: 1 1 0; min-width: 0; }
    public-list .comp-stats, .comp-stats {
        width: 100% !important;
        display: flex !important; flex-wrap: wrap; align-items: center; justify-content: center; gap: .3em 1em;
        padding: 6px 10px !important;
    }
    public-list .comp-stats .ui.divider, .comp-stats .ui.divider { display: none !important; }

    /* public list: filters above the list instead of beside it */
    public-list .content-container { flex-direction: column !important; }
    public-list .filters-panel { width: 100% !important; margin-right: 0 !important; margin-bottom: 10px; }
    public-list .list-panel { width: 100% !important; min-width: 0; }
    public-list .page-header { flex-wrap: wrap; gap: .6em; }
    public-list .page-title { font-size: 1.5em !important; flex: 1 1 100%; }
    public-list .action-buttons { display: flex; gap: .5em; }
    public-list .external-competitions-banner { flex-wrap: wrap; }

    /* ---------- competition detail: header ---------- */
    comp-detail-header .ui.relaxed.grid > .row > .column,
    comp-detail-header .ui.grid > .row > .column.wide { width: 100% !important; }
    comp-detail-header .ui.grid { margin-left: 0 !important; margin-right: 0 !important; }
    comp-detail-header .ui.grid > .row { padding-left: 0 !important; padding-right: 0 !important; flex-wrap: wrap; }
    comp-detail-header .ui.grid > .row > .column { padding-left: 0 !important; padding-right: 0 !important; }
    comp-detail-header .ui.grid > .row > .column { margin-bottom: .6em; }
    comp-detail-header .competition-image { width: 84px !important; height: 84px !important; margin: 0 !important; }
    comp-detail-header .competition-name { font-size: 1.7em !important; line-height: 1.2em !important; text-transform: none !important; }
    comp-detail-header .stat-buttons { display: flex; gap: 8px; }
    comp-detail-header .stat-buttons .tiny.left.labeled.button { flex: 1 1 0; margin-top: 0 !important; justify-content: flex-start !important; }
    comp-detail-header .stat-buttons .ui.tiny.button { width: auto !important; flex: 1 1 auto; }
    comp-detail-header .detail-label, comp-detail-header .detail-item,
    comp-detail-header .contact-email { font-size: .95em !important; word-break: break-word; }

    /* timeline: keep inside the screen */
    comp-detail-timeline { display: block; width: 100%; }
    comp-detail-timeline section { width: 100% !important; height: 175px; position: relative; margin-bottom: 1rem !important; }

    /* ---------- competition detail: tabs ---------- */
    comp-tabs .details-menu.menu {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        margin-left: 0 !important; margin-right: 0 !important;
    }
    comp-tabs .details-menu.menu > .item { flex: 0 0 auto; white-space: nowrap; padding: .8em .9em; }
    comp-tabs .details-menu.menu > .right.menu { display: none; }
    comp-tabs .ui.grid > .row > .column,
    comp-tabs .ui.relaxed.grid > .row > .column { width: 100% !important; }
    comp-tabs .ui.grid { margin-left: 0 !important; margin-right: 0 !important; }

    /* page list (left vertical menu) -> horizontal scrolling strip */
    comp-tabs .ui.side.vertical.tabular.pages-menu.menu {
        display: flex !important;
        flex-direction: row;
        width: 100% !important;
        float: none !important;
        overflow-x: auto;
        border: none !important;
        border-bottom: 1px solid #d4d4d5 !important;
        margin-bottom: .5em;
        -webkit-overflow-scrolling: touch;
    }
    comp-tabs .pages-menu.menu > .item {
        flex: 0 0 auto;
        white-space: nowrap;
        border: none !important;
        border-bottom: 2px solid transparent !important;
        border-radius: 0 !important;
        margin: 0 0 -1px 0 !important;
        background: none !important;
        padding: .8em 1em;
    }
    comp-tabs .pages-menu.menu > .active.item { border-bottom-color: #2185d0 !important; font-weight: 700; }

    comp-tabs .pages-tab.ui.tab { padding: 0 !important; }
    comp-tabs .twelve.wide.column .tab.active { margin: 0 !important; padding: 1em !important; }
    comp-tabs .ui.relaxed.grid > .row > .column { padding-left: 0 !important; padding-right: 0 !important; }

    /* page content */
    comp-tabs .ui.tab { max-width: 100%; }
    comp-tabs .ui.tab img { max-width: 100%; height: auto; }
    comp-tabs [id^="page_"] { overflow-x: auto; word-break: break-word; }
    comp-tabs [id^="page_"] table { display: block; max-width: 100%; overflow-x: auto; }
    comp-tabs [id^="page_"] pre { max-width: 100%; overflow-x: auto; }
    comp-tabs [id^="page_"] h2 { font-size: 1.4em; }
    comp-tabs [id^="page_"] .katex-display { overflow-x: auto; overflow-y: hidden; }

    /* leaderboard, my submissions and other tables scroll sideways inside their tab */
    comp-tabs .ui.tab { overflow-x: auto; }
    comp-tabs submission-manager, comp-tabs leaderboards, comp-tabs competition-leaderboard { display: block; max-width: 100%; overflow-x: auto; }
    comp-tabs .ui.tab .ui.table td, comp-tabs .ui.tab .ui.table th { white-space: nowrap; }
    /* Semantic stacks tables into blocks on phones; keep real tables and let their wrapper scroll */
    #page_content .ui.table:not(.unstackable) { display: table !important; width: 100% !important; }
    #page_content .ui.table:not(.unstackable) thead { display: table-header-group !important; }
    #page_content .ui.table:not(.unstackable) tbody { display: table-row-group !important; }
    #page_content .ui.table:not(.unstackable) tr { display: table-row !important; padding: 0 !important; box-shadow: none !important; }
    #page_content .ui.table:not(.unstackable) th,
    #page_content .ui.table:not(.unstackable) td { display: table-cell !important; width: auto !important; padding: .6em .7em !important; box-shadow: none !important; }
    #page_content .ui.table:not(.unstackable) td { border-top: 1px solid rgba(34,36,38,.1) !important; }
    .hide-mobile, #page_content .ui.table:not(.unstackable) .hide-mobile { display: none !important; }
    comp-tabs .ui.accordion, comp-tabs .ui.styled.accordion { width: 100% !important; }

    /* ---------- forms / auth pages ---------- */
    .ui.form .fields { display: block; margin-left: 0 !important; margin-right: 0 !important; }
    .ui.form .fields > .field { padding-left: 0 !important; padding-right: 0 !important; }
    .ui.action.input { display: flex !important; width: 100%; }
    .ui.action.input > input { flex: 1 1 0; min-width: 0 !important; width: auto !important; }
    organization-create, organization-edit { display: block; width: 100% !important; margin-left: 0 !important; margin-right: 0 !important; }
    organization-create > .ui.segment, organization-edit > .ui.segment { margin-left: 0 !important; margin-right: 0 !important; }
    .ui.form .two.fields > .field, .ui.form .three.fields > .field { width: 100% !important; padding-left: 0; padding-right: 0; }
    .ui.segment { max-width: 100%; }
    .ui.modal { width: 94% !important; margin-left: 3% !important; margin-right: 3% !important; left: auto !important; }
    .ui.modals.dimmer .ui.modal { margin: 1rem auto !important; }
    .ui.table:not(.unstackable) { max-width: 100%; }

    /* ---------- footer ---------- */
    .footer.segment .ui.grid > .column { width: 100% !important; padding-top: .5em; padding-bottom: .5em; }
    .footer.segment { padding: 1.2em 0 !important; }

    /* toasts */
    #toast-container { margin-top: 0 !important; margin-right: 0 !important; }
    #toast-container > div { width: auto !important; max-width: 92vw; margin: 0 4vw 8px !important; }
}
