/* Host app layout per screen size (breakpoints as ui/responsive.css: phone ≤640px, tablet
   641–1024px, laptop ≥1025px). Loaded after theme.css and responsive.css; theme.css's
   "body.tv #tv-layout" rules use !important, so ours carry one more class (body.tv.host) to win.
   - laptop: the 3-column workstation exactly as theme.css draws it (side-panel width settings),
     with a slim header above it;
   - tablet: 2 columns — stage, now playing + transport, display controls | QR, queue, navigation —
     and the DJ Co-Pilot as a slide-over drawer (#copilot view);
   - phone: one column split into the bottom tabs (stage / queue / Co-Pilot), finger-sized controls.
   The columns become "display: contents" on tablet and phone so the cards themselves are placed. */
#host-app { height: 100%; }
@supports (height: 1dvh) { #host-app { height: 100dvh; } }

/* ── Views (host/router.js sets body[data-view]) ───────────────────────────── */
body.host[data-view="library"] #view-stage { display: none; }
body.host[data-view="library"] #view-library { display: block; }
/* Long lists read better on the plain darker stage of the other pages than under the TV spotlight */
body.tv.host[data-view="library"]::after {
  background: linear-gradient(180deg, rgba(11, 7, 5, .62) 0%, rgba(11, 7, 5, .84) 55%, rgba(11, 7, 5, .96) 100%);
}
body.host #mini-bar { display: none; }
body.host[data-view="library"] #mini-bar { display: flex; }
.host-nav { color: rgb(168 162 158); transition: background .15s, color .15s; }
.host-nav:hover { color: rgb(231 229 228); }
.host-nav.is-active { background: rgb(251 191 36); color: rgb(12 10 9); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }

/* Settings popup on a phone: a long option name must not push its row past the screen edge */
body.host .popup [data-key] > div { max-width: 100%; }
body.host .popup [data-key] select { max-width: 100%; }

/* Controller mode (host/mode.js): microphones and the singing game belong to the player */
body.host-controller #hw-controls { display: none !important; }

/* ── Touch screens: every control at least a finger wide ──────────────────── */
@media (pointer: coarse) {
  body.host #transport-bar > button { min-height: var(--tap); min-width: var(--tap); }
  body.host :is(#tv-sidebar, #view-library) li button, body.host #view-library button { min-height: var(--tap); min-width: var(--tap); }
  body.host #tv-sidebar li .drag-handle { display: none; }   /* drag & drop needs a mouse; ⤒ ▲ ▼ remain */
  body.host :is(#host-header button, #game-controls select) { min-height: var(--tap); }
}
/* A narrow queue column: a row's buttons wrap under the singer instead of running off the edge */
@media (max-width: 1024px), (pointer: coarse) {
  body.host #tv-sidebar li > div.min-w-0 > div { flex-wrap: wrap; row-gap: .25rem; }
  body.host #tv-sidebar li > div.min-w-0 > div > span:first-child { flex-basis: 100%; }
  body.host #tv-sidebar li > img { display: none; }   /* the title needs the room more */
}

/* ── Tablet: two columns, Co-Pilot drawer ──────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1024px) {
  body.tv.host #tv-layout {
    grid-template-columns: minmax(0, 1fr) minmax(17rem, min(var(--side-panel-width, 26rem), 42vw)) !important;
    grid-template-rows: auto minmax(0, 1fr) auto auto !important;
    grid-template-areas: "preview qr" "preview queue" "np queue" "display nav" !important;
    height: 100% !important; min-height: 0 !important; overflow: hidden !important;
    gap: .75rem !important; padding: .75rem !important;
  }
  body.host :is(#col-left, #col-center, #col-right):not(.hidden) { display: contents !important; }
  body.host #qr-card { grid-area: qr; }
  body.host #preview-card { grid-area: preview; min-height: 11rem; }
  body.host #now-playing-card { grid-area: np; }
  body.host #display-panel { grid-area: display; }
  body.host #nav-panel { grid-area: nav; }
  body.host #tv-sidebar { grid-area: queue; }
  body.host #agent-drawer {
    position: fixed !important; inset: 0 0 0 auto !important; z-index: 25;
    width: min(var(--agent-panel-width, 27rem), 92vw) !important;
    transform: translateX(105%) !important; transition: transform .25s ease;
    border-radius: 1rem 0 0 1rem !important; background: rgba(14, 9, 6, .97) !important;
    box-shadow: -12px 0 40px rgba(0, 0, 0, .55) !important;
    padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
  }
  body.host[data-view="copilot"] #agent-drawer { transform: none !important; }
  #drawer-shade {
    position: fixed; inset: 0; z-index: 24; background: rgba(0, 0, 0, .55);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.host[data-view="copilot"] #drawer-shade { opacity: 1; pointer-events: auto; }
  /* Landscape tablets are short: a smaller idle card leaves room for the monitor */
  body.host #idle-mic { max-height: 3.5rem; }
}
@media (min-width: 641px) and (max-width: 1024px) and (max-height: 820px) {
  body.host #display-panel > div:first-child, body.host #nav-panel > div:first-child { display: none; }
  body.host #qr-card { padding: .75rem; }
  body.host #qr-card #qr { height: 3.5rem; width: 3.5rem; }
}

/* ── Phone: one column, bottom tabs ───────────────────────────────────────── */
@media (max-width: 640px) {
  #host-app { padding-top: var(--safe-top); }
  body.tv.host #tv-layout {
    grid-template-columns: minmax(0, 1fr) !important; grid-auto-rows: auto; align-content: start;
    height: 100% !important; min-height: 0 !important; overflow-x: hidden !important; overflow-y: auto !important;
    gap: .75rem !important;
    padding: .75rem max(.75rem, var(--safe-right)) 1rem max(.75rem, var(--safe-left)) !important;
  }
  body.host :is(#col-left, #col-center, #col-right):not(.hidden) { display: contents !important; }
  body.host #preview-card { order: 1; flex: none; height: clamp(13rem, 66vw, 22rem); }
  body.host #now-playing-card { order: 2; }
  body.host #display-panel { order: 3; }
  body.host #nav-panel { order: 4; }
  body.host #qr-card { order: 5; }
  body.host #tv-sidebar { order: 6; overflow: visible; }
  body.host #side-lists { overflow: visible; }
  body.host #agent-drawer { order: 7; height: 100%; }
  body.host #tv-layout #idle-mic { max-height: 4rem; }
  body.host #idle h1[data-title] { font-size: 1.75rem; }
  body.host #idle { padding: 1rem; }
  body.host [data-lyrics-box] { padding: 0 .75rem 1rem; gap: .5rem; }
  body.host #display-panel > div.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  body.host #transport-bar .btn-nav-prefix { display: none; }
  body.host :is(#btn-prev, #btn-next) { min-width: 0; }

  /* Each tab shows its own cards */
  body.host[data-view="stage"] :is(#qr-card, #agent-drawer, #tv-sidebar),
  body.host[data-view="queue"] :is(#agent-drawer, #preview-card, #display-panel, #nav-panel, #now-playing-card),
  body.host[data-view="copilot"] :is(#qr-card, #preview-card, #display-panel, #nav-panel, #now-playing-card, #tv-sidebar),
  body.host[data-view="library"] #view-stage { display: none !important; }
  body.tv.host[data-view="copilot"] #tv-layout { grid-template-rows: minmax(0, 1fr) !important; overflow: hidden !important; }
  body.host:is([data-view="queue"], [data-view="copilot"]) #mini-bar { display: flex; }
  body.host #mini-bar { margin: .5rem max(.75rem, var(--safe-left)) 0; }

  #host-tabs {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); flex-shrink: 0; z-index: 20;
    background: rgba(14, 9, 6, .94); border-top: 1px solid rgba(244, 194, 91, .16);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    padding-left: var(--safe-left); padding-right: var(--safe-right); padding-top: .25rem;
  }
  .host-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
    min-height: 3.5rem; font-size: .7rem; font-weight: 700; color: rgb(168 162 158);
  }
  .host-tab.is-active { color: var(--gold); }
  .host-tab-add > span:first-child {
    display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 9999px;
    background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #1c1206;
  }
}
