/* Phone and small-tablet layout.

   Every rule here lives inside a media query, deliberately. The desktop
   stylesheets are the source of truth for the desktop; a rule that leaks out of
   this file silently restyles a working layout, and that is a very slow bug to
   find. Loaded last so it wins on specificity ties without needing !important.

   The base stylesheet already turns the sidebar into a drawer at 860px. This
   file covers everything added since - the grids, the drill modal, the state
   deck, the pickers - plus the things a phone needs that a desktop never does:
   thumb-sized targets, no accidental zoom on focus, and safe-area insets. */

/* ── everywhere below a laptop ─────────────────────────────────────────── */
@media (max-width: 860px) {

  /* The drawer covers most of the screen, so there needs to be an obvious way
     back. The scrim is the tap target; app.js closes the drawer on any click
     outside it. */
  body.navopen::after {
    content: ""; position: fixed; inset: 0; z-index: 15;
    background: rgba(4, 20, 34, .45); backdrop-filter: blur(1px);
  }
  .side { z-index: 20; }

  /* The drawer is the whole nav, and it has 17 modules in it, so it has to be
     scrollable to its true end.

     100vh is the trap here: on mobile it means the viewport INCLUDING the area
     behind the address bar, so the last item - Capstone - sits below anything a
     thumb can reach. 100dvh is the visible height and shrinks with the chrome.
     The bottom padding then keeps the final item clear of the home indicator. */
  .side {
    height: 100dvh; max-height: 100dvh;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding-top: env(safe-area-inset-top);
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
  /* Slightly tighter rows so more of the course is reachable without scrolling
     at all - four day-groups plus 17 lessons is a long list on a phone. */
  .navgroup { padding: 12px 12px 0; }
  .navgroup h5 { margin-bottom: 4px; }
  .navlink { padding: 10px 10px; font-size: 15px; }
  .brand { padding: 14px 18px 12px; }
  .brand img { width: 36px; height: 36px; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .wrap { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* The top bar was built for a 1400px window. On a phone the progress bar and
     the role pill are the first things to go - both repeat information that is
     either in the sidebar or simply not urgent. */
  .topbar { gap: 8px; flex-wrap: wrap; }
  .prog, .rolepill { display: none; }
  .crumbs { font-size: 11px; letter-spacing: 1px; }
  .themebtn { padding: 8px 10px; font-size: 13px; }
  /* "◐ Theme" becomes the glyph alone; three text buttons do not fit beside a
     hamburger at 390px. */
  #theme { font-size: 0; padding: 8px 11px; }
  #theme::before { content: "\25d0"; font-size: 15px; }

  h1 { font-size: clamp(24px, 7vw, 32px); }
  .lead { font-size: 16px; }
  .content { font-size: 16px; }
  .wrap.wide { padding-left: 16px; padding-right: 16px; }

  /* iOS zooms the whole page when a focused input is under 16px. Every control
     that can take focus gets bumped, which is why this is a blanket rule. */
  input, select, textarea,
  .ab-row input, .ab-row select,
  .sptable input.inline, .sptable select.inline,
  .spick-search, .firmpick select { font-size: 16px !important; }

  /* Thumb-sized targets. */
  .btn, .tinybtn, .linkbtn, .pencil, .iconbtn, .settab, .sttab { min-height: 40px; }
  .linkbtn { padding: 8px 10px; }
  .rowacts { display: flex; flex-wrap: wrap; gap: 4px; }

  /* ── team and firms become stacked cards ───────────────────────────────
     A six-column table cannot be made to fit, and side-scrolling a table you
     are meant to EDIT is miserable. Each row becomes a card and each cell
     carries its own label via data-l, so nothing loses its meaning. */
  .sptable { border: 0; overflow: visible; background: none; box-shadow: none; }
  .sptable table, .sptable thead, .sptable tbody, .sptable tr, .sptable td { display: block; width: auto; }
  .sptable thead { display: none; }
  .sptable tr {
    background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
    box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
  }
  .sptable tr.editing { border-color: var(--steel); }
  .sptable td { border: 0; padding: 5px 0; display: flex; align-items: center; gap: 10px; }
  .sptable td[data-l]::before {
    content: attr(data-l);
    flex: 0 0 88px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); font-weight: 700;
  }
  .sptable td.nm {
    display: block; font-size: 17px; font-family: var(--disp); font-weight: 700;
    border-bottom: 1px solid var(--line); padding-bottom: 9px; margin-bottom: 6px;
  }
  .sptable td.nm .em { font-size: 12.5px; }
  .sptable td.trunc { max-width: none; white-space: normal; }
  .sptable td.rowacts { padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--line); }
  .sptable input.inline, .sptable input.inline.wide, .sptable select.inline { flex: 1; min-width: 0; }
  .movebox { flex-wrap: wrap; }

  /* ── the score grids ───────────────────────────────────────────────────
     These stay tables. They are a matrix - agents against objections - and
     stacking them destroys the one thing they are for, which is reading across
     a row and down a column. Side-scrolling is the honest answer here. */
  .sctable { border-radius: 12px; }
  .sctable::after {
    content: "Scroll sideways for the rest \203a";
    display: block; padding: 7px 12px; font-size: 11.5px; color: var(--muted);
    border-top: 1px solid var(--line); background: var(--cream);
  }
  .sctable .sticky { min-width: 108px; }
  .sctable table { font-size: 12px; }
  .sctable th.vert span { max-width: 60px; font-size: 9.5px; }
  .sctable td.weak { min-width: 116px; }

  /* ── settings and score tabs ───────────────────────────────────────────*/
  .settabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .settab { white-space: nowrap; padding: 9px 12px; }
  .firmpick { flex-wrap: wrap; }
  .firmpick select { min-width: 0; width: 100%; }
  .addbox .ab-row { gap: 10px; }
  .ab-row input, .ab-row select, .ab-row .btn { flex: 1 1 100%; }

  /* ── the drill modal ───────────────────────────────────────────────────
     Full-bleed: a centred card with margins wastes the little height a phone
     has, and the transcript is the part that needs the room. dvh rather than
     vh so the collapsing address bar does not cut the footer off. */
  .rp-modal { padding: 0; }
  .rp-card { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .rp-head { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
  .rp-title { font-size: 18px; }
  .rp-stage { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
  .rp-caller { gap: 8px; }
  .rp-caller-cue { width: 100%; margin-left: 0; text-align: left; }
  .rp-orb { width: 62px; height: 62px; }
  .rp-live { max-height: 34dvh; }
  .rp-foot .btn { flex: 1; }
  .sc-big { font-size: 40px; }
  .sc-grid { grid-template-columns: 1fr 1fr; }
  .recbox audio { width: 100%; }

  /* ── drills ────────────────────────────────────────────────────────────*/
  .dgrid { grid-template-columns: 1fr; }
  .ws-row { flex-direction: column; gap: 5px; }
  .ws-row .dc-dir { align-self: flex-start; }

  /* ── the state deck ────────────────────────────────────────────────────*/
  .stslide { padding: 18px 15px; min-height: 0; }
  .st-blocks.cols { grid-template-columns: 1fr; }
  .st-table { font-size: 13px; }
  .st-table th, .st-table td { padding: 8px 6px; }
  .st-table tr td:first-child { width: 42%; }
  .sttabs { gap: 6px; }
  .sttab { font-size: 13px; padding: 8px 12px; }

  /* ── slide viewer ──────────────────────────────────────────────────────*/
  .viewer .ctl { flex-wrap: wrap; gap: 8px; justify-content: center; }
  .viewer .dots { order: 3; width: 100%; justify-content: center; }
  .vbtn { padding: 9px 12px; }

  /* ── downloads ─────────────────────────────────────────────────────────*/
  .resource { min-width: 0; flex: 1 1 100%; }

  /* ── quizzes ───────────────────────────────────────────────────────────*/
  .quiz-body { padding: 14px 15px; }
  .opt { padding: 11px 12px; }
  .quiz-foot { flex-wrap: wrap; gap: 10px; }
  .quiz-foot .nextup { margin-left: 0; flex: 1 1 100%; }

  /* ── jeopardy ──────────────────────────────────────────────────────────
     Six categories across a phone gives 60px columns, so the board scrolls
     sideways with the tiles kept big enough to hit.

     The flow MUST stay row-based. The markup is row-major - six category
     headings, then six tiles per value row - so switching to column flow lays
     the whole board out as one long strip with the categories interleaved
     among the tiles. Only the column WIDTH changes here. */
  .jboard {
    grid-auto-flow: row;
    grid-template-columns: repeat(6, 98px);
    overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    padding-bottom: 8px;
  }
  .jtile { font-size: 19px; padding: 15px 6px; }
  .jcat { font-size: 11px; min-height: 56px; padding: 9px 6px; line-height: 1.2; }
  .jshead { flex-wrap: wrap; row-gap: 8px; }
  .jshead .jactions { margin-left: auto; }
  .jhint { display: block; }

  /* The clue is read aloud off this screen, so it takes the room the board
     does not need. */
  .jmodal { padding: 14px; }
  .jm-card { padding: 20px 18px; max-height: 88dvh; overflow-y: auto; }
  .jm-clue { font-size: 20px; margin-bottom: 14px; }
  .jm-ans { font-size: 15.5px; padding: 12px 14px; margin-bottom: 16px; }
  .jm-val { margin-bottom: 10px; }
  .jm-ctl { flex-wrap: wrap; }
  .jm-ctl .btn { flex: 1; }

  /* ── pickers and panels ────────────────────────────────────────────────*/
  .spick-panel { width: min(320px, calc(100vw - 24px)); }
  .spick-list { max-height: 46dvh; }
  .spick-opt { padding: 9px 6px; }

  /* ── manager material ──────────────────────────────────────────────────*/
  .tscripts .rpwrap { padding: 0 12px 12px; }
  .lockpanel { flex-direction: column; gap: 10px; padding: 16px; }
}

/* ── phones held sideways ───────────────────────────────────────────────
   A landscape phone is 700-950px WIDE, so it clears the 860px breakpoint and
   would otherwise get the desktop layout in 390px of height. Height is the
   scarce dimension here, not width. */
@media (orientation: landscape) and (max-height: 520px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 270px;
          height: 100dvh; max-height: 100dvh; overflow-y: auto;
          -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
          padding-bottom: calc(24px + env(safe-area-inset-bottom));
          transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  .navlink { padding: 7px 10px; font-size: 14px; }
  .navgroup { padding: 8px 12px 0; }
  .brand { padding: 10px 16px 8px; }
  .side.open { transform: none; }
  .mobtoggle { display: inline-grid; place-items: center; width: 36px; height: 36px;
               border-radius: 9px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; }
  body.navopen::after { content: ""; position: fixed; inset: 0; z-index: 15; background: rgba(4,20,34,.45); }

  .topbar { padding: 6px 14px; }
  .prog { display: none; }
  h1 { font-size: 24px; margin: .2em 0 .1em; }
  .wrap { padding: 14px 18px 40px; }
  .shead { margin: 20px 0 10px; }

  /* The modal has almost no vertical room, so the orb goes and the transcript
     takes what is left - reading what you said matters more than the pulse. */
  .rp-card { height: 100dvh; max-height: 100dvh; border-radius: 0; width: 100%; }
  .rp-orbwrap { flex-direction: row; gap: 12px; padding: 0; }
  .rp-orb { width: 40px; height: 40px; }
  .rp-live { max-height: 30dvh; }
  .sc-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Very narrow phones: the two-column score cells stop fitting. */
@media (max-width: 380px) {
  .sc-grid { grid-template-columns: 1fr; }
  .sptable td[data-l]::before { flex-basis: 74px; }
  .wrap { padding-left: 14px; padding-right: 14px; }
}

/* ── courses on a phone ───────────────────────────────────────────────── */
@media (max-width: 860px) {
  .coursepick { padding: 12px 12px; }
  .cp-current { padding: 12px 34px 13px 13px; }
  .cp-opt { padding: 11px 10px; }
  .grantbox { gap: 2px; }
  .grant { padding: 7px 5px; }
}
