/* =====================================================================
   SPECTRE — responsive component overrides
   The page frame (header, rail/drawer, footer) is responsive in
   theme.css. This file tightens view-level components on tablets and
   phones. Desktop is unaffected: every rule sits inside a media query.
   ===================================================================== */

/* ---------- tablet and below (<= 1024px) ---------- */
@media (max-width: 1024px) {
    .card .card-body, .card-body { padding: 4px 0; }
}

/* ---------- phones (<= 768px) ---------- */
@media (max-width: 768px) {
    .sp-main { overflow-wrap: break-word; }
    .sp-main :is(iframe, video) { max-width: 100%; }

    h1.page-head, .page-head { font-size: 1.45rem; }
    h2.page-subhead, .page-subhead { font-size: 1.12rem; }

    th, td { padding: 7px 6px; }

    /* classic "p > kbd + input" forms stack the label above the field */
    .kbd-form p, .post-form p { flex-direction: column !important; align-items: stretch !important; gap: 4px !important; }
    .kbd-form kbd, .post-form kbd { min-width: 0 !important; text-align: left !important; }
    .kbd-form :is(input, select, textarea), .post-form :is(input, select, textarea) { width: 100% !important; max-width: none !important; }

    /* manifest cards: 2-up */
    .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
    .crew-card-img, .crew-card-placeholder { height: 140px !important; }
    .crew-card-name { font-size: 0.8rem !important; }
    .crew-card-position { font-size: 0.7rem !important; }

    /* post "featuring" banner */
    .portrait-img, .portrait-placeholder { width: 120px !important; height: 152px !important; }
    .portrait-wrap { width: 120px !important; }
    .featuring-portraits { gap: 12px !important; }

    /* previous / next post buttons stack */
    .post-nav-bar { flex-direction: column !important; }
    .post-nav-btn, .post-nav-btn.post-nav-next { max-width: 100% !important; margin-left: 0 !important; text-align: left !important; }

    /* bio header stacks */
    .bio-profile-header { flex-direction: column !important; }
    .bio-profile-image img { max-width: 100% !important; }

    /* audit log rows */
    .audit-header { flex-direction: column !important; align-items: flex-start !important; gap: 4px !important; }

    /* front-page mission art */
    .main-mission-banner img, .featuring-mission-img { height: auto !important; max-height: 200px !important; }
}

/* ---------- small phones (<= 640px) ---------- */
@media (max-width: 640px) {
    /* !important: many headings carry an inline font-size sized for desktop */
    h1 { font-size: 1.4rem !important; line-height: 1.2 !important; }
    h2 { font-size: 1.2rem !important; }
    h3 { font-size: 1.05rem !important; }

    /* fields go full width */
    input[type=text], input[type=email], input[type=password], input[type=search],
    input[type=number], input[type=url], input[type=tel], input[type=date],
    input:not([type]), select, textarea, .form-control {
        width: 100% !important;
        max-width: 100% !important;
    }
    textarea { min-height: 100px; }

    /* "p > kbd" labels sit above their field */
    p > kbd { display: block !important; min-width: 0 !important; width: auto !important; margin-bottom: 6px !important; padding: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; }
    p > kbd + :is(input, select, textarea) { display: block !important; width: 100% !important; margin-top: 4px !important; }
    .img-picker-btn { display: inline-block; margin-top: 6px !important; margin-left: 0 !important; }

    /* wide tables scroll sideways inside their own box instead of the page */
    .card { overflow-x: auto; }
    table:not(.login-table) {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap !important;
        font-size: 0.86rem;
    }
    table th, table td { padding: 6px 8px !important; }

    .card { margin-bottom: 10px; padding: 12px; }

    /* grids collapse to one column */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 12px !important; }

    .cards-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; gap: 10px !important; }

    .post-meta-bar { display: block !important; }
    .post-meta-bar > div { display: block !important; margin-bottom: 4px; }

    .featuring-portraits { display: flex !important; overflow-x: auto !important; gap: 10px !important; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
    .portrait-wrap { flex-shrink: 0; width: 90px; }
    .featuring-mission-img { max-width: 100% !important; max-height: 200px !important; }
    .main-mission-banner img { max-height: 180px !important; }

    .btn-row { display: flex !important; flex-direction: column !important; gap: 8px !important; }
    .btn-row .btn { width: 100% !important; }

    /* image picker modal goes near full screen */
    #image-picker-modal > div { max-height: 95vh !important; margin: 8px !important; }
    #image-picker-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important; gap: 8px !important; padding: 10px !important; }

    .welcome-list-item, .list-item { padding: 10px !important; }
    .welcome-list-item h4 { font-size: 0.95rem !important; }

    .upload-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; gap: 10px !important; }
    .upload-tile-img { height: 110px !important; }

    .filter-row { flex-direction: column !important; align-items: stretch !important; }
    .filter-row > div { width: 100%; }

    /* admin dashboard */
    .stat-grid { grid-template-columns: 1fr 1fr !important; gap: 0.6em !important; }
    .admin-content-grid { grid-template-columns: 1fr !important; }
    .dash-tabs { flex-wrap: nowrap !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
    .dash-tabs::-webkit-scrollbar { height: 3px; }
    .dash-tabs::-webkit-scrollbar-thumb { background: rgba(var(--pp-rgb),0.4); border-radius: 3px; }
    .dash-tab { white-space: nowrap; }

    .mission-edit-btn { font-size: 0.8rem !important; padding: 2px 10px !important; }

    /* player dashboard stat bar wraps 2-up */
    .stat-bar { flex-wrap: wrap; min-height: 0; }
    .stat-item { flex: 1 1 50%; width: 50%; padding: 12px 4px; border-bottom: 1px solid var(--sp-line); }
    .stat-item.stat-mission { flex: 1 1 100%; width: 100%; }

    /* sign-in form is a layout table: stack it */
    table.login-table, table.login-table tbody, table.login-table tr, table.login-table td {
        display: block !important;
        width: 100% !important;
        overflow: visible !important;
        white-space: normal !important;
        text-align: left !important;
    }
    table.login-table td { padding: 8px 0 !important; }
    table.login-table :is(input[type=email], input[type=password]) { display: block; width: 100% !important; margin-top: 5px; }

    /* application form grids */
    .apply-name-grid, .form-grid-3 { grid-template-columns: 1fr !important; }
    .form-grid-4 { grid-template-columns: 1fr 1fr !important; }
}

/* ---------- very small phones (<= 380px) ---------- */
@media (max-width: 380px) {
    body { font-size: 14px; }
    h1 { font-size: 1.25rem !important; }
    .cards-grid { grid-template-columns: 1fr !important; }
    .crew-card-img, .crew-card-placeholder { height: 200px !important; }
    .upload-grid { grid-template-columns: 1fr 1fr !important; }
}
