/* =====================================================================
   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; }
    /* stacked: the portrait/facts blocks dissolve into the column, and what a plugin draws under the bio (slot character.bio.under_portrait) comes right after the portrait */
    .bio-profile-main, .bio-profile-top { display: contents !important; }
    .bio-profile-header .bio-profile-info, .bio-profile-header .bio-profile-timeline { order: 2; }
    .bio-profile-header .bio-profile-image { order: 0; align-self: stretch; }
    .bio-profile-header .bio-under-portrait { order: 1; flex: 0 0 auto; align-self: stretch; width: 100%; box-sizing: border-box; margin-top: 0; }
    .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.
       Never on a skin-frame page (body.sp-skin): there the headings are the old site's, and an !important in
       the base layer would beat the old sheet's own phone sizes (no later rule can roll it back to them). */
    :where(body:not(.sp-skin)) h1 { font-size: 1.4rem !important; line-height: 1.2 !important; }
    :where(body:not(.sp-skin)) h2 { font-size: 1.2rem !important; }
    :where(body:not(.sp-skin)) 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.
       On a skin-frame page only Spectre's own tables (a class, inside the page area) do: a plain table there is
       the old site's, which its own sheet draws (same reason as the headings above; specificity unchanged). */
    .card { overflow-x: auto; }
    table:not(.login-table):not(:where(body.sp-skin table:not(:is(.sp-skin-content, :has(> .sp-skin-anchor)) table[class]))) {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        font-size: 0.86rem;
    }
    /* one line per cell, never on a skin-frame page: there a table in the page area is a page set's (Nova's manifest)
       and its crew names wrap instead of being cut off at the column's edge (Owner 2026-11-26; pass 7: starbase-mojave,
       valhalla-fleet-yards). It still scrolls sideways, above, when it is wider than the column even so. */
    table:not(.login-table):not(:where(body.sp-skin table)) { white-space: nowrap !important; }
    /* cells' phone padding: never on a skin page either (a page set's table has the old sheet's and its cellpadding;
       16px a cell pushed Nova's five-column manifest out of a narrow phone column) */
    :is(table th, table td):not(:where(body.sp-skin :is(th, td))) { padding: 6px 8px !important; }

    /* Label / value tables (the bio's Demographics and its other lists) are short: they stay real tables at the full
       column width, the value wrapping inside its cell, instead of the sideways-scrolling block above (which shrank
       them to the width of their words). */
    table.bio-table { display: table !important; width: 100% !important; overflow: visible !important; white-space: normal !important; }
    table.bio-table td:last-child { overflow-wrap: anywhere; }

    .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; }
    .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; }
    :where(body:not(.sp-skin)) 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; }
}

/* Admin > Episodes > Edit: Episode Timeline entries on phones. The entry text gets the
   whole width and the Auto / Edit / delete controls move to their own row under it
   (they used to keep their width and squeeze the text to one letter a line). */
@media (max-width: 640px) {
    #timeline-card .card-header { flex-wrap: wrap; }
    #timeline-card #tl-add-btn { white-space: nowrap; }
    #timeline-card .tl-entry { flex-wrap: wrap; padding: 12px; }
    #timeline-card .tl-entry > div:nth-child(2) { flex: 1 1 calc(100% - 40px); }
    #timeline-card .tl-entry > div:last-child { flex: 1 1 100%; flex-wrap: wrap; justify-content: flex-end; }
}

/* Bio timeline In character / Out of character tabs: both on one line on phones */
@media (max-width: 640px) {
    .sim-hist-bio__tabs button { padding: 4px 10px; letter-spacing: 0.04em; }
}
