/* Mobile-only layout and interaction overrides.
 * app.css remains the visual source of truth; keep shared colors, typography,
 * borders and component styling inherited so desktop changes flow to mobile.
 */

@media (max-width: 700px) {
    .header-inner {
        gap: 10px;
        padding: 12px 10px 10px;
    }

    .header-right {
        min-width: 0;
        gap: 8px;
    }

    .nav {
        width: 100%;
        min-width: 0;
        flex-wrap: nowrap;
        gap: 4px;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .nav::-webkit-scrollbar,
    .profile-tabs::-webkit-scrollbar,
    .pagination::-webkit-scrollbar,
    .request-editor-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav a {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        min-height: 44px;
        padding: 0 10px;
    }

    .auth-area {
        width: 100%;
        min-width: 0;
        gap: 6px;
    }

    .login-button,
    .logout-button,
    .user-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }

    .logout-form {
        display: flex;
    }

    .user-link {
        overflow: hidden;
        max-width: min(58vw, 240px);
        white-space: nowrap;
    }

    .user-link span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea,
    .language-search {
        font-size: 16px;
    }

    .button-primary,
    .button-primary-link,
    .button-secondary-link,
    .copy-button,
    .request-editor-tabs a,
    .problem-edit-request-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
    }

    .back-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        margin-bottom: 8px;
    }

    .problem-card {
        padding: 16px;
    }

    .problem-title-main,
    .profile-title,
    .profile-description {
        overflow-wrap: anywhere;
    }

    .info-table code {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

    .table-scroll > .info-table th,
    .table-scroll > .info-table td {
        display: table-cell;
        width: auto;
    }

    .environment-table {
        min-width: 800px;
    }

    .request-list-table {
        min-width: 760px;
    }

    .home-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .stat-card {
        min-width: 0;
        padding: 14px 6px;
    }

    .stat-value {
        font-size: 24px;
    }

    .stat-label {
        font-size: 12px;
    }

    .problem-filter-summary {
        min-height: 44px;
    }

    .problem-filter-actions {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .problem-filter-actions .button-primary {
        width: 100%;
        min-height: 44px;
    }

    .problem-search-reset {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
    }

    .difficulty-range-slider {
        height: 48px;
        margin-top: 0;
    }

    .difficulty-range-slider::before,
    .difficulty-range-slider::after {
        top: 21px;
    }

    .difficulty-range-slider input[type="range"]::-webkit-slider-runnable-track {
        height: 32px;
    }

    .difficulty-range-slider input[type="range"]::-moz-range-track {
        height: 32px;
    }

    .difficulty-range-slider input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
        margin-top: 4px;
    }

    .difficulty-range-slider input[type="range"]::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }

    .problem-table {
        min-width: 0;
        table-layout: fixed;
    }

    .problem-table th,
    .problem-table td {
        padding: 11px 5px;
    }

    .problem-table .col-tags {
        display: none;
    }

    .problem-table .col-solved {
        width: 38px;
    }

    .problem-table .col-id {
        width: 52px;
    }

    .problem-table .col-difficulty {
        width: 90px;
    }

    .problem-table .problem-title {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .contributor-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .contributor-table th,
    .contributor-table td {
        padding: 11px 5px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .contributor-table .contributor-col-role {
        display: none;
    }

    .contributor-table th:first-child,
    .contributor-table td:first-child {
        width: 36%;
    }

    .contributor-table th:nth-child(3),
    .contributor-table td:nth-child(3) {
        width: auto;
    }

    .contributor-table .col-problem-count {
        width: 64px;
        min-width: 0;
    }

    .contributor-table .problem-title {
        display: block;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .submission-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .submission-table th,
    .submission-table td {
        padding: 11px 5px;
    }

    .submission-table .col-lang,
    .submission-table .col-time,
    .submission-table .col-memory,
    .submission-table .col-created {
        display: none;
    }

    .submission-table .col-id {
        width: 72px;
    }

    .submission-table .col-problem {
        width: 52px;
    }

    .submission-table .col-user {
        width: 92px;
    }

    .submission-table .col-status {
        width: auto;
    }

    .submission-table td.col-user a,
    .submission-table td.col-user span {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .submission-meta > div {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .submission-meta .meta-label {
        display: block;
        min-width: 0;
        margin-bottom: 4px;
    }

    .submit-card .form-row {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .submit-card .form-row label {
        width: auto;
        min-width: 0;
    }

    .submit-card .language-picker,
    .submit-card .language-search,
    .submit-card .language-options {
        width: 100%;
        min-width: 0;
    }

    .language-option {
        display: flex;
        align-items: center;
        min-height: 44px;
    }

    .submit-actions {
        display: grid;
        gap: 8px;
    }

    .submit-actions .button-primary {
        width: 100%;
        min-height: 48px;
    }

    .code-input:not(#sourceCode) {
        min-height: 220px;
    }

    .profile-tabs {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .profile-tab {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        min-height: 44px;
    }

    .profile-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .profile-stat {
        min-height: 76px;
    }

    .profile-description-edit-trigger,
    .profile-result-stat {
        min-height: 44px;
    }

    .profile-description-input {
        font-size: 16px;
    }

    .profile-problem-list {
        grid-template-columns: 1fr;
    }

    .pagination {
        justify-content: flex-start;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        gap: 6px;
        padding: 2px 0 6px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .pagination a {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    .pagination .page-info,
    .pagination-ellipsis {
        flex: 0 0 auto;
    }

    .ranking-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .ranking-table th,
    .ranking-table td {
        display: table-cell;
        width: auto;
    }

    .ranking-table .ranking-col-status,
    .ranking-table .ranking-col-submissions,
    .ranking-table .ranking-col-authored {
        display: none;
    }

    .ranking-table th:nth-child(1),
    .ranking-table td:nth-child(1) {
        width: 46px;
    }

    .ranking-table th:nth-child(2),
    .ranking-table td:nth-child(2) {
        width: auto;
        min-width: 0;
    }

    .ranking-table th:nth-child(4),
    .ranking-table td:nth-child(4),
    .ranking-table th:nth-child(7),
    .ranking-table td:nth-child(7) {
        width: 72px;
    }

    .ranking-user {
        gap: 6px;
        min-width: 0;
    }

    .ranking-avatar {
        width: 28px;
        height: 28px;
    }

    .request-editor-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .request-editor-tabs a {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .request-modal-backdrop {
        padding: 10px;
    }

    .request-modal {
        max-height: calc(100dvh - 20px);
        padding: 16px;
    }

    .request-modal-close {
        width: 44px;
        height: 44px;
    }

    .request-modal-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .request-modal-actions .button-primary,
    .request-modal-actions .button-secondary-link {
        width: 100%;
    }

    .source-file-header {
        align-items: stretch;
        flex-direction: column;
    }

    .source-file-name {
        width: 100%;
    }

    .request-test-toolbar,
    .polygon-test-actions {
        flex-wrap: wrap;
    }

    .polygon-test-actions {
        width: 100%;
    }

    .polygon-test-actions > .button-secondary-link,
    .polygon-test-actions form {
        flex: 1 1 120px;
        min-width: 0;
    }

    .polygon-test-actions form .button-secondary-link {
        width: 100%;
    }

    .contributor-item {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .contributor-count {
        text-align: left;
    }
}

@media (max-width: 420px) {
    .nav a {
        padding-right: 9px;
        padding-left: 9px;
    }

    .problem-table .col-solved {
        width: 34px;
    }

    .problem-table .col-id {
        width: 46px;
    }

    .problem-table .col-difficulty {
        width: 78px;
    }

    .problem-table th,
    .problem-table td,
    .submission-table th,
    .submission-table td {
        font-size: 13px;
    }

    .contributor-table th:first-child,
    .contributor-table td:first-child {
        width: 38%;
    }

    .contributor-table .col-problem-count {
        width: 56px;
    }

    .submission-table .col-user {
        display: none;
    }

    .submission-table .col-id {
        width: 64px;
    }

    .submission-table .col-problem {
        width: 50px;
    }

    .home-stats {
        gap: 6px;
    }

    .stat-card {
        padding-right: 5px;
        padding-left: 5px;
    }
}
