/* Anticode on a phone (the owner, 13 Nov 2026: "fix mobile interface like crazy", "make the mobile interface look
   like its own anticode"). Loaded last by the home page and builder (index.html), the dashboard, Settings and
   sign-in. Every rule here is inside a width or touch query, so nothing changes on a desktop; test/phone.test.mjs
   checks that, and that no main screen scrolls sideways at 375px.

   Three things run through it:
   - a control you tap is at least 44px tall. Where the control is drawn smaller (an icon, a petite pill), the tap
     area is widened around it with ::after and the drawing stays as it is;
   - a text field is 16px on touch, so iOS doesn't zoom the page when it gets the caret;
   - bars keep clear of the notch and the home indicator (env(safe-area-inset-*)), and the builder and dashboard
     end above the on-screen keyboard (--kb, kept by public/prefs.js from visualViewport). */

/* ---------- on touch, everywhere ---------- */
@media (pointer: coarse) and (max-width: 820px) {
  :is(body, #build) :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"]), textarea, select) { font-size: 16px !important; }
}

/* the tap area around a small control: the control keeps its drawn size. The first list is controls that sit in the
   flow, which need to become the box the area is measured from; the second is ones that are placed already. */
@media (pointer: coarse) and (max-width: 820px) {
  :is(.icon-btn:not(.mob-menu), .seg2 button, .browse, .si-link, .sp-brand, .release-more summary, .top .brand, .lib-body .cm-sort button) { position: relative; }
  :is(.icon-btn:not(.mob-menu), .seg2 button, .browse, .si-link, .sp-brand, .release-more summary, .top .brand, .lib-body .cm-sort button,
      .ws-icon, .build.ws .wtab, .si-show)::after {
    content: ""; position: absolute; top: 50%; left: 50%; width: max(100%, 44px); height: max(100%, 44px); translate: -50% -50%; }
  /* these have a tap area already (calm.css), as tall as their words: taller */
  body.dash .home-rail :is(.rail-btn, .rail-link)::after { inset: -12px 0; }
  /* menus: every row is a full 44px */
  .dash .menu.dmenu :is(button, a), .ws-menu :is(button, a), .dash .pick-menu button, .dash .mgroup > button { min-height: 44px; }
}

/* ================= the builder ================= */
@media (max-width: 820px) {
  #build.ws { bottom: var(--kb, 0px); }
  /* the preview's toolbar: one row, the icons at the left and Publish at the right edge */
  #build.ws .stage-bar { padding: 4px 8px 8px; gap: 6px; }
  #build.ws .wbar-end { gap: 2px; }
  #build.ws .wbar-start .to-board { flex: none; width: 32px; }
  /* Publish is the one button here that keeps its word; Grow gives up its own to make the room */
  #build.ws .wbar-end #publish { gap: 6px; padding: 0 12px; font-size: 13px; }
  #build.ws .wbar-end #grow-open { gap: 0; padding: 0 11px; font-size: 0; }
  /* Files: the search takes what's left of the row and New stays on the page */
  #build.ws .wsp-head { gap: 8px; padding: 12px 14px; border-bottom: 0; }
  #build.ws .wsp-files { border-radius: calc(16px + 14px); }
  #build.ws .wsp-head .wsearch { flex: 1 1 0; min-width: 0; }
  #build.ws .wsp-head .wsearch input { width: 100%; min-width: 0; }
  #build.ws .wsp-head .wschat-menu-wrap { flex: none; }
  #build.ws .stage-fine { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }

  /* the sidebar slides over the page, with the page dimmed behind it; a tap on the dimmed part closes it */
  #build.ws[data-nav="open"]::before { content: ""; position: fixed; inset: 0; z-index: 59; background: rgba(0, 0, 0, 0.5); }
  #build.ws[data-nav="open"] .wsnav { padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); overflow-y: auto; border-right: 0; }

  /* the canvas: a frame's name stays on one line beside its Laptop or Phone label */
  #build.ws .frame-label { min-width: 0; }
  #build.ws .frame-label b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #build.ws .frame-label .pill { flex: none; }
  #build.ws .board-tools { inset-block-end: calc(14px + env(safe-area-inset-bottom, 0px)); max-width: calc(100% - 12px); gap: 2px; }
  #build.ws .board-tools .sep { margin-inline: 2px; }
}
@media (max-width: 820px) and (pointer: coarse) {
  #build.ws .wsnav :is(a, button):not(.wsnav-logo, .av-edit) { min-height: 44px; }
  #build.ws .board-tools button { height: 44px; }
  #build.ws .release-more summary { padding-block: 12px; margin-block: -12px; }
  #build.ws .wschat-title .proj-name { min-height: 44px; }
}

/* ================= the dashboard ================= */
@media (max-width: 820px) {
  /* A bar of its own at the top: the sidebar's button, and the mark. Before, the 32px button floated over each
     page's heading. The page scrolls under it and fades out at its edge. */
  body.dash .app { height: calc(100dvh - var(--kb, 0px)); }
  body.dash .panel { --pbar: calc(52px + env(safe-area-inset-top, 0px)); }
  body.dash .panel > .panel-scroll { height: calc(100% - var(--pbar)); margin-top: var(--pbar); }
  body.dash .panel::before { content: ""; position: absolute; inset: 0 0 auto; z-index: 4; height: calc(var(--pbar) + 14px); pointer-events: none;
    background: linear-gradient(to bottom, var(--c-main, var(--panel)) var(--pbar), transparent); }
  body.dash .panel::after { content: ""; position: absolute; z-index: 5; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 50%; width: 21px; height: 24px; translate: -50% 0; pointer-events: none;
    background: var(--text); -webkit-mask: url(/mark.svg) center / contain no-repeat; mask: url(/mark.svg) center / contain no-repeat; }
  body.dash .mob-menu { left: max(6px, env(safe-area-inset-left, 0px)); top: calc(env(safe-area-inset-top, 0px) + 4px); width: 44px; height: 44px; border-radius: 50%; color: var(--text); }
  body.dash .mob-menu .ic { width: 20px; height: 20px; }
  /* The sidebar as a drawer. The page behind is dimmed and blurred enough that its cut-off pieces (half a heading,
     the composer's buttons) no longer read as part of the drawer, and the drawer has a close button of its own. */
  body.dash .drawer-scrim { background: rgba(0, 0, 0, 0.62); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
  body.dash .side { width: min(320px, 86vw); padding-left: max(8px, env(safe-area-inset-left, 0px)); box-shadow: 24px 0 64px rgba(0, 0, 0, 0.45); overscroll-behavior: contain; }
  body.dash .side .side-top { height: 44px; padding: 0 0 0 8px; }
  body.dash .side-close { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--text); }
  body.dash .side-close .ic { width: 20px; height: 20px; }
  /* the pages start right under the bar */
  body.dash .view-home { padding-top: 0; }
  body.dash .home-main { min-height: calc(100dvh - var(--pbar) - var(--kb, 0px)); padding-inline: 16px; }
  body.dash .home-main > .connect { top: 4px; right: 16px; }
  body.dash .greet { padding-top: 64px; }
  body.dash .panel-scroll > .view:not(.view-home) { padding: 8px 16px calc(56px + env(safe-area-inset-bottom, 0px)); }
  body.dash .view-home { padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }

  /* Projects: the search takes the row, with the grid and list switch beside it */
  body.dash .pview-tools { flex-wrap: wrap; gap: 10px; }
  body.dash .pview-tools .field { flex: 1 1 160px; min-width: 0; min-height: 44px; }
  body.dash .pview-tools .field input { width: 100%; min-width: 0; }
  body.dash .seg2 button { min-width: 40px; min-height: 36px; }
  /* a template's line of description wraps to two lines and is not cut after one */
  body.dash .shelf .card-foot > div > span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; white-space: normal; overflow: hidden; text-overflow: clip; }
  body.dash .card .badge { font-size: 11.5px; }

  /* the sidebar, as a drawer */
  body.dash .side { overflow-y: auto; overscroll-behavior: contain; padding-left: max(8px, env(safe-area-inset-left, 0px)); }
}
@media (max-width: 820px) and (pointer: coarse) {
  body.dash .side .snav :is(a, button), body.dash .side .recents :is(a, button), body.dash .side .ws-btn, body.dash .side .acct-btn { min-height: 44px; }
  body.dash .dcomp :is(.dcomp-plus, #mic) { width: 44px; height: 44px; }
  body.dash .effort-btn, body.dash .pick-btn { min-height: 44px; }
  body.dash :is(.gr-field select, .gr-web-form input, .gr-actions input) { min-height: 44px; }
  body.dash .card-more { width: 44px; height: 44px; margin-right: -8px; }
  body.dash .seg2 button { min-height: 44px; }
}

/* ================= the home page ================= */
@media (max-width: 640px) {
  /* The builder's window in "Everything a real product needs": one column, the chat at full width. The rule that
     puts the chat on the right (.duo-l .app-body) outranked the phone rule, so the chat was squeezed into about
     90px beside an empty panel (the owner's screenshot, 13 Nov 2026). */
  .home .duo .app-body, .home .duo-l .app-body { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .home .duo-l .app-rail { order: 0; }
  .home .duo .app-rail { padding: 16px; }
  .home .duo .app-me { max-width: 85%; }
  .home .duo .app-bar { gap: 10px; padding: 0 12px; }
  .home .duo .app-pub { margin-left: auto; }
  .home .duo-art .app, .home .duo-l .duo-art .app, .home .duo-r .duo-art .app { margin: 0 16px; }
}

/* ================= Settings and sign-in ================= */
@media (max-width: 820px) and (pointer: coarse) {
  body.sp .sp-nav a, body.sp .sp-search input { min-height: 44px; }
  body.sp .sp-bar .btn, body.sp .settings-actions .btn { min-height: 44px; }
}

/* ================= Team, the pop-up over the dashboard (public/team.js) ================= */
/* it fills the screen as Settings' pop-up does (settings-page.css); here its controls get a finger's room */
@media (max-width: 820px) {
  .tm-dialog :is(.btn, select, input[type="text"], input[type="email"], .sp-nav a, .sp-x) { min-height: 44px; }
  .tm-dialog .sp-x { width: 44px; }
  .tm-dialog :is(input[type="text"], input[type="email"]) { font-size: 16px; }
  .tm-dialog .tm-pick { min-height: 44px; }
  .tm-dialog .tm-ctl { flex: 1 1 100%; }
  .tm-dialog .tm-link { flex-wrap: wrap; }
  .tm-dialog .tm-link input { flex: 1 1 100%; }
  .tm-dialog .sp-scroll { padding-bottom: env(safe-area-inset-bottom); }
}

/* the home page's footer: links a finger apart */
@media (pointer: coarse) and (max-width: 820px) {
  .home .foot-cols nav { gap: 0; }
  .home .foot-cols a { display: inline-flex; align-items: center; min-height: 40px; }
  .home .foot-h { min-height: 32px; }
}

/* the dashboard's three platforms side by side (two and one left a hole) once there is the width for their names;
   the narrowest phones keep two */
@media (min-width: 360px) and (max-width: 600px) {
}
/* the narrowest phones: Publish goes back to its rocket alone so the toolbar stays one row */
@media (max-width: 359px) {
  #build.ws .wbar-end #publish { gap: 0; padding: 0 11px; font-size: 0; }
}

/* ================= the admin panel's Builds list (public/admin.js) ================= */
/* one column: when it was and how it ended share the first line, and the request has the full width under them */
@media (max-width: 820px) {
  .adm-card-builds { padding: 6px; }
  .adm-build { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 12px 10px; }
  .adm-build-when time { display: flex; align-items: baseline; gap: 8px; }
  .adm-build-main { grid-column: 1 / -1; grid-row: 2; }
  .adm-build-end { grid-column: 2; grid-row: 1; grid-auto-flow: column; align-items: baseline; gap: 8px; }
  .adm-link { min-height: 44px; }
}

/* Connectors on a phone: the sheet's title, "Add custom" and its close button come first, then the search and the
   categories, then the list (they were under the search and the categories, halfway down the sheet). The main panel's
   parts join the sheet's own grid so they can be ordered */
@media (max-width: 820px) {
  body.dash .conn { grid-template-rows: auto auto minmax(0, 1fr); }
  body.dash .conn-main { display: contents; }
  body.dash .conn-top { grid-row: 1; grid-column: 1; }
  body.dash .conn-side { grid-row: 2; grid-column: 1; padding-top: 0; }
  body.dash :is(.conn-scroll, .conn-detail) { grid-row: 3; grid-column: 1; margin: 0 8px 8px; border-radius: 10px; background: var(--conn-panel); }
}

/* Startups and Artifacts on a phone (public/startups.css): two artifacts a row, the viewer edge to edge, 44px taps */
@media (max-width: 820px) {
  .dash .st-title { font-size: 22px; }
  .dash .st-search { flex-basis: 100%; max-width: none; }
  .dash .art-filters .art-sel, .dash .art-filters .art-sel select { width: 100%; }
  .dash .art-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dash .art-foot { padding: 8px 10px 10px; }
  .dash .art-kinds { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  .dash .art-kind { flex: none; min-height: 44px; }
  .dash .art-view { width: 100%; max-width: 100%; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .dash .art-v { max-height: 100dvh; height: 100%; }
  .dash .art-v-head .icon-btn, .dash .st-k-del, .dash .st-rows .card-more { min-width: 44px; min-height: 44px; }
  .dash .st-send { width: 44px; height: 44px; }
  .dash .view-projects { padding-top: 8px; }
  .dash .st-head-row :is(h1, .view-h) { font-size: 24px; }
  .dash .st-tool, .dash .st-card-more { width: 44px; height: 44px; }
  .dash .st-card-hit { min-height: 64px; padding-right: 60px; }
  .dash .st-card > .st-card-more { right: 6px; }
}
