/* The phone layout. One column, everything within reach of a thumb, and the
   canvas left as clear as it can be. Loaded last so it has the final word. */

/* The "Menu" button that folds the top bar's actions away: phones only. */
.top-more { display: none; }

/* Fingers, not a mouse: bigger targets, no keyboard hints, no zoom on focus. */
@media (pointer: coarse) {
  .talk kbd { display: none; }
  input, select, textarea { font-size: 16px !important; }
  .node-fold { min-width: 28px; height: 28px; border-radius: 14px; font-size: 12px; }
  .ce-x { width: 40px; height: 40px; }
  .ce-x-small { width: 32px; height: 28px; }
  .btn-small { min-height: 34px; }
}

/* The top bar folds on anything narrower than a laptop: phones either way
   up, and tablets. */
@media (max-width: 1023px) {
  :root { --bar-h: 112px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px); }
  /* ---------- top bar: two rows, the rest behind Menu ---------- */
  .topbar { top: calc(var(--s2) + var(--safe-t)); left: var(--s2); right: var(--s2); flex-wrap: wrap; gap: var(--s2); align-items: center; }
  .topbar .home-btn, .topbar .project-name, .top-more { min-height: 40px; padding: 0 var(--s3); }
  .topbar .project-name { flex: 1 1 0; min-width: 0; max-width: none; justify-content: flex-start; }
  .topbar .project-rename { flex: 1 1 0; min-width: 0; width: auto; min-height: 40px; }
  .topbar > .seg { flex: none; }
  .topbar > .seg .seg-btn { padding: 0 var(--s2); }
  .top-more { display: inline-flex; flex: none; box-shadow: var(--shadow); }
  .goalbar { order: 3; flex: 1 1 100%; min-height: 40px; }
  .goalbar-text { font-size: 15px; }
  .top-actions {
    display: none; order: 4; flex: 1 1 100%; flex-wrap: wrap; margin: 0; padding: var(--s3);
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow);
  }
  .topbar.is-more .top-actions { display: flex; }
  .topbar.is-more { z-index: 40; }
  .top-actions .btn, .top-actions .menu > summary { min-height: 40px; box-shadow: none; border-color: var(--line-strong); }
  #paceMenu { display: block; }

  /* a menu opens as a sheet across the screen, wherever its button is */
  .menu { position: static; }
  .menu-pop, .menu-pop.micpop, .menu-pop.agentpop, .menu-pop.legend {
    position: fixed; left: var(--s2); right: var(--s2); width: auto; max-width: none;
    max-height: 70dvh; overflow-y: auto; z-index: 60;
  }
  .menu-pop-right { top: calc(var(--bar-h) + var(--s3) + var(--safe-t)); bottom: auto; }
  .menu-pop-up { top: auto; bottom: calc(150px + var(--safe-b)); }
  .side-toggle { top: calc(var(--bar-h) + var(--s2) + var(--safe-t)); }
}

@media (max-width: 767px) {
  :root {
    --bar-h: 112px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
  }
  html, body { overscroll-behavior: none; }

  /* ---------- what the agent is doing and saying: a strip under the top bar ---------- */
  .cursor-bubble, .cursor-tag { display: none; }
  .says {
    position: fixed; z-index: 21; left: 92px; right: var(--s2); top: calc(var(--bar-h) + var(--s2) + var(--safe-t));
    display: grid; gap: 1px; min-height: 36px; padding: 5px var(--s3); text-align: left;
    background: var(--surface); border: 1.5px solid var(--agent); border-radius: var(--r2); box-shadow: var(--shadow);
    font-family: inherit; color: var(--ink);
  }
  .says b { font-size: 11px; color: var(--agent-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .says span { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
  .says.is-busy { background: var(--agent-tint); }

  /* ---------- the panel: a sheet between the bars ---------- */
  .side-toggle { top: calc(var(--bar-h) + var(--s2) + var(--safe-t)); left: var(--s2); min-height: 36px; }
  .side { left: var(--s2); right: var(--s2); width: auto; top: calc(var(--bar-h) + var(--s2) + 44px + var(--safe-t)); bottom: calc(132px + var(--safe-b)); }

  /* ---------- the bottom: message bar, with zoom tucked at the side ---------- */
  .inputbar {
    left: var(--s2); right: var(--s2); width: auto; transform: none; bottom: calc(var(--s2) + var(--safe-b));
    flex-direction: column-reverse; align-items: stretch; gap: var(--s2);
  }
  .input-main { padding: 6px; }
  .input-row { gap: 6px; }
  .input-row .iconbtn { width: 40px; height: 40px; flex: none; }
  .msg { min-height: 40px; }
  .input-side { justify-content: flex-end; }
  .input-side .btn { min-height: 38px; }
  .ctx-chip { max-width: 200px; }
  .zoomctl {
    left: auto; right: var(--s2); bottom: calc(168px + var(--safe-b)); max-width: none;
    flex-direction: column; flex-wrap: nowrap; align-items: stretch; padding: 4px;
  }
  .zoomctl .zoom-label, .zoomctl #legend, .zoomctl .menu { display: none; }
  .zoomctl .iconbtn { width: 38px; height: 38px; align-self: center; }
  /* two fingers zoom: the buttons for it would only be in the way */
  .zoomctl > .iconbtn:nth-of-type(1), .zoomctl > .iconbtn:nth-of-type(2) { display: none; }
  .zoomctl .btn { min-height: 34px; padding: 0 6px; justify-content: center; font-size: 11px; }
  /* a lesson that is open has the screen to itself */
  body:has(.node.is-open) .zoomctl { display: none; }
  /* lassoing is a mouse's job */
  .zoomctl .seg { display: none; }
  .selbar { left: var(--s2); right: 60px; bottom: calc(168px + var(--safe-b)); transform: none; flex-wrap: wrap; justify-content: flex-start; }
  .moment { left: var(--s2); right: var(--s2); width: auto; transform: none; bottom: calc(168px + var(--safe-b)); max-height: 60dvh; overflow-y: auto; }
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } }
  .toasts { left: var(--s2); right: var(--s2); transform: none; top: calc(var(--bar-h) + var(--s3) + var(--safe-t)); }
  .welcome { padding: 0 var(--s4); }
  .welcome h1 { font-size: 26px; }

  /* ---------- drawers and dialogs take the whole screen ---------- */
  .drawer {
    left: 0; right: 0; top: 0; bottom: 0; width: auto; border: 0; border-radius: 0; z-index: 46;
    padding-top: var(--safe-t); padding-bottom: var(--safe-b);
  }
  .drawer-head { padding: var(--s2) var(--s3); }
  .drawer .tab { min-height: 40px; }
  .drawer-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .dialog { width: calc(100vw - 24px); max-height: 86dvh; overflow-y: auto; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .btn { flex: 1 1 auto; min-height: 44px; justify-content: center; }

  /* ---------- a lesson frame: laid out for a phone's width ---------- */
  .node-frame { width: 380px; transform: scale(.5); }
  .frame-head { padding: var(--s3); gap: var(--s2); }
  .frame-title { font-size: var(--fs-lg); flex-basis: 100%; }
  .block { padding: var(--s3); }
  .frame pre, .frame .code { font-size: 12px; }
  .frame .btn { min-height: 40px; }
  .frame textarea, .frame input[type="text"] { min-height: 44px; }

  /* ---------- widgets on the canvas ---------- */
  .widget-head { flex-wrap: wrap; row-gap: 6px; }
  .widget-head .btn { min-height: 34px; }

  /* ---------- home and login ---------- */
  .home-inner { padding: calc(24px + var(--safe-t)) 0 calc(32px + var(--safe-b)); }
  .home-new { flex-wrap: wrap; }
  .home-new input { flex: 1 1 100%; min-height: 44px; }
  .home-new .btn { flex: 1 1 100%; min-height: 44px; justify-content: center; }
  .home-card { flex-wrap: wrap; padding: 0 0 var(--s2); }
  .home-open { flex: 1 1 100%; }
  .home-card .btn-danger { margin-left: var(--s4); }
  .login-box { padding: var(--s5); }
  .login-box input { min-height: 44px; }
  .login-box .btn { min-height: 46px; }

  /* ---------- the course editor ---------- */
  .ce { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
  .ce-top { gap: var(--s2); padding: var(--s2) var(--s3); min-height: 0; }
  .ce-eyebrow { display: none; }
  .ce-top-title { flex: 1 1 120px; min-width: 120px; }
  .ce-title { font-size: var(--fs-body); }
  .ce-back { min-height: 38px; padding: 0 var(--s2); }
  .ce-status { order: 0; padding: 2px var(--s2); font-size: var(--fs-xs); }
  .ce-top > .btn-surface { order: 6; min-height: 38px; font-size: var(--fs-sm); }
  .ce-viewseg { order: 5; flex: 1 1 55%; display: flex; }
  .ce-viewseg .seg-btn { flex: 1 1 0; justify-content: center; min-height: 36px; }
  .ce-thread { padding: var(--s4) var(--s3); gap: var(--s4); }
  .ce-strip { padding: var(--s2) var(--s3); }
  .ce-strip p { font-size: var(--fs-sm); }
  .ce-strip .btn { flex: 1 1 auto; min-height: 40px; justify-content: center; white-space: normal; text-align: center; }
  .ce-typing { padding: var(--s2) var(--s3); }
  .ce-composer { padding: var(--s2) var(--s3) var(--s3); }
  .ce-composer .btn-primary { min-height: 48px; }
  .ce-composer-tools .btn { min-height: 40px; }
  /* the legend is a luxury a phone cannot afford */
  .ce-draft-head { display: none; }
  .ce-draft-body { padding: var(--s3) var(--s2) var(--s8); }
  .ce-doc { gap: var(--s4); }
  .ce-sec { padding: var(--s3); border-radius: var(--r2); }
  .ce-sec h2 { font-size: var(--fs-lg); }
  .ce-epi { padding: var(--s3); }
  .ce-pair .ce-field { min-width: 0; flex: 1 1 100%; }
  .ce-hours { width: auto; }
  .ce-add { flex-wrap: wrap; }
  .ce-add .ce-input { flex: 1 1 60%; min-height: 40px; }
  .ce-add .btn { min-height: 40px; }
  .ce-lesson-facts .ce-select { flex: 1 1 100%; min-height: 40px; }
  .ce-select { min-height: 40px; }
  .ce-commit .btn { flex: 1 1 100%; min-height: 46px; justify-content: center; }
  .ce-source .od-row-top { flex-wrap: wrap; }
  .ce-part .od-row { flex-wrap: wrap; }
  .ce-part .ce-part-title { flex: 1 1 60%; }
  .ce-partrow { flex-wrap: nowrap; }
  .ce-pre { font-size: 11px; }
  .ce-depths .ce-read { grid-template-columns: minmax(0, 1fr); }
}

/* The editor's steps on anything narrower than a wide laptop: numbers in a
   row, with only the present one spelled out. */
@media (max-width: 1180px) {
  .ce-steps { padding: var(--s2) var(--s3); }
  .ce-rail { display: flex; gap: 6px; overflow: visible; }
  .ce-rail > li { flex: none; width: auto; }
  .ce-rail > li:has([aria-current="step"]) { flex: 1 1 0; min-width: 0; }
  .ce-step { min-height: 40px; padding: 4px 8px; column-gap: 6px; }
  .ce-step-n { display: none; }
  .ce-step-mark { grid-row: auto; }
  .ce-step:not([aria-current="step"]) { grid-template-columns: auto; }
  .ce-step:not([aria-current="step"]) .ce-step-label { display: none; }
  .ce-step-label { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* A phone held sideways: very little height, so the editor keeps only what
   is needed to talk and to read. */
@media (max-height: 520px) and (pointer: coarse) {
  .ce-top { padding: 4px var(--s3); }
  .ce-steps { padding: 4px var(--s3); }
  .ce-step { min-height: 34px; }
  .ce-strip { padding: 4px var(--s3); }
  .ce-strip p, .ce-composer-head label { display: none; }
  .ce-strip .btn { min-height: 34px; }
  .ce-composer { padding: 4px var(--s3) 6px; gap: 4px; }
  .ce-composer textarea.ce-input { min-height: 40px; height: 40px; }
  .ce-composer .btn-primary { min-height: 40px; }
  .ce-composer-tools .btn { min-height: 34px; }
  .ce-thread { padding: var(--s2) var(--s3); }
  .inputbar { flex-direction: row; align-items: flex-end; }
  .inputbar .input-main { flex: 1 1 0; }
  .zoomctl { bottom: calc(72px + var(--safe-b)); flex-direction: row; }
}
